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

block & thread

Started by citronrock Apr 11, 2006 at 8:51 AM 2 replies 650+ views
Original Post
citronrock
citronrock
hello everybody, i am making a game and i've got a problem . mainly i've got this : main() { display(); // only graphics } and there is game() { // many things ... // and on the end scanf( ..&var); // scanf is waiting for a number } but i don't don't know how to call game() without block graphics , because scanf() block main . so i need to call game() ... thx you
Trahern
Trahern
well, the obvious solution would be to call main() and game() in different threads so they do not block each other..you would just need to do some synchronization job.

However for this simple situation that's probably unnecessary complicated. Usualy you just have to specify some callback function which process input keyboard events and you just react to them.. How to setup this callback function depends on your OS or library used to handle OS events ( ie. GLUT ).
Palidine
Palidine
Are you entering a string at that point or just tyring to get keyboard input? If you're just looking for keypresses(i.e. w,s,a,d etc) look into using the Windows GetAsyncKeyState function. It won't block your main thread waiting for input.

link to that function:
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/winui/winui/windowsuserinterface/userinput/keyboardinput/keyboardinputreference/keyboardinputfunctions/getasynckeystate.asp

-me
citronrock
citronrock
okay,thank you(s) just for information the "scanf()" is only to substitute a server which is work is to give some "int variable" to the game.so it is for me an input by the keyboard , but it won't be in the future, ( but it the same of course ) .

Topic Locked

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

Sign in to reply to this topic.