game menu system very slow
BlitzMax Forums/BlitzMax Beginners Area/game menu system very slow
| ||
The menu I have written for my game seems to be very slow / laggy when I click on an option (or press a key). Moving up and down via the mouse or cursor keys is fine, it's just sometimes slow when I click on an option. For example if I click on "Quit" it may take a couple of seconds to recognise this, by which point I've moved up to "load game" and rather than quitting it tries to load a game. Then the next time I do the same thing it could be fine. I think it must either be my event handler, or the that I have multiple "if" statements within my "case" The menu I'm using needs to work for both mouse and keyboard controls. I'd be grateful if someone could have a look at my code, or provide some code for a working mouse and keyboard menu system thanks in advance :-) |
| ||
Rather than pulling mousex and mousey continuously, you may want to put it in a variable once and do the successive comparisons against it? |
| ||
That shouldnt make it slow. Are you suffering from frame lag? ie is your driver showing you a frame which was rendered several frames ago? |
| ||
Could it possibly be from WaitEvent()? |
| ||
I was thinking it might be the waitevent, so how do I change it to make it less laggy? |
| ||
Use PollEvent instead. From the docs: If there are no events in the event queue, WaitEvent halts program execution until an event is available. If there are no events in the event queue, PollEvent returns 0. |
| ||
okay I'll try replacing my waitEvent with pollEvent - thanks |
| ||
I've replaced the waitEvent with pollEvent but it still seems as laggy. Any other ideas? |
| ||
The problem might be in your logic. Can you post a working sample? |
| ||
What is your frame rate before and during the menu? |
| ||
Sorry for not replying - haven't been on my home PC for a couple of days - probably won't get the chance to look at it again till the weekend. I must be doing something stupid as most of the other examples I've searched for on here seem to use waitevent() and then catch event_timertick() fine. I need to spend some time debugging this error properly Also it's not consistently slow - when the game first loads it seems fine. It seems to be slower after exiting out of a game back to the main menu. Using pollEvent instead of waitEvent seems to make the slowdown of the menu happen less frequently - although it still happens! The actual error is that when you are over a menu item i.e. quit and you press return or click the mouse button I would expect the program to exit straight away. However it takes up to 5 seconds for the program to respond to the mouse click, during which time the user could move the mouse to the next menu item. The program then rather than execute the "Quit" command will execute the menu item that the cursor is currently highlighted over. So it is still responding to the single mouse click and therefore picking it up from the event queue (I'm not pressing the mouse button again) - it's just taking ages to respond to it. But the whole screen hasn't slowed down because moving the mouse still highlights the other menu options as quickly as normal - it just doesn't respond quickly to the mouse click - very strange!! (Note: the movement of the mouse up/down isn't handled in the waitevent loop) thanks for the suggestions so far ... |
| ||
Are you taking ALL events out of the queue each loop? My guess is that you are taking one event then looping, then one event, then looping. Problem is, you are generating more than one vent per loop. So, they are building up and it seems like your app is lagging. You have to make sure you take ALL of the events out of the event queue each loop. |