hi all!
i need just a little help on the SetEventReceiver.
i ve got 2 class (Intro and Company)which are base on the IEventReceiver.
here is my main loop
main()
{
Intro.Open(); // create all gui and graphic stuff
Intro.Run(); // go in while(escape_key) loop
Intro.Close() // delete all stuff
Company.Open(); // create all gui and graphic stuff
Company.Run(); // go in while(escape_key) loop
Company.Close() // delete all stuff
}
and in Intro.Open()
{
Irrlicht.Device->setEventReceiver(this);
StaticText = guienv->addStaticText(L"",false,rect<int>(0,0,150,20));
// other init stuff
}
in Intro.Run()
{
// basic draw loop
while(!Exit)
{
if (Irrlicht.Device->isWindowActive())
{
float elapsedtime= GameTimer.ElapsedTime();
Irrlicht.Device->run();
Update(elapsedtime);
Irrlicht.Driver->beginScene(true, true,SColor(0,0,0,0));
guienv->drawAll();
Irrlicht.Driver->endScene();
StaticText->setText(text);
}
}
in Intro.Close()
{
Irrlicht.Device->setEventReceiver(NULL);
StaticText->Remove();
}
and in event:
OnEvent(SEvent event)
{
if(event.EventType == EET_KEY_INPUT_EVENT )
{
s32 id = event.KeyInput.Key;
switch(id)
{
case KEY_ESCAPE: LogFile.Write(LOGERROR,"INTRO ESCAPE KEY PRESS",true);
Exit=true;
break;
}
}
return false;
}
and i ve got the same code in company class (just graphic stuff change)
so what i want is when i am in the intro loop, if i press escape i close intro (so unallocate all graphic stuff) and create company event and go thrue the loop.
All is ok, all is working, allocation and unallocation is good but there is something wrong...
when i press the first time escape, it close the intro ,set eventreceiver to NULL so it s ok, and when i create the company class, in the event function, it goes directly in the escape sequence. the engine has save the key input KEY_ESCAPE.
So i would like to know if there is a function after having set the EventReceiver to NULL with Device->setEventReceiver(NULL) that can "clean" the inputreceiver or Maybe NiKo can you implement a function like this:
Device->unsetEventReceiver(); that doing things in the right way...
thx, i hope you have understand...
help on SetEventReceiver
help on SetEventReceiver
-----------------------------
Sans danger, pas de gloire...
http;//bappy.free.fr
-----------------------------
Sans danger, pas de gloire...
http;//bappy.free.fr
-----------------------------
-
nebukadnezzar
- Posts: 25
- Joined: Tue Dec 02, 2003 7:45 pm
- Location: Germany - Bornheim
maybe you should not return false.
try return true; in onEvent().
quote from api-doc
try return true; in onEvent().
quote from api-doc
so let the engine know that ypu have processed the event - otherwise the engine keeps this event until its processed.virtual bool irr::IEventReceiver::OnEvent ( SEvent event ) [pure virtual]
called if an event happened. returns true if event was processed
State Machine
I am new to c++ and program design but i would use something like a state machine. There is a class which handles the current state and is able to switch between all know states. There is one eventreceiver in the handle class that receives all the events coming from the irrlicht engine and calls the state onevent function which processes all the events for the state. Every state is supposed to have its own draw function.
There is a simply state machine avaible using irrlicht by keless.
http://irrlicht.sourceforge.net/phpBB2/ ... .php?t=924
I modified it myself and its working great.
There is a simply state machine avaible using irrlicht by keless.
http://irrlicht.sourceforge.net/phpBB2/ ... .php?t=924
I modified it myself and its working great.
thanks for the plug schick
yes, there is no reason to have to shut down your device, unless you are switching renderers or bit depths/etc. If you download my framework, the example code given will allow you to compile it right away and see exactly how to switch between different states (such as intro and company).
part of the design issues you will come up with are, what deserves its own state? and what is merely a sub-state? I suggest you draw out a state-diagram or a program flow-chart to plan out how your program should act before coding.
yes, there is no reason to have to shut down your device, unless you are switching renderers or bit depths/etc. If you download my framework, the example code given will allow you to compile it right away and see exactly how to switch between different states (such as intro and company).
part of the design issues you will come up with are, what deserves its own state? and what is merely a sub-state? I suggest you draw out a state-diagram or a program flow-chart to plan out how your program should act before coding.
a screen cap is worth 0x100000 DWORDS
thats ok, i have found what was the problem, here is the solution:
if(event.EventType == EET_KEY_INPUT_EVENT && EVENT.KEYINPUT.PRESSEDDOWN==FALSE)
i have forget to test if the key escape was release...
thx
if(event.EventType == EET_KEY_INPUT_EVENT && EVENT.KEYINPUT.PRESSEDDOWN==FALSE)
i have forget to test if the key escape was release...
thx
-----------------------------
Sans danger, pas de gloire...
http;//bappy.free.fr
-----------------------------
Sans danger, pas de gloire...
http;//bappy.free.fr
-----------------------------