Sign in to follow this  

MS Tutorial - why all the events ?

This topic is 4713 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

hello, in MS SDK starting with tutorial 2 there is something like: this.OnCreateDevice(device, null); which (in my understanding) starts implicitly: public void OnCreateDevice(object sender, EventArgs e) the same situation is created many times in this tutorial; my qestion is: what is the point in creating events if they have to be manually called? Or maybe I understand something wrong, then please tell me how this OnCreate... is being called in program execution. Thank You in advance. best regards, tnts

Share this post


Link to post
Share on other sites
The method OnCreateDevice(..) does not start implicitly, it is merely a function that is called by InitializeGraphics(). These are not events, they are just methods of the class 'Vertices'.

It would be the same as doing this:


void SetupVertexBuffer(Device d)
{
d.CreateVertexBuffer();
d.FillVertexBufferWithData(somedata);

}
void InitMyGfx()
{
Device device;
device.Init();
if(device)
{
SetupVertexBuffer(device);
}

}

does that make sense?
Now, if you were working with the framework, there probably would be such an event. Because the framework handles recovery of the device from resizing and etc, so it would probably require you to register an event to be called when that device is recovered.

Share this post


Link to post
Share on other sites
Quote:
Original post by tnts
my qestion is: what is the point in creating events if they have to be manually called?
Or maybe I understand something wrong, then please tell me how this OnCreate... is being called in program execution.


When registered, those methods will be automatically called by the events triggering without any manual intervention. However, since that code initializes everything, it's convenient to use the same code when the app is starting up, so an explicit call is made to those methods.

I think this is another example of programmers being too clever and obfuscating their meaning. There are certainly clearer ways to do it.

Share this post


Link to post
Share on other sites
Quote:
When registered, those methods will be automatically called by the events triggering without any manual intervention. However, since that code initializes everything, it's convenient to use the same code when the app is starting up, so an explicit call is made to those methods.


Did you read the tutorial? Those are not registered events.

Share this post


Link to post
Share on other sites
Quote:
Original post by bit64
Did you read the tutorial? Those are not registered events.


That one specific tutorial doesn't, but others do and they all use the same style. A later tutorial has this:


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


In some of the tutorials they register them, in others they don't. Especially in the ones they don't, this style is very poor.

Share this post


Link to post
Share on other sites
that's what i thought. I'm new to .net but I could not find CreateDevice event in Device class.
Another question; Which of typical structures (eg. vertexBuffer) are lost on deviceReset?

Share this post


Link to post
Share on other sites

This topic is 4713 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.

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