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.

DLL Talk / [Plugin][DBPro]DBPEventManager -- DBPro now has VB6, .NET style custom events

Author
Message
MoomanFL
19
Years of Service
User Offline
Joined: 12th Nov 2005
Location:
Posted: 12th Feb 2008 14:26 Edited at: 21st Feb 2008 02:02
UPDATE: New Version 0.1.0.369 beta

Changes v0.1.0.369 beta:
-- Feb. 20, 2008
Added some premade core events for mouse, keyboard, and joystick.
Added event queue throttling commands for all event queues.
Added commands to turn core event queues on and off.
Updated Example code with some new commands.

Changes v0.0.2.77 beta: -- Feb. 12, 2008
Now accepts up to 10 parameters instead of just 8 on RAISE DBP EVENT.
Fixed error in example code that kept results of Test3() event handler from printing.
Added new parameters to Test3() event handler to reflect the above change.

I would be most interested in know the frame rates you get when using this plugin on the test code. Also if you can think of event related features you would like added, I am all ears.

-----------------------------------------------------------------------------


Ok... unlike my other plugin, this one is being released first as a beta with no source.

Purpose: Creates a set of commands to let the user declare, raise, and handle events in the style of VB6, VB.NET, and C#. It is capable of raising core events such as "OnMouseMove", "OnKeyDown", and "OnJoystickXChanged". The user can set up multiple event queues which can be set to process at different times in the loop. Each queue can be throttled to only process events after a specified number of loops. Core events such as the mouse, keyboard, and joystick can be turned on and off at will by the user.

It uses the function pointer capabilities provided by IanM's Matrix1Util_20 plug-in, and as such this plugin is REQUIRED for this plug-in to work. Because of this requirement, the VC++ redistributables may be needed as well. His Matrix1 plug-ins, and the VC++ redistributables can be found here at the bottom of the first post:

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

Why An Event Handler?

The goal of this plugin was to make things easier for the DBPro programmer that is coming from a VB6 or .NET background. However, once the concepts of events and how they can be used are grasped, pretty much anyone can benefit from them.

DBPro is a procedural language. That is to say it processes commands in a linear fashion. Because of this, code tends to be actionary. You have to make things happen. On the other hand, event based programming is reactionary. Things happen, and you design code to respond to those events.

An illustration of the difference is in handling a mouse click:

In a procedural language like DBPro you would set up a loop, and poll the mouse every loop checking to see if the mouse has been clicked. Once it is clicked, then you perform the appropriate action.

In an event based language, you would make a function that does something when the mouse is clicked. You declare that function as a handler for mouseclick events. Then when the mouse is clicked and event call is fired. The appropriate function is automatically called to handle that event. There is no need to constantly check for these things to happen; it is all done behind the scenes. You just design code to react to it.

That is what this is what this plugin does.

Here is the current function list. You will need IanM's plugin mentioned above to get the function pointer for the DECLARE statment:

DECLARE DBP EVENT HANDLER DBP EventName as String, FunctionPtr as Long
RAISE DBP EVENT Index as Integer, EventName as String, [param1, param2, param3,.... param10]
DBP DO EVENTS Index as Integer
DBP DO CORE EVENTS *no parameters*
MOUSE EVENTS ON *no parameters*
KEYBOARD EVENTS ON *no parameters*
JOYSTICK EVENTS ON *no parameters*
SET EVENT QUEUE THROTTLE Index as Integer, NumberofLoops as Integer
SET MOUSE EVENT THROTTLE NumberofLoops as Integer
SET KEYBOARD EVENT THROTTLE NumberofLoops as Integer
SET JOYSTICK EVENT THROTTLE NumberofLoops as Integer

The recognized core events are as follows (these are the premade events. No need to raise them, just declare a handler for them. Some events send parameters to your handler function. If a handler needs to send parameters, the necessary declarations are next to the event name. These would be placed as arguments in your handler function:

Mouse Events:


Keyboard Events


Joystick Events


You might have noticed a few events missing, such as key up events for some of the named keys (OnUp, OnTab, etc.) and a "OnJoystickFireX" event. Those will be coming in a later update. Also at this time, core events can be turned on and off, but there is no corresponding function for custom event queues. This will also be coming in a later update.

Ok... a brief explanation and then some example code.

You declare your event handlers at the beginning of your code. If you wish to use core events you must turn them on. To get the function pointer for the handler declaration you must use IanM's Matrix1Util_20.dll plugin. Make the function you want to be your event handler. Right before that function in your code, make another function with one command in it like so:



Your declaration should now look like this:



Now put the DBP DO EVENTS code in your main loop where you want it to handle your events. In any of your code you can raise an event like this:



The number 1 is the index of the event queue your events will go into it. The DBP DO EVENTS function with a matching index will process that event. Optionally you can have up to 10 parameters sent with your event, but the handler function must be set up to take the same number and types of parameters.

Here is an example program that should run fine using this plugin. It isn't fancy, but it should give you an idea of how it works. Try left clicking the mouse when running it. Also take special notice of the last function of the program. Something like this is necessary if you are using core events as it forces the compiler to include the necessary DLL by using a command from it. That code never gets run so it doesn't matter which Input command you put in there.



Just download the attached zip file and extract the contents to your DarkBASIC Professional directory.

Enjoy.

Design documents?!? What design documents??? I thought we were just going to wing it!!!

Attachments

Login to view attachments
Xsnip3rX
17
Years of Service
User Offline
Joined: 20th Feb 2007
Location: Washington State
Posted: 13th Feb 2008 07:02
This is *almost* as good as my godlyness. good job.

MoomanFL
19
Years of Service
User Offline
Joined: 12th Nov 2005
Location:
Posted: 14th Feb 2008 03:06 Edited at: 14th Feb 2008 03:13
Thanks for the compliment, Xsnip3rX.... I think.

Has anyone given it a shot yet? Still hoping to see what kind of framerates other people are getting with this.

Design documents?!? What design documents??? I thought we were just going to wing it!!!
MoomanFL
19
Years of Service
User Offline
Joined: 12th Nov 2005
Location:
Posted: 20th Feb 2008 22:33
Got a major update to this plugin... see the first post for details. There now core events added.

Design documents?!? What design documents??? I thought we were just going to wing it!!!
wildbill
18
Years of Service
User Offline
Joined: 14th Apr 2006
Location:
Posted: 21st Feb 2008 04:35
Just tried it out and it worked as advertised. I get approximately 1000 fps on my dell M70 laptop.

Have you duplicated this code in straight DBP to see what the difference in FPS would be?
MoomanFL
19
Years of Service
User Offline
Joined: 12th Nov 2005
Location:
Posted: 21st Feb 2008 12:09 Edited at: 21st Feb 2008 12:57
Have you duplicated this code in straight DBP to see what the difference in FPS would be?

Wildbill, thanks for the response. No I haven't tried doing this in DBPro. That would be a massive amount of code as I would have had to do a lot of work arounds for things that are easy in C++.

As a test, try REMing out all the text statements in the demo except for the one that prints out the FPS. That means the ones in the main loop and the ones in Test3(). I think you will find that the FPS almost doubles. DBPro is notoriously slow with text, and normally I would use Cloggy's plugin for that, but I didn't want yet another requirement for the demo.

As a way of comparison, I get a high of 2250 FPS on the demo with text, and 3300 with the text REM'd out. I am using an Athalon 64 x2 4200+ with 2gb RAM and a GeForce 7900 GS.

With the lines that use TPC's REM'd out (meaning they don't even get included with the EXE) I get about 3400 FPS which isn't much of a net gain.

It seems that the big slow down in the Demo is with the Text commands.

Design documents?!? What design documents??? I thought we were just going to wing it!!!

Login to post a reply

Server time is: 2024-11-23 03:03:10
Your offset time is: 2024-11-23 03:03:10