Sending external messages to nodes

You are an experienced programmer and have a problem with the engine, shaders, or advanced effects? Here you'll get answers.
No questions about C++ programming or topics which are answered in the tutorials!
Post Reply
gizmocuz

Sending external messages to nodes

Post by gizmocuz »

I dont know if it's possible.... let's say i made a custom node (a camera) and want to call from my run() thread a function how can this be easly done?

Or for example i want to send a message to my node (i can execute functions with this) like a messagetype,WParam,LParam, is this possible?
If not, maybe it's a good idea to implement such feature?
etcaptor
Posts: 871
Joined: Fri Apr 09, 2004 10:32 pm
Location: Valhalla
Contact:

Post by etcaptor »

You can make your user defined node - see CustomSceneNode example.
If you can post windows events to irrlicht maybe is it possible if you transform structure of these events to appropriate Irrlicht event.
Also there is virtual bool postEventFromUser function defined in ISceneManager class. You can use it when you want to post events to environment, but I'm still have not trying that.
gizmocuz

Post by gizmocuz »

Well i have done it this way... maybe it's a nice feature to implement in the next release:

To implement custom messages to scene nodes change the following:

ISceneNode.h
//message handler
virtual u32 OnMessage(u32 message, u32 wParam, u32 lParam) {
return 0;
}


now in a node that need messages implement the above function.

To send messages just do:

node->OnMessage(messagetype, param1, param2).

Thanks for the help.
etcaptor
Posts: 871
Joined: Fri Apr 09, 2004 10:32 pm
Location: Valhalla
Contact:

Post by etcaptor »

Seem you need event handler :lol: . I'm not sure that u32 wParam, u32 lParam are most important parameters. I that know this message parameters are used in Wiindows, but Irrlicht works on different OS. Maybe is more important realization of any event handler that works for every scene node? At this time events are cached with switch by common event receiver. I saw in IrrlichtNX forum some good Zola's ideas about.
Guest

Post by Guest »

Wparam and Lparam are just variable names... it's importend you can pass parameters with your event...
The above routine does the trick very well...
puh
Posts: 356
Joined: Tue Aug 26, 2003 3:53 pm

Post by puh »

gizmocuz, could you please write an example of your code? Is it possible with this way sending mouse events to node?
gizmocuz
Posts: 3
Joined: Tue Oct 19, 2004 11:37 am

Post by gizmocuz »

Hi Puh,

Afcourse it is possible to send mouse messages to the node this way. If you implement the above function (onmessage) you have two parameters. You can for example pass a structure to the message like this:

struct tagMouse
{
unsigned short posx;
unsigned short posy;
char bLeftMouseState;
char bMiddleMouseState;
char bRightMouseState;
... and so on
} IMOUSE;

IMOUSE mymouse;
mymouse.posx=....;

mynode->OnMessage(IMOUSE_EVENT,(u32)&mymouse,NULL);

IMOUSE_EVENT is just a number representing a mouse structure.

u32 MyNode::OnMessage(u32 message, u32 wParam, u32 lParam)
{
IMOUSE *tmouse;
switch (message)
{
case IMOUSE_EVENT:
tmouse=(IMOUSE*)wParam;
... do something
break;
case .....
}
}

Hope this example explain a bit how to use this...
Sparks
Posts: 19
Joined: Thu Oct 21, 2004 1:30 am
Location: Montreal

Post by Sparks »

Did you think of an observer or visitor design pattern, to send a message from one object to another. That's how I do my physics
XL Game Development
Post Reply