13 January 2024, 03:00 | #1 |
Registered User
Join Date: Aug 2018
Location: Minneapolis, USA
Posts: 301
|
Timing of enabling/disabling menu items?
Hi All,
I'm working on a roguelike game. This is an "OS-friendly" game, or at least that's my goal. Now that almost all the features are in place, I'm looking to do some optimization to speed it up on 68000 machines. My first profile pass shows that the OnMenu() and OffMenu() OS functions are called a lot, and consuming a fair chunk of time. Hit Count MS Per Call MS Overall Min MS Max MS I have a menu system. Some menu items need to be disabled under certain conditions. The way I set that up is to, as soon as any signal is received, call a function that first enables all menu items, then runs through a few conditions and potentially disables some specific menu items. I never disable entire menus, just items within a menu. Ideally, this wouldn't get called until any one menu is actually opened. And wouldn't get called for key input signals at all. but then how would keyboard shortcuts work (AMIGA-C, etc.). so... 1. I copied this system from another more complicated-menu app. I can re-write a bit so that I don't actually re-enable every menu every time. fine. 2. is there a smarter way to know if I should actually bother with the menu enable/disable code? I assumed from documentation that I have to do it before a user could possibly select a menu item, so I'm doing it basically all the time, but a better way? event hander: wait until a signal is received, then call the enable/disable code: Code:
Wait( 1 << parentWindow->UserPort->mp_SigBit ); Menu_EnableDisable(); The enable/disable code looks like this: Code:
// enable all menu items Menu_EnableAllMenuItems(the_window); // selectively disable specific menu items based on conditions if (global_active_window == global_splash_window) { Menu_EnableDisableMenuItem(the_window, MENU_APP, MENU_APP_HELP, false); Menu_EnableDisableMenuItem(the_window, MENU_APP, MENU_APP_ABOUT, false); Menu_EnableDisableMenuItem(the_window, MENU_GAME, MENU_GAME_ABANDON, false); Menu_EnableDisableMenuItem(the_window, MENU_ACTIONS, MENU_ACTIONS_CYCLE_WEAPONS, false); Menu_EnableDisableMenuItem(the_window, MENU_ACTIONS, MENU_ACTIONS_CYCLE_MAGIC, false); Menu_EnableDisableMenuItem(the_window, MENU_ACTIONS, MENU_ACTIONS_RANGED_ATTACK, false); Menu_EnableDisableMenuItem(the_window, MENU_ACTIONS, MENU_ACTIONS_TOGGLE_LANTERN, false); Menu_EnableDisableMenuItem(the_window, MENU_ACTIONS, MENU_ACTIONS_DROP_LAST_ITEM, false); Menu_EnableDisableMenuItem(the_window, MENU_ACTIONS, MENU_ACTIONS_REST, false); Menu_EnableDisableMenuItem(the_window, MENU_ACTIONS, MENU_ACTIONS_INVENTORY, false); } else { Menu_EnableDisableMenuItem(the_window, MENU_GAME, MENU_GAME_NEW, false); Menu_EnableDisableMenuItem(the_window, MENU_GAME, MENU_GAME_RESTORE, false); if (global_gameover_active == true || global_inventory_active == true || global_dialog_active == true || global_noticeboard_active == true) { Menu_EnableDisableMenuItem(the_window, MENU_APP, MENU_APP_HELP, false); Menu_EnableDisableMenuItem(the_window, MENU_GAME, MENU_GAME_ABANDON, false); Menu_EnableDisableMenuItem(the_window, MENU_GAME, MENU_GAME_NEW, false); Menu_EnableDisableMenuItem(the_window, MENU_GAME, MENU_GAME_RESTORE, false); Menu_EnableDisableMenuItem(the_window, MENU_ACTIONS, MENU_ACTIONS_CYCLE_WEAPONS, false); Menu_EnableDisableMenuItem(the_window, MENU_ACTIONS, MENU_ACTIONS_CYCLE_MAGIC, false); Menu_EnableDisableMenuItem(the_window, MENU_ACTIONS, MENU_ACTIONS_RANGED_ATTACK, false); Menu_EnableDisableMenuItem(the_window, MENU_ACTIONS, MENU_ACTIONS_TOGGLE_LANTERN, false); Menu_EnableDisableMenuItem(the_window, MENU_ACTIONS, MENU_ACTIONS_DROP_LAST_ITEM, false); Menu_EnableDisableMenuItem(the_window, MENU_ACTIONS, MENU_ACTIONS_REST, false); Menu_EnableDisableMenuItem(the_window, MENU_ACTIONS, MENU_ACTIONS_INVENTORY, false); } } |
13 January 2024, 06:53 | #2 |
Coder/webmaster/gamer
Join Date: Oct 2001
Location: Canberra/Australia
Posts: 2,712
|
Calling OnMenu()/OffMenu() every time you get a signal is overkill, better to just call them when strictly necessary.
A ghosted menu item will ignore its Amiga-key keyboard shortcut automatically, no need to worry about that. If the example code you used does things like that, maybe it would be a good idea to base it on some better example code :-D Not sure what documentation you are using but maybe it is not the RKRM Libraries; I would suggest a read of the "Intuition: Menus" chapter, it is very informative. |
13 January 2024, 15:27 | #3 | |
Registered User
Join Date: Aug 2018
Location: Minneapolis, USA
Posts: 301
|
An example of dynamically enabling and disabling menu items would be great!
This is the entire sum of information in the RKRM about enabling/disabling menus: Quote:
I may have overreacted to the notes, but they do imply, at least to me, that it's too late to try and disable a menu once a user has the right mouse button down: • Of course, by the time you have disabled the item, the user may have already selected it. Thus, the program may receive a IDCMP_MENUPICK message for that item, even though it considers the item disabled. and • These routines [OnMenu, OffMenu] check if the user is currently using the menus and whether the menus need to be redrawn to reflect the new states. If the menus are currently in use, these routines wait for the user to finish before proceeding. Having an internal structure to check which menus should be enabled or not is easy of course. But I don't want a menu to show as active, and the user thinks they can select it, but then it's not really active and I skip their input anyway. I'll see if I can pick up some better example menu code on google. |
|
13 January 2024, 15:45 | #4 |
Coder/webmaster/gamer
Join Date: Oct 2001
Location: Canberra/Australia
Posts: 2,712
|
Of course there won't be much if you are using the 1986 edition, you can get the later editions here: https://commodore.bombjack.org/amiga/amiga-books.htm
|
13 January 2024, 15:54 | #5 | |
Registered User
Join Date: Aug 2018
Location: Minneapolis, USA
Posts: 301
|
Quote:
|
|
13 January 2024, 17:31 | #6 |
Coder/webmaster/gamer
Join Date: Oct 2001
Location: Canberra/Australia
Posts: 2,712
|
Sorry, I had read it too quickly as "this is the entire sum of information in the RKMs about menus" for some reason :-/
Certainly by the time the menu is being displayed it is too late to be making changes, maybe it could be done at the time an IDCMP_MENUVERIFY is received but that's not really how it's meant to be done. Better to just call your "function that first enables all menu items, then runs through a few conditions and potentially disables some specific menu items" (ie. OnMenu()/OffMenu() calls) when one of those conditions actually changes. If this is still too slow then the optimization is to not call On/OffMenu() for every menu item, only the ones whose on/off status actually needs to be changed. |
13 January 2024, 18:43 | #7 | ||
Registered User
Join Date: Aug 2018
Location: Minneapolis, USA
Posts: 301
|
Quote:
Quote:
Thanks for helping me think through it. |
||
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | |
Thread Tools | |
Similar Threads | ||||
Thread | Thread Starter | Forum | Replies | Last Post |
How to handle CHECKIT|MENUTOGGLE menu items? | desiv | Coders. C/C++ | 7 | 12 April 2023 05:37 |
Enabling interrupts -> lockup? | Ernst Blofeld | Coders. C/C++ | 6 | 20 November 2020 11:28 |
Enabling Auto-load option | sodapop | support.WinUAE | 6 | 25 November 2019 17:03 |
Enabling Firecracker 24? | StrangeVoyager | support.WinUAE | 2 | 23 May 2019 21:24 |
Crash on enabling 68030 MMU with 3.0.0 | mark_k | support.WinUAE | 14 | 25 January 2015 14:09 |
|
|