int lr_free_memory (lrnode *listhead, lrstat *stats) { lrnode *state; /* Pointer to state in dialog list */ int feedback = 0; ASSERT (stats-> mnames != NULL); ASSERT (stats-> enames != NULL); ASSERT (stats-> snames != NULL); ASSERT (stats-> source != NULL); free (stats-> mnames); /* Drop list of modules */ free (stats-> enames); /* and list of events */ free (stats-> snames); /* and list of states */ free (stats-> source); /* and source file name */ state = listhead-> child; /* Free main states list */ while (state) state = DeleteState (listhead, state); free (listhead-> name); /* Free symbol table */ return (feedback); }
GameState::~GameState(void) { DeleteState(); }
int lr_sort_dialog (lrnode *listhead, lrstat *stats) { int feedback = 0, actions, /* Nbr actions for this event */ scan; /* Index used for scanning */ lrnode *state, /* Pointer to state in dialog list */ *cmpstate, /* Pointer to state in dialog list */ *event, /* Pointer to event */ *nextstate, /* Pointer to next state */ *module; /* Pointer to module */ Bool used; /* State used in dialog? */ char *symptr; /* Pointer into symbol table */ ASSERT (listhead != NULL); ASSERT (stats != NULL); stats-> snames = (char **) Check (calloc (LR_STATEMAX, sizeof (char *))); stats-> enames = (char **) Check (calloc (LR_EVENTMAX, sizeof (char *))); stats-> mnames = (char **) Check (calloc (LR_MODULEMAX, sizeof (char *))); /* Remove any unused states from dialog */ for (state = listhead-> child; state; state = state-> next) { /* Ignore first state and defaults state */ if (state != listhead-> child && strneq (state-> name, OPT_DEFAULTS.value)) { used = FALSE; for (cmpstate = listhead-> child; cmpstate && !used; cmpstate = cmpstate-> next) if (cmpstate != state) for (event = cmpstate-> child; event && !used; event = event-> next) { nextstate = event-> child; if (streq (nextstate-> name, state-> name)) used = TRUE; } if (!used && OPT_COMPRESS.flags & OPT_ON) DeleteState (listhead, state); } } /* Collect and sort states, events, and modules */ stats-> states = collect_names (listhead, 's', stats-> snames, 0); stats-> events = collect_names (listhead, 'e', stats-> enames, 1); stats-> modules = collect_names (listhead, 'm', stats-> mnames, OPT_SORT.flags & OPT_ON? 1: 0); stats-> maxaction = 0; /* Find defaults state */ stats-> defaults = LR_NULL_STATE; /* Assume none defined */ for (scan = 0; stats-> snames [scan]; scan++) if (streq (stats-> snames [scan], OPT_DEFAULTS.value)) stats-> defaults = scan; /* Perform a few checks on the dialog */ /* - next state cannot be initial state */ /* - same state does not exist twice */ for (state = listhead-> child; state; state = state-> next) { for (cmpstate = state-> next; cmpstate; cmpstate = cmpstate-> next) if (streq (state-> name, cmpstate-> name)) PrintMessage (MSG_DUPLICATE_STATE, state-> name); for (event = state-> child; event; event = event-> next) { nextstate = event-> child; if (streq (listhead-> child-> name, nextstate-> name) && strneq (listhead-> child-> name, state-> name)) PrintMessage (MSG_NEXT_STATE_NFG, nextstate-> name); } } /* Insert numberings into list of states/events/modules */ for (state = listhead-> child; state; state = state-> next) { state-> number = GetSymNumber (state-> name); for (event = state-> child; event; event = event-> next) { event-> number = GetSymNumber (event-> name); actions = 0; nextstate = event-> child; find_next_state (nextstate, stats-> snames, state-> number); for (module = nextstate-> next; module; module = module-> next) { actions++; module-> number = GetSymNumber (module-> name); } if (stats-> maxaction < actions) stats-> maxaction = actions; } } /* Report dialog statistics if necessary */ if (OPT_STATS.flags & OPT_ON) { /* Find size of symbol table */ for (symptr = listhead-> name; *symptr; ) symptr = strchr (symptr + 3, 0) + 1; PrintMessage (MSG_STATS, stats-> states, stats-> events, stats-> modules); PrintMessage (MSG_SYM_USED, (int) (symptr - listhead-> name) / (LR_SYMBOLMAX / 100)); } return (feedback); }
BOOL CALLBACK InternalEmulatorSettingsProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam) { switch (message) { case WM_INITDIALOG: { DialogData *d; std::string s; for (unsigned i = 0; i < 16; i++) { std::stringstream ss; ss << "JOY" << i; SendMessage(GetDlgItem(hWnd, IDC_IEJOYNUM), CB_ADDSTRING, 0, (LPARAM)ss.str().c_str()); } s = "DISABLE"; SendMessage(GetDlgItem(hWnd, IDC_IEJOYNUM), CB_ADDSTRING, 0, (LPARAM)s.c_str()); SendMessage(GetDlgItem(hWnd, IDC_IEJOYNUM), CB_SETCURSEL, set.joyNum, 0); d = new DialogData; d->setting = set.emulatorButtons[unsigned(InternalEmulatorButtonType::UP)]; SetWindowSubclass(GetDlgItem(hWnd, IDC_IEKEYUP), InternalEmulatorInputDialogProc, 0, DWORD_PTR(d)); s = GetButtonText(d); SetWindowText(GetDlgItem(hWnd, IDC_IEKEYUP), s.c_str()); d = new DialogData; d->setting = set.emulatorButtons[unsigned(InternalEmulatorButtonType::DOWN)]; SetWindowSubclass(GetDlgItem(hWnd, IDC_IEKEYDOWN), InternalEmulatorInputDialogProc, 0, DWORD_PTR(d)); s = GetButtonText(d); SetWindowText(GetDlgItem(hWnd, IDC_IEKEYDOWN), s.c_str()); d = new DialogData; d->setting = set.emulatorButtons[unsigned(InternalEmulatorButtonType::LEFT)]; SetWindowSubclass(GetDlgItem(hWnd, IDC_IEKEYLEFT), InternalEmulatorInputDialogProc, 0, DWORD_PTR(d)); s = GetButtonText(d); SetWindowText(GetDlgItem(hWnd, IDC_IEKEYLEFT), s.c_str()); d = new DialogData; d->setting = set.emulatorButtons[unsigned(InternalEmulatorButtonType::RIGHT)]; SetWindowSubclass(GetDlgItem(hWnd, IDC_IEKEYRIGHT), InternalEmulatorInputDialogProc, 0, DWORD_PTR(d)); s = GetButtonText(d); SetWindowText(GetDlgItem(hWnd, IDC_IEKEYRIGHT), s.c_str()); d = new DialogData; d->setting = set.emulatorButtons[unsigned(InternalEmulatorButtonType::A)]; SetWindowSubclass(GetDlgItem(hWnd, IDC_IEKEYA), InternalEmulatorInputDialogProc, 0, DWORD_PTR(d)); s = GetButtonText(d); SetWindowText(GetDlgItem(hWnd, IDC_IEKEYA), s.c_str()); d = new DialogData; d->setting = set.emulatorButtons[unsigned(InternalEmulatorButtonType::B)]; SetWindowSubclass(GetDlgItem(hWnd, IDC_IEKEYB), InternalEmulatorInputDialogProc, 0, DWORD_PTR(d)); s = GetButtonText(d); SetWindowText(GetDlgItem(hWnd, IDC_IEKEYB), s.c_str()); d = new DialogData; d->setting = set.emulatorButtons[unsigned(InternalEmulatorButtonType::X)]; SetWindowSubclass(GetDlgItem(hWnd, IDC_IEKEYX), InternalEmulatorInputDialogProc, 0, DWORD_PTR(d)); s = GetButtonText(d); SetWindowText(GetDlgItem(hWnd, IDC_IEKEYX), s.c_str()); d = new DialogData; d->setting = set.emulatorButtons[unsigned(InternalEmulatorButtonType::Y)]; SetWindowSubclass(GetDlgItem(hWnd, IDC_IEKEYY), InternalEmulatorInputDialogProc, 0, DWORD_PTR(d)); s = GetButtonText(d); SetWindowText(GetDlgItem(hWnd, IDC_IEKEYY), s.c_str()); d = new DialogData; d->setting = set.emulatorButtons[unsigned(InternalEmulatorButtonType::L)]; SetWindowSubclass(GetDlgItem(hWnd, IDC_IEKEYL), InternalEmulatorInputDialogProc, 0, DWORD_PTR(d)); s = GetButtonText(d); SetWindowText(GetDlgItem(hWnd, IDC_IEKEYL), s.c_str()); d = new DialogData; d->setting = set.emulatorButtons[unsigned(InternalEmulatorButtonType::R)]; SetWindowSubclass(GetDlgItem(hWnd, IDC_IEKEYR), InternalEmulatorInputDialogProc, 0, DWORD_PTR(d)); s = GetButtonText(d); SetWindowText(GetDlgItem(hWnd, IDC_IEKEYR), s.c_str()); d = new DialogData; d->setting = set.emulatorButtons[unsigned(InternalEmulatorButtonType::SELECT)]; SetWindowSubclass(GetDlgItem(hWnd, IDC_IEKEYSELECT), InternalEmulatorInputDialogProc, 0, DWORD_PTR(d)); s = GetButtonText(d); SetWindowText(GetDlgItem(hWnd, IDC_IEKEYSELECT), s.c_str()); d = new DialogData; d->setting = set.emulatorButtons[unsigned(InternalEmulatorButtonType::START)]; SetWindowSubclass(GetDlgItem(hWnd, IDC_IEKEYSTART), InternalEmulatorInputDialogProc, 0, DWORD_PTR(d)); s = GetButtonText(d); SetWindowText(GetDlgItem(hWnd, IDC_IEKEYSTART), s.c_str()); d = new DialogData; d->setting = set.emulatorButtons[unsigned(InternalEmulatorButtonType::NEXTSTATE)]; SetWindowSubclass(GetDlgItem(hWnd, IDC_IEKEYNEXTSTATE), InternalEmulatorInputDialogProc, 0, DWORD_PTR(d)); s = GetButtonText(d); SetWindowText(GetDlgItem(hWnd, IDC_IEKEYNEXTSTATE), s.c_str()); d = new DialogData; d->setting = set.emulatorButtons[unsigned(InternalEmulatorButtonType::PREVSTATE)]; SetWindowSubclass(GetDlgItem(hWnd, IDC_IEKEYPREVSTATE), InternalEmulatorInputDialogProc, 0, DWORD_PTR(d)); s = GetButtonText(d); SetWindowText(GetDlgItem(hWnd, IDC_IEKEYPREVSTATE), s.c_str()); d = new DialogData; d->setting = set.emulatorButtons[unsigned(InternalEmulatorButtonType::SAVESTATE)]; SetWindowSubclass(GetDlgItem(hWnd, IDC_IEKEYSAVESTATE), InternalEmulatorInputDialogProc, 0, DWORD_PTR(d)); s = GetButtonText(d); SetWindowText(GetDlgItem(hWnd, IDC_IEKEYSAVESTATE), s.c_str()); d = new DialogData; d->setting = set.emulatorButtons[unsigned(InternalEmulatorButtonType::LOADSTATE)]; SetWindowSubclass(GetDlgItem(hWnd, IDC_IEKEYLOADSTATE), InternalEmulatorInputDialogProc, 0, DWORD_PTR(d)); s = GetButtonText(d); SetWindowText(GetDlgItem(hWnd, IDC_IEKEYLOADSTATE), s.c_str()); d = new DialogData; d->setting = set.emulatorButtons[unsigned(InternalEmulatorButtonType::FASTFORWARD)]; SetWindowSubclass(GetDlgItem(hWnd, IDC_IEKEYFASTFORWARD), InternalEmulatorInputDialogProc, 0, DWORD_PTR(d)); s = GetButtonText(d); SetWindowText(GetDlgItem(hWnd, IDC_IEKEYFASTFORWARD), s.c_str()); SendMessage(GetDlgItem(hWnd, IDC_IEVOLUME), TBM_SETRANGEMIN, 0, DSBVOLUME_MIN + 10000); SendMessage(GetDlgItem(hWnd, IDC_IEVOLUME), TBM_SETRANGEMAX, 0, DSBVOLUME_MAX + 10000); SendMessage(GetDlgItem(hWnd, IDC_IEVOLUME), TBM_SETPOS, 1, set.volume + 10000); break; } case WM_COMMAND: { switch (LOWORD(wParam)) { case IDC_IESAVE: { DialogData *d; GetWindowSubclass(GetDlgItem(hWnd, IDC_IEKEYUP), InternalEmulatorInputDialogProc, NULL, (DWORD_PTR *)(&d)); set.emulatorButtons[unsigned(InternalEmulatorButtonType::UP)] = d->setting; GetWindowSubclass(GetDlgItem(hWnd, IDC_IEKEYDOWN), InternalEmulatorInputDialogProc, NULL, (DWORD_PTR *)(&d)); set.emulatorButtons[unsigned(InternalEmulatorButtonType::DOWN)] = d->setting; GetWindowSubclass(GetDlgItem(hWnd, IDC_IEKEYLEFT), InternalEmulatorInputDialogProc, NULL, (DWORD_PTR *)(&d)); set.emulatorButtons[unsigned(InternalEmulatorButtonType::LEFT)] = d->setting; GetWindowSubclass(GetDlgItem(hWnd, IDC_IEKEYRIGHT), InternalEmulatorInputDialogProc, NULL, (DWORD_PTR *)(&d)); set.emulatorButtons[unsigned(InternalEmulatorButtonType::RIGHT)] = d->setting; GetWindowSubclass(GetDlgItem(hWnd, IDC_IEKEYA), InternalEmulatorInputDialogProc, NULL, (DWORD_PTR *)(&d)); set.emulatorButtons[unsigned(InternalEmulatorButtonType::A)] = d->setting; GetWindowSubclass(GetDlgItem(hWnd, IDC_IEKEYB), InternalEmulatorInputDialogProc, NULL, (DWORD_PTR *)(&d)); set.emulatorButtons[unsigned(InternalEmulatorButtonType::B)] = d->setting; GetWindowSubclass(GetDlgItem(hWnd, IDC_IEKEYX), InternalEmulatorInputDialogProc, NULL, (DWORD_PTR *)(&d)); set.emulatorButtons[unsigned(InternalEmulatorButtonType::X)] = d->setting; GetWindowSubclass(GetDlgItem(hWnd, IDC_IEKEYY), InternalEmulatorInputDialogProc, NULL, (DWORD_PTR *)(&d)); set.emulatorButtons[unsigned(InternalEmulatorButtonType::Y)] = d->setting; GetWindowSubclass(GetDlgItem(hWnd, IDC_IEKEYL), InternalEmulatorInputDialogProc, NULL, (DWORD_PTR *)(&d)); set.emulatorButtons[unsigned(InternalEmulatorButtonType::L)] = d->setting; GetWindowSubclass(GetDlgItem(hWnd, IDC_IEKEYR), InternalEmulatorInputDialogProc, NULL, (DWORD_PTR *)(&d)); set.emulatorButtons[unsigned(InternalEmulatorButtonType::R)] = d->setting; GetWindowSubclass(GetDlgItem(hWnd, IDC_IEKEYSELECT), InternalEmulatorInputDialogProc, NULL, (DWORD_PTR *)(&d)); set.emulatorButtons[unsigned(InternalEmulatorButtonType::SELECT)] = d->setting; GetWindowSubclass(GetDlgItem(hWnd, IDC_IEKEYSTART), InternalEmulatorInputDialogProc, NULL, (DWORD_PTR *)(&d)); set.emulatorButtons[unsigned(InternalEmulatorButtonType::START)] = d->setting; GetWindowSubclass(GetDlgItem(hWnd, IDC_IEKEYNEXTSTATE), InternalEmulatorInputDialogProc, NULL, (DWORD_PTR *)(&d)); set.emulatorButtons[unsigned(InternalEmulatorButtonType::NEXTSTATE)] = d->setting; GetWindowSubclass(GetDlgItem(hWnd, IDC_IEKEYPREVSTATE), InternalEmulatorInputDialogProc, NULL, (DWORD_PTR *)(&d)); set.emulatorButtons[unsigned(InternalEmulatorButtonType::PREVSTATE)] = d->setting; GetWindowSubclass(GetDlgItem(hWnd, IDC_IEKEYSAVESTATE), InternalEmulatorInputDialogProc, NULL, (DWORD_PTR *)(&d)); set.emulatorButtons[unsigned(InternalEmulatorButtonType::SAVESTATE)] = d->setting; GetWindowSubclass(GetDlgItem(hWnd, IDC_IEKEYLOADSTATE), InternalEmulatorInputDialogProc, NULL, (DWORD_PTR *)(&d)); set.emulatorButtons[unsigned(InternalEmulatorButtonType::LOADSTATE)] = d->setting; GetWindowSubclass(GetDlgItem(hWnd, IDC_IEKEYFASTFORWARD), InternalEmulatorInputDialogProc, NULL, (DWORD_PTR *)(&d)); set.emulatorButtons[unsigned(InternalEmulatorButtonType::FASTFORWARD)] = d->setting; set.volume = SendMessage(GetDlgItem(hWnd, IDC_IEVOLUME), TBM_GETPOS, NULL, NULL) - 10000; set.joyNum = SendMessage(GetDlgItem(hWnd, IDC_IEJOYNUM), CB_GETCURSEL, 0, 0); DeleteState(hWnd); EndDialog(hWnd, 0); break; } case IDC_IECANCEL: { DeleteState(hWnd); EndDialog(hWnd, 0); break; } } break; } case WM_HSCROLL: { unsigned v = SendMessage(GetDlgItem(hWnd, IDC_IEVOLUME), TBM_GETPOS, NULL, NULL) - 10000; SetVolume(v); break; } case WM_CLOSE: { DeleteState(hWnd); EndDialog(hWnd, 0); break; } default: return FALSE; } return TRUE; }