Event Receiver on Win32 app

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
Eventide
Posts: 23
Joined: Fri Jul 19, 2013 4:46 am

Event Receiver on Win32 app

Post by Eventide »

I'm developing an Win32 app with a Irrlicht render inside, following this tutorial: http://irrlicht.sourceforge.net/docu/example014.html

By what i understood from
Now the only thing missing is the drawing loop using IrrlichtDevice::run(). We do this as usual. But instead of this, there is another possibility: You can also simply use your own message loop using GetMessage, DispatchMessage and whatever. Calling Device->run() will cause Irrlicht to dispatch messages internally too. You need not call Device->run() if you want to do your own message dispatching loop, but Irrlicht will not be able to fetch user input then and you have to do it on your own using the window messages, DirectInput, or whatever.
An event receiver object should work properly, right? But it isn't, I'm unable to detect mouse input, already debugged it and OnEvent function isn't being called.

is there any way to make it work or I'll need to write my own event receiver with the Windows API? Is it possible to make the Irrlicht event receiver work like that? Is it possible to detect when the Irrlicht render area of the window is being focused?

Thanks in advance.
CuteAlien
Admin
Posts: 9734
Joined: Mon Mar 06, 2006 2:25 pm
Location: Tübingen, Germany
Contact:

Re: Event Receiver on Win32 app

Post by CuteAlien »

What are you trying? When you don't call run() the eventreceiver will not receive any events (as run() does the checking for system events). So if you don't call that but still want Irrlicht do get the event then you have to send them to Irrlicht yourself. I think you can use IrrlichtDevice::postEventFromUser for that. That way you can inform Irrlicht about mouse-events etc.
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
Eventide
Posts: 23
Joined: Fri Jul 19, 2013 4:46 am

Re: Event Receiver on Win32 app

Post by Eventide »

CuteAlien wrote:When you don't call run() the eventreceiver will not receive any events
You mean...

Code: Select all

 
while (device->run())
    {
 
That run? Already calling it.

I forgot to paste the codes here, sorry, hope that helps solving the problem
main.cpp

Code: Select all

 
    EventManager* event_manager = new EventManager();
    event_manager->setVars(smgr, cam);
    device->setEventReceiver(event_manager);
 
    while (device->run())
    {
        driver->beginScene(true, true, 0, videodata);
        smgr->drawAll();
        driver->endScene();
        event_manager->check();
    }
 
eventmanager.h

Code: Select all

 
#ifndef EVENTMANAGER_HEADERFILE
#   define EVENTMANAGER_HEADERFILE
#   include <irrlicht.h>
#   include <iostream>
 
class EventManager : public IEventReceiver
{
    public:
        virtual bool OnEvent(const SEvent& event)
        {
            std::cout << "BANG" << std::endl;
            if (event.EventType == irr::EET_MOUSE_INPUT_EVENT)
            {
                if(event.MouseInput.Event == EMIE_MOUSE_WHEEL)
                {
                    mwheel = true;
                    mwheel_quant = event.MouseInput.Wheel;
                }
                else
                {
                    mwheel = false;
                    mwheel_quant = 0.f;
                }
            }
            return false;
        }
 
        void check()
        {
            if(mwheel == true)
            {
                core::vector3df target = cam->getTarget();
                cam->setTarget(core::vector3df(target.X, target.Y, target.Z+mwheel_quant));
            }
        }
 
        EventManager()
        {
            for (u32 i=0; i<KEY_KEY_CODES_COUNT; ++i)
                KeyIsDown[i] = false;
        }
 
        void setVars(scene::ISceneManager* _smgr, scene::ICameraSceneNode* _cam)
        {
            smgr = _smgr;
            cam = _cam;
        }
 
    private:
        bool mwheel;
        f32 mwheel_quant;
        scene::ISceneManager* smgr;
        scene::ICameraSceneNode* cam;
        bool KeyIsDown[KEY_KEY_CODES_COUNT];
};
 
#endif
 
PS: call me a noob as much as you want, but console printing is the best way of "debugging"!
CuteAlien
Admin
Posts: 9734
Joined: Mon Mar 06, 2006 2:25 pm
Location: Tübingen, Germany
Contact:

Re: Event Receiver on Win32 app

Post by CuteAlien »

Hm, maybe you additionally catch the events in the messageloop in another places? run() basically read the messageloop and takes all events it find there. If you have another part of your application doing that as well you'll run into problems (as then 2 different parts of your application will clean up the Windows messages at different times more or less randomly - each stealing events from the other).

So only use run() if you want Irrlicht to handle the events. If you have another framework handling events you have to pass them on manually to Irrlicht like I described in the last post.
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
Eventide
Posts: 23
Joined: Fri Jul 19, 2013 4:46 am

Re: Event Receiver on Win32 app

Post by Eventide »

CuteAlien wrote:Hm, maybe you additionally catch the events in the messageloop in another places? run() basically read the messageloop and takes all events it find there. If you have another part of your application doing that as well you'll run into problems (as then 2 different parts of your application will clean up the Windows messages at different times more or less randomly - each stealing events from the other).

So only use run() if you want Irrlicht to handle the events. If you have another framework handling events you have to pass them on manually to Irrlicht like I described in the last post.
It seems that it's exactly what's happening, i have some events of the Windows API running, i removed the cursor of the Windows API and now OnEvent is being properly called, unfortunately removing the cursor made the whole Windows API broken, only remaining the Irrlicht render, so it isn't a solution(stupid idea, i know), but your solution seems fine and relatively easy to implement... Thanks. :D
Post Reply