migration from directdraw to direct3d

romanhoehne

Newcomer
Joined
Dec 23, 2003
Messages
8
Hi,
I have started writing a turn based game in directdraw with 2 layers (ground like gras, dessert.. and objects like trees or buldings over the ground) and animated sprites (loaded in frames, based on a timer), which I can move over the 2 other layers.
But now... it seems, that the performance is not that good, if I have 50 animated sprites for example.
Are there solutions (may be in c#), how to do this easy with direct3d? Does direct3d improves the performance compared to directdraw?
Thanks,
Roman
 
Well, I had an engine that showed 255 terrain tiles, tons of units and other misc stuff, plus a complicated sidebar and I was getting about 180-220FPS on a 1.8GHz P4. If you're only getting 50 FPS, you're probably not doing any optimization/caching.

I assume you're currently drawing each terrain tile on each frame? If so, try drawing each of them to another surface once when you start your game, and then drawing *that* surface to the backbuffer each frame. On my game, I was able to condense 255 (15x15) draw operations each frame down to one by doing that sort of trick. It's then just a matter of going through your game and figuring out what can be 'flattened' into cache surfaces, and then using those cached surfaces to draw to the backbuffer each frame.

As for performance in D3D vs DD, it's hard to tell. We actually converted our entire DD game to D3D so that we would have alpha blending and dynamic coloring. D3D seems to max out the framerate at the screen's refresh rate, which for me is 60 FPS. So I'm not sure how many FPS I could get in theory, but making an intelligent guess (based on CPU usage and other factors) it seems like D3D can 'draw' individual sprites/tiles faster, but it doesn't seem like we can do as much optimization in D3D as we could in DD. (Or maybe we're just not as good at D3D yet.)

If you definitely won't need alpha blending or dynamic coloring, I would personally advise trying to stick with DD, and just learning to optimize it as much as you can.

Hope that helps.

-Hiro_Antagonist
 
TBFG (turn based fantasy game)

That is the Code for the 1st Layer.
numberOfBitmaps = how many different 32x32 pixel-Bitmaps will be used
Game.mapBase = Array of integer (2dimensional)

How can I improve permormance in this code?
How can I do this in Direct3d?

Thanks alot,
Roman

//Draw surface (gras, whater..)

Code:
using System;
using System.Drawing;
using Microsoft.DirectX;
using Microsoft.DirectX.DirectDraw;
using TBFG;
using TBFG.Global;

namespace TBFG.Drawing
{
	public class MapDrawObject
	{
		public MapDrawObject(Device display, int numberOfBitmaps)
		{
			_theMapSurfaces = new Surface [numberOfBitmaps];
			_description=new SurfaceDescription();
			_description.Clear();
			_description.Width=32;
			_description.Height=32;
			for (int i = 0; i<numberOfBitmaps; i++)
			{
				_theMapSurfaces [i] =  new Surface("Bilder\\Base\\" + i.ToString() +".bmp", _description, display);
			}
		}

		private SurfaceDescription _description;
		public Surface [] _theMapSurfaces;


		
		public void Draw(int xPos, int yPos, Surface _back)
		{
			int i = yPos;
			Rectangle destination = new Rectangle(0,0,32,32);
			for (i = yPos; i<Global.GlobalData.YResSqr +yPos; i++)
			{
				int j = xPos;
				for(j = xPos; j<Global.GlobalData.XResSqr +xPos; j++)
				{
					
					try
					{
						destination.Location=Game.target.PointToScreen(new Point((j-xPos)*GlobalData.SqaureResolution+32,(i-yPos)*GlobalData.SqaureResolution+32));				
						_back.DrawFast(destination.X, destination.Y, DrawingUtils.MapTile(j,i, Game.mapBase), new Rectangle(0,0,32,32), DrawFastFlags.DoNotWait );
					}
					catch	{}
				}
			}
		}
	}
}


//Draw trees, buidungs

Code:
using System;
using System.Drawing;
using Microsoft.DirectX;
using Microsoft.DirectX.DirectDraw;
using TBFG;
using TBFG.Global;
namespace TBFG.Drawing
{
	/// <summary>
	/// Summary description for BuildingDrawObject.
	/// </summary>
	public class BuildingDrawObject
	{
		public BuildingDrawObject(Device display, int numberOfBitmaps)
		{
			_description =new SurfaceDescription();
			_buildingsurfaces = new Surface [numberOfBitmaps + 1];
			_description.Clear();
			ColorKey CC = new ColorKey();
			int aColor = Color.FromArgb(148,101,66).ToArgb();
			CC.ColorSpaceHighValue = aColor;
			CC.ColorSpaceLowValue =  aColor;
			_buildingsurfaces [1] =  new Surface("Bilder\\Advanced\\Dragonhost.bmp", _description, display);
			_buildingsurfaces [1].SetColorKey(Microsoft.DirectX.DirectDraw.ColorKeyFlags.SourceDraw, CC);
			_description.Clear();
			aColor = Color.FromArgb(115,109,181).ToArgb();
			CC.ColorSpaceHighValue = aColor;
			CC.ColorSpaceLowValue =  aColor;
			_buildingsurfaces [2] =  new Surface("Bilder\\Advanced\\Tree1.bmp", _description, display);
			_buildingsurfaces [2].SetColorKey(Microsoft.DirectX.DirectDraw.ColorKeyFlags.SourceDraw, CC);
			_description.Clear();

			aColor = Color.FromArgb(191,123,199).ToArgb();
			CC.ColorSpaceHighValue = aColor;
			CC.ColorSpaceLowValue =  aColor;
			_buildingsurfaces [3] =  new Surface("Bilder\\Advanced\\Rock1.bmp", _description, display);
			_buildingsurfaces [3].SetColorKey(Microsoft.DirectX.DirectDraw.ColorKeyFlags.SourceDraw, CC);
		}

		private SurfaceDescription _description;
		public Surface [] _buildingsurfaces;
	

		public void Draw(int xPos, int yPos, Surface _back)
		{
			int i = yPos;
			Rectangle destination = new Rectangle(0,0,0,0);
			for (i = yPos; i<Global.GlobalData.YResSqr+yPos; i++)
			{
				int j = xPos;
				for(j = xPos; j<Global.GlobalData.XResSqr+xPos; j++)
				{
					destination.Location=Game.target.PointToScreen(new Point((j-xPos)*GlobalData.SqaureResolution+32,(i-yPos)*GlobalData.SqaureResolution+32));
					try
					{
						if(Game.mapAdvanced.GetMapValue(j, i)!=0)
						{
													_back.DrawFast(destination.X, destination.Y, DrawingUtils.MapTile(j,i, Game.mapAdvanced), DrawFastFlags.DoNotWait |DrawFastFlags.SourceColorKey );
							
						}
					}
					catch 	{}
				}
			}
		}
	}
}
 
Last edited:
Back
Top