Event queuing / waiting for an event to happen

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
Solver
Posts: 6
Joined: Tue Nov 21, 2006 6:30 pm

Event queuing / waiting for an event to happen

Post by Solver »

First of all, I want to thank all the developers of Irrlicht - I am very impressed by the engine.

I have an issue with queuing events. Here's a short description of the situation. When a user presses a button, the game processes a bunch of different stuff. Some of that stuff may be in-game events. And, there's a game event that causes a window to pop up, with a listbox and a confirmation button (let's call it selection window).

I have an event receiver class, and everything is fine. The selection window has functionality. The problem is, if the in-game event triggering its appearance happens twice in a row, I get two of these windows. What I want to do is to delay the appearance of further windows until the current one has been dealt with by making a choice in it. How would I go about doing it? I have a segment like:

Code: Select all

public void ProcessMessageQueue()
        {
            foreach (GameGUIMessage msg in GUIMessageQueue)
            {
                if (msg == null) break;
                ProcessMessage(msg);
            }
            GUIMessageQueue.Clear();
        }
Say, the ProcessMessage() function pops up the selection window. Ideally, I would want the next iteration of that loop above delayed until the selection window is deal with. I have a feeling that it's pretty easy, and I know how to check if a selection has been made, but I'm having a mind eclipse and can't figure out how to pause the loop and achieve what I want :).
Acki
Posts: 3496
Joined: Tue Jun 29, 2004 12:04 am
Location: Nobody's Place (Venlo NL)
Contact:

Post by Acki »

What about a boolean for the window(s) ???
If a window is shown you set the boolean to true and if it's closed to false...
In the loop you can check then for this boolean...
while(!asleep) sheep++;
IrrExtensions:Image
http://abusoft.g0dsoft.com
try Stendhal a MORPG written in Java
Solver
Posts: 6
Joined: Tue Nov 21, 2006 6:30 pm

Post by Solver »

Yes, I do have a boolean... but I can't pause the loop by checking for it. I can quit the loop if the window is up, but then the rest of it obviously won't execute. But pausing is a problem. I still feel that it's something simple I'm missing...
Acki
Posts: 3496
Joined: Tue Jun 29, 2004 12:04 am
Location: Nobody's Place (Venlo NL)
Contact:

Post by Acki »

Well, I don't know how the function above is called ???
I guess it's called every main loop ???
I also guess GUIMessageQueue is an array ???
Maybe you should do the message loop in another way ???
Maybe something like this:

Code: Select all

public void ProcessMessageQueue(){
  while((GUIMessageQueue.size() > 0) && !isWinActive){
    if(GUIMessageQueue[0] == null){
      GUIMessageQueue.clear();
      break;
    }
    ProcessMessage(GUIMessageQueue[0]);
    GUIMessageQueue.erase(0);
  }
}
let's say isWinActive is the boolean for the window.
If the window is opened by ProcessMessage() it's set to true and if the window is closed it's set back to false...
This way it should work like you want...
while(!asleep) sheep++;
IrrExtensions:Image
http://abusoft.g0dsoft.com
try Stendhal a MORPG written in Java
Solver
Posts: 6
Joined: Tue Nov 21, 2006 6:30 pm

Post by Solver »

Ahhh. Thank you!
Post Reply