Archived

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

carbon14

direct draw question

Recommended Posts

carbon14    122
hi i am stuck on something stupid: what does: if(i) { Sleep(1); i--; } else break; in the following code do, for the while((ddrval=surf->BltFast(105,25,g_lpddsFlash,NULL, DDBLTFAST_WAIT ))!=DD_OK) if(i) { Sleep(1); i--; } else break; here is the code: thanks void Flash(LPDIRECTDRAWSURFACE7 surf,bool white) { // static DDBLTFX fxblank; // if(!syncsize) // return; HRESULT ddrval; // fxblank.dwSize=sizeof(fxblank); // fxblank.dwFillColor=(white?0x00FFFFFF:0x0); // SetSyncRect(syncsize); if(usedebug) debuglog<<"Flash "; if(surf) { // while((ddrval=surf->Blt(&SyncRect,NULL,NULL, // DDBLT_COLORFILL |DDBLT_ASYNC |DDBLT_DONOTWAIT // ,&fxblank))!=DD_OK) // Sleep(1); int i=5; if(white&&g_lpddsFlash) while((ddrval=surf->BltFast(105,25,g_lpddsFlash,NULL, DDBLTFAST_WAIT ))!=DD_OK) if(i) { Sleep(1); i--; } else break; else if(g_lpddsFlashBlack) while((ddrval=surf->BltFast(105,25,g_lpddsFlashBlack,NULL, DDBLTFAST_WAIT ))!=DD_OK) if(i) { Sleep(1); i--; } else break; } }

Share this post


Link to post
Share on other sites
Peon    276
Before the loop, i = 5 and while i (is true; > 1), it goes through the loop and Sleeps() for one...millisecond? When i reaches 0, the loop breaks, because 0 is considered 'false'. It's basically a way of slowing the blit down, I think. The thing with 'i' seems a bit weird though; wouldn't a for loop be better?

EDIT: Looking at it while I waited for my original message to post, it looks like it only pauses if there is an error with the blit? Not sure why you would want to do this...? (whoever's code it is)

ie:


for (int i = 0; i < 5; i++)
{
Sleep(1)
}


Maybe I'm missing something...

-Peon

[edited by - Peon on March 5, 2003 2:04:14 AM]

Share this post


Link to post
Share on other sites
Guest Anonymous Poster   
Guest Anonymous Poster
FYI:

On Win 2000 and XP systems the default resolution of Sleep is 10 ms even if you specify 1 ms it will default to 10. You can change this behavior via an API call but I do not remember what the call is.

Share this post


Link to post
Share on other sites
carbon14    122
is it possible that the
if(i)
{
Sleep(1);
i--;
} else break;

can make the flash surface last for 5 refresh rates of the monitor?

thanks

Share this post


Link to post
Share on other sites
Bashar    122
The code is justified, I believe. If the system can''t blit, maybe the surface needs to be reacquired. I don''t agree with the Sleep(1), because timing shouldn''t be the issue as he passes DDBLTFAST_WAIT.

Wow, I haven''t used DX in a while...it''s good to see BltFast again, I love the name, makes the function seem superfast!...lol

Share this post


Link to post
Share on other sites