problem with simple d3d9 app

Started by
13 comments, last by pai 20 years, 2 months ago
sorry.. for that post

[edited by - pai on February 6, 2004 6:51:14 PM]
Advertisement
for that one too.. pressed wrong button

[edited by - pai on February 6, 2004 6:51:34 PM]
PeekMessage will return immediately, whether there was a message or not. If there was, then it returns true, and the message structure is filled in (and removed if you specify PM_REMOVE). If there was no message, then it returns false, and it doesn''t matter what''s in the message structure.

GetMessage does not always return immediately. If there is at least one message, it fills in the message structure and returns. If there are no messages at the moment, it will just wait from within GetMessage until a message occurs, and then fill in the message structure and return.

For game development, PeekMessage is usually what is wanted, because we usually need to do stuff every frame, whether there is a message or not, such as rendering, physics, etc.

A suggestion, now that I think about it... Put a Sleep(0) right at the end of (but inside) your main while loop. That''ll tell Windows that other programs can do other stuff if they need to, but that you want control back again as soon as possible.

As for asking what threads are, they allow multiple streams of execution to occur at once. Just as you have multiple programs running on your computer at once, with Windows determining when each one can get control of the processor, you can also get multiple threads to run inside your program alone, and Windows (or any other OS) will manage how much CPU time is allotted to each. For example, you could have a rendering thread, that just loops around and around rendering, while another thread runs and handles input and the physics engine. In effect they''ll be running at the same time. But you needn''t worry about that right now.
"We should have a great fewer disputes in the world if words were taken for what they are, the signs of our ideas only, and not for things themselves." - John Locke
quote:Original post by Agony
A suggestion, now that I think about it... Put a Sleep(0) right at the end of (but inside) your main while loop. That''ll tell Windows that other programs can do other stuff if they need to, but that you want control back again as soon as possible.

As far as I recall, the default minimum timer resolution is 10 ms. That means a Sleep(0) will sleep for at least 10 ms. So if you want to use Sleep, make sure you call timeBeginPeriod(1) to set the resolution to 1ms.


Muhammad Haggag

Timer resolution shouldn''t affect how Sleep() works. And I tested it, just to make sure. Indeed, Sleep(0) on average seemed to sleep for 0.002 milliseconds (I didn''t have any other major programs running), while Sleep(10) slept for just about exactly 10 milliseconds. This was with timeBeginPeriod(10) called before anything else. Here''s the test code (which needs to be linked with winmm.lib for timeBeginPeriod to work):

#include <windows.h>#include <cstdio>int main(){  LARGE_INTEGER Frequency;  LARGE_INTEGER StartTime;  LARGE_INTEGER CurrentTime;  int i;  timeBeginPeriod(10);  QueryPerformanceFrequency(&Frequency);  for (i = 0; i < 8; ++i)  {    QueryPerformanceCounter(&StartTime);    Sleep(0);    QueryPerformanceCounter(&CurrentTime);    printf("%14.12f\n", (double)(CurrentTime.QuadPart - StartTime.QuadPart) / (double)(Frequency.QuadPart) * 1000.0);  }  for (i = 0; i < 8; ++i)  {    QueryPerformanceCounter(&StartTime);    Sleep(10);    QueryPerformanceCounter(&CurrentTime);    printf("%14.12f\n", (double)(CurrentTime.QuadPart - StartTime.QuadPart) / (double)(Frequency.QuadPart) * 1000.0);  }  return 0;}

"We should have a great fewer disputes in the world if words were taken for what they are, the signs of our ideas only, and not for things themselves." - John Locke

This topic is closed to new replies.

Advertisement