From 7e287a08cee75965916ff9ef3500525c4ef9afe9 Mon Sep 17 00:00:00 2001 From: Willem Jan Palenstijn Date: Fri, 26 May 2006 17:38:12 +0000 Subject: replace agi/list.h by Common::List; cleanup svn-id: r22666 --- engines/agi/list.h | 140 --------------------------------- engines/agi/menu.cpp | 209 +++++++++++++++++++++---------------------------- engines/agi/sprite.cpp | 29 +++---- 3 files changed, 102 insertions(+), 276 deletions(-) delete mode 100644 engines/agi/list.h (limited to 'engines') diff --git a/engines/agi/list.h b/engines/agi/list.h deleted file mode 100644 index 440536362a..0000000000 --- a/engines/agi/list.h +++ /dev/null @@ -1,140 +0,0 @@ -/* - * $Id$ - * - * List management macros from the Linux kernel - */ - -#ifndef AGI_IST_H -#define AGI_LIST_H - -#include "agi/agi.h" - -namespace Agi { - -/** - * Simple doubly linked list implementation. - * - * Some of the internal functions ("__xxx") are useful when - * manipulating whole lists rather than single entries, as - * sometimes we already know the next/prev entries and we can - * generate better code by using them directly rather than - * using the generic single-entry routines. - */ - -struct list_head { - struct list_head *next, *prev; -}; - -#define LIST_HEAD_INIT(name) { &(name), &(name) } - -#define LIST_HEAD(name) \ - struct list_head name = LIST_HEAD_INIT(name) - -#define INIT_LIST_HEAD(ptr) do { \ - (ptr)->next = (ptr); (ptr)->prev = (ptr); \ -} while (0) - -/* - * Insert a new entry between two known consecutive entries. - * - * This is only for internal list manipulation where we know - * the prev/next entries already! - */ -static FORCEINLINE void __list_add(struct list_head *tnew, struct list_head *prev, struct list_head *next) { - next->prev = tnew; - tnew->next = next; - tnew->prev = prev; - prev->next = tnew; -} - -/** - * add a new entry - * Insert a new entry after the specified head. - * This is good for implementing stacks. - * - * @param new new entry to be added - * @param head list head to add it after - */ -static FORCEINLINE void list_add(struct list_head *tnew, struct list_head *head) { - __list_add(tnew, head, head->next); -} - -/** - * add a new entry - * Insert a new entry before the specified head. - * This is useful for implementing queues. - * - * @new: new entry to be added - * @head: list head to add it before - */ -static FORCEINLINE void list_add_tail(struct list_head *tnew, struct list_head *head) { - __list_add(tnew, head->prev, head); -} - -/** - * Delete a list entry (makes prev/next entries point to each other) - * - * This is only for internal list manipulation where we know - * the prev/next entries already! - */ -static FORCEINLINE void __list_del(struct list_head *prev, struct list_head *next) { - next->prev = prev; - prev->next = next; -} - -/** - * deletes entry from list. - * @param entry the element to delete from the list. - */ -static FORCEINLINE void list_del(struct list_head *entry) { - __list_del(entry->prev, entry->next); -} - -/** - * tests whether a list is empty - * @param head the list to test. - */ -static FORCEINLINE int list_empty(struct list_head *head) { - return head->next == head; -} - -/** - * join two lists - * @param list the new list to add. - * @param head the place to add it in the first list. - */ -static FORCEINLINE void list_splice(struct list_head *list, struct list_head *head) { - struct list_head *first = list->next; - - if (first != list) { - struct list_head *last = list->prev; - struct list_head *at = head->next; - - first->prev = head; - head->next = first; - - last->next = at; - at->prev = last; - } -} - -/** - * get the struct for this entry - * @param ptr the &struct list_head pointer. - * @param type the type of the struct this is embedded in. - * @param member the name of the list_struct within the struct. - */ -#define list_entry(ptr, type, member) \ - ((type *)((char *)(ptr)-(unsigned long)(&((type *)0)->member))) - -/** - * iterate over a list - * @param pos the &struct list_head to use as a loop counter. - * @param head the head for your list. - */ -#define list_for_each(pos, head, next) \ - for (pos = (head)->next; pos != (head); pos = pos->next) - -} // End of namespace Agi - -#endif /* AGI_LIST_H */ diff --git a/engines/agi/menu.cpp b/engines/agi/menu.cpp index 3d4cb76bfe..8253217f54 100644 --- a/engines/agi/menu.cpp +++ b/engines/agi/menu.cpp @@ -30,13 +30,21 @@ #include "agi/keyboard.h" #include "agi/menu.h" #include "agi/text.h" -#include "agi/list.h" +#include "common/list.h" namespace Agi { +struct agi_menu_option { + int enabled; /**< option is enabled or disabled */ + int event; /**< menu event */ + int index; /**< number of option in this menu */ + char *text; /**< text of menu option */ +}; + +typedef Common::List MenuOptionList; + struct agi_menu { - struct list_head list; /**< list head for menubar list */ - struct list_head down; /**< list head for menu options */ + MenuOptionList down; /**< list head for menu options */ int index; /**< number of menu in menubar */ int width; /**< width of menu in characters */ int height; /**< height of menu in characters */ @@ -45,40 +53,28 @@ struct agi_menu { char *text; /**< menu name */ }; -struct agi_menu_option { - struct list_head list; /**< list head for menu options */ - int enabled; /**< option is enabled or disabled */ - int event; /**< menu event */ - int index; /**< number of option in this menu */ - char *text; /**< text of menu option */ -}; +typedef Common::List MenuList; -static LIST_HEAD(menubar); +static MenuList menubar; static int h_cur_menu; static int v_cur_menu; -static struct agi_menu *get_menu(int i) { - struct list_head *h; - struct agi_menu *m; - - list_for_each(h, &menubar, next) { - m = list_entry(h, struct agi_menu, list); +static agi_menu *get_menu(int i) { + MenuList::iterator iter; + for (iter = menubar.begin(); iter != menubar.end(); ++iter) { + agi_menu *m = *iter; if (m->index == i) return m; } return NULL; } -static struct agi_menu_option *get_menu_option(int i, int j) { - struct list_head *h; - struct agi_menu *m; - struct agi_menu_option *d; - - m = get_menu(i); - - list_for_each(h, &m->down, next) { - d = list_entry(h, struct agi_menu_option, list); +static agi_menu_option *get_menu_option(int i, int j) { + agi_menu *m = get_menu(i); + MenuOptionList::iterator iter; + for (iter = m->down.begin(); iter != m->down.end(); ++iter) { + agi_menu_option* d = *iter; if (d->index == j) return d; } @@ -87,23 +83,19 @@ static struct agi_menu_option *get_menu_option(int i, int j) { } static void draw_menu_bar() { - struct list_head *h; - struct agi_menu *m; - clear_lines(0, 0, MENU_BG); flush_lines(0, 0); - list_for_each(h, &menubar, next) { - m = list_entry(h, struct agi_menu, list); + MenuList::iterator iter; + for (iter = menubar.begin(); iter != menubar.end(); ++iter) { + agi_menu *m = *iter; print_text(m->text, 0, m->col, 0, 40, MENU_FG, MENU_BG); } } static void draw_menu_hilite(int cur_menu) { - struct agi_menu *m; - - m = get_menu(cur_menu); + agi_menu *m = get_menu(cur_menu); debugC(6, kDebugLevelMenu, "[%s]", m->text); print_text(m->text, 0, m->col, 0, 40, MENU_BG, MENU_FG); flush_lines(0, 0); @@ -111,29 +103,23 @@ static void draw_menu_hilite(int cur_menu) { /* draw box and pulldowns. */ static void draw_menu_option(int h_menu) { - struct list_head *h; - struct agi_menu *m = NULL; - struct agi_menu_option *d = NULL; - /* find which vertical menu it is */ - m = get_menu(h_menu); + agi_menu *m = get_menu(h_menu); draw_box(m->wincol * CHAR_COLS, 1 * CHAR_LINES, (m->wincol + m->width + 2) * CHAR_COLS, (1 + m->height + 2) * CHAR_LINES, MENU_BG, MENU_LINE, 0); - list_for_each(h, &m->down, next) { - d = list_entry(h, struct agi_menu_option, list); + MenuOptionList::iterator iter; + for (iter = m->down.begin(); iter != m->down.end(); ++iter) { + agi_menu_option* d = *iter; print_text(d->text, 0, m->wincol + 1, d->index + 2, m->width + 2, d->enabled ? MENU_FG : MENU_DISABLED, MENU_BG); } } static void draw_menu_option_hilite(int h_menu, int v_menu) { - struct agi_menu *m; - struct agi_menu_option *d; - - m = get_menu(h_menu); - d = get_menu_option(h_menu, v_menu); + agi_menu *m = get_menu(h_menu); + agi_menu_option *d = get_menu_option(h_menu, v_menu); print_text(d->text, 0, m->wincol + 1, v_menu + 2, m->width + 2, MENU_BG, d->enabled ? MENU_FG : MENU_DISABLED); @@ -170,20 +156,18 @@ static int v_max_menu[10]; #if 0 static void add_about_option() { - struct agi_menu *m; - struct agi_menu_option *d; - char text[] = "About AGI engine"; + const char *text = "About AGI engine"; - d = malloc(sizeof(struct agi_menu_option)); + agi_menu_option *d = new agi_menu_option; d->text = strdup(text); d->enabled = true; d->event = 255; d->index = (v_max_menu[0] += 1); - m = list_entry(menubar.next, struct agi_menu, list); - list_add_tail(&d->list, &m->down); + agi_menu *m = *menubar.begin(); + m->down.push_back(d); m->height++; - if (m->width < strlen(text)) + if (m->width < (int)strlen(text)) m->width = strlen(text); } #endif @@ -200,37 +184,29 @@ void menu_init() { } void menu_deinit() { - struct list_head *h, *h2, *v, *v2; - struct agi_menu *m = NULL; - struct agi_menu_option *d = NULL; - - for (h = (&menubar)->prev; h != (&menubar); h = h2) { - m = list_entry(h, struct agi_menu, list); - h2 = h->prev; + MenuList::iterator iterh; + for (iterh = menubar.reverse_begin(); iterh != menubar.end(); ) { + agi_menu *m = *iterh; debugC(3, kDebugLevelMenu, "deiniting hmenu %s", m->text); - for (v = (&m->down)->prev; v != (&m->down); v = v2) { - d = list_entry(v, struct agi_menu_option, list); - v2 = v->prev; + MenuOptionList::iterator iterv; + for (iterv = m->down.reverse_begin(); iterv != m->down.end(); ) { + agi_menu_option *d = *iterv; debugC(3, kDebugLevelMenu, " deiniting vmenu %s", d->text); - list_del(v); free(d->text); - free(d); + delete d; + iterv = m->down.reverse_erase(iterv); } - list_del(h); free(m->text); - free(m); + delete m; + iterh = menubar.reverse_erase(iterh); } } void menu_add(char *s) { - struct agi_menu *m; - - m = (agi_menu *) malloc(sizeof(struct agi_menu)); + agi_menu *m = new agi_menu; m->text = strdup(s); while (m->text[strlen(m->text) - 1] == ' ') m->text[strlen(m->text) - 1] = 0; - m->down.next = &m->down; - m->down.prev = &m->down; m->width = 0; m->height = 0; m->index = h_index++; @@ -242,21 +218,21 @@ void menu_add(char *s) { h_max_menu = m->index; debugC(3, kDebugLevelMenu, "add menu: '%s' %02x", s, m->text[strlen(m->text)]); - list_add_tail(&m->list, &menubar); + menubar.push_back(m); } void menu_add_item(char *s, int code) { - struct agi_menu *m; - struct agi_menu_option *d; int l; - d = (agi_menu_option *) malloc(sizeof(struct agi_menu_option)); + agi_menu_option* d = new agi_menu_option; d->text = strdup(s); d->enabled = true; d->event = code; d->index = v_index++; - m = list_entry(menubar.prev, struct agi_menu, list); + // add to last menu in list + assert(menubar.reverse_begin() != menubar.end()); + agi_menu *m = *menubar.reverse_begin(); m->height++; v_max_menu[m->index] = d->index; @@ -270,26 +246,25 @@ void menu_add_item(char *s, int code) { m->width = l; debugC(3, kDebugLevelMenu, "Adding menu item: %s (size = %d)", s, m->height); - list_add_tail(&d->list, &m->down); + m->down.push_back(d); } void menu_submit() { - struct list_head *h, *h2; - struct agi_menu *m = NULL; - debugC(3, kDebugLevelMenu, "Submitting menu"); /* add_about_option (); */ /* If a menu has no options, delete it */ - for (h = (&menubar)->prev; h != (&menubar); h = h2) { - m = list_entry(h, struct agi_menu, list); - h2 = h->prev; - if ((&m->down)->prev == (&m->down)) { - list_del(h); + MenuList::iterator iter; + for (iter = menubar.reverse_begin(); iter != menubar.end(); ) { + agi_menu *m = *iter; + if (m->down.empty()) { free(m->text); - free(m); + delete m; h_max_menu--; + iter = menubar.reverse_erase(iter); + } else { + --iter; } } } @@ -297,9 +272,6 @@ void menu_submit() { int menu_keyhandler(int key) { static int clock_val; static int menu_active = false; - struct agi_menu_option *d; - struct list_head *h; - struct agi_menu *m; static int button_used = 0; if (!getflag(F_menus_work)) @@ -321,8 +293,9 @@ int menu_keyhandler(int key) { /* on the menubar */ hmenu = 0; - list_for_each(h, &menubar, next) { - m = list_entry(h, struct agi_menu, list); + MenuList::iterator iterh; + for (iterh = menubar.begin(); iterh != menubar.end(); ++iterh) { + agi_menu *m = *iterh; if (mouse_over_text(0, m->col, m->text)) { break; } else { @@ -339,13 +312,12 @@ int menu_keyhandler(int key) { } } else { /* not in menubar */ - struct agi_menu_option *do1; - vmenu = 0; - m = get_menu(h_cur_menu); - list_for_each(h, &m->down, next) { - do1 = list_entry(h, struct agi_menu_option, list); + agi_menu *m = get_menu(h_cur_menu); + MenuOptionList::iterator iterv; + for (iterv = m->down.begin(); iterv != m->down.end(); ++iterv) { + agi_menu_option *do1 = *iterv; if (mouse_over_text(2 + do1->index, m->wincol + 1, do1->text)) { break; } else { @@ -376,11 +348,11 @@ int menu_keyhandler(int key) { /* on the menubar */ } else { /* see which option we selected */ - m = get_menu(h_cur_menu); - list_for_each(h, &m->down, next) { - d = list_entry(h, struct agi_menu_option, list); - if (mouse_over_text(2 + d->index, - m->wincol + 1, d->text)) { + agi_menu *m = get_menu(h_cur_menu); + MenuOptionList::iterator iterv; + for (iterv = m->down.begin(); iterv != m->down.end(); ++iterv) { + agi_menu_option *d = *iterv; + if (mouse_over_text(2 + d->index, m->wincol + 1, d->text)) { /* activate that option */ if (d->enabled) { debugC(6, kDebugLevelMenu | kDebugLevelInput, "event %d registered", d->event); @@ -409,14 +381,16 @@ int menu_keyhandler(int key) { debugC(6, kDebugLevelMenu | kDebugLevelInput, "KEY_ESCAPE"); goto exit_menu; case KEY_ENTER: + { debugC(6, kDebugLevelMenu | kDebugLevelInput, "KEY_ENTER"); - d = get_menu_option(h_cur_menu, v_cur_menu); + agi_menu_option* d = get_menu_option(h_cur_menu, v_cur_menu); if (d->enabled) { debugC(6, kDebugLevelMenu | kDebugLevelInput, "event %d registered", d->event); game.ev_keyp[d->event].occured = true; goto exit_menu; } break; + } case KEY_DOWN: case KEY_UP: v_cur_menu += key == KEY_DOWN ? 1 : -1; @@ -462,17 +436,15 @@ exit_menu: } void menu_set_item(int event, int state) { - struct list_head *h, *v; - struct agi_menu *m = NULL; - struct agi_menu_option *d = NULL; - /* scan all menus for event number # */ debugC(6, kDebugLevelMenu, "event = %d, state = %d", event, state); - list_for_each(h, &menubar, next) { - m = list_entry(h, struct agi_menu, list); - list_for_each(v, &m->down, next) { - d = list_entry(v, struct agi_menu_option, list); + MenuList::iterator iterh; + for (iterh = menubar.begin(); iterh != menubar.end(); ++iterh) { + agi_menu *m = *iterh; + MenuOptionList::iterator iterv; + for (iterv = m->down.begin(); iterv != m->down.end(); ++iterv) { + agi_menu_option *d = *iterv; if (d->event == event) { d->enabled = state; return; @@ -482,18 +454,15 @@ void menu_set_item(int event, int state) { } void menu_enable_all() { - struct list_head *h, *v; - struct agi_menu *m = NULL; - struct agi_menu_option *d = NULL; - - list_for_each(h, &menubar, next) { - m = list_entry(h, struct agi_menu, list); - list_for_each(v, &m->down, next) { - d = list_entry(v, struct agi_menu_option, list); + MenuList::iterator iterh; + for (iterh = menubar.begin(); iterh != menubar.end(); ++iterh) { + agi_menu *m = *iterh; + MenuOptionList::iterator iterv; + for (iterv = m->down.begin(); iterv != m->down.end(); ++iterv) { + agi_menu_option *d = *iterv; d->enabled = true; } } - } } // End of namespace Agi diff --git a/engines/agi/sprite.cpp b/engines/agi/sprite.cpp index ca125f038a..32574192e7 100644 --- a/engines/agi/sprite.cpp +++ b/engines/agi/sprite.cpp @@ -433,16 +433,14 @@ static void build_nonupd_blitlist() { * Clear the given sprite list. */ static void free_list(SpriteList& l) { - SpriteList::iterator i; - for (i = l.end(); i != l.begin();) { - --i; - sprite* s = *i; + SpriteList::iterator iter; + for (iter = l.reverse_begin(); iter != l.end(); ) { + sprite* s = *iter; pool_release(s->hires); pool_release(s->buffer); pool_release(s); + iter = l.reverse_erase(iter); } - - l.clear(); } /** @@ -450,9 +448,9 @@ static void free_list(SpriteList& l) { * sprites of the given list have moved. */ static void commit_sprites(SpriteList& l) { - SpriteList::iterator i; - for (i = l.begin(); i != l.end(); ++i) { - sprite *s = *i; + SpriteList::iterator iter; + for (iter = l.begin(); iter != l.end(); ++iter) { + sprite *s = *iter; int x1, y1, x2, y2, w, h; w = (s->v->cel_data->width > s->v->cel_data_2->width) ? @@ -500,10 +498,9 @@ static void commit_sprites(SpriteList& l) { * Erase all sprites in the given list. */ static void erase_sprites(SpriteList& l) { - SpriteList::iterator i; - for (i = l.end(); i != l.begin(); ) { - --i; - sprite *s = *i; + SpriteList::iterator iter; + for (iter = l.reverse_begin(); iter != l.end(); --iter) { + sprite *s = *iter; objs_restorearea(s); } @@ -515,9 +512,9 @@ static void erase_sprites(SpriteList& l) { */ static void blit_sprites(SpriteList& l) { int hidden; - SpriteList::iterator i; - for (i = l.begin(); i != l.end(); ++i) { - sprite *s = *i; + SpriteList::iterator iter; + for (iter = l.begin(); iter != l.end(); ++iter) { + sprite *s = *iter; objs_savearea(s); debugC(8, kDebugLevelSprites, "s->v->entry = %d (prio %d)", s->v->entry, s->v->priority); hidden = blit_cel(s->x_pos, s->y_pos, s->v->priority, s->v->cel_data); -- cgit v1.2.3