Sorry your browser is not supported!

You are using an outdated browser that does not support modern web technologies, in order to use this site please update to a new browser.

Browsers supported include Chrome, FireFox, Safari, Opera, Internet Explorer 10+ or Microsoft Edge.

Newcomers DBPro Corner / [DBPRo][Tutorial] Using VB6/.NET style events in DBPro.

Author
Message
MoomanFL
19
Years of Service
User Offline
Joined: 12th Nov 2005
Location:
Posted: 21st Feb 2008 18:45 Edited at: 21st Feb 2008 18:48
Anyone like me, that has come from a VB6/VB.NET/C# background has probably found themselves sorely missing events in DBPro. Those that haven't had experience with them, just don't know what they are missing. Well, no longer... events are now possible in DBPro.

Here is how you can get them to work...

First of all, you will need two plugins: Matrix1Util_20.dll and DBPEventManager.dll.

The first one can be found at the bottom of the first post on this thread (you may also need the VC++ redistributables located at the same place):

http://forum.thegamecreators.com/?m=forum_view&t=85209&b=18

The second plugin can be found attached to the first post at this thread:

http://forum.thegamecreators.com/?m=forum_view&t=123804&b=18

To install the plugins, just put the archive in your DBPro root folder and extract them. Download the VC++ redistributables and run the installer if you need those as well.

Now for the fun part... here is a simple demo program that uses events to handle a click of the left mouse button to change the color of a cube. You should already know how to do basic coding in DBPro including setting up a camera, making an object, and setting up a main loop. This is about as bare bones as it gets:



Now lets examine this code and see what it was doing. I will skip over the common DBPro commands as there are other tutorials to teach these.

The first thing, after setting up the camera and cube is this line:



What that does is pretty self explanitory. It tells DBPro that we are going to be using the mouse and want the event manager to tell us when something is done with the mouse.

Now that we have done that we need to create a function that will handle the mouse clicks. First we will make a function that will be triggered when the left mouse button has been pressed down. We will make this function change the color of the cube from red, to green. I won't bother repeating the whole function here, I will just show you the relevant parts:



You will notice that there are two functions that are similarly named and are grouped together. You should treat these as one big function. The first one is used to get a pointer to the second function using the "Get PTR to Next Function()" command. A function pointer is just a memory address where our function is located. This is used in a second when we add our handler declaration.

Next we go back to the top of our code and add this line:



What this does is give the name of the event that we want to handle (ie. "OnMouseLeftDown"), and gives the address of our function we just made. Now the event manager knows what to do if it we press the left mouse button.

Now that just handles when the mouse button is pressed down, but we want the cube to turn back to red when we release the button. For that we need another event handler. At the bottom of the code we will add another set of functions:



This should look very familiar. This is the same way we set up our OnMouseLeftDown function. So the next set should be just as familiar. At the top portion of our code add this:



We have given it a new event name (ie. "OnMouseLeftUp") this time and are passing it the pointer to our new function.

There is only one more necessary step to get our events to work... we need to tell DBPro when to do then. Consequently the next command does just that. In the main loop of our program add this line:



When this line is executed, DBPro will look for mouse activity and look to see if a handler function has been declared for it. If one has, it will run that function.

At the second link listed above is a more in-depth demo of what the Event Manager plugin can do, as well as a full list of supported core events. It can handle mouse, keyboard, and joystick events as well as allow you to make your own events.

Enjoy.

Design documents?!? What design documents??? I thought we were just going to wing it!!!
Zotoaster
19
Years of Service
User Offline
Joined: 20th Dec 2004
Location: Scotland
Posted: 21st Feb 2008 19:47
This is very interesting and looks extremely useful.

Do you mind if I add this to the tutorials thread?

Don't you just hate that Zotoaster guy?
MoomanFL
19
Years of Service
User Offline
Joined: 12th Nov 2005
Location:
Posted: 21st Feb 2008 20:02
Go right ahead Zotoaster... I would be honored.

Design documents?!? What design documents??? I thought we were just going to wing it!!!
Zotoaster
19
Years of Service
User Offline
Joined: 20th Dec 2004
Location: Scotland
Posted: 21st Feb 2008 20:53
Done!

Don't you just hate that Zotoaster guy?

Login to post a reply

Server time is: 2024-11-25 07:32:27
Your offset time is: 2024-11-25 07:32:27