Jump to content
  • Advertisement

Archived

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

djsteffey

removing the message pump

This topic is 6470 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I remember reading an article on this site about a month ago about removing the message pump from windows programming and just doing the programming like we did back in the DOS days. for example if i want to wait at a certain screen and wait for the user to type in their name or something, I would need some kind of gameState variable that told me in my mainGameFunction to go and run the function that draws that specific image to the screen and accept user input, etc..... I want to just be able to do a loop in that one function that loops until they press enter or something. But I have heard that it is bad to keep windows programs in loops like this. Why is it bad ? Can i just not run the message pump and be OK ? Or can I just start a different thread for the game like the article stated ? "Now go away or I shall taunt you a second time" - Monty Python and the Holy Grail

Share this post


Link to post
Share on other sites
Advertisement
One thing you can do is have a function called "ProcessMessages" which returns false if the user pressed alt-F4 or whatnot. Then you can have functions which take up multiple frames, so long as you have the line "if(!ProcessMessages()) return false;" or something to that effect. That could work nicely, and won''t require multithreaded programming.

Share this post


Link to post
Share on other sites
quote:

I want to just be able to do a loop in that one function that loops until they press enter or something. But I have heard that it is bad to keep windows programs in loops like this. Why is it bad ? Can i just not run the message pump and be OK ? Or can I just start a different thread for the game like the article stated ?



Put simply, yes you can do it but no, you shouldn''t. Cutting off the message loop cuts off everything until you get it back. The exception is Alt-F4, I think. Anyways, it''s bad to do that: pretend you''re making a game like Chrono Trigger for the SNES. In that game, you could often walk around while a textbox is up. This means that it''s in a loop for the textbox (waiting to be closed) but also it''s able to receive user input. If you cut off the Windows message loop, you can''t get input without using DirectInput or GetAsyncKeyState (). I know it''s a bad hypothetical situation but you get the idea.

Anyway, it means you could miss more important messages, such as the keypress for quitting or the click on the close box. If the message loop is suspended, those probably won''t work.

Either use states or threads. Be warned though that threads have their own drawbacks.


-Goku
SANE Productions Homepage

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
I don''t know what your all on about. In all of my program''s i cut off the message loop cause im used to programming dos applications. The programs work fine. I have an RTS game up and running, which features music, sound effects, mouse input, keyboard and the program doesn''t miss any keystrokes or clicks.

All ive done is have my whole program in the initialisation of the window. The program doesn''t even touch the windows pump.

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
I don''t know what your all on about. In all of my program''s i cut off the message loop cause im used to programming dos applications. The programs work fine. I have an RTS game up and running, which features music, sound effects, mouse input, keyboard and the program doesn''t miss any keystrokes or clicks.

All ive done is have my whole program in the initialisation of the window. The program doesn''t even touch the message pump.

So if you don''t want to use the message pump then simply dont.

Share this post


Link to post
Share on other sites
im not using any windows dialogs in my game and dont plan too. I am already using DirectInput anyway.....so why should I not cut off the message pump. There arent going to be any windows messages sent to my window anyway......
and one else have an opinion ?


"Now go away or I shall taunt you a second time"
- Monty Python and the Holy Grail

Share this post


Link to post
Share on other sites
If you read the article a bit deeper you would have seen that what they suggested was to create a second thread. In this second thread you can create your game loop or whatever just like the old days. The main thread is still running a message pump just like any normal Windows application.

You need the message pump to handle such things as task switching, shutdown, power-saving and a broad range of other possibilities. Don''t cause yourself a whole load of heartache by trying to remove it entirely.

To the anonymous poster who claims to have no message loop at all. How friendly does your application interact with other applications on the system? If someone task-switches to another application, does yours go to sleep and recover when it becomes again?

Steve ''Sly'' Williams  Code Monkey  Krome Studios

Share this post


Link to post
Share on other sites
quote:
Original post by Anonymous Poster

I don't know what your all on about. In all of my program's i cut off the message loop cause im used to programming dos applications. The programs work fine. I have an RTS game up and running, which features music, sound effects, mouse input, keyboard and the program doesn't miss any keystrokes or clicks.

All ive done is have my whole program in the initialisation of the window. The program doesn't even touch the message pump.

So if you don't want to use the message pump then simply dont.



Actually, I don't think you know what you're talking about. You can't create a program and have it working perfectly and not have a message pump to handle the messages. If you switch the task, your program will crash or cause some illegal operation errors. Unless you use MFC which actually take care of the PUMP for you but then you still have one, it's just hidden in a class member function. Now, unless you know what you're talking about, don't post.

Oh and:

Have a nice day...


Cyberdrek
Headhunter Soft
DLC Multimedia

Edited by - Cyberdrek on February 18, 2001 12:25:49 AM

Share this post


Link to post
Share on other sites
That''s true. The first thread in any Win32 process is given a message pump (yes even a console mode program has one).

Any secondary threads you create do NOT start off with a message pump until you make a UI API call (example PeekMessage()). As soon as you use one of those functions, Windows will automatically attach a message pump for you.

There is no reason for you to cut the Windows message pump out of the loop. You can still achieve DOS style programming by not returning from some game function.

Don''t over complicate a simple problem.

Dire Wolf
direwolf@digitalfiends.com

Share this post


Link to post
Share on other sites
well if i just dont return from a game function, then i wont get back to the part of my program that process messages.
In winmain i have
  
while (true)
{
if (PeekMessage(&msg, NULL, 0, 0, PM_NOREMOVE))
{
// Handle messages

if (!GetMessage(&msg, NULL, 0, 0))
{
return msg.wParam;
}
TranslateMessage(&msg);
DispatchMessage(&msg);
}
else
{
// No messages? then run program loop

if (appActive)
{
// Call critical in game.cpp

mainEngineCritical();
}
else
{
// Pause if application is not active

WaitMessage();
}
}

that is how i process the messages
so if i never return out of a game function then i never get back to this point and wont process anymore messages


"Now go away or I shall taunt you a second time"
- Monty Python and the Holy Grail

Share this post


Link to post
Share on other sites

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!