EET_USER_EVENT. Possible collisions with window messages.

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
sash
Competition winner
Posts: 35
Joined: Thu Nov 05, 2009 8:46 am
Location: Novosibirsk

EET_USER_EVENT. Possible collisions with window messages.

Post by sash »

Hi all, just some thoughts about user events:

I need some specific messaging between components of my application (win/linux/possibe mac). This is why EET_USER_EVENT exists for, right?
However I think using EET_USER_EVENT is not very safe, because device forwards WM_USER messages and others for another platforms there.
How to distinguish between my "real_user" events and those, possibly posted by some library/another application which I'm not aware of?

Currently I'm using this workaround:

Code: Select all

const u32 EET_CUSTOM_EVENT = (u32)EET_USER_EVENT + 1;
but it looks like a hack and requires additional typecasts each time I post and read messages.
What about to extend EEVENT_TYPE enum with EET_CUSTOM_EVENT (or EET_USER_EVENT_EX :)) ?

Any other thoughts about it ?
Thanks.
CuteAlien
Admin
Posts: 9682
Joined: Mon Mar 06, 2006 2:25 pm
Location: Tübingen, Germany
Contact:

Re: EET_USER_EVENT. Possible collisions with window messages

Post by CuteAlien »

Can you give some concrete use-case? Maybe we can propose other solutions.
IRC: #irrlicht on irc.libera.chat
Code snippet repository: https://github.com/mzeilfelder/irr-playground-micha
Free racer made with Irrlicht: http://www.irrgheist.com/hcraftsource.htm
sash
Competition winner
Posts: 35
Joined: Thu Nov 05, 2009 8:46 am
Location: Novosibirsk

Re: EET_USER_EVENT. Possible collisions with window messages

Post by sash »

Here it is (simplified for clarity)

Code: Select all

 
// define my own user event
const u32 EET_CUSTOM_EVENT = (u32)EET_USER_EVENT + 1;
 
// ...... eventReceiver
    switch (evt.EventType)
    {
      // .....
      case (EET_KEY_INPUT_EVENT) :
        return actionManager->handleKeyboard(evt.KeyInput);
 
      // ...
      case ( (EEVENT_TYPE) EET_CUSTOM_EVENT) :
        switch (evt.UserEvent.UserData1)
        {
            case ACTION_JUMP: .....
            case ACTION_FIRE: .....
            case ACTION_RUN: .....
        };
     };
 
// ........
 
CActionManager::handleKeyboard(evt.KeyInput)
{
  s32 action = findAction(evt.KeyInput) //transform keystroke to action
  if ( action )
  {
    SEvent evt;
    evt.EventType = (EEVENT_TYPE) EET_CUSTOM_EVENT; 
    evt.UserEvent.UserData1 =  action;
    return device->postEventFromUser(evt);
  }
  else
    return false;
};
 
In case I'd use EET_USER_EVENT there is no guarantees some other application will never send WM_USER with f.i. WParam == 0 to my window thus triggering my internal actions.
After all, it is not a big concern, my code works. This is just a notice.
CuteAlien
Admin
Posts: 9682
Joined: Mon Mar 06, 2006 2:25 pm
Location: Tübingen, Germany
Contact:

Re: EET_USER_EVENT. Possible collisions with window messages

Post by CuteAlien »

This looks on first view like events send & received by your application. There is no advantage if you send those through the engine (except if you want to slow down your application somehow... but I'm sure you find better ways to do that ^_^). There's no need to handle everything that looks like an event in a single function - that won't make your code easier to read or write.

Using the irrlicht evenreceiver really only makes sense if you pass around events that matter for Irrlicht in some way.
If you just put any custom event in there all the engine would do would be passing it around internally a while until it passes it on to your event-receiver again without ever doing anything with it. So... you can just pass stuff to your eventreceiver directly in that case with any function/structure you want.

edit: Note, if you actually need this for gui-stuff in custom gui-elements it might make sense. Pretty much the only scenario I could think of were it would be useful.
IRC: #irrlicht on irc.libera.chat
Code snippet repository: https://github.com/mzeilfelder/irr-playground-micha
Free racer made with Irrlicht: http://www.irrgheist.com/hcraftsource.htm
sash
Competition winner
Posts: 35
Joined: Thu Nov 05, 2009 8:46 am
Location: Novosibirsk

Re: EET_USER_EVENT. Possible collisions with window messages

Post by sash »

CuteAlien, thanks.
Although this is not my actual code, but I think you convinced me not to use EventReceiver, especially for tasks not related to Irrlicht device.
Post Reply