# Tips on efficiency?

## Recommended Posts

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 www.angrymel.com. 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 on other sites
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).

## Create an account

Register a new account

• ### Forum Statistics

• Total Topics
628329
• Total Posts
2982105

• 22
• 9
• 9
• 13
• 11