Advertisement

HELP!!!!!!!!!!

Started by December 02, 2005 11:53 PM
12 comments, last by Surg AKA Kunark 19 years, 2 months ago
It would be interesting to know how you compute acceleration and how the timer is retriggered. If all your computations are based on the WM_TIMER message and you miss one beat, your computations are going to get skewed. You can miss one if the time spent in the OnTimer() routine exceeds the timer delay. By waiting on a blocking Send(), for example.

I think you should review the way you do your game loog and process timer values. Below is what I have in mind:

	//---- Main message loop:	DWORD l_dwTimeBase = timeGetTime();	for (;;)	{		if ( ::PeekMessage( &l_msg, NULL, 0, 0, PM_REMOVE ) )		{			if ( l_msg.message == WM_QUIT )				break;			::TranslateMessage( &l_msg );			::DispatchMessage ( &l_msg );		}		else		{			//---- Update players and execute game simulation			if( timeGetTime() > l_dwTimeBase + 50 )			{				//---- Process all incoming/outgoing messages.				npDPlay_ProcessMessages();				//---- Update the game simulation with latest input				npPlayer_Update( timeGetTime() - l_dwTimeBase );				npGamePlay_Update( timeGetTime() - l_dwTimeBase );				//---- Update the client window				::InvalidateRect( g_hWndMain, NULL, TRUE );				l_dwTimeBase = timeGetTime();			}		}	}


Hope this helps.

-cb
Im sorry guys, I forgot to mention that Im using MFC here, so there is no game message loop. This timer takes care of almost everything. I've fixed the bugs I had and am now working on drawing problems.

Heres my render function or atleast the part that isn't working perhaps you guys have some ideas. It works the way I thin it should before

		//Get the rect area of the entire screen		CRect rect;		GetClientRect (&rect);		//Create a DC for the primary surface		CClientDC dc (this);		// off-screen pixels		CBitmap bmOff;		bmOff.CreateCompatibleBitmap (&dc, rect.Width(), rect.Height());		//create a memory DC compatible with the primary surface		CDC memDC;		memDC.CreateCompatibleDC (&dc);		//make sure to save the old 1x1 Bitmap		CBitmap * pOldOffBM = memDC.SelectObject (&bmOff);		// draw to offscreen DC		//memDC.FillSolidRect (&rect, RGB (215, 215, 0)); //desert to buggie on		/*			No more desert to buggie on, its time to buggie on something			more realisitic. Implementing map rendering here.		*/		// Load bitmap		//create an instance of CBitmap		CBitmap bmMap;		// DC		CDC memBitmapDC;		memBitmapDC.CreateCompatibleDC(&dc);		// load the bitmap resource into the bitmap instance		bmMap.LoadBitmap(IDB_DEFAULTMAP);		// select the bitmap into the DC (remember to save the old one!)		CBitmap * pOldddddddy = memBitmapDC.SelectObject(&bmMap);		//		TRACE("[%f,%f]\n", m_cNewBuggie.GetXPos(), m_cNewBuggie.GetYPos());		// This will do the drawing		int iYOffSet(static_cast<int>(m_cNewBuggie.GetYPos())%32);		int iXOffSet(static_cast<int>(m_cNewBuggie.GetXPos())%32);		for(int iWinYPos(-32), iLogicalY((m_cNewBuggie.GetYPos()-(550/2)+64)/32); iWinYPos<576; iWinYPos += 32, iLogicalY++)			for(int iWinXPos(-32), iLogicalX((m_cNewBuggie.GetXPos()-(1000/2)+64)/32); iWinXPos<1028; iWinXPos += 32, iLogicalX++){				// Our window variables for drawing				// We have twenty tiles				switch(m_gmCurrent.iMapTiles[iLogicalY][iLogicalX]){					case 0:						memDC.BitBlt(iWinXPos, iWinYPos, 32, 32, &memBitmapDC, 0, 0, SRCCOPY);						break;					case 1:						memDC.BitBlt(iWinXPos, iWinYPos, 32, 32, &memBitmapDC, 32, 0, SRCCOPY);						break;					case 2:						memDC.BitBlt(iWinXPos, iWinYPos, 32, 32, &memBitmapDC, 64, 0, SRCCOPY);						break;					case 3:						memDC.BitBlt(iWinXPos, iWinYPos, 32, 32, &memBitmapDC, 96, 0, SRCCOPY);					case 4:						memDC.BitBlt(iWinXPos, iWinYPos, 32, 32, &memBitmapDC, 0, 32, SRCCOPY);						break;					case 5:						memDC.BitBlt(iWinXPos, iWinYPos, 32, 32, &memBitmapDC, 32, 32, SRCCOPY);						break;					case 6:						memDC.BitBlt(iWinXPos, iWinYPos, 32, 32, &memBitmapDC, 64, 32, SRCCOPY);						break;					case 7:						memDC.BitBlt(iWinXPos, iWinYPos, 32, 32, &memBitmapDC, 96, 32, SRCCOPY);						break;					case 8:						memDC.BitBlt(iWinXPos, iWinYPos, 32, 32, &memBitmapDC, 0, 64, SRCCOPY);						break;					case 9:						memDC.BitBlt(iWinXPos, iWinYPos, 32, 32, &memBitmapDC, 32, 64, SRCCOPY);						break;					case 10:						memDC.BitBlt(iWinXPos, iWinYPos, 32, 32, &memBitmapDC, 64, 64, SRCCOPY);						break;					case 11:						memDC.BitBlt(iWinXPos, iWinYPos, 32, 32, &memBitmapDC, 96, 64, SRCCOPY);						break;					case 12:						memDC.BitBlt(iWinXPos, iWinYPos, 32, 32, &memBitmapDC, 0, 96, SRCCOPY);						break;					case 13:						memDC.BitBlt(iWinXPos, iWinYPos, 32, 32, &memBitmapDC, 32, 96, SRCCOPY);						break;					case 14:						memDC.BitBlt(iWinXPos, iWinYPos, 32, 32, &memBitmapDC, 64, 96, SRCCOPY);						break;					case 15:						memDC.BitBlt(iWinXPos, iWinYPos, 32, 32, &memBitmapDC, 96, 96, SRCCOPY);						break;					case 16:						memDC.BitBlt(iWinXPos, iWinYPos, 32, 32, &memBitmapDC, 0, 129, SRCCOPY);						break;					case 17:						memDC.BitBlt(iWinXPos, iWinYPos, 32, 32, &memBitmapDC, 32, 129, SRCCOPY);						break;					case 18:						memDC.BitBlt(iWinXPos, iWinYPos, 32, 32, &memBitmapDC, 64, 129, SRCCOPY);						break;					case 19:						memDC.BitBlt(iWinXPos, iWinYPos, 32, 32, &memBitmapDC, 96, 129, SRCCOPY);						break;					default:						memDC.BitBlt(iWinXPos, iWinYPos, 32, 32, &memBitmapDC, 96, 129, SRCCOPY);						break;				}			}		memBitmapDC.SelectObject(pOldddddddy);		m_cNewBuggie.Render (&memDC);				for(int i(0); i < 4; i++)			if(m_cbBuggies)				m_cbBuggies->Render(&memDC);		// flip to primary		dc.BitBlt (0, 0, rect.Width(), rect.Height(), &memDC, 0, 0, SRCCOPY);		// restore all surfaces/objects		memDC.SelectObject (pOldOffBM);


Thats just all the code, though you only need to pay attention to the for loop with the offset. Im trying to draw a grid of map tiles. But I want it to look smooth as the buggy moves per pixel. Anyways again thanks for any of the help that you can offer.

Okay I fixed some of the code, it now looks like this, runs better but still doesn't run correctly. As well Im having some more troubles, these toubles are with collission detection. If you have any suggestions feel free.

[Edited by - Surg AKA Kunark on December 6, 2005 8:57:44 PM]
~~Johnathan~~LTM my new fad, know it, use it, love it, LAUGHING TO MYSELF
Advertisement
You will need to bypass the MFC message pump. MFC was not designed for real-time 3D games. Here is an article that shows you how:

http://www.gamedev.net/reference/articles/article2204.asp ( clicky ).

-cb
Haha yea the game isn't 3D :( Im not that advanced yet. Its just 2D. Ive gotten alittle further and so far nothing is wrong with the timer, if I miss a beat its okay because nothing happens unless its in the timer. So all it does is just doesn't process anything during that round. This doesn't really affect gameplay what so ever so yea. Anyways thanks for the help so far, the socket connections always did work in the end so yea now its just getting the map to scroll right and understand collision detection better.

Yay so thanks to the help of a friend, he was able to tell me what I was doing wrong with my scrolling. Determining the offset alittle off. Thanks for the help guys now all I have left is to optimize my collision detection.

[Edited by - Surg AKA Kunark on December 9, 2005 3:03:20 AM]
~~Johnathan~~LTM my new fad, know it, use it, love it, LAUGHING TO MYSELF

This topic is closed to new replies.

Advertisement