treading a background

The Partridge Family were neither partridges nor a family. Discuss.
Post Reply
somename
Posts: 9
Joined: March 13th, 2013, 6:34 am

treading a background

Post by somename » March 17th, 2013, 4:48 pm

so my program was running slow at about 30-40 fps, depends if it's presented each frame or once per 2 loop runs.
so i thought about doing a thread for the background, since the background took all the fps.
now my problem is that i draw the background but only a portion of it goes to the backbuffer, what it already draw by that time. any help?
my idea was to lock the backbuffer to draw this background and the unlocking it for the main procedur to finish and draw to the backbuffer, but not only it is stacking bad, it is also a bad idea in my opinion :\
S.O.S please, - - - _ _ _ ---

Code: Select all

DWORD WINAPI ThreadFn(LPVOID vpParam)
{ 
		HRESULT result;
	Game* newgame(NULL);//,kServ,mServ);
newgame = (Game*)vpParam;

DrawBMP( newgame->maplemap, -newgame->Mapx, newgame->Mapy,&newgame->gfx ,-1);
result = newgame->gfx.pDevice->Present( NULL,NULL,NULL,NULL );
	assert( !FAILED( result ) );
return 0;
}

Code: Select all

			theGame.gfx.BeginFrame();
			theGame.ComposeFrame();
			hThread  = CreateThread(0, 0, ThreadFn, &theGame, 0, &qThreadID);
			theGame.gfx.EndFrame();
			//theGame.Go();

Musi
Posts: 106
Joined: November 25th, 2012, 1:06 am

Re: treading a background

Post by Musi » March 20th, 2013, 7:48 am

Just to say, i've never used threads but...

Having the background in a separate thread doesn't really make sense. If the main thread has to wait for it to be drawn anyway, it doesn't really speed up anything. And if the main thread doesn't wait it sound like you could get problems like tearing, or the background being drawn over everything ells etc.
Musi

There are 10 types of people that understand binary.
Those that do, and those that don't.

somename
Posts: 9
Joined: March 13th, 2013, 6:34 am

Re: treading a background

Post by somename » March 20th, 2013, 2:48 pm

well that's exacly what you have said except for the speeding part...
but i am stuck on 40fps and i don't no how to speed up my game :\

User avatar
viruskiller
Posts: 399
Joined: June 14th, 2012, 5:07 pm

Re: treading a background

Post by viruskiller » March 21st, 2013, 5:18 pm

to have background in a separate thread u'd need 2 separate buffers , one that the background thread will work on and one that the main thread will work on.
should be main thread's job to draw it's buffer to the back buffer,and also swap between buffers once the background thread has finished a full frame.
it depends on what kind of background u have, but if is a static one u could just make a copy of the buffer and copy that over the buffer u have to draw the background on each frame.
if is a scrooling background try to implement some kind of tile format instead a big giant background map from which u pick a region to draw each frame, memory copying works faster if is done in small or big chunks if the read/write is done at once, drawing a portion of a big surface means u have to jump trough the memory for each line of that image,while making the images smaller u only jump trough memory for each new tile, so in a way if the number of tiles is less than the number of rows u already have an advantage.

i wrote all this without any knoweldge of how ram actually works so don't take it all for granted, but reading this pages might give u some hints on how to work with large amounts of data and how to properly manage it:)
http://en.wikipedia.org/wiki/Locality_of_reference
http://en.wikipedia.org/wiki/Thrashing_ ... r_science)

somename
Posts: 9
Joined: March 13th, 2013, 6:34 am

Re: treading a background

Post by somename » March 24th, 2013, 6:49 pm

well my game cannot use tiles, but ill try the idea of copying a portion to the buffer, or a virtual buffer actually...

Post Reply