Click here to Skip to main content
15,927,127 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
GeneralRe: Handling input and graphics in a game engine Pin
Cyrilix18-Jun-07 8:29
Cyrilix18-Jun-07 8:29 
GeneralRe: Handling input and graphics in a game engine [modified] Pin
Force Code18-Jun-07 8:51
Force Code18-Jun-07 8:51 
GeneralRe: Handling input and graphics in a game engine Pin
Cyrilix18-Jun-07 9:01
Cyrilix18-Jun-07 9:01 
GeneralRe: Handling input and graphics in a game engine Pin
Force Code18-Jun-07 9:15
Force Code18-Jun-07 9:15 
GeneralRe: Handling input and graphics in a game engine Pin
Cyrilix18-Jun-07 9:26
Cyrilix18-Jun-07 9:26 
GeneralRe: Handling input and graphics in a game engine Pin
Force Code18-Jun-07 9:51
Force Code18-Jun-07 9:51 
GeneralRe: Handling input and graphics in a game engine [modified] Pin
Cyrilix18-Jun-07 10:01
Cyrilix18-Jun-07 10:01 
GeneralRe: Handling input and graphics in a game engine Pin
Force Code18-Jun-07 10:33
Force Code18-Jun-07 10:33 
The code sample you provided is in a loop with a PeekMessage. If any messages for the application are pending it processes those before going back to frame updates.

Here was your proposed design:

Cyrilix wrote:
I was thinking of using a key array (of bools) and catching WM_KEYDOWN / WM_KEYUP to change the states of the keys from the input thread, then sending the states to the graphics thread. The input thread would have the WndProc function, whereas the graphics thread would simply check the local key array (in a while loop) to determine what happens.

Basically, it would look sort of like this:

WndProc (which runs in the input thread) catches WM_KEYDOWN where the key is VK_ESCAPE. The input thread sets key[VK_ESCAPE] = true. The graphics thread has a while loop that checks for VK_ESCAPE, and if true, it will return the thread (quit), if it sees another command such as the movement keys, then it will draw the next frame.


You weren't relinquishing control in anyway to process application messages. However, I'm not entirely clear on your design, because your last statement seems to say that movement in the game is only triggered by user input, whereas I thought there would be game animation regardless of user input.

But as to whether the code sample you provided is bad design, I will say I've never had much use for PeekMessage. In the code sample, you could just take the PeekMessage portion out, and put the remaining code in its own thread, where the OS itself would interrupt it as necessary. The GetMessage loop in the main thread would continue to handle application messages. Maybe you can tell me if I'm missing something



l
GeneralRe: Handling input and graphics in a game engine Pin
Cyrilix18-Jun-07 10:43
Cyrilix18-Jun-07 10:43 
GeneralRe: Handling input and graphics in a game engine Pin
Force Code18-Jun-07 10:48
Force Code18-Jun-07 10:48 
GeneralRe: Handling input and graphics in a game engine Pin
Cyrilix18-Jun-07 11:18
Cyrilix18-Jun-07 11:18 
GeneralRe: Handling input and graphics in a game engine Pin
Force Code18-Jun-07 12:10
Force Code18-Jun-07 12:10 
GeneralRe: Handling input and graphics in a game engine Pin
Cyrilix18-Jun-07 12:29
Cyrilix18-Jun-07 12:29 
GeneralRe: Handling input and graphics in a game engine Pin
Matthew Faithfull18-Jun-07 10:55
Matthew Faithfull18-Jun-07 10:55 
GeneralRe: Handling input and graphics in a game engine Pin
Cyrilix18-Jun-07 11:09
Cyrilix18-Jun-07 11:09 
GeneralRe: Handling input and graphics in a game engine Pin
Matthew Faithfull18-Jun-07 13:03
Matthew Faithfull18-Jun-07 13:03 
QuestionMultiple bitmap in VMR9 Pin
houari_id18-Jun-07 7:30
houari_id18-Jun-07 7:30 
AnswerRe: Multiple bitmap in VMR9 Pin
Mark Salsbery18-Jun-07 7:45
Mark Salsbery18-Jun-07 7:45 
GeneralRe: Multiple bitmap in VMR9 Pin
houari_id18-Jun-07 8:00
houari_id18-Jun-07 8:00 
GeneralRe: Multiple bitmap in VMR9 Pin
Mark Salsbery18-Jun-07 8:47
Mark Salsbery18-Jun-07 8:47 
QuestionC++ Program with date and class Pin
berni2k18-Jun-07 6:41
berni2k18-Jun-07 6:41 
AnswerRe: C++ Program with date and class Pin
led mike18-Jun-07 7:10
led mike18-Jun-07 7:10 
GeneralRe: C++ Program with date and class Pin
berni2k18-Jun-07 8:36
berni2k18-Jun-07 8:36 
Questionstack overflow Pin
Lord_Vader18-Jun-07 6:26
Lord_Vader18-Jun-07 6:26 
AnswerRe: stack overflow Pin
led mike18-Jun-07 6:39
led mike18-Jun-07 6:39 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.