• Advertisement
Sign in to follow this  

Tiling performance in c++

This topic is 3987 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I started working on a tile engine the other day all done in c++ and within a dll everything was coming along smoothly, but I noticed some performance issues. I have an older version of the program that does 5 layers of tiles, gui and animations and still maintains 50-60fps, but the new engine is very similar but gets about 30-40fps with 1 layer, no gui/animations. The only thing I can think of that I did change was old engine used arrays, and new engine is using vectors to store the map data. Would this impact performance that much by just switching the two, or is it just my code or something else. Here is my draw loop.
void Draw()
{
        DrawCount = 0;
        std::vector<tileInfo>::iterator it;
	if(Map.size() > 0)
	{
	        renderSprite->Begin(D3DXSPRITE_ALPHABLEND | D3DXSPRITE_SORT_DEPTH_BACKTOFRONT | D3DXSPRITE_SORT_TEXTURE);
		for(int x = 0; x < 5; x++)
		{
			for(it = Map.begin(); it != Map.end();it++)
			{
				if(it->dirty)
				{
					renderSprite->Draw(Texture,&it->rect,new D3DXVECTOR3(0,0,0), new D3DXVECTOR3(it->X, it->Y, 0), it->color);						DrawCount++;
					it->dirty = false;
				}
			}
		}

		renderSprite->Flush();
		renderSprite->End();
	}
};

Thanks for your time, Slyprid

Share this post


Link to post
Share on other sites
Advertisement
On first draw its entire map, so 768 draws. (32x24). Once thats done it sets tiles to dirty = false and only draws if those tiles are dirty (moved, changed, something moves over them). So my drawcount at that point is literally 0.

Share this post


Link to post
Share on other sites
Sorry, I meant the difference in draw calls with your older version that gets 50-60fps

Share this post


Link to post
Share on other sites
Doing this in your render loop ????

new D3DXVECTOR3(0,0,0), new D3DXVECTOR3(it->X, it->Y, 0)

Is that needed ???

I assume the get destroyed somewhere. (cant see whats going on inside Draw()...)

(A Free Pool could eliminate the overhead and you could allocate only once at the start......)

Share this post


Link to post
Share on other sites
Wow didn't even think about those declares in the draw method. By defining them at start of method it increased it to 75fps with 5 layers. Even with drawing every tile on the screen (3840 tiles) I still get 45fps. Thanks for the help. Will post some more later to see if there is anything else that can be tightened up to make it faster.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement