boe, OSX and menu[hack]: try to avoid crashes by postponing the creation of dialogs in the main loop.

This commit is contained in:
Laurent Alonso(fr)
2020-05-12 08:16:05 +02:00
committed by Celtic Minstrel
parent c558518a60
commit 3d7d465c7e
4 changed files with 50 additions and 3 deletions

View File

@@ -166,4 +166,13 @@ const int UI_LAYER_MENUBAR = 1200;
const int talk_gword_offset_x = 19;
const int talk_gword_offset_y = 7;
#ifdef __APPLE__
enum eMenuChoice {
MENU_CHOICE_NONE,
MENU_CHOICE_GENERIC,
MENU_CHOICE_MONSTER_INFO,
MENU_CHOICE_SPELL
};
#endif
#endif

View File

@@ -108,6 +108,11 @@ extern long anim_ticks;
static void init_boe(int, char*[]);
#ifdef __APPLE__
eMenuChoice menuChoice=eMenuChoice::MENU_CHOICE_NONE;
short menuChoiceId=-1;
#endif
int main(int argc, char* argv[]) {
#if 0
void debug_oldstructs();
@@ -252,6 +257,26 @@ void handle_events() {
cFramerateLimiter fps_limiter;
while(!All_Done) {
#ifdef __APPLE__
if (menuChoiceId>=0) {
eMenuChoice aMenuChoice=menuChoice;
menuChoice=eMenuChoice::MENU_CHOICE_NONE;
switch(aMenuChoice) {
case eMenuChoice::MENU_CHOICE_GENERIC:
handle_menu_choice(eMenu(menuChoiceId));
break;
case eMenuChoice::MENU_CHOICE_SPELL:
handle_menu_spell(eSpell(menuChoiceId));
break;
case eMenuChoice::MENU_CHOICE_MONSTER_INFO:
handle_monster_info_menu(menuChoiceId);
break;
case eMenuChoice::MENU_CHOICE_NONE:
break;
}
menuChoiceId=-1;
}
#endif
while(mainPtr.pollEvent(currentEvent)) handle_one_event(currentEvent);
// It would be nice to have minimap inside the main game window (we have lots of screen space in fullscreen mode).

View File

@@ -1,6 +1,10 @@
#include <SFML/Graphics.hpp>
#ifdef __APPLE__
extern eMenuChoice menuChoice;
extern short menuChoiceId;
#endif
int main(int argc, char* argv[]);
void update_everything();
void redraw_everything();

View File

@@ -16,6 +16,9 @@
#include "boe.consts.hpp"
#include "spell.hpp"
extern eMenuChoice menuChoice;
extern short menuChoiceId;
extern short on_spell_menu[2][62];
extern short on_monst_menu[256];
extern bool party_in_memory;
@@ -282,16 +285,22 @@ void menu_activate() {
-(void) monstMenu:(id) sender {
cMonster* monst = [[sender representedObject] monst];
(void) monst; // Mark variable as unused
handle_monster_info_menu([monster_info_menu indexOfItem: sender] - 1);
menuChoice=eMenuChoice::MENU_CHOICE_MONSTER_INFO;
menuChoiceId=short([monster_info_menu indexOfItem: sender] - 1);
//handle_monster_info_menu([monster_info_menu indexOfItem: sender] - 1);
}
-(void) spellMenu:(id) sender {
SpellWrapper* spell = [sender representedObject];
handle_menu_spell(cSpell::fromNum([spell type], [spell num]));
menuChoice=eMenuChoice::MENU_CHOICE_SPELL;
menuChoiceId=short(cSpell::fromNum([spell type], [spell num]));
//handle_menu_spell(cSpell::fromNum([spell type], [spell num]));
}
-(void) menuChoice:(id) sender {
handle_menu_choice(eMenu([[sender representedObject] intValue]));
menuChoice=eMenuChoice::MENU_CHOICE_GENERIC;
menuChoiceId=short([[sender representedObject] intValue]);
//handle_menu_choice(eMenu([[sender representedObject] intValue]));
}
@end