Archived

This topic is now archived and is closed to further replies.

d000hg

Getting stuff inside

Recommended Posts

How do I get the message handler in windows to know about the classes being used. e.g if I get a WM_KEYDOWN message how do I call Object.MoveRight(); Currently I have some global vars which tell what''s happened since last render loop wrt messages, and acts on tthem. But there must be a better way? I don''t want to use global vars really, but It''ll be like the game class or engine class that needs informing, so there may well only be one of the object available. If I have a singleton, does that make things easier? John 3:16

Share this post


Link to post
Share on other sites
If possible, use DirectInput. Otherwise, the most straightforward way would be to do this:



  
//some .h file

extern bool keys[256];

//some msg handling func

switch(msg)
{
case WM_KEYDOWN:
keys[wParam] = true;
break;
case WM_KEYUP:
keys[wParam] = false;
break;
}

FOR_EACH_OF_YOUR_OBJECTS
Object[i]->Move();



Since keys is global, you can access it from anywhere.

If you''re usign glut - go for the glut input handling calls.

Hope this helps,
Crispy

Share this post


Link to post
Share on other sites
PS - if you want to completely lose globals, I''d say that''s pretty much impossible. You will need somekind of global variable to coordinate stuff in different files. Or am I missing your point here?

Crispy

Share this post


Link to post
Share on other sites