MS Tutorial - why all the events ?

Started by
6 comments, last by tnts 19 years, 3 months ago
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
Advertisement
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.
Don't be afraid to be yourself. Nobody else ever will be.
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.
Stay Casual,KenDrunken Hyena
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.
Don't be afraid to be yourself. Nobody else ever will be.
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.
Stay Casual,KenDrunken Hyena
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?
any resource that resides on the device, including VBs and textures
Don't be afraid to be yourself. Nobody else ever will be.
thanks :) now I've got a whole picture.

This topic is closed to new replies.

Advertisement