|
-
Sep 10th, 2002, 08:19 PM
#1
Thread Starter
Frenzied Member
DoEvents() or DoNothing()
okay. in vb6 i know that when you enter a loop that is going to loop for a very long time yo need to use DoEvents once or twice in there, but i have never heard of anything like this in c++. Is it some magic that the compiler does i don't need to concern myself with or is there a proc i need to call every so often?
Magiaus
If I helped give me some points.
-
Sep 10th, 2002, 08:59 PM
#2
Frenzied Member
Its called a message loop =). Your standard loop would look something like this:
Code:
while(GetMessage(...))
{
TranslateMessage();
DispatchMessage();
}
A standard game loop would look like this:
Code:
while(running)
{
if(PeekMessage(...))
{
TranslateMessage();
DispatchMessage();
}
// do frame stuff here
}
VB simply hides all of this away.
Z.
-
Sep 11th, 2002, 03:37 AM
#3
In C++ you don't need DoEvents because the programming guidelines say you never get into a long loop with your main thread. Everything that takes really long (meaning more than 1/10 of a second) should be done in a worker thread. This way, the main thread can continue to serve the message loop. Look into CreateThread (or beginthreadex if you want to use the CRT in the new thread) to learn more about multithreading.
All the buzzt
 CornedBee
"Writing specifications is like writing a novel. Writing code is like writing poetry."
- Anonymous, published by Raymond Chen
Don't PM me with your problems, I scan most of the forums daily. If you do PM me, I will not answer your question.
-
Sep 11th, 2002, 06:34 AM
#4
Thread Starter
Frenzied Member
ok. i am implamenting a make shift msgloop in a class constructor that will raise events for the class. would i use a basic game loop? this is for the joystick api wrapper i am working on.
Magiaus
If I helped give me some points.
-
Sep 11th, 2002, 07:25 AM
#5
I don't think you need a game loop for .NET apps. It's not what .NET was designed for.
All the buzzt
 CornedBee
"Writing specifications is like writing a novel. Writing code is like writing poetry."
- Anonymous, published by Raymond Chen
Don't PM me with your problems, I scan most of the forums daily. If you do PM me, I will not answer your question.
-
Sep 11th, 2002, 01:45 PM
#6
Thread Starter
Frenzied Member
ok
what would yu recomend. I want tis thing to be fast and not eat resources. The design I had in mind was you instance the class AddHandlers for the events and either the msgloop starts in the consructor or have an intialize method. what do you guys think the best way to go is? I suppose I could just wrap the api and leave implementation up to the programmer using it but i wanted it to be easier than the api and hopefully give more control than just the straight api wrap would.
api
joySetCapture
joyReleaseCapture
joyGetPos
joyGetPosEx
joyGetDevCaps
.Net has no way of useing a joystick until directX9 and well everybody doesn't need directX anyway.
ideas..?
Magiaus
If I helped give me some points.
-
Sep 11th, 2002, 01:47 PM
#7
Thread Starter
Frenzied Member
can a class have a message proc? I assume it could but vb makes it chalangeing so i hadn't considerd that. In vb you have to use copy memory to have a callback in a class....
Magiaus
If I helped give me some points.
-
Sep 12th, 2002, 03:30 AM
#8
You shouldn't have a message loop in your classes simply because there already is one: System.Window.Forms.Application.Run is the standard message loop. All apps will probably use this loop.
joyGetPos and joyGetPosEx are pretty easy to wrap. You only need to create subclasses that can be matched to JOYPOS and JOYPOSEX and provide some enumerations.
If you wrap joyGetCapture, you should not only call joyGetCapture but also System.Windows.Forms.Appplication.AddMessageFilter, which allows you to intercept all messages and raise events when you find joystick messages.
In this case your joystick class needs to implement IMessageFilter, which contains one function: PreFilterMessage (stupid and misleading name btw), which is sent every message to handle and which returns true if the message should not be processed any further.
All the buzzt
 CornedBee
"Writing specifications is like writing a novel. Writing code is like writing poetry."
- Anonymous, published by Raymond Chen
Don't PM me with your problems, I scan most of the forums daily. If you do PM me, I will not answer your question.
-
Sep 12th, 2002, 06:47 AM
#9
Thread Starter
Frenzied Member
so
ok that sounds like what i wanted to do anyway. i was just trying to think of ways to do it, i had a feeling a object that did nothing but looped and raised events might be a bad idea though. I look into using the filter interface and AddMessageFilter. I haven't looked yet but does AddMessageFilter need to be called from the app using the class or the class? I assume b the app since it would be what is getting filtered...
another question I hve is what if I want to capture the joystick but my application has no windows? would passing a handle of 0 work or would it cause the problems i think it could by sending the messages to a null refreance. I know you can do the 0 handle for things like memory bitmaps/DC's but I don't know I get the feeling it might not work so well for joySetCapture.
Thanks for all the help btw CornedBee
Magiaus
If I helped give me some points.
-
Sep 12th, 2002, 07:09 AM
#10
Thread Starter
Frenzied Member
ahh i see
yes very nice. So after i implement the IMessageFilter and write my class the program can simply instance my object, add handlers for the events and attach it to its thread as a messagefilter. Very interesting. I whish MSDN had more in depth information I have kinds of question about precedence.
CornedBee what did you look for to find this?
I was just thinking about how MCSD and how I was ready to take the tests and now I have to study for another who knows how many years.....
Magiaus
If I helped give me some points.
-
Sep 12th, 2002, 07:50 AM
#11
I knew that Run is a static method of the Application class, so I guessed that this class would be the best place to find out if there is something like a generic "message" event. I didn't find this, but I found the filter.
You need a window. Just let the user pass any control to you and get the associated HWND.
AddMessageFilter must be called by the thread - it doesn't matter whether the user does it or your class, except that to serve the principle of encapsulation and user friendliness your class should do it.
What's MCSD?
All the buzzt
 CornedBee
"Writing specifications is like writing a novel. Writing code is like writing poetry."
- Anonymous, published by Raymond Chen
Don't PM me with your problems, I scan most of the forums daily. If you do PM me, I will not answer your question.
-
Sep 12th, 2002, 07:52 AM
#12
Thread Starter
Frenzied Member
yes. i don't like that they have to use AddHandler either and was thinking of adding an interface for the whole thing but i think that is beyond my c++ skill at this point
Magiaus
If I helped give me some points.
-
Sep 12th, 2002, 12:47 PM
#13
Look into operator overloading, it is described in the little book that comes with VC++.NET.
Might help you get a better way to add event handlers in C#:
Joystick += MyHandler;
All the buzzt
 CornedBee
"Writing specifications is like writing a novel. Writing code is like writing poetry."
- Anonymous, published by Raymond Chen
Don't PM me with your problems, I scan most of the forums daily. If you do PM me, I will not answer your question.
-
Sep 12th, 2002, 01:37 PM
#14
Thread Starter
Frenzied Member
Magiaus
If I helped give me some points.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|