Skip to main content
gamedev.net
🔒 Locked

Redraw problems.

Started by Ryanrk 5 replies 550+ views
Original Post
Ryanrk
Ryanrk
I create a thread yesterday saying i had timing issues for my tetris game and after looking at it longer, i realize it wasn't the timer that was not working right it was that the render only redraws if i'm doing sometihng in the window, (ie, move the mouse over the window, or hit a key or something.) I'm not sure how to tell it to redraw each time. I tried creating a thread and putting the render in a new thread and that worked ok but my keyboard responces were very slow.
    
void Render(HWND hWnd)
{
     
     if( dx8._pd3dDevice == NULL)
	     return;

     dx8._pd3dDevice->Clear( 0, NULL, D3DCLEAR_TARGET, 
		      D3DCOLOR_XRGB(0,0,0), 1.0f, 0 );

     dx8._pd3dDevice->BeginScene();

     BltSpriteEx( NULL, texture, NULL, NULL );

     DWORD timer;
			
     int up[4] = {0,0,0,0};
		
     timer = GetTickCount();
     blocks.movedown();
	
     while(GetTickCount() - timer < 800){

        m_keyboard->GetDeviceState(sizeof(unsigned char[256]), (LPVOID)keystate);
	if (KeyDown(keystate, DIK_LEFT)){
		up[0] = 1;
				
	} else if (KeyDown(keystate, DIK_RIGHT)){
		up[1] = 1;

	} else if (KeyDown(keystate, DIK_DOWN)){
		up[2] = 1;

	} else if (KeyDown(keystate, DIK_UP)){
		up[3] = 1;
			}
	if(KeyUp(keystate, DIK_LEFT) && (up[0] == 1)){
		blocks.moveleft();
		up[0] = 0;
	} else if(KeyUp(keystate, DIK_RIGHT) && (up[1] == 1)){
		blocks.moveright();
		up[1] = 0;
	} else if(KeyUp(keystate, DIK_DOWN) && (up[2] == 1)){
		blocks.movedown();
		up[2] = 0;
	} else if(KeyUp(keystate, DIK_UP) && (up[3] == 1)){
		blocks.rotate();
		up[3] = 0;
	}
    }	
    blocks.showpiece();  //draws the board on the screen

		// End the scene


     dx8._pd3dDevice->EndScene();
     // Present the backbuffer contents to the display

     dx8._pd3dDevice->Present( NULL, NULL, NULL, NULL );


}    
[edited by - Ryanrk on July 30, 2002 4:11:22 PM]
Kylotan
Kylotan
So what exactly are you asking for here? That code above will loop for 800 ticks gathering input, draw the screen, and return. Looks to me like you have some reorganising to do as a ''render'' function should do just that - render the screen, not pause, collect input, or whatever.

[ MSVC Fixes | STL | SDL | Game AI | Sockets | C++ Faq Lite | Boost | Asking Questions | Organising code files ]
Ryanrk
Ryanrk
Well that''s kind of my problem. The render only seems to render the screen when it gets some kind of message, for instance like the mouse moves over the window or a keystroke it hit until then it just sit and not move, and then when i do move the mouse things start to happen. Make sense? I know if i was doing this in window graphics api, all i would need to call is Invalidate(FALSE) to get the screen to redraw again. I''m not sure how to do that in this case? Just call the render function again?
DBX
DBX
Sounds like maybe your message loop. Are you using PeekMessage instead of WaitMessage ?
dabx11
dabx11
Sounds like you have your message loop setup wrong...


  

do
{
if (PeekMessage(&msg, NULL, 0, 0, PM_REMOVE))
{
if (msg.message == WM_QUIT) break;
TranslateMessage(&msg);
DispatchMessage(&msg);
}
else {

Render(hWnd);
}
}
while (TRUE)

[\source]
Ryanrk
Ryanrk
mine is this
I'll try yours.


    
if( SUCCEEDED( InitD3D( hWnd ) ) )
{
D3DXCreateSprite( dx8._pd3dDevice, &dx8._pd3dxSprite);
texture = LoadTexture("single.bmp");
// Show the window

ShowWindow( hWnd, SW_SHOWDEFAULT );
UpdateWindow( hWnd );

MSG msg;
while( GetMessage( &msg, NULL, 0, 0 ) ){
TranslateMessage( &msg );
DispatchMessage( &msg );
}
}


[edited by - Ryanrk on July 30, 2002 7:43:21 PM]
Zipster
Zipster
Well, GetMessage won''t return if there''s nothing in the queue. That''s probably why your program doesn''t do anything when there''s no messages to process, because GetMessage sits and waits

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.