Archived

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

Ryanrk

Tetris timing issues!

Recommended Posts

I'm trying to get my blocks fall but they only fall when there is messages for the window. For instance if I move the mouse over the top of the window it works great. I believe this is due to the fact that i'm not refresh the window each time in DirectX. In windows there's a function called InvalidateRect (hWnd, NULL, FALSE); that does this. Is there a function in Directx that does this? [edited by - Ryanrk on July 29, 2002 10:19:33 PM]

Share this post


Link to post
Share on other sites
first, waiting 100 miliseconds is nothing. it should prob be more like 800 or something to start. second, your method prob won''t work really well. GetTickCount just gets the current time sinse startup so calling it twice doesn''t really make any sence. First, here''s what your code will look like if simplified and given a default time.

//timer stuff
DWORD timer;

timer=10020502849;
blocks.movedown();
while(10020502849-10020502849 /* 0 */<100)
blocks.showpiece();

for one, it already moves the blocks down every frame. and what does showpiece do? anyways, here''s what should work:

static DWORD timer=GetTickCount();
int tc=GetTickCount();
if(tc-timer>TIME_NEEDED_TO_DROP /* 800 maybe? */)
{
blocks.moveDown();
blocks.showpiece();//what does this do?
timer=tc;
}
else
timer++;


---
My Site
Come join us on IRC in #directxdev @ irc.afternet.org

Share this post


Link to post
Share on other sites
the way d3d explains how to do a message pump is partially wrong because it doesn''t update constantly. here''s how the message pump should look: (Btw, get rid of invalidaterect. you don''t need it)

if(!g_App.Initialize(g_hWnd)) return(0); //initialize the game

MSG msg; //start the message pump
while(true)
{
if(PeekMessage(&msg,NULL,0,0,PM_REMOVE)) //peek for a message
{
if(msg.message==WM_QUIT) break; //quit if the program is exiting

TranslateMessage(&msg); //translate and dispatch the message to the processor
DispatchMessage(&msg);
}

g_App.Process(); //process the game

}

g_App.Shutdown(); //deinitialize the game

---
My Site
Come join us on IRC in #directxdev @ irc.afternet.org

Share this post


Link to post
Share on other sites