Advice for Event structure?

If you are a new Irrlicht Engine user, and have a newbie-question, this is the forum for you. You may also post general programming questions here.
Post Reply
Liquidream
Posts: 36
Joined: Fri Feb 20, 2004 9:23 am
Contact:

Advice for Event structure?

Post by Liquidream »

Hi all,

Basically what I want to do is setup a good event system so that all of my objects/classes can respond to various types of events (built-in an "additional" ones).

In addition to Irrlicht's built-in events, I want to look for "Double-clicks" and "Mouse-hovers". Now, I have the code for both of these events working, but they are currently located outside the main program's OnEvent() section.

Let's say for example that I want to make a small application that has lots of boxes that can be selected, double-clicked and should respond to the mouse-hover. Each box is a Class (say, CBox) that has the Node's pointer and other useful information including WHAT should happen when particular events occur.

Now if in my main application's OnEvent method, I call each of the CBox's OnEvent() method: how can I also pass on the information such as SelectedNode (gathered from getSceneNodeFromRayBB), and bDoubleClick (whether or not a double-click has happened), etc..

I know I could do something like:

Code: Select all

CBox->OnEvent(event, SelectedNode, bDoubleClick, ...);
But this is evil even by my standards. :roll:

Can anyone please suggest some good coding standards to implement this properly. Many thanks.
jox
Bug Slayer
Posts: 726
Joined: Thu Apr 22, 2004 6:55 pm
Location: Germany

Post by jox »

A quite integrated solution would maybe be to implement a similar EventHandling mechanism that the gui elements have for the scene nodes.

Add virtual OnEvent() to ISceneNode.
Extend CSceneManager::postEventFromUser() to pick a node if any and pass the event to it.

This happens already but only with camera scene nodes (without the picking of course).

Take a look also to CIrrDeviceStub::postEventFromUser() to see how events get delegated.

Have you checked out my double click implementation? (somewhere in faqs & tools I think).
It is like it is. And because it is like it is, things are like they are.
Liquidream
Posts: 36
Joined: Fri Feb 20, 2004 9:23 am
Contact:

Post by Liquidream »

Thanks Jox I'll take a look. I think I did see your post elsewhere, it's probably where I found the double-click code I'm using now :wink:
Liquidream
Posts: 36
Joined: Fri Feb 20, 2004 9:23 am
Contact:

Post by Liquidream »

Just an idea, but does anyone know if SEvent can be customised without changing the Irrlicht source?

That way, I wonder if I could just add in some extra custom event types (such as Double-click, Drag and maybe SelectedNode) so that I just have my main Event Routine, which calls all my objects' OnEvent() methods and passes the custom SEvent to it??

Is this even possible? :?
Guest

Post by Guest »

Maybe you could try inheriting it into your own class?
jox
Bug Slayer
Posts: 726
Joined: Thu Apr 22, 2004 6:55 pm
Location: Germany

Post by jox »

As of Irrlicht 0.9 SEvent has a user type:

Code: Select all

	struct
	{
		s32 UserData1; // Some user specified data as int
		s32 UserData2; // Another user specified data as int
		f32 UserData3; // Some user specified data as float
	} UserEvent;
It is like it is. And because it is like it is, things are like they are.
Post Reply