Sign in to follow this  

Tips on efficiency?

Recommended Posts

melanieab    122
Hi, I have a Windows form project that runs a DirectX intro. At the end of the intro, I clear the screen and display a bitmap (actually a .png file) which the user can click to get to the tabpage of their choice. I can get this all to run just fine. I run into trouble though if the intro runs, the png comes up, and the user waits a little before deciding to click on something. It seems that, the longer the user waits before clicking, the longer it takes the tabpage to load after something is clicked. (It can get pretty bad so that you wonder if it's ever going to load.) I'm assuming this has to do with my not really doing things efficiently. I've posted my Render() code at Under SetupCamera(), I give whatever specs apply to the first chunk of code (Type, Direction, ...)(PresentParameters were set up in InitialGraphics). Under SetupCamera2(), I have: PresentParameters presentParams = new PresentParameters(); device.Reset(presentParams); if (alpha != 255){ View and Projection } *** Here I'm just trying to have a different png file fade in. When its alpha = 255, I go to the screen with the choices *** else { different View and Projection } *** this is the screen where the user can click *** device.DeviceReset += new EventHandler(this.OnResetDevice); this.OnResetDevice(device, null); Does anyone know what may be causing this extended load time? Or some suggestions on how to be more efficient? (i.e. am I disposing of everything I need to?) Thanks so much! Mel

Share this post

Link to post
Share on other sites
Enselic    829
It appears as if it executes this:

else { different View and Projection }
device.DeviceReset += new EventHandler(this.OnResetDevice);
this.OnResetDevice(device, null);

every frame until the user clicks?

Then the slowness is because you are adding new instances of DeviceReset delegates every frame, which means that this.OnResetDevice might be called hundreds of times in a row.

In any case, it seems like you've mixed the event pattern up a bit. The line

device.DeviceReset += new EventHandler(this.OnResetDevice);

should not be in game loop code, but rather in the constructor or form_FormLoad(), because it generally is a 'do once' thing.

Also, the "correct" name of your OnResetDevice() would be device_DeviceReset(). You would use the name OnResetDevice() only if you were inheriting from the Device (in which case you would override Device.OnResetDevice().

Also, it makes no sense to first add a delegate of this.OnResetDevice() and then call it yourself (that is the job of the device).

As a final note, you can post source in these forums by using the [source][/source] tags. (Refer to the Forum FAQ).

Share this post

Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this