# HG changeset patch # User Matti Hamalainen # Date 1316869173 -10800 # Node ID a68786b9c74b92076b04f028cd03a5271b61c01a # Parent 594dea11ccd964d7b07b8e063c7de6cfb295e236 Oops, used indent with tabs enabled. Remove tabs. diff -r 594dea11ccd9 -r a68786b9c74b src/_edit.h --- a/src/_edit.h Sat Sep 24 15:01:56 2011 +0300 +++ b/src/_edit.h Sat Sep 24 15:59:33 2011 +0300 @@ -1,6 +1,6 @@ /* - * _edit.h - * AYM 1998-09-06 + * _edit.h + * AYM 1998-09-06 */ @@ -27,7 +27,7 @@ */ -#ifndef YH__EDIT /* DO NOT INSERT ANYTHING BEFORE THIS LINE */ +#ifndef YH__EDIT /* DO NOT INSERT ANYTHING BEFORE THIS LINE */ #define YH__EDIT @@ -64,7 +64,7 @@ MBM_EDIT, MBM_VIEW, MBM_SEARCH, - MBM_MISC_L, // The "Misc. operations" menus changes with the mode + MBM_MISC_L, // The "Misc. operations" menus changes with the mode MBM_MISC_S, MBM_MISC_T, MBM_MISC_V, @@ -86,43 +86,43 @@ // FIXME: make a class of it. typedef struct { - public:int mb_ino[MBI_COUNT]; // The numbers of the items on the menu bar - Menu *mb_menu[MBM_COUNT]; // The actual menu objects + public:int mb_ino[MBI_COUNT]; // The numbers of the items on the menu bar + Menu *mb_menu[MBM_COUNT]; // The actual menu objects - int move_speed; // Movement speed. - int extra_zoom; // Act like the zoom was 4 times what it is - int obj_type; // The mode (OBJ_LINEDEF, OBJ_SECTOR...) - bool global; // Global mode (experimental) - tool_t tool; // The current tool - int grid_step; // The grid step - int grid_step_min; // The floor of the grid step - int grid_step_max; // The ceiling of the grid step - int grid_step_locked; // Whether the grid step is locked - int grid_shown; // Whether the grid is shown - int grid_snap; // Whether objects forced to be on the grid - bool infobar_shown; // Whether the info bar is shown - bool objinfo_shown; // Whether the object info boxes are shown - bool show_object_numbers; // Whether the object numbers are shown - bool show_things_squares; // Whether the things squares are shown - bool show_things_sprites; // Whether the things sprites are shown - int rulers_shown; // Whether the rulers are shown (unused ?) - int pointer_x; // Map coordinates of pointer + int move_speed; // Movement speed. + int extra_zoom; // Act like the zoom was 4 times what it is + int obj_type; // The mode (OBJ_LINEDEF, OBJ_SECTOR...) + bool global; // Global mode (experimental) + tool_t tool; // The current tool + int grid_step; // The grid step + int grid_step_min; // The floor of the grid step + int grid_step_max; // The ceiling of the grid step + int grid_step_locked; // Whether the grid step is locked + int grid_shown; // Whether the grid is shown + int grid_snap; // Whether objects forced to be on the grid + bool infobar_shown; // Whether the info bar is shown + bool objinfo_shown; // Whether the object info boxes are shown + bool show_object_numbers; // Whether the object numbers are shown + bool show_things_squares; // Whether the things squares are shown + bool show_things_sprites; // Whether the things sprites are shown + int rulers_shown; // Whether the rulers are shown (unused ?) + int pointer_x; // Map coordinates of pointer int pointer_y; - int pointer_in_window; // If false, pointer_[xy] are not meaningful. - Objid clicked; // The object that was under the pointer when + int pointer_in_window; // If false, pointer_[xy] are not meaningful. + Objid clicked; // The object that was under the pointer when // when the left click occurred. If clicked on // empty space, == CANVAS. - int click_ctrl; // Was Ctrl pressed at the moment of the click? - unsigned long click_time; // Date of last left click in ms - Objid highlighted; // The highlighted object - SelPtr Selected; // Linked list of selected objects (or NULL) + int click_ctrl; // Was Ctrl pressed at the moment of the click? + unsigned long click_time; // Date of last left click in ms + Objid highlighted; // The highlighted object + SelPtr Selected; // Linked list of selected objects (or NULL) - selbox_c *selbox; // The selection box - edisplay_c *edisplay; // The display manager - menubar_c *menubar; // The menu bar - spot_c *spot; // The insertion spot + selbox_c *selbox; // The selection box + edisplay_c *edisplay; // The display manager + menubar_c *menubar; // The menu bar + spot_c *spot; // The insertion spot - modpopup_c *modpopup; // The modal popup menu (only one at a time!) + modpopup_c *modpopup; // The modal popup menu (only one at a time!) char modal; } edit_t; diff -r 594dea11ccd9 -r a68786b9c74b src/acolours.cc --- a/src/acolours.cc Sat Sep 24 15:01:56 2011 +0300 +++ b/src/acolours.cc Sat Sep 24 15:59:33 2011 +0300 @@ -1,16 +1,16 @@ /* - * acolours.cc - * Allocate and free the application colours. + * acolours.cc + * Allocate and free the application colours. * - * By "application colours", I mean the colours used to draw - * the windows, the menus and the map, as opposed to the - * "game colours" which depend on the game (they're in the - * PLAYPAL lump) and are used to draw the game graphics - * (flats, textures, sprites...). + * By "application colours", I mean the colours used to draw + * the windows, the menus and the map, as opposed to the + * "game colours" which depend on the game (they're in the + * PLAYPAL lump) and are used to draw the game graphics + * (flats, textures, sprites...). * - * The game colours are handled in gcolour1.cc and gcolour2.cc. + * The game colours are handled in gcolour1.cc and gcolour2.cc. * - * AYM 1998-11-29 + * AYM 1998-11-29 */ @@ -49,31 +49,31 @@ char deleted; } ac_table_entry_t; -static ac_table_entry_t *table = 0; // The list -static acolour_t table_size = 0; // The size of the list -static acolour_t ac_count = 0; // The number of entries really used +static ac_table_entry_t *table = 0; // The list +static acolour_t table_size = 0; // The size of the list +static acolour_t ac_count = 0; // The number of entries really used /* - * add_app_colour - * Add colour to the list of application colours - * and return a brand new application colour# for it. + * add_app_colour + * Add colour to the list of application colours + * and return a brand new application colour# for it. */ pcolour_t add_app_colour(rgb_c rgb) { size_t i; for (i = 0; i < table_size; i++) - if (table[i].deleted) - break; + if (table[i].deleted) + break; if (i == table_size) { - table_size++; - table = - (ac_table_entry_t *) realloc(table, table_size * sizeof *table); - if (table == NULL) - fatal_error(msg_nomem); + table_size++; + table = + (ac_table_entry_t *) realloc(table, table_size * sizeof *table); + if (table == NULL) + fatal_error(msg_nomem); } ac_count++; table[i].rgb = rgb; @@ -83,16 +83,16 @@ /* - * delete_app_colour - * Remove colour# from the list of application colours. + * delete_app_colour + * Remove colour# from the list of application colours. */ void delete_app_colour(acolour_t acn) { if (acn >= table_size) - fatal_error("delete_app_colour called with non-existent colour %d", - acn); + fatal_error("delete_app_colour called with non-existent colour %d", + acn); if (table[acn].deleted) - fatal_error("colour %d deleted twice", acn); + fatal_error("colour %d deleted twice", acn); ac_count--; table[acn].deleted = 1; } @@ -105,9 +105,9 @@ /* - * commit_app_colours - * Return an array containing the physical colour numbers - * for the application colours in the list. + * commit_app_colours + * Return an array containing the physical colour numbers + * for the application colours in the list. */ pcolour_t *commit_app_colours() { @@ -120,20 +120,20 @@ rgb_c *rgb = rgb_values; int items_on_line = 0; for (size_t n = 0; n < table_size; n++) - if (!table[n].deleted) - { - if (items_on_line == 0) - verbmsg("colours: committing: "); - verbmsg("%d ", int (rgb - rgb_values)); - *rgb++ = table[n].rgb; - if (++items_on_line == 16) - { - verbmsg("\n"); - items_on_line = 0; - } - } + if (!table[n].deleted) + { + if (items_on_line == 0) + verbmsg("colours: committing: "); + verbmsg("%d ", int (rgb - rgb_values)); + *rgb++ = table[n].rgb; + if (++items_on_line == 16) + { + verbmsg("\n"); + items_on_line = 0; + } + } if (items_on_line != 0) - verbmsg("\n"); + verbmsg("\n"); // Then do the actual allocation. committed_colours = ac_count; @@ -144,9 +144,9 @@ /* - * uncommit_app_colours - * Free all the colours that were allocated by alloc_app_colours(). - * They are _not_ removed from the list ! + * uncommit_app_colours + * Free all the colours that were allocated by alloc_app_colours(). + * They are _not_ removed from the list ! */ void uncommit_app_colours(pcolour_t * app_colours) { diff -r 594dea11ccd9 -r a68786b9c74b src/acolours.h --- a/src/acolours.h Sat Sep 24 15:01:56 2011 +0300 +++ b/src/acolours.h Sat Sep 24 15:59:33 2011 +0300 @@ -1,16 +1,16 @@ /* - * acolours.h - * Allocate and free the application colours. + * acolours.h + * Allocate and free the application colours. * - * By "application colours", I mean the colours used to draw - * the windows, the menus and the map, as opposed to the - * "game colours" which depend on the game (they're in the - * PLAYPAL lump) and are used to draw the game graphics - * (flats, textures, sprites...). + * By "application colours", I mean the colours used to draw + * the windows, the menus and the map, as opposed to the + * "game colours" which depend on the game (they're in the + * PLAYPAL lump) and are used to draw the game graphics + * (flats, textures, sprites...). * - * The game colours are handled in gcolour1.cc and gcolour2.cc. + * The game colours are handled in gcolour1.cc and gcolour2.cc. * - * AYM 1998-11-29 + * AYM 1998-11-29 */ diff -r 594dea11ccd9 -r a68786b9c74b src/aym.cc --- a/src/aym.cc Sat Sep 24 15:01:56 2011 +0300 +++ b/src/aym.cc Sat Sep 24 15:59:33 2011 +0300 @@ -1,7 +1,7 @@ /* - * aym.cc - * Misc. functions - * AYM 1997-??-?? + * aym.cc + * Misc. functions + * AYM 1997-??-?? */ @@ -33,79 +33,79 @@ /* - * levelname2levelno - * Used to know if directory entry is ExMy or MAPxy - * For "ExMy" (case-insensitive), returns 10x + y - * For "ExMyz" (case-insensitive), returns 100*x + 10y + z - * For "MAPxy" (case-insensitive), returns 1000 + 10x + y - * E0My, ExM0, E0Myz, ExM0z are not considered valid names. - * MAP00 is considered a valid name. - * For other names, returns 0. + * levelname2levelno + * Used to know if directory entry is ExMy or MAPxy + * For "ExMy" (case-insensitive), returns 10x + y + * For "ExMyz" (case-insensitive), returns 100*x + 10y + z + * For "MAPxy" (case-insensitive), returns 1000 + 10x + y + * E0My, ExM0, E0Myz, ExM0z are not considered valid names. + * MAP00 is considered a valid name. + * For other names, returns 0. */ int levelname2levelno(const char *name) { const unsigned char *s = (const unsigned char *) name; if (toupper(s[0]) == 'E' - && isdigit(s[1]) - && s[1] != '0' - && toupper(s[2]) == 'M' - && isdigit(s[3]) && s[3] != '0' && s[4] == '\0') - return 10 * dectoi(s[1]) + dectoi(s[3]); + && isdigit(s[1]) + && s[1] != '0' + && toupper(s[2]) == 'M' + && isdigit(s[3]) && s[3] != '0' && s[4] == '\0') + return 10 * dectoi(s[1]) + dectoi(s[3]); if (yg_level_name == YGLN_E1M10 - && toupper(s[0]) == 'E' - && isdigit(s[1]) - && s[1] != '0' - && toupper(s[2]) == 'M' - && isdigit(s[3]) && s[3] != '0' && isdigit(s[4]) && s[5] == '\0') - return 100 * dectoi(s[1]) + 10 * dectoi(s[3]) + dectoi(s[4]); + && toupper(s[0]) == 'E' + && isdigit(s[1]) + && s[1] != '0' + && toupper(s[2]) == 'M' + && isdigit(s[3]) && s[3] != '0' && isdigit(s[4]) && s[5] == '\0') + return 100 * dectoi(s[1]) + 10 * dectoi(s[3]) + dectoi(s[4]); if (toupper(s[0]) == 'M' - && toupper(s[1]) == 'A' - && toupper(s[2]) == 'P' - && isdigit(s[3]) && isdigit(s[4]) && s[5] == '\0') - return 1000 + 10 * dectoi(s[3]) + dectoi(s[4]); + && toupper(s[1]) == 'A' + && toupper(s[2]) == 'P' + && isdigit(s[3]) && isdigit(s[4]) && s[5] == '\0') + return 1000 + 10 * dectoi(s[3]) + dectoi(s[4]); return 0; } /* - * levelname2rank - * Used to sort level names. - * Identical to levelname2levelno except that, for "ExMy", - * it returns 100x + y, so that - * - f("E1M10") = f("E1M9") + 1 - * - f("E2M1") > f("E1M99") - * - f("E2M1") > f("E1M99") + 1 - * - f("MAPxy") > f("ExMy") - * - f("MAPxy") > f("ExMyz") + * levelname2rank + * Used to sort level names. + * Identical to levelname2levelno except that, for "ExMy", + * it returns 100x + y, so that + * - f("E1M10") = f("E1M9") + 1 + * - f("E2M1") > f("E1M99") + * - f("E2M1") > f("E1M99") + 1 + * - f("MAPxy") > f("ExMy") + * - f("MAPxy") > f("ExMyz") */ int levelname2rank(const char *name) { const unsigned char *s = (const unsigned char *) name; if (toupper(s[0]) == 'E' - && isdigit(s[1]) - && s[1] != '0' - && toupper(s[2]) == 'M' - && isdigit(s[3]) && s[3] != '0' && s[4] == '\0') - return 100 * dectoi(s[1]) + dectoi(s[3]); + && isdigit(s[1]) + && s[1] != '0' + && toupper(s[2]) == 'M' + && isdigit(s[3]) && s[3] != '0' && s[4] == '\0') + return 100 * dectoi(s[1]) + dectoi(s[3]); if (yg_level_name == YGLN_E1M10 - && toupper(s[0]) == 'E' - && isdigit(s[1]) - && s[1] != '0' - && toupper(s[2]) == 'M' - && isdigit(s[3]) && s[3] != '0' && isdigit(s[4]) && s[5] == '\0') - return 100 * dectoi(s[1]) + 10 * dectoi(s[3]) + dectoi(s[4]); + && toupper(s[0]) == 'E' + && isdigit(s[1]) + && s[1] != '0' + && toupper(s[2]) == 'M' + && isdigit(s[3]) && s[3] != '0' && isdigit(s[4]) && s[5] == '\0') + return 100 * dectoi(s[1]) + 10 * dectoi(s[3]) + dectoi(s[4]); if (toupper(s[0]) == 'M' - && toupper(s[1]) == 'A' - && toupper(s[2]) == 'P' - && isdigit(s[3]) && isdigit(s[4]) && s[5] == '\0') - return 1000 + 10 * dectoi(s[3]) + dectoi(s[4]); + && toupper(s[1]) == 'A' + && toupper(s[2]) == 'P' + && isdigit(s[3]) && isdigit(s[4]) && s[5] == '\0') + return 1000 + 10 * dectoi(s[3]) + dectoi(s[4]); return 0; } /* - * spec_path - * Extract the path of a spec + * spec_path + * Extract the path of a spec */ const char *spec_path(const char *spec) { @@ -115,18 +115,18 @@ *path = '\0'; strncat(path, spec, sizeof path - 1); for (n = strlen(path); n > 0 && !al_fisps(path[n - 1]); n--) - ; + ; path[n] = '\0'; return path; } /* - * fncmp - * Compare two filenames - * For Unix, it's a simple strcmp. - * For DOS, it's case insensitive and "/" and "\" are equivalent. - * FIXME: should canonicalize both names and compare that. + * fncmp + * Compare two filenames + * For Unix, it's a simple strcmp. + * For DOS, it's case insensitive and "/" and "\" are equivalent. + * FIXME: should canonicalize both names and compare that. */ int fncmp(const char *name1, const char *name2) { @@ -134,16 +134,16 @@ char c1, c2; for (;;) { - c1 = tolower((unsigned char) *name1++); - c2 = tolower((unsigned char) *name2++); - if (c1 == '\\') - c1 = '/'; - if (c2 == '\\') - c2 = '/'; - if (c1 != c2) - return c1 - c2; - if (!c1) - return 0; + c1 = tolower((unsigned char) *name1++); + c2 = tolower((unsigned char) *name2++); + if (c1 == '\\') + c1 = '/'; + if (c2 == '\\') + c2 = '/'; + if (c1 != c2) + return c1 - c2; + if (!c1) + return 0; } #elif defined Y_UNIX return strcmp(name1, name2); @@ -152,15 +152,15 @@ /* - * is_absolute - * Tell whether a file name is absolute or relative. + * is_absolute + * Tell whether a file name is absolute or relative. * - * Note: for DOS, a filename of the form "d:foo" is - * considered absolute, even though it's technically - * relative to the current working directory of "d:". - * My reasoning is that someone who wants to specify a - * name that's relative to one of the standard - * directories is not going to put a "d:" in front of it. + * Note: for DOS, a filename of the form "d:foo" is + * considered absolute, even though it's technically + * relative to the current working directory of "d:". + * My reasoning is that someone who wants to specify a + * name that's relative to one of the standard + * directories is not going to put a "d:" in front of it. */ int is_absolute(const char *filename) { @@ -168,57 +168,57 @@ return *filename == '/'; #elif defined Y_DOS return *filename == '/' - || *filename == '\\' || isalpha(*filename) && filename[1] == ':'; + || *filename == '\\' || isalpha(*filename) && filename[1] == ':'; #endif } /* - * y_stricmp - * A case-insensitive strcmp() - * (same thing as DOS stricmp() or GNU strcasecmp()) + * y_stricmp + * A case-insensitive strcmp() + * (same thing as DOS stricmp() or GNU strcasecmp()) */ int y_stricmp(const char *s1, const char *s2) { for (;;) { - if (tolower(*s1) != tolower(*s2)) - return (unsigned char) *s1 - (unsigned char) *s2; - if (!*s1) - return *s2 ? -1 : 0; - if (!*s2) - return 1; - s1++; - s2++; + if (tolower(*s1) != tolower(*s2)) + return (unsigned char) *s1 - (unsigned char) *s2; + if (!*s1) + return *s2 ? -1 : 0; + if (!*s2) + return 1; + s1++; + s2++; } } /* - * y_strnicmp - * A case-insensitive strncmp() - * (same thing as DOS strnicmp() or GNU strncasecmp()) + * y_strnicmp + * A case-insensitive strncmp() + * (same thing as DOS strnicmp() or GNU strncasecmp()) */ int y_strnicmp(const char *s1, const char *s2, size_t len) { while (len-- > 0) { - if (tolower(*s1) != tolower(*s2)) - return (unsigned char) *s1 - (unsigned char) *s2; - if (!*s1) - return *s2 ? -1 : 0; - if (!*s2) - return 1; - s1++; - s2++; + if (tolower(*s1) != tolower(*s2)) + return (unsigned char) *s1 - (unsigned char) *s2; + if (!*s1) + return *s2 ? -1 : 0; + if (!*s2) + return 1; + s1++; + s2++; } return 0; } /* - * y_snprintf - * If available, snprintf(). Else sprintf(). + * y_snprintf + * If available, snprintf(). Else sprintf(). */ int y_snprintf(char *buf, size_t size, const char *fmt, ...) { @@ -233,8 +233,8 @@ /* - * y_vsnprintf - * If available, vsnprintf(). Else vsprintf(). + * y_vsnprintf + * If available, vsnprintf(). Else vsprintf(). */ int y_vsnprintf(char *buf, size_t size, const char *fmt, va_list args) { @@ -247,24 +247,24 @@ /* - * y_strupr - * Upper-case a string + * y_strupr + * Upper-case a string */ void y_strupr(char *string) { while (*string) { - *string = toupper(*string); - string++; + *string = toupper(*string); + string++; } } /* - * is_one_of - * Return non-zero if is equal (in the strcmp() sense) - * to one of the other strings (retrieved from the argument - * list as const char *). The last string must be followed - * by (const char *) 0. + * is_one_of + * Return non-zero if is equal (in the strcmp() sense) + * to one of the other strings (retrieved from the argument + * list as const char *). The last string must be followed + * by (const char *) 0. */ int is_one_of(const char *needle, ...) { @@ -272,11 +272,11 @@ va_start(args, needle); for (;;) { - const char *haystack = va_arg(args, const char *); - if (haystack == Y_NULL) - break; - if (!strcmp(needle, haystack)) - return 1; + const char *haystack = va_arg(args, const char *); + if (haystack == Y_NULL) + break; + if (!strcmp(needle, haystack)) + return 1; } return 0; } @@ -284,72 +284,72 @@ /* - * file_exists - * Check whether a file exists and is readable. - * Returns true if it is, false if it isn't. + * file_exists + * Check whether a file exists and is readable. + * Returns true if it is, false if it isn't. */ bool file_exists(const char *filename) { FILE *test; if ((test = fopen(filename, "rb")) == NULL) - return 0; + return 0; fclose(test); return 1; } /* - * y_filename - * Copies into a string that is a close as possible - * to but is guaranteed to be no longer than - * - 1 and contain only printable characters. Non - * printable characters are replaced by question marks. - * Excess characters are replaced by an ellipsis. + * y_filename + * Copies into a string that is a close as possible + * to but is guaranteed to be no longer than + * - 1 and contain only printable characters. Non + * printable characters are replaced by question marks. + * Excess characters are replaced by an ellipsis. */ void y_filename(char *buf, size_t size, const char *filename) { if (size == 0) - return; + return; if (size == 1) { - *buf = '\0'; - return; + *buf = '\0'; + return; } size_t len = strlen(filename); size_t maxlen = size - 1; - if (len > 3 && maxlen <= 3) // Pathological case, fill with dots + if (len > 3 && maxlen <= 3) // Pathological case, fill with dots { - memset(buf, '.', maxlen); - buf[maxlen] = '\0'; - return; + memset(buf, '.', maxlen); + buf[maxlen] = '\0'; + return; } size_t len1 = len; size_t len2 = 0; if (len > maxlen) { - len1 = (maxlen - 3) / 2; - len2 = maxlen - 3 - len1; + len1 = (maxlen - 3) / 2; + len2 = maxlen - 3 - len1; } char *p = buf; for (size_t n = 0; n < len1; n++) { - *p++ = y_isprint(*filename) ? *filename : '?'; - filename++; + *p++ = y_isprint(*filename) ? *filename : '?'; + filename++; } if (len2 > 0) { - *p++ = '.'; - *p++ = '.'; - *p++ = '.'; - filename += len - len1 - len2; - for (size_t n = 0; n < len2; n++) - { - *p++ = y_isprint(*filename) ? *filename : '?'; - filename++; - } + *p++ = '.'; + *p++ = '.'; + *p++ = '.'; + filename += len - len1 - len2; + for (size_t n = 0; n < len2; n++) + { + *p++ = y_isprint(*filename) ? *filename : '?'; + filename++; + } } *p++ = '\0'; } diff -r 594dea11ccd9 -r a68786b9c74b src/aym.h --- a/src/aym.h Sat Sep 24 15:01:56 2011 +0300 +++ b/src/aym.h Sat Sep 24 15:59:33 2011 +0300 @@ -1,7 +1,7 @@ /* - * aym.h - * Misc. functions - * AYM 1999-03-15 + * aym.h + * Misc. functions + * AYM 1999-03-15 */ @@ -28,7 +28,7 @@ */ -#ifndef YH_AYM /* DO NOT INSERT ANYTHING BEFORE THIS LINE */ +#ifndef YH_AYM /* DO NOT INSERT ANYTHING BEFORE THIS LINE */ #define YH_AYM @@ -48,8 +48,8 @@ /* - * within - * Is >= and <= ? + * within + * Is >= and <= ? */ inline int within(int value, int lower_bound, int upper_bound) { @@ -58,8 +58,8 @@ /* - * outside - * Is < or > ? + * outside + * Is < or > ? */ inline int outside(int value, int lower_bound, int upper_bound) { @@ -68,60 +68,60 @@ /* - * dectoi - * If is a decimal digit ("[0-9]"), return its value. - * Else, return a negative number. + * dectoi + * If is a decimal digit ("[0-9]"), return its value. + * Else, return a negative number. */ inline int dectoi(char c) { if (isdigit((unsigned char) c)) - return c - '0'; + return c - '0'; else - return -1; + return -1; } /* - * hextoi - * If is a hexadecimal digit ("[0-9A-Fa-f]"), return its value. - * Else, return a negative number. + * hextoi + * If is a hexadecimal digit ("[0-9A-Fa-f]"), return its value. + * Else, return a negative number. */ inline int hextoi(char c) { if (isdigit((unsigned char) c)) - return c - '0'; + return c - '0'; else if (c >= 'a' && c <= 'f') - return c - 'a' + 10; + return c - 'a' + 10; else if (c >= 'A' && c <= 'F') - return c - 'A' + 10; + return c - 'A' + 10; else - return -1; + return -1; } /* - * b36toi - * If is a base 36 digit ("[0-9A-Za-z]"), return its value. - * Else, return a negative number. + * b36toi + * If is a base 36 digit ("[0-9A-Za-z]"), return its value. + * Else, return a negative number. */ inline int b36toi(char c) { if (isdigit((unsigned char) c)) - return c - '0'; + return c - '0'; else if (islower(c)) - return c - 'a' + 10; + return c - 'a' + 10; else if (isupper(c)) - return c - 'A' + 10; + return c - 'A' + 10; else - return -1; + return -1; } /* - * y_isident - return true iff is one of a-z, A-Z, 0-9 or "_". + * y_isident - return true iff is one of a-z, A-Z, 0-9 or "_". * - * Intentionally not using isalpha() and co. because I - * don't want the results to depend on the locale. + * Intentionally not using isalpha() and co. because I + * don't want the results to depend on the locale. */ inline bool y_isident(char c) { @@ -194,20 +194,20 @@ case '_': - return true; + return true; default: - return false; + return false; } } /* - * fnewline - * Write a newline to a binary file. For Unix, LF. For - * other platforms, CR LF. - * Return EOF on failure. + * fnewline + * Write a newline to a binary file. For Unix, LF. For + * other platforms, CR LF. + * Return EOF on failure. */ inline int fnewline(FILE * fd) { @@ -220,10 +220,10 @@ /* - * round_up - * Round a value up to the next multiple of quantum. + * round_up + * Round a value up to the next multiple of quantum. * - * Both the value and the quantum are supposed to be positive. + * Both the value and the quantum are supposed to be positive. */ inline void round_up(int &value, int quantum) { @@ -232,8 +232,8 @@ /* - * y_isprint - * Is a printable character in ISO-8859-1 ? + * y_isprint + * Is a printable character in ISO-8859-1 ? */ inline bool y_isprint(char c) { diff -r 594dea11ccd9 -r a68786b9c74b src/bench.cc --- a/src/bench.cc Sat Sep 24 15:01:56 2011 +0300 +++ b/src/bench.cc Sat Sep 24 15:59:33 2011 +0300 @@ -1,7 +1,7 @@ /* - * bench.cc - * Benchmark functions. - * AYM 2000-04-13 + * bench.cc + * Benchmark functions. + * AYM 2000-04-13 */ @@ -44,18 +44,18 @@ /* - * benchmark - run the benchmarks specified by . + * benchmark - run the benchmarks specified by . */ void benchmark(const char *what) { // Insert parsing of here if (!strcmp(what, "loadpic")) - bench_LoadPicture(); + bench_LoadPicture(); } /* - * bench_LoadPicture - run a benchmark of LoadPicture() + * bench_LoadPicture - run a benchmark of LoadPicture() */ static void bench_LoadPicture() { @@ -67,13 +67,13 @@ wad_res.sprites.loc_by_name(sprite_name, sprite_loc); if (sprite_loc.wad == 0) - fprintf(stderr, "Could not locate sprite %s\n", sprite_name); + fprintf(stderr, "Could not locate sprite %s\n", sprite_name); Img img(width, height, false); struct tms t0; times(&t0); for (unsigned long n = 0; n < iterations; n++) - LoadPicture(img, sprite_name, sprite_loc, 0, 0, 0, 0); + LoadPicture(img, sprite_name, sprite_loc, 0, 0, 0, 0); struct tms t1; times(&t1); @@ -83,16 +83,16 @@ #endif const char *unit = "s"; double value = (double) (t1.tms_utime - t0.tms_utime) - / CLOCKS_PER_SEC / iterations; + / CLOCKS_PER_SEC / iterations; if (value < 1E-3) { - unit = "µs"; - value *= 1000000; + unit = "µs"; + value *= 1000000; } else if (value < 1.0) { - unit = "ms"; - value *= 1000; + unit = "ms"; + value *= 1000; } printf("LoadPicture: %f %s per call\n", value, unit); } diff -r 594dea11ccd9 -r a68786b9c74b src/bench.h --- a/src/bench.h Sat Sep 24 15:01:56 2011 +0300 +++ b/src/bench.h Sat Sep 24 15:59:33 2011 +0300 @@ -1,11 +1,11 @@ /* - * bench.h - * Benchmark functions. - * AYM 2000-04-13 + * bench.h + * Benchmark functions. + * AYM 2000-04-13 */ -#ifndef YH_BENCH /* DO NOT INSERT ANYTHING BEFORE THIS LINE */ +#ifndef YH_BENCH /* DO NOT INSERT ANYTHING BEFORE THIS LINE */ #define YH_BENCH diff -r 594dea11ccd9 -r a68786b9c74b src/bitvec.cc --- a/src/bitvec.cc Sat Sep 24 15:01:56 2011 +0300 +++ b/src/bitvec.cc Sat Sep 24 15:59:33 2011 +0300 @@ -1,6 +1,6 @@ /* - * bitvec.cc - * AYM 1999-08-15 + * bitvec.cc + * AYM 1999-08-15 */ diff -r 594dea11ccd9 -r a68786b9c74b src/bitvec.h --- a/src/bitvec.h Sat Sep 24 15:01:56 2011 +0300 +++ b/src/bitvec.h Sat Sep 24 15:59:33 2011 +0300 @@ -1,7 +1,7 @@ /* - * bitvec.h - * A rudimentary bit vector class. - * AYM 1998-11-22 + * bitvec.h + * A rudimentary bit vector class. + * AYM 1998-11-22 */ @@ -28,7 +28,7 @@ */ -#ifndef YH_BITVEC /* DO NOT INSERT ANYTHING BEFORE THIS LINE */ +#ifndef YH_BITVEC /* DO NOT INSERT ANYTHING BEFORE THIS LINE */ #define YH_BITVEC @@ -53,51 +53,51 @@ { public: bitvec_c(size_t n_elements) { - a = (char *) GetMemory(n_elements / CHAR_BIT + 1); - memset(a, 0, n_elements / CHAR_BIT + 1); - _n_elements = n_elements; + a = (char *) GetMemory(n_elements / CHAR_BIT + 1); + memset(a, 0, n_elements / CHAR_BIT + 1); + _n_elements = n_elements; } ~bitvec_c() { - FreeMemory(a); + FreeMemory(a); } - size_t nelements() const // Return the number of elements + size_t nelements() const // Return the number of elements { - return _n_elements; + return _n_elements; } - int get(size_t n) const // Get bit + int get(size_t n) const // Get bit { - return a[n / CHAR_BIT] & (1 << (n % CHAR_BIT)); + return a[n / CHAR_BIT] & (1 << (n % CHAR_BIT)); } - void set(size_t n) // Set bit to 1 + void set(size_t n) // Set bit to 1 { - a[n / CHAR_BIT] |= 1 << (n % CHAR_BIT); + a[n / CHAR_BIT] |= 1 << (n % CHAR_BIT); } - void unset(size_t n) // Set bit to 0 + void unset(size_t n) // Set bit to 0 { - a[n / CHAR_BIT] &= ~(1 << (n % CHAR_BIT)); + a[n / CHAR_BIT] &= ~(1 << (n % CHAR_BIT)); } - void toggle(size_t n) // Toggle bit + void toggle(size_t n) // Toggle bit { - a[n / CHAR_BIT] ^= (1 << (n % CHAR_BIT)); + a[n / CHAR_BIT] ^= (1 << (n % CHAR_BIT)); } - void frob(size_t n, bitvec_op_t op) // Set, unset or toggle bit + void frob(size_t n, bitvec_op_t op) // Set, unset or toggle bit { - if (op == BV_SET) - set(n); - else if (op == BV_CLEAR) - unset(n); - else if (op == BV_TOGGLE) - toggle(n); - else - nf_bug(_bitvec_msg1, (int) op); + if (op == BV_SET) + set(n); + else if (op == BV_CLEAR) + unset(n); + else if (op == BV_TOGGLE) + toggle(n); + else + nf_bug(_bitvec_msg1, (int) op); } private: diff -r 594dea11ccd9 -r a68786b9c74b src/cfgfile.cc --- a/src/cfgfile.cc Sat Sep 24 15:01:56 2011 +0300 +++ b/src/cfgfile.cc Sat Sep 24 15:59:33 2011 +0300 @@ -1,6 +1,6 @@ /* - * cfgfile.cc - * AYM 1998-09-30 + * cfgfile.cc + * AYM 1998-09-30 */ /* @@ -44,7 +44,7 @@ /* - * Description of the command line arguments and config file keywords + * Description of the command line arguments and config file keywords */ typedef enum { @@ -100,21 +100,21 @@ typedef struct { - const char *long_name; // Command line arg. or keyword - const char *short_name; // Abbreviated command line argument - opt_type_t opt_type; // Type of this option - const char *flags; // Flags for this option : + const char *long_name; // Command line arg. or keyword + const char *short_name; // Abbreviated command line argument + opt_type_t opt_type; // Type of this option + const char *flags; // Flags for this option : // "1" = process only on pass 1 of // parse_command_line_options() // "b" = BGI only (ignored ifndef Y_BGI) // "x" = X only (ignored ifndef Y_X11) - const char *desc; // Description of the option - void *data_ptr; // Pointer to the data + const char *desc; // Description of the option + void *data_ptr; // Pointer to the data } opt_desc_t; /* The first option has neither long name nor short name. It is used for "lonely" arguments (i.e. file names). */ -opt_desc_t options[] = // Description of the command line options +opt_desc_t options[] = // Description of the command line options { {0, 0, @@ -550,17 +550,17 @@ static void append_item_to_list(const char ***list, const char *item); static int parse_config_file(const char *filename, - cfg_parse_flags_t flags = CFG_PARSE_); + cfg_parse_flags_t flags = CFG_PARSE_); static confirm_t confirm_e2i(const char *external); static const char *confirm_i2e(confirm_t internal); /* - * parse_config_file_default - parse the default config file(s) + * parse_config_file_default - parse the default config file(s) * - * Return non-zero if parse error occurred (i.e. at least - * one call to parse_config_file() returned non-zero), zero - * otherwise. + * Return non-zero if parse error occurred (i.e. at least + * one call to parse_config_file() returned non-zero), zero + * otherwise. */ int parse_config_file_default() { @@ -572,23 +572,23 @@ for (matches = 0; (pathname = locate.get_next()) != NULL; matches++) { - printf("Reading config file \"%s\".\n", pathname); - int r = parse_config_file(pathname); - if (r != 0) - rc = 1; + printf("Reading config file \"%s\".\n", pathname); + int r = parse_config_file(pathname); + if (r != 0) + rc = 1; } if (matches == 0) - warn("%s: not found\n", name); + warn("%s: not found\n", name); return rc; } /* - * parse_config_file_user - parse a user-specified config file + * parse_config_file_user - parse a user-specified config file * - * Return non-zero if the file couldn't be found or if - * parse error occurred (i.e. parse_config_file() returned - * non-zero), zero otherwise. + * Return non-zero if the file couldn't be found or if + * parse error occurred (i.e. parse_config_file() returned + * non-zero), zero otherwise. */ int parse_config_file_user(const char *name) { @@ -598,8 +598,8 @@ pathname = locate.get_next(); if (pathname == NULL) { - err("%s: not found", name); - return 1; + err("%s: not found", name); + return 1; } printf("Reading config file \"%s\".\n", pathname); return parse_config_file(pathname); @@ -607,30 +607,30 @@ /* - * parse_config_file - try to parse a config file by pathname. + * parse_config_file - try to parse a config file by pathname. * - * If (flags & CFG_PARSE_MAGIC_ERROR) is true, the file must - * begin with config_file_magic on a line by itself or the - * function will exit immediately with a non-zero value. + * If (flags & CFG_PARSE_MAGIC_ERROR) is true, the file must + * begin with config_file_magic on a line by itself or the + * function will exit immediately with a non-zero value. * - * If (flags & CFG_PARSE_MAGIC_WARN) is true, the file must - * begin with config_file_magic on a line by itself or the - * function will print a warning. + * If (flags & CFG_PARSE_MAGIC_WARN) is true, the file must + * begin with config_file_magic on a line by itself or the + * function will print a warning. * - * If (flags & CFG_PARSE_ANAL_NAME) is true, unknown - * variables name cause the function to return immediately - * with a non-zero value. Otherwise, unknown variables - * cause the line to be skipped with a warning and do not - * cause the return value to be non-zero. + * If (flags & CFG_PARSE_ANAL_NAME) is true, unknown + * variables name cause the function to return immediately + * with a non-zero value. Otherwise, unknown variables + * cause the line to be skipped with a warning and do not + * cause the return value to be non-zero. * - * If (flags & CFG_PARSE_ANAL_SYNTAX) is true, lines that - * do not follow the = syntax cause the - * function to emit an error message and return immediately - * with a non-zero value. Otherwise, such lines are simply - * ignored with a warning message and do not cause the - * return value to be non-zero. + * If (flags & CFG_PARSE_ANAL_SYNTAX) is true, lines that + * do not follow the = syntax cause the + * function to emit an error message and return immediately + * with a non-zero value. Otherwise, such lines are simply + * ignored with a warning message and do not cause the + * return value to be non-zero. * - * Return 0 on success, <>0 on failure. + * Return 0 on success, <>0 on failure. */ #define RETURN_FAILURE do { rc = 1; goto byebye; } while (0) static int parse_config_file(const char *filename, cfg_parse_flags_t flags) @@ -642,298 +642,298 @@ cfgfile = fopen(filename, "r"); if (cfgfile == NULL) { - err("Can't open config file \"%s\" (%s)", filename, strerror(errno)); - RETURN_FAILURE; + err("Can't open config file \"%s\" (%s)", filename, strerror(errno)); + RETURN_FAILURE; } /* The first line of the configuration file must contain exactly config_file_magic. */ if (fgets(line, sizeof line, cfgfile) == NULL - || memcmp(line, config_file_magic, sizeof config_file_magic - 1) - || line[sizeof config_file_magic - 1] != '\n' - || line[sizeof config_file_magic] != '\0') + || memcmp(line, config_file_magic, sizeof config_file_magic - 1) + || line[sizeof config_file_magic - 1] != '\n' + || line[sizeof config_file_magic] != '\0') { - if (flags & CFG_PARSE_MAGIC_ERROR) - { - err("%s(1): bad magic, not a valid Yadex configuration file", - filename); - err("Perhaps a leftover from a previous version of Yadex ?"); - RETURN_FAILURE; - } - if (flags & CFG_PARSE_MAGIC_WARN) - warn("%s(1): bad magic, perhaps from a different version of Yadex\n", filename); - rewind(cfgfile); + if (flags & CFG_PARSE_MAGIC_ERROR) + { + err("%s(1): bad magic, not a valid Yadex configuration file", + filename); + err("Perhaps a leftover from a previous version of Yadex ?"); + RETURN_FAILURE; + } + if (flags & CFG_PARSE_MAGIC_WARN) + warn("%s(1): bad magic, perhaps from a different version of Yadex\n", filename); + rewind(cfgfile); } // Execute one line on each iteration for (unsigned lnum = 1; fgets(line, sizeof line, cfgfile) != NULL; lnum++) { - char *name = 0; - char *value = 0; - char *p = line; + char *name = 0; + char *value = 0; + char *p = line; - // Skip leading whitespace - while (isspace(*p)) - p++; + // Skip leading whitespace + while (isspace(*p)) + p++; - // Skip comments - if (*p == '#') - continue; + // Skip comments + if (*p == '#') + continue; - // Remove trailing newline - { - size_t len = strlen(p); - if (len >= 1 && p[len - 1] == '\n') - p[len - 1] = '\0'; - } + // Remove trailing newline + { + size_t len = strlen(p); + if (len >= 1 && p[len - 1] == '\n') + p[len - 1] = '\0'; + } - // Skip empty lines - if (*p == '\0') - continue; + // Skip empty lines + if (*p == '\0') + continue; - // Make point on the field - name = p; - while (y_isident(*p)) - p++; - if (*p == '\0') - { - if (flags & CFG_PARSE_ANAL_SYNTAX) - { - err("%s(%u): expected an \"=\"", filename, lnum); - RETURN_FAILURE; - } - else - { - warn("%s(%u): expected an \"=\", skipping\n", filename, lnum); - goto next_line; - } - } - if (*p == '=') - { - // Mark the end of the option name - *p = '\0'; - } - else - { - // Mark the end of the option name - *p = '\0'; - p++; - // Skip blanks after the option name - while (isspace((unsigned char) *p)) - p++; - if (*p != '=') - { - if (flags & CFG_PARSE_ANAL_SYNTAX) - { - err("%s(%u,%d): expected an \"=\"", - filename, lnum, 1 + (int) (p - line)); - RETURN_FAILURE; - } - else - { - warn("%s(%u,%d): expected an \"=\", skipping\n", - filename, lnum, 1 + (int) (p - line)); - goto next_line; - } - } - } - p++; + // Make point on the field + name = p; + while (y_isident(*p)) + p++; + if (*p == '\0') + { + if (flags & CFG_PARSE_ANAL_SYNTAX) + { + err("%s(%u): expected an \"=\"", filename, lnum); + RETURN_FAILURE; + } + else + { + warn("%s(%u): expected an \"=\", skipping\n", filename, lnum); + goto next_line; + } + } + if (*p == '=') + { + // Mark the end of the option name + *p = '\0'; + } + else + { + // Mark the end of the option name + *p = '\0'; + p++; + // Skip blanks after the option name + while (isspace((unsigned char) *p)) + p++; + if (*p != '=') + { + if (flags & CFG_PARSE_ANAL_SYNTAX) + { + err("%s(%u,%d): expected an \"=\"", + filename, lnum, 1 + (int) (p - line)); + RETURN_FAILURE; + } + else + { + warn("%s(%u,%d): expected an \"=\", skipping\n", + filename, lnum, 1 + (int) (p - line)); + goto next_line; + } + } + } + p++; - /* First parameter : points on the first character. - Put a NUL at the end. If there is a second parameter, - holler. */ - while (isspace((unsigned char) *p)) - p++; - value = p; - { - unsigned char *p2 = (unsigned char *) value; - while (*p2 != '\0' && !isspace(*p2)) - p2++; - if (*p2 != '\0') // There's trailing whitespace after 1st parameter - { - for (unsigned char *p3 = p2; *p3 != '\0'; p3++) - if (!isspace(*p3)) - { - err("%s(%u,%d): extraneous argument", - filename, lnum, 1 + (int) ((char *) p3 - line)); - RETURN_FAILURE; - } - } - *p2 = '\0'; - } + /* First parameter : points on the first character. + Put a NUL at the end. If there is a second parameter, + holler. */ + while (isspace((unsigned char) *p)) + p++; + value = p; + { + unsigned char *p2 = (unsigned char *) value; + while (*p2 != '\0' && !isspace(*p2)) + p2++; + if (*p2 != '\0') // There's trailing whitespace after 1st parameter + { + for (unsigned char *p3 = p2; *p3 != '\0'; p3++) + if (!isspace(*p3)) + { + err("%s(%u,%d): extraneous argument", + filename, lnum, 1 + (int) ((char *) p3 - line)); + RETURN_FAILURE; + } + } + *p2 = '\0'; + } - for (const opt_desc_t * o = options + 1;; o++) - { - if (o->opt_type == OPT_END) - { - if (flags & CFG_PARSE_ANAL_NAME) - { - err("%s(%u): invalid variable \"%s\"", filename, lnum, - name); - RETURN_FAILURE; - } - else - { - warn("%s(%u): invalid variable \"%s\", skipping\n", - filename, lnum, name); - goto next_line; - } - } - if (!o->long_name || strcmp(name, o->long_name) != 0) - continue; + for (const opt_desc_t * o = options + 1;; o++) + { + if (o->opt_type == OPT_END) + { + if (flags & CFG_PARSE_ANAL_NAME) + { + err("%s(%u): invalid variable \"%s\"", filename, lnum, + name); + RETURN_FAILURE; + } + else + { + warn("%s(%u): invalid variable \"%s\", skipping\n", + filename, lnum, name); + goto next_line; + } + } + if (!o->long_name || strcmp(name, o->long_name) != 0) + continue; - if (o->flags != NULL && strchr(o->flags, '1')) - break; + if (o->flags != NULL && strchr(o->flags, '1')) + break; #if ! defined Y_X11 - if (o->flags != NULL && strchr(o->flags, 'x')) - break; + if (o->flags != NULL && strchr(o->flags, 'x')) + break; #endif - switch (o->opt_type) - { - case OPT_BOOLEAN: - if (!strcmp(value, "yes") || !strcmp(value, "true") - || !strcmp(value, "on") || !strcmp(value, "1")) - { - if (o->data_ptr) - *((bool *) (o->data_ptr)) = true; - } - else if (!strcmp(value, "no") || !strcmp(value, "false") - || !strcmp(value, "off") || !strcmp(value, "0")) - { - if (o->data_ptr) - *((bool *) (o->data_ptr)) = false; - } - else - { - err("%s(%u): invalid value for option %s: \"%s\"", - filename, lnum, name, value); - RETURN_FAILURE; - } - break; + switch (o->opt_type) + { + case OPT_BOOLEAN: + if (!strcmp(value, "yes") || !strcmp(value, "true") + || !strcmp(value, "on") || !strcmp(value, "1")) + { + if (o->data_ptr) + *((bool *) (o->data_ptr)) = true; + } + else if (!strcmp(value, "no") || !strcmp(value, "false") + || !strcmp(value, "off") || !strcmp(value, "0")) + { + if (o->data_ptr) + *((bool *) (o->data_ptr)) = false; + } + else + { + err("%s(%u): invalid value for option %s: \"%s\"", + filename, lnum, name, value); + RETURN_FAILURE; + } + break; - case OPT_CONFIRM: - if (o->data_ptr) - *((confirm_t *) o->data_ptr) = confirm_e2i(value); - break; + case OPT_CONFIRM: + if (o->data_ptr) + *((confirm_t *) o->data_ptr) = confirm_e2i(value); + break; - case OPT_INTEGER: - if (o->data_ptr) - *((int *) (o->data_ptr)) = atoi(value); - break; + case OPT_INTEGER: + if (o->data_ptr) + *((int *) (o->data_ptr)) = atoi(value); + break; - case OPT_UNSIGNED: - if (o->data_ptr) - { - if (*value == '\0') - { - err("%s(%u,%d): missing argument", - filename, lnum, 1 + (int) (value - line)); - RETURN_FAILURE; - } - bool neg = false; - if (value[0] == '-') - neg = true; - char *endptr; - errno = 0; - *((unsigned long *) (o->data_ptr)) = - strtoul(value, &endptr, 0); - if (*endptr != '\0' && !isspace(*endptr)) - { - err("%s(%u,%d): illegal character in unsigned integer", filename, lnum, 1 + (int) (endptr - line)); - RETURN_FAILURE; - } - /* strtoul() sets errno to ERANGE if overflow. In - addition, we don't want any non-zero negative - numbers. In terms of regexp, /^(0x)?0*$/i. */ - if (errno != 0 || neg && ! - (strspn(value + 1, "0") == strlen(value + 1) || value[1] == '0' && tolower(value[2]) == 'x' - && strspn(value + 3, "0") == strlen(value + 3))) - { - err("%s(%u,%d): unsigned integer out of range", - filename, lnum, 1 + (int) (value - line)); - RETURN_FAILURE; - } - } - break; + case OPT_UNSIGNED: + if (o->data_ptr) + { + if (*value == '\0') + { + err("%s(%u,%d): missing argument", + filename, lnum, 1 + (int) (value - line)); + RETURN_FAILURE; + } + bool neg = false; + if (value[0] == '-') + neg = true; + char *endptr; + errno = 0; + *((unsigned long *) (o->data_ptr)) = + strtoul(value, &endptr, 0); + if (*endptr != '\0' && !isspace(*endptr)) + { + err("%s(%u,%d): illegal character in unsigned integer", filename, lnum, 1 + (int) (endptr - line)); + RETURN_FAILURE; + } + /* strtoul() sets errno to ERANGE if overflow. In + addition, we don't want any non-zero negative + numbers. In terms of regexp, /^(0x)?0*$/i. */ + if (errno != 0 || neg && ! + (strspn(value + 1, "0") == strlen(value + 1) || value[1] == '0' && tolower(value[2]) == 'x' + && strspn(value + 3, "0") == strlen(value + 3))) + { + err("%s(%u,%d): unsigned integer out of range", + filename, lnum, 1 + (int) (value - line)); + RETURN_FAILURE; + } + } + break; - case OPT_WINDIM: - if (o->data_ptr) - if (((Win_dim *) (o->data_ptr))->set(value)) - { - err("%s(%u): bad dimension spec \"%s\"", filename, - lnum, value); - RETURN_FAILURE; - } - break; + case OPT_WINDIM: + if (o->data_ptr) + if (((Win_dim *) (o->data_ptr))->set(value)) + { + err("%s(%u): bad dimension spec \"%s\"", filename, + lnum, value); + RETURN_FAILURE; + } + break; - case OPT_STRINGBUF8: - if (o->data_ptr) - al_scps((char *) o->data_ptr, value, 8); - break; + case OPT_STRINGBUF8: + if (o->data_ptr) + al_scps((char *) o->data_ptr, value, 8); + break; - case OPT_STRINGPTR: - { - char *dup = (char *) GetMemory(strlen(value) + 1); - strcpy(dup, value); - if (o->data_ptr) - *((char **) (o->data_ptr)) = dup; - break; - } + case OPT_STRINGPTR: + { + char *dup = (char *) GetMemory(strlen(value) + 1); + strcpy(dup, value); + if (o->data_ptr) + *((char **) (o->data_ptr)) = dup; + break; + } - case OPT_STRINGPTRACC: - { - char *dup = (char *) GetMemory(strlen(value) + 1); - strcpy(dup, value); - if (o->data_ptr) - append_item_to_list((const char ***) o->data_ptr, - dup); - break; - } + case OPT_STRINGPTRACC: + { + char *dup = (char *) GetMemory(strlen(value) + 1); + strcpy(dup, value); + if (o->data_ptr) + append_item_to_list((const char ***) o->data_ptr, + dup); + break; + } - case OPT_STRINGPTRLIST: - while (*value != '\0') - { - char *v = value; - while (*v != '\0' && !isspace((unsigned char) *v)) - v++; - char *dup = (char *) GetMemory(v - value + 1); - memcpy(dup, value, v - value); - dup[v - value] = '\0'; - if (o->data_ptr) - append_item_to_list((const char ***) o->data_ptr, - dup); - while (isspace(*v)) - v++; - value = v; - } - break; + case OPT_STRINGPTRLIST: + while (*value != '\0') + { + char *v = value; + while (*v != '\0' && !isspace((unsigned char) *v)) + v++; + char *dup = (char *) GetMemory(v - value + 1); + memcpy(dup, value, v - value); + dup[v - value] = '\0'; + if (o->data_ptr) + append_item_to_list((const char ***) o->data_ptr, + dup); + while (isspace(*v)) + v++; + value = v; + } + break; - default: - { - nf_bug("%s(%u): unknown option type %d", - filename, lnum, (int) o->opt_type); - RETURN_FAILURE; - } - } - break; - } + default: + { + nf_bug("%s(%u): unknown option type %d", + filename, lnum, (int) o->opt_type); + RETURN_FAILURE; + } + } + break; + } next_line:; } byebye: if (cfgfile != 0) - fclose(cfgfile); + fclose(cfgfile); return rc; } /* - * parse_command_line_options - * If is set to 1, ignores all options except those - * that have the "1" flag. - * Else, ignores all options that have the "1" flag. - * If an error occurs, report it with err() - * and returns non-zero. Else, returns 0. + * parse_command_line_options + * If is set to 1, ignores all options except those + * that have the "1" flag. + * Else, ignores all options that have the "1" flag. + * If an error occurs, report it with err() + * and returns non-zero. Else, returns 0. */ int parse_command_line_options(int argc, const char *const *argv, int pass) { @@ -941,202 +941,202 @@ while (argc > 0) { - int ignore; + int ignore; - // Which option is this ? - if (**argv != '-' && **argv != '+') - { - o = options; - argc++; - argv--; - } - else - for (o = options + 1;; o++) - { - if (o->opt_type == OPT_END) - { - err("invalid option: \"%s\"", argv[0]); - return 1; - } - if (o->short_name && !strcmp(argv[0] + 1, o->short_name) - || o->long_name && !strcmp(argv[0] + 1, o->long_name)) - break; - } + // Which option is this ? + if (**argv != '-' && **argv != '+') + { + o = options; + argc++; + argv--; + } + else + for (o = options + 1;; o++) + { + if (o->opt_type == OPT_END) + { + err("invalid option: \"%s\"", argv[0]); + return 1; + } + if (o->short_name && !strcmp(argv[0] + 1, o->short_name) + || o->long_name && !strcmp(argv[0] + 1, o->long_name)) + break; + } - // If this option has the "1" flag but pass is not 1 - // or it doesn't but pass is 1, ignore it. - ignore = (o->flags != NULL && strchr(o->flags, '1')) != (pass == 1); + // If this option has the "1" flag but pass is not 1 + // or it doesn't but pass is 1, ignore it. + ignore = (o->flags != NULL && strchr(o->flags, '1')) != (pass == 1); - switch (o->opt_type) - { - case OPT_BOOLEAN: - if (argv[0][0] == '-') - { - if (o->data_ptr && !ignore) - *((bool *) (o->data_ptr)) = true; - } - else - { - if (o->data_ptr && !ignore) - *((bool *) (o->data_ptr)) = false; - } - break; + switch (o->opt_type) + { + case OPT_BOOLEAN: + if (argv[0][0] == '-') + { + if (o->data_ptr && !ignore) + *((bool *) (o->data_ptr)) = true; + } + else + { + if (o->data_ptr && !ignore) + *((bool *) (o->data_ptr)) = false; + } + break; - case OPT_CONFIRM: - if (argc <= 1) - { - err("missing argument after \"%s\"", argv[0]); - return 1; - } - argv++; - argc--; - if (o->data_ptr && !ignore) - *((confirm_t *) o->data_ptr) = confirm_e2i(argv[0]); - break; + case OPT_CONFIRM: + if (argc <= 1) + { + err("missing argument after \"%s\"", argv[0]); + return 1; + } + argv++; + argc--; + if (o->data_ptr && !ignore) + *((confirm_t *) o->data_ptr) = confirm_e2i(argv[0]); + break; - case OPT_INTEGER: - if (argc <= 1) - { - err("missing argument after \"%s\"", argv[0]); - return 1; - } - argv++; - argc--; - if (o->data_ptr && !ignore) - *((int *) (o->data_ptr)) = atoi(argv[0]); - break; + case OPT_INTEGER: + if (argc <= 1) + { + err("missing argument after \"%s\"", argv[0]); + return 1; + } + argv++; + argc--; + if (o->data_ptr && !ignore) + *((int *) (o->data_ptr)) = atoi(argv[0]); + break; - case OPT_UNSIGNED: - if (argc <= 1) - { - err("missing argument after \"%s\"", argv[0]); - return 1; - } - argv++; - argc--; - if (o->data_ptr && !ignore) - { - const char *value = argv[0]; - if (*value == '\0') - { - err("not an unsigned integer \"%s\"", value); - return 1; - } - bool neg = false; - if (*value == '-') - neg = true; - char *endptr; - errno = 0; - *((unsigned long *) (o->data_ptr)) = - strtoul(value, &endptr, 0); - while (*endptr != '\0' && isspace(*endptr)) - endptr++; - if (*endptr != '\0') - { - err("illegal characters in unsigned int \"%s\"", endptr); - return 1; - } - /* strtoul() sets errno to ERANGE if overflow. In - addition, we don't want any non-zero negative - numbers. In terms of regexp, /^(0x)?0*$/i. */ - if (errno != 0 - || neg - && ! - (strspn(value + 1, "0") == strlen(value + 1) - || value[1] == '0' - && tolower(value[2]) == 'x' - && strspn(value + 3, "0") == strlen(value + 3))) - { - err("unsigned integer out of range \"%s\"", value); - return 1; - } - } - break; + case OPT_UNSIGNED: + if (argc <= 1) + { + err("missing argument after \"%s\"", argv[0]); + return 1; + } + argv++; + argc--; + if (o->data_ptr && !ignore) + { + const char *value = argv[0]; + if (*value == '\0') + { + err("not an unsigned integer \"%s\"", value); + return 1; + } + bool neg = false; + if (*value == '-') + neg = true; + char *endptr; + errno = 0; + *((unsigned long *) (o->data_ptr)) = + strtoul(value, &endptr, 0); + while (*endptr != '\0' && isspace(*endptr)) + endptr++; + if (*endptr != '\0') + { + err("illegal characters in unsigned int \"%s\"", endptr); + return 1; + } + /* strtoul() sets errno to ERANGE if overflow. In + addition, we don't want any non-zero negative + numbers. In terms of regexp, /^(0x)?0*$/i. */ + if (errno != 0 + || neg + && ! + (strspn(value + 1, "0") == strlen(value + 1) + || value[1] == '0' + && tolower(value[2]) == 'x' + && strspn(value + 3, "0") == strlen(value + 3))) + { + err("unsigned integer out of range \"%s\"", value); + return 1; + } + } + break; - case OPT_WINDIM: - if (argc <= 1) - { - err("missing argument after \"%s\"", argv[0]); - return 1; - } - argv++; - argc--; - if (o->data_ptr && !ignore) - if (((Win_dim *) (o->data_ptr))->set(argv[0])) - { - err("bad dimension spec \"%s\"", argv[0]); - return 1; - } - break; + case OPT_WINDIM: + if (argc <= 1) + { + err("missing argument after \"%s\"", argv[0]); + return 1; + } + argv++; + argc--; + if (o->data_ptr && !ignore) + if (((Win_dim *) (o->data_ptr))->set(argv[0])) + { + err("bad dimension spec \"%s\"", argv[0]); + return 1; + } + break; - case OPT_STRINGBUF8: - if (argc <= 1) - { - err("missing argument after \"%s\"", argv[0]); - return 1; - } - argv++; - argc--; - if (o->data_ptr && !ignore) - al_scps((char *) o->data_ptr, argv[0], 8); - break; + case OPT_STRINGBUF8: + if (argc <= 1) + { + err("missing argument after \"%s\"", argv[0]); + return 1; + } + argv++; + argc--; + if (o->data_ptr && !ignore) + al_scps((char *) o->data_ptr, argv[0], 8); + break; - case OPT_STRINGPTR: - if (argc <= 1) - { - err("missing argument after \"%s\"", argv[0]); - return 1; - } - argv++; - argc--; - if (o->data_ptr && !ignore) - *((const char **) (o->data_ptr)) = argv[0]; - break; + case OPT_STRINGPTR: + if (argc <= 1) + { + err("missing argument after \"%s\"", argv[0]); + return 1; + } + argv++; + argc--; + if (o->data_ptr && !ignore) + *((const char **) (o->data_ptr)) = argv[0]; + break; - case OPT_STRINGPTRACC: - if (argc <= 1) - { - err("missing argument after \"%s\"", argv[0]); - return 1; - } - argv++; - argc--; - if (o->data_ptr && !ignore) - append_item_to_list((const char ***) o->data_ptr, argv[0]); - break; + case OPT_STRINGPTRACC: + if (argc <= 1) + { + err("missing argument after \"%s\"", argv[0]); + return 1; + } + argv++; + argc--; + if (o->data_ptr && !ignore) + append_item_to_list((const char ***) o->data_ptr, argv[0]); + break; - case OPT_STRINGPTRLIST: - if (argc <= 1) - { - err("missing argument after \"%s\"", argv[0]); - return 1; - } - while (argc > 1 && argv[1][0] != '-' && argv[1][0] != '+') - { - argv++; - argc--; - if (o->data_ptr && !ignore) - append_item_to_list((const char ***) o->data_ptr, - argv[0]); - } - break; + case OPT_STRINGPTRLIST: + if (argc <= 1) + { + err("missing argument after \"%s\"", argv[0]); + return 1; + } + while (argc > 1 && argv[1][0] != '-' && argv[1][0] != '+') + { + argv++; + argc--; + if (o->data_ptr && !ignore) + append_item_to_list((const char ***) o->data_ptr, + argv[0]); + } + break; - default: - { - nf_bug("unknown option type (%d)", (int) o->opt_type); - return 1; - } - } - argv++; - argc--; + default: + { + nf_bug("unknown option type (%d)", (int) o->opt_type); + return 1; + } + } + argv++; + argc--; } return 0; } /* - * dump_parameters - * Print a list of the parameters with their current value. + * dump_parameters + * Print a list of the parameters with their current value. */ void dump_parameters(FILE * fp) { @@ -1146,67 +1146,67 @@ for (o = options + 1; o->opt_type != OPT_END; o++) { - int len = strlen(o->desc); - desc_maxlen = al_amax(desc_maxlen, len); - if (o->long_name) - { - len = strlen(o->long_name); - name_maxlen = al_amax(name_maxlen, len); - } + int len = strlen(o->desc); + desc_maxlen = al_amax(desc_maxlen, len); + if (o->long_name) + { + len = strlen(o->long_name); + name_maxlen = al_amax(name_maxlen, len); + } } for (o = options + 1; o->opt_type != OPT_END; o++) { - if (!o->long_name) - continue; - fprintf(fp, "%-*s %-*s ", name_maxlen, o->long_name, desc_maxlen, - o->desc); - if (o->opt_type == OPT_BOOLEAN) - fprintf(fp, "%s", - *((bool *) o->data_ptr) ? "enabled" : "disabled"); - else if (o->opt_type == OPT_CONFIRM) - fputs(confirm_i2e(*((confirm_t *) o->data_ptr)), fp); - else if (o->opt_type == OPT_STRINGBUF8) - fprintf(fp, "\"%s\"", (char *) o->data_ptr); - else if (o->opt_type == OPT_STRINGPTR) - { - if (o->data_ptr) - fprintf(fp, "\"%s\"", *((char **) o->data_ptr)); - else - fprintf(fp, "--none--"); - } - else if (o->opt_type == OPT_INTEGER) - fprintf(fp, "%d", *((int *) o->data_ptr)); - else if (o->opt_type == OPT_UNSIGNED) - fprintf(fp, "%lu", *((unsigned long *) o->data_ptr)); - else if (o->opt_type == OPT_WINDIM) - { - char buf[50]; // Much slack - ((Win_dim *) (o->data_ptr))->string(buf, sizeof buf); - fputs(buf, fp); - } - else if (o->opt_type == OPT_STRINGPTRACC - || o->opt_type == OPT_STRINGPTRLIST) - { - if (o->data_ptr) - { - char **list; - for (list = *((char ***) o->data_ptr); list && *list; list++) - fprintf(fp, "\"%s\" ", *list); - if (list == *((char ***) o->data_ptr)) - fprintf(fp, "--none--"); - } - else - fprintf(fp, "--none--"); - } - fputc('\n', fp); + if (!o->long_name) + continue; + fprintf(fp, "%-*s %-*s ", name_maxlen, o->long_name, desc_maxlen, + o->desc); + if (o->opt_type == OPT_BOOLEAN) + fprintf(fp, "%s", + *((bool *) o->data_ptr) ? "enabled" : "disabled"); + else if (o->opt_type == OPT_CONFIRM) + fputs(confirm_i2e(*((confirm_t *) o->data_ptr)), fp); + else if (o->opt_type == OPT_STRINGBUF8) + fprintf(fp, "\"%s\"", (char *) o->data_ptr); + else if (o->opt_type == OPT_STRINGPTR) + { + if (o->data_ptr) + fprintf(fp, "\"%s\"", *((char **) o->data_ptr)); + else + fprintf(fp, "--none--"); + } + else if (o->opt_type == OPT_INTEGER) + fprintf(fp, "%d", *((int *) o->data_ptr)); + else if (o->opt_type == OPT_UNSIGNED) + fprintf(fp, "%lu", *((unsigned long *) o->data_ptr)); + else if (o->opt_type == OPT_WINDIM) + { + char buf[50]; // Much slack + ((Win_dim *) (o->data_ptr))->string(buf, sizeof buf); + fputs(buf, fp); + } + else if (o->opt_type == OPT_STRINGPTRACC + || o->opt_type == OPT_STRINGPTRLIST) + { + if (o->data_ptr) + { + char **list; + for (list = *((char ***) o->data_ptr); list && *list; list++) + fprintf(fp, "\"%s\" ", *list); + if (list == *((char ***) o->data_ptr)) + fprintf(fp, "--none--"); + } + else + fprintf(fp, "--none--"); + } + fputc('\n', fp); } } /* - * dump_command_line_options - * Print a list of all command line options (usage message). + * dump_command_line_options + * Print a list of all command line options (usage message). */ void dump_command_line_options(FILE * fd) { @@ -1216,113 +1216,113 @@ for (o = options + 1; o->opt_type != OPT_END; o++) { - int len; - if (!o->short_name) - continue; - len = strlen(o->desc); - desc_maxlen = al_amax(desc_maxlen, len); - if (o->long_name) - { - len = strlen(o->long_name); - name_maxlen = al_amax(name_maxlen, len); - } + int len; + if (!o->short_name) + continue; + len = strlen(o->desc); + desc_maxlen = al_amax(desc_maxlen, len); + if (o->long_name) + { + len = strlen(o->long_name); + name_maxlen = al_amax(name_maxlen, len); + } } for (o = options; o->opt_type != OPT_END; o++) { - if (!o->short_name) - continue; + if (!o->short_name) + continue; #if ! defined Y_X11 - if (o->flags && strchr(o->flags, 'x')) - continue; + if (o->flags && strchr(o->flags, 'x')) + continue; #endif - if (o->short_name) - fprintf(fd, " -%-3s ", o->short_name); - else - fprintf(fd, " "); - if (o->long_name) - fprintf(fd, "-%-*s ", name_maxlen, o->long_name); - else - fprintf(fd, "%*s", name_maxlen + 2, ""); - switch (o->opt_type) - { - case OPT_BOOLEAN: - fprintf(fd, " "); - break; - case OPT_CONFIRM: - fprintf(fd, "yes|no|ask "); - break; - case OPT_STRINGBUF8: - case OPT_STRINGPTR: - case OPT_STRINGPTRACC: - fprintf(fd, " "); - break; - case OPT_INTEGER: - fprintf(fd, " "); - break; - case OPT_UNSIGNED: - fprintf(fd, " "); - break; - case OPT_WINDIM: - fprintf(fd, "[%%]"); - break; - case OPT_STRINGPTRLIST: - fprintf(fd, " ..."); - break; - case OPT_END:; // This line is here only to silence a GCC warning. - } - fprintf(fd, " %s\n", o->desc); + if (o->short_name) + fprintf(fd, " -%-3s ", o->short_name); + else + fprintf(fd, " "); + if (o->long_name) + fprintf(fd, "-%-*s ", name_maxlen, o->long_name); + else + fprintf(fd, "%*s", name_maxlen + 2, ""); + switch (o->opt_type) + { + case OPT_BOOLEAN: + fprintf(fd, " "); + break; + case OPT_CONFIRM: + fprintf(fd, "yes|no|ask "); + break; + case OPT_STRINGBUF8: + case OPT_STRINGPTR: + case OPT_STRINGPTRACC: + fprintf(fd, " "); + break; + case OPT_INTEGER: + fprintf(fd, " "); + break; + case OPT_UNSIGNED: + fprintf(fd, " "); + break; + case OPT_WINDIM: + fprintf(fd, "[%%]"); + break; + case OPT_STRINGPTRLIST: + fprintf(fd, " ..."); + break; + case OPT_END:; // This line is here only to silence a GCC warning. + } + fprintf(fd, " %s\n", o->desc); } } /* - * confirm_e2i - * Convert the external representation of a confirmation - * flag ("yes", "no", "ask", "ask_once") to the internal - * representation (YC_YES, YC_NO, YC_ASK, YC_ASK_ONCE or - * '\0' if none). + * confirm_e2i + * Convert the external representation of a confirmation + * flag ("yes", "no", "ask", "ask_once") to the internal + * representation (YC_YES, YC_NO, YC_ASK, YC_ASK_ONCE or + * '\0' if none). */ static confirm_t confirm_e2i(const char *external) { if (external != NULL) { - if (!strcmp(external, "yes")) - return YC_YES; - if (!strcmp(external, "no")) - return YC_NO; - if (!strcmp(external, "ask")) - return YC_ASK; - if (!strcmp(external, "ask_once")) - return YC_ASK_ONCE; + if (!strcmp(external, "yes")) + return YC_YES; + if (!strcmp(external, "no")) + return YC_NO; + if (!strcmp(external, "ask")) + return YC_ASK; + if (!strcmp(external, "ask_once")) + return YC_ASK_ONCE; } return YC_ASK; } /* - * confirm_i2e - * Convert the internal representation of a confirmation - * flag (YC_YES, YC_NO, YC_ASK, YC_ASK_ONCE) to the external - * representation ("yes", "no", "ask", "ask_once" or "?"). + * confirm_i2e + * Convert the internal representation of a confirmation + * flag (YC_YES, YC_NO, YC_ASK, YC_ASK_ONCE) to the external + * representation ("yes", "no", "ask", "ask_once" or "?"). */ static const char *confirm_i2e(confirm_t internal) { if (internal == YC_YES) - return "yes"; + return "yes"; if (internal == YC_NO) - return "no"; + return "no"; if (internal == YC_ASK) - return "ask"; + return "ask"; if (internal == YC_ASK_ONCE) - return "ask_once"; + return "ask_once"; return "?"; } /* - * append_item_to_list - * Append a string to a null-terminated string list + * append_item_to_list + * Append a string to a null-terminated string list */ static void append_item_to_list(const char ***list, const char *item) { @@ -1331,16 +1331,16 @@ i = 0; if (*list != 0) { - // Count the number of elements in the list (last = null) - while ((*list)[i] != 0) - i++; - // Expand the list - *list = (const char **) ResizeMemory(*list, (i + 2) * sizeof **list); + // Count the number of elements in the list (last = null) + while ((*list)[i] != 0) + i++; + // Expand the list + *list = (const char **) ResizeMemory(*list, (i + 2) * sizeof **list); } else { - // Create a new list - *list = (const char **) GetMemory(2 * sizeof **list); + // Create a new list + *list = (const char **) GetMemory(2 * sizeof **list); } // Append the new element (*list)[i] = item; @@ -1354,7 +1354,7 @@ const size_t MAX_TOKENS = 10; /* - * word_splitting - perform word splitting on a string + * word_splitting - perform word splitting on a string */ int word_splitting(std::vector < std::string > &tokens, const char *string) { @@ -1368,37 +1368,37 @@ whitespace can be enclosed in double quotes. */ for (;; iptr++) { - if (*iptr == '\n' || *iptr == '\0') - break; + if (*iptr == '\n' || *iptr == '\0') + break; - else if (*iptr == '"') - quoted = !quoted; + else if (*iptr == '"') + quoted = !quoted; - // "#" at the beginning of a token - else if (!in_token && !quoted && *iptr == '#') - break; + // "#" at the beginning of a token + else if (!in_token && !quoted && *iptr == '#') + break; - // First character of token - else if (!in_token && (quoted || !isspace(*iptr))) - { - ntokens++; - if (ntokens > MAX_TOKENS) - return 2; // Too many tokens - in_token = true; - } + // First character of token + else if (!in_token && (quoted || !isspace(*iptr))) + { + ntokens++; + if (ntokens > MAX_TOKENS) + return 2; // Too many tokens + in_token = true; + } - // First space between two tokens - else if (in_token && !quoted && isspace(*iptr)) - { - tokens.push_back(std::string(token_start, iptr - token_start)); - in_token = false; - } + // First space between two tokens + else if (in_token && !quoted && isspace(*iptr)) + { + tokens.push_back(std::string(token_start, iptr - token_start)); + in_token = false; + } } if (in_token) - tokens.push_back(std::string(token_start, iptr - token_start)); + tokens.push_back(std::string(token_start, iptr - token_start)); if (quoted) - return 1; // Unmatched double quote + return 1; // Unmatched double quote return 0; } diff -r 594dea11ccd9 -r a68786b9c74b src/cfgfile.h --- a/src/cfgfile.h Sat Sep 24 15:01:56 2011 +0300 +++ b/src/cfgfile.h Sat Sep 24 15:59:33 2011 +0300 @@ -1,6 +1,6 @@ /* - * cfgfile.h - * AYM 1998-09-30 + * cfgfile.h + * AYM 1998-09-30 */ diff -r 594dea11ccd9 -r a68786b9c74b src/checks.cc --- a/src/checks.cc Sat Sep 24 15:01:56 2011 +0300 +++ b/src/checks.cc Sat Sep 24 15:59:33 2011 +0300 @@ -1,7 +1,7 @@ /* - * checks.cc - * Level integrity checking - * AYM 1998-01-29 + * checks.cc + * Level integrity checking + * AYM 1998-01-29 */ @@ -45,45 +45,45 @@ /* - * CheckLevel - * check the level consistency - * FIXME should be integrated into editloop.cc + * CheckLevel + * check the level consistency + * FIXME should be integrated into editloop.cc */ -void CheckLevel(int x0, int y0) /* SWAP! */ +void CheckLevel(int x0, int y0) /* SWAP! */ { const char *line5 = 0; if (Registered) { - /* Commented out AYM 19971130 - wouldn't work with Doom 2 - if (! FindMasterDir (MasterDir, "TEXTURE2")) - NumVertexes--; - else - */ - line5 = "Check texture names"; + /* Commented out AYM 19971130 - wouldn't work with Doom 2 + if (! FindMasterDir (MasterDir, "TEXTURE2")) + NumVertexes--; + else + */ + line5 = "Check texture names"; } switch (vDisplayMenu(x0, y0, "Check level consistency", - "Number of objects", YK_, 0, - "Check if all Sectors are closed", YK_, 0, - "Check all cross-references", YK_, 0, - "Check for missing textures", YK_, 0, - line5, YK_, 0, NULL)) + "Number of objects", YK_, 0, + "Check if all Sectors are closed", YK_, 0, + "Check all cross-references", YK_, 0, + "Check for missing textures", YK_, 0, + line5, YK_, 0, NULL)) { case 1: - Statistics(); - break; + Statistics(); + break; case 2: - CheckSectors(); - break; + CheckSectors(); + break; case 3: - CheckCrossReferences(); - break; + CheckCrossReferences(); + break; case 4: - CheckTextures(); - break; + CheckTextures(); + break; case 5: - CheckTextureNames(); - break; + CheckTextureNames(); + break; } } @@ -113,44 +113,44 @@ DrawScreenText(-1, -1, ""); if (!Things) - set_colour(WINFG_DIM); + set_colour(WINFG_DIM); else - set_colour(WINFG); + set_colour(WINFG); DrawScreenText(-1, -1, "Number of things: %4d (%lu K)", NumThings, - ((unsigned long) NumThings * sizeof(struct Thing) + - 512L) / 1024L); + ((unsigned long) NumThings * sizeof(struct Thing) + + 512L) / 1024L); if (!Vertices) - set_colour(WINFG_DIM); + set_colour(WINFG_DIM); else - set_colour(WINFG); + set_colour(WINFG); DrawScreenText(-1, -1, "Number of vertices: %4d (%lu K)", NumVertices, - ((unsigned long) NumVertices * sizeof(struct Vertex) + - 512L) / 1024L); + ((unsigned long) NumVertices * sizeof(struct Vertex) + + 512L) / 1024L); if (!LineDefs) - set_colour(WINFG_DIM); + set_colour(WINFG_DIM); else - set_colour(WINFG); + set_colour(WINFG); DrawScreenText(-1, -1, "Number of linedefs: %4d (%lu K)", NumLineDefs, - ((unsigned long) NumLineDefs * sizeof(struct LineDef) + - 512L) / 1024L); + ((unsigned long) NumLineDefs * sizeof(struct LineDef) + + 512L) / 1024L); if (!SideDefs) - set_colour(WINFG_DIM); + set_colour(WINFG_DIM); else - set_colour(WINFG); + set_colour(WINFG); DrawScreenText(-1, -1, "Number of sidedefs: %4d (%lu K)", NumSideDefs, - ((unsigned long) NumSideDefs * sizeof(struct SideDef) + - 512L) / 1024L); + ((unsigned long) NumSideDefs * sizeof(struct SideDef) + + 512L) / 1024L); if (!Sectors) - set_colour(WINFG_DIM); + set_colour(WINFG_DIM); else - set_colour(WINFG); + set_colour(WINFG); DrawScreenText(-1, -1, "Number of sectors: %4d (%lu K)", NumSectors, - ((unsigned long) NumSectors * sizeof(struct Sector) + - 512L) / 1024L); + ((unsigned long) NumSectors * sizeof(struct Sector) + + 512L) / 1024L); DrawScreenText(-1, -1, ""); set_colour(WINTITLE); @@ -174,26 +174,26 @@ */ bool CheckFailed(int x0, int y0, char *prompt1, char *prompt2, bool fatal, - bool & first_time) + bool & first_time) { int key; size_t maxlen; if (fatal) - maxlen = 44; + maxlen = 44; else - maxlen = 27; + maxlen = 27; if (strlen(prompt1) > maxlen) - maxlen = strlen(prompt1); + maxlen = strlen(prompt1); if (prompt2 && strlen(prompt2) > maxlen) - maxlen = strlen(prompt2); + maxlen = strlen(prompt2); int width = 2 * BOX_BORDER + 2 * WIDE_HSPACING + FONTW * maxlen; int height = - 2 * BOX_BORDER + 2 * WIDE_VSPACING + FONTH * (prompt2 ? 6 : 5); + 2 * BOX_BORDER + 2 * WIDE_VSPACING + FONTH * (prompt2 ? 6 : 5); if (x0 < 0) - x0 = (ScrMaxX - width) / 2; + x0 = (ScrMaxX - width) / 2; if (y0 < 0) - y0 = (ScrMaxY - height) / 2; + y0 = (ScrMaxY - height) / 2; int text_x0 = x0 + BOX_BORDER + WIDE_HSPACING; int text_y0 = y0 + BOX_BORDER + WIDE_VSPACING; int cur_y = text_y0; @@ -201,36 +201,36 @@ set_colour(LIGHTRED); DrawScreenText(text_x0, cur_y, "Verification failed:"); if (first_time) - Beep(); + Beep(); set_colour(WHITE); DrawScreenText(text_x0, cur_y += FONTH, prompt1); LogMessage("\t%s\n", prompt1); if (prompt2) { - DrawScreenText(text_x0, cur_y += FONTH, prompt2); - LogMessage("\t%s\n", prompt2); + DrawScreenText(text_x0, cur_y += FONTH, prompt2); + LogMessage("\t%s\n", prompt2); } if (fatal) { - DrawScreenText(text_x0, cur_y += 2 * FONTH, - "The game will crash if you play with this level."); - set_colour(WINTITLE); - DrawScreenText(text_x0, cur_y += FONTH, - "Press any key to see the object"); - LogMessage("\n"); + DrawScreenText(text_x0, cur_y += 2 * FONTH, + "The game will crash if you play with this level."); + set_colour(WINTITLE); + DrawScreenText(text_x0, cur_y += FONTH, + "Press any key to see the object"); + LogMessage("\n"); } else { - set_colour(WINTITLE); - DrawScreenText(text_x0, cur_y += 2 * FONTH, - "Press Esc to see the object,"); - DrawScreenText(text_x0, cur_y += FONTH, - "or any other key to continue"); + set_colour(WINTITLE); + DrawScreenText(text_x0, cur_y += 2 * FONTH, + "Press Esc to see the object,"); + DrawScreenText(text_x0, cur_y += FONTH, + "or any other key to continue"); } key = get_key(); if (key != YK_ESC) { - DrawScreenBox3D(x0, y0, x0 + width - 1, y0 + height - 1); + DrawScreenBox3D(x0, y0, x0 + width - 1, y0 + height - 1); // DrawScreenText (x0 + 10 + 4 * (maxlen - 26), y0 + 28, // "Verifying other objects..."); } @@ -243,7 +243,7 @@ check if all sectors are closed */ -void CheckSectors() /* SWAP! */ +void CheckSectors() /* SWAP! */ { int s, n, sd; char *ends; @@ -255,51 +255,51 @@ ends = (char *) GetMemory(NumVertices); for (s = 0; s < NumSectors; s++) { - /* clear the "ends" array */ - for (n = 0; n < NumVertices; n++) - ends[n] = 0; - /* for each sidedef bound to the Sector, store a "1" in the "ends" */ - /* array for its starting Vertex, and a "2" for its ending Vertex */ - for (n = 0; n < NumLineDefs; n++) - { - sd = LineDefs[n].sidedef1; - if (sd >= 0 && SideDefs[sd].sector == s) - { - ends[LineDefs[n].start] |= 1; - ends[LineDefs[n].end] |= 2; - } - sd = LineDefs[n].sidedef2; - if (sd >= 0 && SideDefs[sd].sector == s) - { - ends[LineDefs[n].end] |= 1; - ends[LineDefs[n].start] |= 2; - } - } - /* every entry in the "ends" array should be "0" or "3" */ - for (n = 0; n < NumVertices; n++) - { - if (ends[n] == 1) - { - sprintf(msg1, "Sector #%d is not closed!", s); - sprintf(msg2, "There is no sidedef ending at Vertex #%d", n); - if (CheckFailed(-1, -1, msg1, msg2, 0, first_time)) - { - GoToObject(Objid(OBJ_VERTICES, n)); - return; - } - } - if (ends[n] == 2) - { - sprintf(msg1, "Sector #%d is not closed!", s); - sprintf(msg2, "There is no sidedef starting at Vertex #%d", - n); - if (CheckFailed(-1, -1, msg1, msg2, 0, first_time)) - { - GoToObject(Objid(OBJ_VERTICES, n)); - return; - } - } - } + /* clear the "ends" array */ + for (n = 0; n < NumVertices; n++) + ends[n] = 0; + /* for each sidedef bound to the Sector, store a "1" in the "ends" */ + /* array for its starting Vertex, and a "2" for its ending Vertex */ + for (n = 0; n < NumLineDefs; n++) + { + sd = LineDefs[n].sidedef1; + if (sd >= 0 && SideDefs[sd].sector == s) + { + ends[LineDefs[n].start] |= 1; + ends[LineDefs[n].end] |= 2; + } + sd = LineDefs[n].sidedef2; + if (sd >= 0 && SideDefs[sd].sector == s) + { + ends[LineDefs[n].end] |= 1; + ends[LineDefs[n].start] |= 2; + } + } + /* every entry in the "ends" array should be "0" or "3" */ + for (n = 0; n < NumVertices; n++) + { + if (ends[n] == 1) + { + sprintf(msg1, "Sector #%d is not closed!", s); + sprintf(msg2, "There is no sidedef ending at Vertex #%d", n); + if (CheckFailed(-1, -1, msg1, msg2, 0, first_time)) + { + GoToObject(Objid(OBJ_VERTICES, n)); + return; + } + } + if (ends[n] == 2) + { + sprintf(msg1, "Sector #%d is not closed!", s); + sprintf(msg2, "There is no sidedef starting at Vertex #%d", + n); + if (CheckFailed(-1, -1, msg1, msg2, 0, first_time)) + { + GoToObject(Objid(OBJ_VERTICES, n)); + return; + } + } + } } FreeMemory(ends); @@ -322,60 +322,60 @@ /* now check if all SideDefs are facing a sidedef with the same Sector number */ for (n = 0; n < NumLineDefs; n++) { - sd = LineDefs[n].sidedef1; - if (sd >= 0) - { - s = GetOppositeSector(n, 1); - if (s < 0 || SideDefs[sd].sector != s) - { - if (s < 0) - { - sprintf(msg1, "Sector #%d is not closed!", - SideDefs[sd].sector); - sprintf(msg2, "Check linedef #%d (first sidedef: #%d)", n, - sd); - } - else - { - sprintf(msg1, "Sectors #%d and #%d are not closed!", - SideDefs[sd].sector, s); - sprintf(msg2, "Check linedef #%d (first sidedef: #%d)" - " and the one facing it", n, sd); - } - if (CheckFailed(-1, -1, msg1, msg2, 0, first_time)) - { - GoToObject(Objid(OBJ_LINEDEFS, n)); - return; - } - } - } - sd = LineDefs[n].sidedef2; - if (sd >= 0) - { - s = GetOppositeSector(n, 0); - if (s < 0 || SideDefs[sd].sector != s) - { - if (s < 0) - { - sprintf(msg1, "Sector #%d is not closed!", - SideDefs[sd].sector); - sprintf(msg2, "Check linedef #%d (second sidedef: #%d)", - n, sd); - } - else - { - sprintf(msg1, "Sectors #%d and #%d are not closed!", - SideDefs[sd].sector, s); - sprintf(msg2, "Check linedef #%d (second sidedef: #%d)" - " and the one facing it", n, sd); - } - if (CheckFailed(-1, -1, msg1, msg2, 0, first_time)) - { - GoToObject(Objid(OBJ_LINEDEFS, n)); - return; - } - } - } + sd = LineDefs[n].sidedef1; + if (sd >= 0) + { + s = GetOppositeSector(n, 1); + if (s < 0 || SideDefs[sd].sector != s) + { + if (s < 0) + { + sprintf(msg1, "Sector #%d is not closed!", + SideDefs[sd].sector); + sprintf(msg2, "Check linedef #%d (first sidedef: #%d)", n, + sd); + } + else + { + sprintf(msg1, "Sectors #%d and #%d are not closed!", + SideDefs[sd].sector, s); + sprintf(msg2, "Check linedef #%d (first sidedef: #%d)" + " and the one facing it", n, sd); + } + if (CheckFailed(-1, -1, msg1, msg2, 0, first_time)) + { + GoToObject(Objid(OBJ_LINEDEFS, n)); + return; + } + } + } + sd = LineDefs[n].sidedef2; + if (sd >= 0) + { + s = GetOppositeSector(n, 0); + if (s < 0 || SideDefs[sd].sector != s) + { + if (s < 0) + { + sprintf(msg1, "Sector #%d is not closed!", + SideDefs[sd].sector); + sprintf(msg2, "Check linedef #%d (second sidedef: #%d)", + n, sd); + } + else + { + sprintf(msg1, "Sectors #%d and #%d are not closed!", + SideDefs[sd].sector, s); + sprintf(msg2, "Check linedef #%d (second sidedef: #%d)" + " and the one facing it", n, sd); + } + if (CheckFailed(-1, -1, msg1, msg2, 0, first_time)) + { + GoToObject(Objid(OBJ_LINEDEFS, n)); + return; + } + } + } } } @@ -384,7 +384,7 @@ check cross-references and delete unused objects */ -void CheckCrossReferences() /* SWAP! */ +void CheckCrossReferences() /* SWAP! */ { char msg[80]; int n, m; @@ -395,39 +395,39 @@ LogMessage("\nVerifying cross-references...\n"); for (n = 0; n < NumLineDefs; n++) { - /* Check for missing first sidedefs */ - if (LineDefs[n].sidedef1 < 0) - { - sprintf(msg, "ERROR: linedef #%d has no first sidedef!", n); - CheckFailed(-1, -1, msg, 0, 1, first_time); - GoToObject(Objid(OBJ_LINEDEFS, n)); - return; - } + /* Check for missing first sidedefs */ + if (LineDefs[n].sidedef1 < 0) + { + sprintf(msg, "ERROR: linedef #%d has no first sidedef!", n); + CheckFailed(-1, -1, msg, 0, 1, first_time); + GoToObject(Objid(OBJ_LINEDEFS, n)); + return; + } // FIXME should make this a mere warning -#ifdef OLD /* ifdef'd out AYM 19970725, I do it and it works */ - /* Check for sidedefs used twice in the same linedef */ - if (LineDefs[n].sidedef1 == LineDefs[n].sidedef2) - { - sprintf(msg, - "ERROR: linedef #%d uses the same sidedef twice (#%d)", n, - LineDefs[n].sidedef1); - CheckFailed(-1, -1, msg, 0, 1, first_time); - GoToObject(Objid(OBJ_LINEDEFS, n)); - return; - } +#ifdef OLD /* ifdef'd out AYM 19970725, I do it and it works */ + /* Check for sidedefs used twice in the same linedef */ + if (LineDefs[n].sidedef1 == LineDefs[n].sidedef2) + { + sprintf(msg, + "ERROR: linedef #%d uses the same sidedef twice (#%d)", n, + LineDefs[n].sidedef1); + CheckFailed(-1, -1, msg, 0, 1, first_time); + GoToObject(Objid(OBJ_LINEDEFS, n)); + return; + } #endif - /* Check for vertices used twice in the same linedef */ - if (LineDefs[n].start == LineDefs[n].end) - { - sprintf(msg, - "ERROR: linedef #%d uses the same vertex twice (#%d)", n, - LineDefs[n].start); - CheckFailed(-1, -1, msg, 0, 1, first_time); - GoToObject(Objid(OBJ_LINEDEFS, n)); - return; - } + /* Check for vertices used twice in the same linedef */ + if (LineDefs[n].start == LineDefs[n].end) + { + sprintf(msg, + "ERROR: linedef #%d uses the same vertex twice (#%d)", n, + LineDefs[n].start); + CheckFailed(-1, -1, msg, 0, 1, first_time); + GoToObject(Objid(OBJ_LINEDEFS, n)); + return; + } } /* check if there aren't two linedefs between the same Vertices */ @@ -435,158 +435,158 @@ /* AYM 19980203 FIXME should use new algorithm */ for (n = NumLineDefs - 1; n >= 1; n--) { - for (m = n - 1; m >= 0; m--) - if ((LineDefs[n].start == LineDefs[m].start - && LineDefs[n].end == LineDefs[m].end) - || (LineDefs[n].start == LineDefs[m].end - && LineDefs[n].end == LineDefs[m].start)) - { - SelectObject(&cur, n); - break; - } + for (m = n - 1; m >= 0; m--) + if ((LineDefs[n].start == LineDefs[m].start + && LineDefs[n].end == LineDefs[m].end) + || (LineDefs[n].start == LineDefs[m].end + && LineDefs[n].end == LineDefs[m].start)) + { + SelectObject(&cur, n); + break; + } } if (cur - && (Expert - || Confirm(-1, -1, - "There are multiple linedefs between the same vertices", - "Do you want to delete the redundant linedefs?"))) - DeleteObjects(OBJ_LINEDEFS, &cur); + && (Expert + || Confirm(-1, -1, + "There are multiple linedefs between the same vertices", + "Do you want to delete the redundant linedefs?"))) + DeleteObjects(OBJ_LINEDEFS, &cur); else - ForgetSelection(&cur); + ForgetSelection(&cur); CheckingObjects(); /* check for invalid flags in the linedefs */ for (n = 0; n < NumLineDefs; n++) - if ((LineDefs[n].flags & 0x01) == 0 && LineDefs[n].sidedef2 < 0) - SelectObject(&cur, n); + if ((LineDefs[n].flags & 0x01) == 0 && LineDefs[n].sidedef2 < 0) + SelectObject(&cur, n); if (cur && (Expert - || Confirm(-1, -1, - "Some linedefs have only one side but their I flag is" - " not set", - "Do you want to set the 'Impassible' flag?"))) - while (cur) - { - LogMessage("Check: 1-sided linedef without I flag: %d", - cur->objnum); - LineDefs[cur->objnum].flags |= 0x01; - UnSelectObject(&cur, cur->objnum); - } + || Confirm(-1, -1, + "Some linedefs have only one side but their I flag is" + " not set", + "Do you want to set the 'Impassible' flag?"))) + while (cur) + { + LogMessage("Check: 1-sided linedef without I flag: %d", + cur->objnum); + LineDefs[cur->objnum].flags |= 0x01; + UnSelectObject(&cur, cur->objnum); + } else - ForgetSelection(&cur); + ForgetSelection(&cur); CheckingObjects(); for (n = 0; n < NumLineDefs; n++) - if ((LineDefs[n].flags & 0x04) != 0 && LineDefs[n].sidedef2 < 0) - SelectObject(&cur, n); + if ((LineDefs[n].flags & 0x04) != 0 && LineDefs[n].sidedef2 < 0) + SelectObject(&cur, n); if (cur - && (Expert - || Confirm(-1, -1, - "Some linedefs have only one side but their 2 flag" - " is set", - "Do you want to clear the 'two-sided' flag?"))) + && (Expert + || Confirm(-1, -1, + "Some linedefs have only one side but their 2 flag" + " is set", + "Do you want to clear the 'two-sided' flag?"))) { - while (cur) - { - LogMessage("Check: 1-sided linedef with 2s bit: %d", cur->objnum); - LineDefs[cur->objnum].flags &= ~0x04; - UnSelectObject(&cur, cur->objnum); - } + while (cur) + { + LogMessage("Check: 1-sided linedef with 2s bit: %d", cur->objnum); + LineDefs[cur->objnum].flags &= ~0x04; + UnSelectObject(&cur, cur->objnum); + } } else - ForgetSelection(&cur); + ForgetSelection(&cur); CheckingObjects(); for (n = 0; n < NumLineDefs; n++) - if ((LineDefs[n].flags & 0x04) == 0 && LineDefs[n].sidedef2 >= 0) - SelectObject(&cur, n); + if ((LineDefs[n].flags & 0x04) == 0 && LineDefs[n].sidedef2 >= 0) + SelectObject(&cur, n); if (cur - && (Expert - || Confirm(-1, -1, - "Some linedefs have two sides but their 2S bit is not set", - "Do you want to set the 'two-sided' flag?"))) + && (Expert + || Confirm(-1, -1, + "Some linedefs have two sides but their 2S bit is not set", + "Do you want to set the 'two-sided' flag?"))) { - while (cur) - { - LineDefs[cur->objnum].flags |= 0x04; - UnSelectObject(&cur, cur->objnum); - } + while (cur) + { + LineDefs[cur->objnum].flags |= 0x04; + UnSelectObject(&cur, cur->objnum); + } } else - ForgetSelection(&cur); + ForgetSelection(&cur); CheckingObjects(); /* select all Vertices */ for (n = 0; n < NumVertices; n++) - SelectObject(&cur, n); + SelectObject(&cur, n); /* unselect Vertices used in a LineDef */ for (n = 0; n < NumLineDefs; n++) { - m = LineDefs[n].start; - if (cur && m >= 0) - UnSelectObject(&cur, m); - m = LineDefs[n].end; - if (cur && m >= 0) - UnSelectObject(&cur, m); - continue; + m = LineDefs[n].start; + if (cur && m >= 0) + UnSelectObject(&cur, m); + m = LineDefs[n].end; + if (cur && m >= 0) + UnSelectObject(&cur, m); + continue; } /* check if there are any Vertices left */ if (cur - && (Expert - || Confirm(-1, -1, "Some vertices are not bound to any linedef", - "Do you want to delete these unused Vertices?"))) + && (Expert + || Confirm(-1, -1, "Some vertices are not bound to any linedef", + "Do you want to delete these unused Vertices?"))) { - DeleteObjects(OBJ_VERTICES, &cur); + DeleteObjects(OBJ_VERTICES, &cur); } else - ForgetSelection(&cur); + ForgetSelection(&cur); CheckingObjects(); /* select all SideDefs */ for (n = 0; n < NumSideDefs; n++) - SelectObject(&cur, n); + SelectObject(&cur, n); /* unselect SideDefs bound to a LineDef */ for (n = 0; n < NumLineDefs; n++) { - m = LineDefs[n].sidedef1; - if (cur && m >= 0) - UnSelectObject(&cur, m); - m = LineDefs[n].sidedef2; - if (cur && m >= 0) - UnSelectObject(&cur, m); - continue; + m = LineDefs[n].sidedef1; + if (cur && m >= 0) + UnSelectObject(&cur, m); + m = LineDefs[n].sidedef2; + if (cur && m >= 0) + UnSelectObject(&cur, m); + continue; } /* check if there are any SideDefs left */ if (cur - && (Expert - || Confirm(-1, -1, "Some sidedefs are not bound to any linedef", - "Do you want to delete these unused sidedefs?"))) - DeleteObjects(OBJ_SIDEDEFS, &cur); + && (Expert + || Confirm(-1, -1, "Some sidedefs are not bound to any linedef", + "Do you want to delete these unused sidedefs?"))) + DeleteObjects(OBJ_SIDEDEFS, &cur); else - ForgetSelection(&cur); + ForgetSelection(&cur); CheckingObjects(); /* select all Sectors */ for (n = 0; n < NumSectors; n++) - SelectObject(&cur, n); + SelectObject(&cur, n); /* unselect Sectors bound to a sidedef */ for (n = 0; n < NumLineDefs; n++) { - m = LineDefs[n].sidedef1; - if (cur && m >= 0 /* && SideDefs[m].sector >= 0 AYM 1998-06-13 */ ) - UnSelectObject(&cur, SideDefs[m].sector); - m = LineDefs[n].sidedef2; - if (cur && m >= 0 /* && SideDefs[m].sector >= 0 AYM 1998-06-13 */ ) - UnSelectObject(&cur, SideDefs[m].sector); - continue; + m = LineDefs[n].sidedef1; + if (cur && m >= 0 /* && SideDefs[m].sector >= 0 AYM 1998-06-13 */ ) + UnSelectObject(&cur, SideDefs[m].sector); + m = LineDefs[n].sidedef2; + if (cur && m >= 0 /* && SideDefs[m].sector >= 0 AYM 1998-06-13 */ ) + UnSelectObject(&cur, SideDefs[m].sector); + continue; } /* check if there are any Sectors left */ if (cur - && (Expert - || Confirm(-1, -1, "Some sectors are not bound to any sidedef", - "Do you want to delete these unused sectors?"))) - DeleteObjects(OBJ_SECTORS, &cur); + && (Expert + || Confirm(-1, -1, "Some sectors are not bound to any sidedef", + "Do you want to delete these unused sectors?"))) + DeleteObjects(OBJ_SECTORS, &cur); else - ForgetSelection(&cur); + ForgetSelection(&cur); } @@ -594,7 +594,7 @@ check for missing textures */ -void CheckTextures() /* SWAP! */ +void CheckTextures() /* SWAP! */ { int n; int sd1, sd2; @@ -606,163 +606,163 @@ LogMessage("\nVerifying textures...\n"); for (n = 0; n < NumSectors; n++) { - if (strcmp(Sectors[n].ceilt, "-") == 0 - || strcmp(Sectors[n].ceilt, "") == 0 - || memcmp(Sectors[n].ceilt, " ", 8) == 0) - { - sprintf(msg1, "Error: sector #%d has no ceiling texture", n); - sprintf(msg2, - "You probably used a brain-damaged editor to do that..."); - CheckFailed(-1, -1, msg1, msg2, 1, first_time); - GoToObject(Objid(OBJ_SECTORS, n)); - return; - } - if (strcmp(Sectors[n].floort, "-") == 0 - || strcmp(Sectors[n].floort, "") == 0 - || memcmp(Sectors[n].floort, " ", 8) == 0) - { - sprintf(msg1, "Error: sector #%d has no floor texture", n); - sprintf(msg2, - "You probably used a brain-damaged editor to do that..."); - CheckFailed(-1, -1, msg1, msg2, 1, first_time); - GoToObject(Objid(OBJ_SECTORS, n)); - return; - } - if (Sectors[n].ceilh < Sectors[n].floorh) - { - sprintf(msg1, - "Error: sector #%d has its ceiling lower than its floor", - n); - sprintf(msg2, - "The textures will never be displayed if you cannot go there"); - CheckFailed(-1, -1, msg1, msg2, 1, first_time); - GoToObject(Objid(OBJ_SECTORS, n)); - return; - } -#if 0 /* AYM 2000-08-13 */ - if (Sectors[n].ceilh - Sectors[n].floorh > 1023) - { - sprintf(msg1, "Error: sector #%d has its ceiling too high", n); - sprintf(msg2, - "The maximum difference allowed is 1023 (ceiling - floor)"); - CheckFailed(-1, -1, msg1, msg2, 1, first_time); - GoToObject(Objid(OBJ_SECTORS, n)); - return; - } + if (strcmp(Sectors[n].ceilt, "-") == 0 + || strcmp(Sectors[n].ceilt, "") == 0 + || memcmp(Sectors[n].ceilt, " ", 8) == 0) + { + sprintf(msg1, "Error: sector #%d has no ceiling texture", n); + sprintf(msg2, + "You probably used a brain-damaged editor to do that..."); + CheckFailed(-1, -1, msg1, msg2, 1, first_time); + GoToObject(Objid(OBJ_SECTORS, n)); + return; + } + if (strcmp(Sectors[n].floort, "-") == 0 + || strcmp(Sectors[n].floort, "") == 0 + || memcmp(Sectors[n].floort, " ", 8) == 0) + { + sprintf(msg1, "Error: sector #%d has no floor texture", n); + sprintf(msg2, + "You probably used a brain-damaged editor to do that..."); + CheckFailed(-1, -1, msg1, msg2, 1, first_time); + GoToObject(Objid(OBJ_SECTORS, n)); + return; + } + if (Sectors[n].ceilh < Sectors[n].floorh) + { + sprintf(msg1, + "Error: sector #%d has its ceiling lower than its floor", + n); + sprintf(msg2, + "The textures will never be displayed if you cannot go there"); + CheckFailed(-1, -1, msg1, msg2, 1, first_time); + GoToObject(Objid(OBJ_SECTORS, n)); + return; + } +#if 0 /* AYM 2000-08-13 */ + if (Sectors[n].ceilh - Sectors[n].floorh > 1023) + { + sprintf(msg1, "Error: sector #%d has its ceiling too high", n); + sprintf(msg2, + "The maximum difference allowed is 1023 (ceiling - floor)"); + CheckFailed(-1, -1, msg1, msg2, 1, first_time); + GoToObject(Objid(OBJ_SECTORS, n)); + return; + } #endif } for (n = 0; n < NumLineDefs; n++) { - sd1 = LineDefs[n].sidedef1; - sd2 = LineDefs[n].sidedef2; - if (sd1 >= 0) - s1 = SideDefs[sd1].sector; - else - s1 = OBJ_NO_NONE; - if (sd2 >= 0) - s2 = SideDefs[sd2].sector; - else - s2 = OBJ_NO_NONE; - if (is_obj(s1) && !is_obj(s2)) - { - if (SideDefs[sd1].tex3[0] == '-' && SideDefs[sd1].tex3[1] == '\0') - { - sprintf(msg1, "Error in one-sided linedef #%d:" - " sidedef #%d has no middle texture", n, sd1); - sprintf(msg2, "Do you want to set the texture to \"%s\"" - " and continue?", default_middle_texture); - if (CheckFailed(-1, -1, msg1, msg2, 0, first_time)) - { - GoToObject(Objid(OBJ_LINEDEFS, n)); - return; - } - strncpy(SideDefs[sd1].tex3, default_middle_texture, - WAD_TEX_NAME); - MadeChanges = 1; - CheckingObjects(); - } - } - if (is_obj(s1) && is_obj(s2) && Sectors[s1].ceilh > Sectors[s2].ceilh) - { - if (SideDefs[sd1].tex1[0] == '-' && SideDefs[sd1].tex1[1] == '\0' - && (!is_sky(Sectors[s1].ceilt) || !is_sky(Sectors[s2].ceilt))) - { - sprintf(msg1, "Error in first sidedef of linedef #%d:" - " sidedef #%d has no upper texture", n, sd1); - sprintf(msg2, "Do you want to set the texture to \"%s\"" - " and continue?", default_upper_texture); - if (CheckFailed(-1, -1, msg1, msg2, 0, first_time)) - { - GoToObject(Objid(OBJ_LINEDEFS, n)); - return; - } - strncpy(SideDefs[sd1].tex1, default_upper_texture, - WAD_TEX_NAME); - MadeChanges = 1; - CheckingObjects(); - } - } - if (is_obj(s1) && is_obj(s2) - && Sectors[s1].floorh < Sectors[s2].floorh) - { - if (SideDefs[sd1].tex2[0] == '-' && SideDefs[sd1].tex2[1] == '\0') - { - sprintf(msg1, "Error in first sidedef of linedef #%d:" - " sidedef #%d has no lower texture", n, sd1); - sprintf(msg2, "Do you want to set the texture to \"%s\"" - " and continue?", default_lower_texture); - if (CheckFailed(-1, -1, msg1, msg2, 0, first_time)) - { - GoToObject(Objid(OBJ_LINEDEFS, n)); - return; - } - strncpy(SideDefs[sd1].tex2, default_lower_texture, - WAD_TEX_NAME); - MadeChanges = 1; - CheckingObjects(); - } - } - if (is_obj(s1) && is_obj(s2) && Sectors[s2].ceilh > Sectors[s1].ceilh) - { - if (SideDefs[sd2].tex1[0] == '-' && SideDefs[sd2].tex1[1] == '\0' - && (!is_sky(Sectors[s1].ceilt) || !is_sky(Sectors[s2].ceilt))) - { - sprintf(msg1, "Error in second sidedef of linedef #%d:" - " sidedef #%d has no upper texture", n, sd2); - sprintf(msg2, "Do you want to set the texture to \"%s\"" - " and continue?", default_upper_texture); - if (CheckFailed(-1, -1, msg1, msg2, 0, first_time)) - { - GoToObject(Objid(OBJ_LINEDEFS, n)); - return; - } - strncpy(SideDefs[sd2].tex1, default_upper_texture, - WAD_TEX_NAME); - MadeChanges = 1; - CheckingObjects(); - } - } - if (is_obj(s1) && is_obj(s2) - && Sectors[s2].floorh < Sectors[s1].floorh) - { - if (SideDefs[sd2].tex2[0] == '-' && SideDefs[sd2].tex2[1] == '\0') - { - sprintf(msg1, "Error in second sidedef of linedef #%d:" - " sidedef #%d has no lower texture", n, sd2); - sprintf(msg2, "Do you want to set the texture to \"%s\"" - " and continue?", default_lower_texture); - if (CheckFailed(-1, -1, msg1, msg2, 0, first_time)) - { - GoToObject(Objid(OBJ_LINEDEFS, n)); - return; - } - strncpy(SideDefs[sd2].tex2, default_lower_texture, - WAD_TEX_NAME); - MadeChanges = 1; - CheckingObjects(); - } - } + sd1 = LineDefs[n].sidedef1; + sd2 = LineDefs[n].sidedef2; + if (sd1 >= 0) + s1 = SideDefs[sd1].sector; + else + s1 = OBJ_NO_NONE; + if (sd2 >= 0) + s2 = SideDefs[sd2].sector; + else + s2 = OBJ_NO_NONE; + if (is_obj(s1) && !is_obj(s2)) + { + if (SideDefs[sd1].tex3[0] == '-' && SideDefs[sd1].tex3[1] == '\0') + { + sprintf(msg1, "Error in one-sided linedef #%d:" + " sidedef #%d has no middle texture", n, sd1); + sprintf(msg2, "Do you want to set the texture to \"%s\"" + " and continue?", default_middle_texture); + if (CheckFailed(-1, -1, msg1, msg2, 0, first_time)) + { + GoToObject(Objid(OBJ_LINEDEFS, n)); + return; + } + strncpy(SideDefs[sd1].tex3, default_middle_texture, + WAD_TEX_NAME); + MadeChanges = 1; + CheckingObjects(); + } + } + if (is_obj(s1) && is_obj(s2) && Sectors[s1].ceilh > Sectors[s2].ceilh) + { + if (SideDefs[sd1].tex1[0] == '-' && SideDefs[sd1].tex1[1] == '\0' + && (!is_sky(Sectors[s1].ceilt) || !is_sky(Sectors[s2].ceilt))) + { + sprintf(msg1, "Error in first sidedef of linedef #%d:" + " sidedef #%d has no upper texture", n, sd1); + sprintf(msg2, "Do you want to set the texture to \"%s\"" + " and continue?", default_upper_texture); + if (CheckFailed(-1, -1, msg1, msg2, 0, first_time)) + { + GoToObject(Objid(OBJ_LINEDEFS, n)); + return; + } + strncpy(SideDefs[sd1].tex1, default_upper_texture, + WAD_TEX_NAME); + MadeChanges = 1; + CheckingObjects(); + } + } + if (is_obj(s1) && is_obj(s2) + && Sectors[s1].floorh < Sectors[s2].floorh) + { + if (SideDefs[sd1].tex2[0] == '-' && SideDefs[sd1].tex2[1] == '\0') + { + sprintf(msg1, "Error in first sidedef of linedef #%d:" + " sidedef #%d has no lower texture", n, sd1); + sprintf(msg2, "Do you want to set the texture to \"%s\"" + " and continue?", default_lower_texture); + if (CheckFailed(-1, -1, msg1, msg2, 0, first_time)) + { + GoToObject(Objid(OBJ_LINEDEFS, n)); + return; + } + strncpy(SideDefs[sd1].tex2, default_lower_texture, + WAD_TEX_NAME); + MadeChanges = 1; + CheckingObjects(); + } + } + if (is_obj(s1) && is_obj(s2) && Sectors[s2].ceilh > Sectors[s1].ceilh) + { + if (SideDefs[sd2].tex1[0] == '-' && SideDefs[sd2].tex1[1] == '\0' + && (!is_sky(Sectors[s1].ceilt) || !is_sky(Sectors[s2].ceilt))) + { + sprintf(msg1, "Error in second sidedef of linedef #%d:" + " sidedef #%d has no upper texture", n, sd2); + sprintf(msg2, "Do you want to set the texture to \"%s\"" + " and continue?", default_upper_texture); + if (CheckFailed(-1, -1, msg1, msg2, 0, first_time)) + { + GoToObject(Objid(OBJ_LINEDEFS, n)); + return; + } + strncpy(SideDefs[sd2].tex1, default_upper_texture, + WAD_TEX_NAME); + MadeChanges = 1; + CheckingObjects(); + } + } + if (is_obj(s1) && is_obj(s2) + && Sectors[s2].floorh < Sectors[s1].floorh) + { + if (SideDefs[sd2].tex2[0] == '-' && SideDefs[sd2].tex2[1] == '\0') + { + sprintf(msg1, "Error in second sidedef of linedef #%d:" + " sidedef #%d has no lower texture", n, sd2); + sprintf(msg2, "Do you want to set the texture to \"%s\"" + " and continue?", default_lower_texture); + if (CheckFailed(-1, -1, msg1, msg2, 0, first_time)) + { + GoToObject(Objid(OBJ_LINEDEFS, n)); + return; + } + strncpy(SideDefs[sd2].tex2, default_lower_texture, + WAD_TEX_NAME); + MadeChanges = 1; + CheckingObjects(); + } + } } } @@ -776,8 +776,8 @@ int n; for (n = 0; n < numelems; n++) - if (!y_strnicmp(name, list[n], WAD_TEX_NAME)) - return true; + if (!y_strnicmp(name, list[n], WAD_TEX_NAME)) + return true; return false; } @@ -786,7 +786,7 @@ check for invalid texture names */ -void CheckTextureNames() /* SWAP! */ +void CheckTextureNames() /* SWAP! */ { int n; char msg1[80], msg2[80]; @@ -797,73 +797,73 @@ // AYM 2000-07-24: could someone explain this one ? if (!FindMasterDir(MasterDir, "F2_START")) - NumThings--; + NumThings--; for (n = 0; n < NumSectors; n++) { - if (!is_flat_name_in_list(Sectors[n].ceilt)) - { - sprintf(msg1, "Invalid ceiling texture in sector #%d", n); - sprintf(msg2, "The name \"%.*s\" is not a floor/ceiling texture", - (int) WAD_FLAT_NAME, Sectors[n].ceilt); - if (CheckFailed(-1, -1, msg1, msg2, 0, first_time)) - { - GoToObject(Objid(OBJ_SECTORS, n)); - return; - } - CheckingObjects(); - } - if (!is_flat_name_in_list(Sectors[n].floort)) - { - sprintf(msg1, "Invalid floor texture in sector #%d", n); - sprintf(msg2, "The name \"%.*s\" is not a floor/ceiling texture", - (int) WAD_FLAT_NAME, Sectors[n].floort); - if (CheckFailed(-1, -1, msg1, msg2, 0, first_time)) - { - GoToObject(Objid(OBJ_SECTORS, n)); - return; - } - CheckingObjects(); - } + if (!is_flat_name_in_list(Sectors[n].ceilt)) + { + sprintf(msg1, "Invalid ceiling texture in sector #%d", n); + sprintf(msg2, "The name \"%.*s\" is not a floor/ceiling texture", + (int) WAD_FLAT_NAME, Sectors[n].ceilt); + if (CheckFailed(-1, -1, msg1, msg2, 0, first_time)) + { + GoToObject(Objid(OBJ_SECTORS, n)); + return; + } + CheckingObjects(); + } + if (!is_flat_name_in_list(Sectors[n].floort)) + { + sprintf(msg1, "Invalid floor texture in sector #%d", n); + sprintf(msg2, "The name \"%.*s\" is not a floor/ceiling texture", + (int) WAD_FLAT_NAME, Sectors[n].floort); + if (CheckFailed(-1, -1, msg1, msg2, 0, first_time)) + { + GoToObject(Objid(OBJ_SECTORS, n)); + return; + } + CheckingObjects(); + } } for (n = 0; n < NumSideDefs; n++) { - if (!IsTextureNameInList(SideDefs[n].tex1, WTexture, NumWTexture)) - { - sprintf(msg1, "Invalid upper texture in sidedef #%d", n); - sprintf(msg2, "The name \"%.*s\" is not a wall texture", - (int) WAD_TEX_NAME, SideDefs[n].tex1); - if (CheckFailed(-1, -1, msg1, msg2, 0, first_time)) - { - GoToObject(Objid(OBJ_SIDEDEFS, n)); - return; - } - CheckingObjects(); - } - if (!IsTextureNameInList(SideDefs[n].tex2, WTexture, NumWTexture)) - { - sprintf(msg1, "Invalid lower texture in sidedef #%d", n); - sprintf(msg2, "The name \"%.*s\" is not a wall texture", - (int) WAD_TEX_NAME, SideDefs[n].tex2); - if (CheckFailed(-1, -1, msg1, msg2, 0, first_time)) - { - GoToObject(Objid(OBJ_SIDEDEFS, n)); - return; - } - CheckingObjects(); - } - if (!IsTextureNameInList(SideDefs[n].tex3, WTexture, NumWTexture)) - { - sprintf(msg1, "Invalid middle texture in sidedef #%d", n); - sprintf(msg2, "The name \"%.*s\" is not a wall texture", - (int) WAD_TEX_NAME, SideDefs[n].tex3); - if (CheckFailed(-1, -1, msg1, msg2, 0, first_time)) - { - GoToObject(Objid(OBJ_SIDEDEFS, n)); - return; - } - CheckingObjects(); - } + if (!IsTextureNameInList(SideDefs[n].tex1, WTexture, NumWTexture)) + { + sprintf(msg1, "Invalid upper texture in sidedef #%d", n); + sprintf(msg2, "The name \"%.*s\" is not a wall texture", + (int) WAD_TEX_NAME, SideDefs[n].tex1); + if (CheckFailed(-1, -1, msg1, msg2, 0, first_time)) + { + GoToObject(Objid(OBJ_SIDEDEFS, n)); + return; + } + CheckingObjects(); + } + if (!IsTextureNameInList(SideDefs[n].tex2, WTexture, NumWTexture)) + { + sprintf(msg1, "Invalid lower texture in sidedef #%d", n); + sprintf(msg2, "The name \"%.*s\" is not a wall texture", + (int) WAD_TEX_NAME, SideDefs[n].tex2); + if (CheckFailed(-1, -1, msg1, msg2, 0, first_time)) + { + GoToObject(Objid(OBJ_SIDEDEFS, n)); + return; + } + CheckingObjects(); + } + if (!IsTextureNameInList(SideDefs[n].tex3, WTexture, NumWTexture)) + { + sprintf(msg1, "Invalid middle texture in sidedef #%d", n); + sprintf(msg2, "The name \"%.*s\" is not a wall texture", + (int) WAD_TEX_NAME, SideDefs[n].tex3); + if (CheckFailed(-1, -1, msg1, msg2, 0, first_time)) + { + GoToObject(Objid(OBJ_SIDEDEFS, n)); + return; + } + CheckingObjects(); + } } } @@ -872,7 +872,7 @@ check for players starting points */ -bool CheckStartingPos() /* SWAP! */ +bool CheckStartingPos() /* SWAP! */ { char msg1[80], msg2[80]; bool p1 = false; @@ -884,62 +884,62 @@ for (t = 0; t < NumThings; t++) { - if (Things[t].type == THING_PLAYER1) - p1 = true; - if (Things[t].type == THING_PLAYER2) - p2 = true; - if (Things[t].type == THING_PLAYER3) - p3 = true; - if (Things[t].type == THING_PLAYER4) - p4 = true; - if (Things[t].type == THING_DEATHMATCH) - dm++; + if (Things[t].type == THING_PLAYER1) + p1 = true; + if (Things[t].type == THING_PLAYER2) + p2 = true; + if (Things[t].type == THING_PLAYER3) + p3 = true; + if (Things[t].type == THING_PLAYER4) + p4 = true; + if (Things[t].type == THING_DEATHMATCH) + dm++; } if (!p1) { - Beep(); - if (!Confirm - (-1, -1, - "Warning: there is no player 1 starting point. The" " game", - "will crash if you play with this level. Save anyway ?")) - return false; - else - return true; // No point in doing further checking ! + Beep(); + if (!Confirm + (-1, -1, + "Warning: there is no player 1 starting point. The" " game", + "will crash if you play with this level. Save anyway ?")) + return false; + else + return true; // No point in doing further checking ! } if (Expert) - return true; + return true; if (!p2 || !p3 || !p4) { - if (!p4) - t = 4; - if (!p3) - t = 3; - if (!p2) - t = 2; - sprintf(msg1, "Warning: there is no player %d start." - " You will not be able", t); - sprintf(msg2, "to use this level for multi-player games." - " Save anyway ?"); - if (!Confirm(-1, -1, msg1, msg2)) - return false; - else - return true; // No point in doing further checking ! + if (!p4) + t = 4; + if (!p3) + t = 3; + if (!p2) + t = 2; + sprintf(msg1, "Warning: there is no player %d start." + " You will not be able", t); + sprintf(msg2, "to use this level for multi-player games." + " Save anyway ?"); + if (!Confirm(-1, -1, msg1, msg2)) + return false; + else + return true; // No point in doing further checking ! } if (dm < DOOM_MIN_DEATHMATCH_STARTS) { - if (dm == 0) - sprintf(msg1, "Warning: there are no deathmatch starts." - " You need at least %d", DOOM_MIN_DEATHMATCH_STARTS); - else if (dm == 1) - sprintf(msg1, "Warning: there is only one deathmatch start." - " You need at least %d", DOOM_MIN_DEATHMATCH_STARTS); - else - sprintf(msg1, "Warning: there are only %d deathmatch starts." - " You need at least %d", dm, DOOM_MIN_DEATHMATCH_STARTS); - sprintf(msg2, "deathmatch starts to play deathmatch games." - " Save anyway ?"); - if (!Confirm(-1, -1, msg1, msg2)) - return false; + if (dm == 0) + sprintf(msg1, "Warning: there are no deathmatch starts." + " You need at least %d", DOOM_MIN_DEATHMATCH_STARTS); + else if (dm == 1) + sprintf(msg1, "Warning: there is only one deathmatch start." + " You need at least %d", DOOM_MIN_DEATHMATCH_STARTS); + else + sprintf(msg1, "Warning: there are only %d deathmatch starts." + " You need at least %d", dm, DOOM_MIN_DEATHMATCH_STARTS); + sprintf(msg2, "deathmatch starts to play deathmatch games." + " Save anyway ?"); + if (!Confirm(-1, -1, msg1, msg2)) + return false; } return true; } diff -r 594dea11ccd9 -r a68786b9c74b src/checks.h --- a/src/checks.h Sat Sep 24 15:01:56 2011 +0300 +++ b/src/checks.h Sat Sep 24 15:59:33 2011 +0300 @@ -1,6 +1,6 @@ /* - * checks.h - * AYM 1998-12-02 + * checks.h + * AYM 1998-12-02 */ diff -r 594dea11ccd9 -r a68786b9c74b src/colour.h --- a/src/colour.h Sat Sep 24 15:01:56 2011 +0300 +++ b/src/colour.h Sat Sep 24 15:59:33 2011 +0300 @@ -1,11 +1,11 @@ /* - * colour.h - * AYM 1998-11-28 + * colour.h + * AYM 1998-11-28 */ -#ifndef YH_COLOUR // Prevent multiple inclusion -#define YH_COLOUR // Prevent multiple inclusion +#ifndef YH_COLOUR // Prevent multiple inclusion +#define YH_COLOUR // Prevent multiple inclusion class rgb_c; @@ -17,8 +17,8 @@ it's a palette index. With BGI 16-colour modes, it's an IRGB value. */ -typedef unsigned long pcolour_t; // X11: up to 32 BPP. -#define PCOLOUR_NONE 0xffffffff /* An "impossible" colour no. */ +typedef unsigned long pcolour_t; // X11: up to 32 BPP. +#define PCOLOUR_NONE 0xffffffff /* An "impossible" colour no. */ pcolour_t *alloc_colours(rgb_c rgb_values[], size_t count); void free_colours(pcolour_t * pc, size_t count); diff -r 594dea11ccd9 -r a68786b9c74b src/colour1.cc --- a/src/colour1.cc Sat Sep 24 15:01:56 2011 +0300 +++ b/src/colour1.cc Sat Sep 24 15:59:33 2011 +0300 @@ -1,7 +1,7 @@ /* - * colour1.cc - * getcolour() - * AYM 1998-01-27 + * colour1.cc + * getcolour() + * AYM 1998-01-27 */ @@ -32,15 +32,15 @@ #include "rgb.h" -#define RGB_DIGITS 2 /* R, G and B are 8-bit wide each */ +#define RGB_DIGITS 2 /* R, G and B are 8-bit wide each */ /* - * getcolour - * Decode an "rgb://" colour specification - * Returns : - * 0 OK - * <>0 malformed colour specification + * getcolour + * Decode an "rgb://" colour specification + * Returns : + * 0 OK + * <>0 malformed colour specification */ int getcolour(const char *s, rgb_c * rgb) { @@ -55,23 +55,23 @@ int globaldigits; if (strncmp(s, "rgb:", 4)) - return 1; + return 1; for (i = 4, r = 0, rdigits = 0; (digit = hextoi(s[i])) >= 0; - i++, rdigits++) - r = (r << 4) | digit; + i++, rdigits++) + r = (r << 4) | digit; if (s[i++] != '/') - return 2; + return 2; for (g = 0, gdigits = 0; (digit = hextoi(s[i])) >= 0; i++, gdigits++) - g = (g << 4) | digit; + g = (g << 4) | digit; if (s[i++] != '/') - return 3; + return 3; for (b = 0, bdigits = 0; (digit = hextoi(s[i])) >= 0; i++, bdigits++) - b = (b << 4) | digit; + b = (b << 4) | digit; if (s[i++] != '\0') - return 4; + return 4; // Force to 8 bits (RGB_DIGITS hex digits) by scaling up or down globaldigits = rdigits; @@ -79,15 +79,15 @@ globaldigits = y_max(globaldigits, bdigits); for (; globaldigits < RGB_DIGITS; globaldigits++) { - r <<= 4; - g <<= 4; - b <<= 4; + r <<= 4; + g <<= 4; + b <<= 4; } for (; globaldigits > RGB_DIGITS; globaldigits--) { - r >>= 4; - g >>= 4; - b >>= 4; + r >>= 4; + g >>= 4; + b >>= 4; } rgb->set(r, g, b); return 0; diff -r 594dea11ccd9 -r a68786b9c74b src/colour2.cc --- a/src/colour2.cc Sat Sep 24 15:01:56 2011 +0300 +++ b/src/colour2.cc Sat Sep 24 15:59:33 2011 +0300 @@ -1,7 +1,7 @@ /* - * colour2.cc - * rgb2irgb() - * AYM 1998-06-28 + * colour2.cc + * rgb2irgb() + * AYM 1998-06-28 */ @@ -32,8 +32,8 @@ /* - * rgb2irgb - * Convert an RGB colour to an IRGB (16-colour VGA) colour. + * rgb2irgb + * Convert an RGB colour to an IRGB (16-colour VGA) colour. */ int rgb2irgb(int r, int g, int b) { @@ -41,6 +41,6 @@ c = 4 * ! !r + 2 * ! !g + 1 * ! !b; if (r > 128 || g > 128 || b > 128) - c += 8; // Set high intensity bit + c += 8; // Set high intensity bit return c; } diff -r 594dea11ccd9 -r a68786b9c74b src/colour3.cc --- a/src/colour3.cc Sat Sep 24 15:01:56 2011 +0300 +++ b/src/colour3.cc Sat Sep 24 15:59:33 2011 +0300 @@ -1,7 +1,7 @@ /* - * colour3.cc - * irgb2rgb() - * AYM 1998-06-28 + * colour3.cc + * irgb2rgb() + * AYM 1998-06-28 */ @@ -33,18 +33,18 @@ /* - * irgb2rgb - * Convert an IRGB colour (16-colour VGA) to an 8-bit-per-component - * RGB colour. + * irgb2rgb + * Convert an IRGB colour (16-colour VGA) to an 8-bit-per-component + * RGB colour. */ void irgb2rgb(int c, rgb_c * rgb) { - if (c == 8) // Special case for DARKGREY - rgb->r = rgb->g = rgb->b = 0x40; + if (c == 8) // Special case for DARKGREY + rgb->r = rgb->g = rgb->b = 0x40; else { - rgb->r = (c & 4) ? ((c & 8) ? 0xff : 0x80) : 0; - rgb->g = (c & 2) ? ((c & 8) ? 0xff : 0x80) : 0; - rgb->b = (c & 1) ? ((c & 8) ? 0xff : 0x80) : 0; + rgb->r = (c & 4) ? ((c & 8) ? 0xff : 0x80) : 0; + rgb->g = (c & 2) ? ((c & 8) ? 0xff : 0x80) : 0; + rgb->b = (c & 1) ? ((c & 8) ? 0xff : 0x80) : 0; } } diff -r 594dea11ccd9 -r a68786b9c74b src/colour4.cc --- a/src/colour4.cc Sat Sep 24 15:01:56 2011 +0300 +++ b/src/colour4.cc Sat Sep 24 15:59:33 2011 +0300 @@ -1,7 +1,7 @@ /* - * colour4.cc - * Allocate and free physical colours. - * AYM 1998-11-27 + * colour4.cc + * Allocate and free physical colours. + * AYM 1998-11-27 */ @@ -42,21 +42,21 @@ with their rgb value and usage count. */ typedef struct { - pcolour_t pcn; // The physical colour# (pixel value). - rgb_c rgb; // Its RGB value. - int usage_count; // Number of logical colours that use it. + pcolour_t pcn; // The physical colour# (pixel value). + rgb_c rgb; // Its RGB value. + int usage_count; // Number of logical colours that use it. } pcolours_table_entry_t; pcolours_table_entry_t *pcolours = 0; -size_t physical_colours = 0; // Number of entries in +size_t physical_colours = 0; // Number of entries in static void dump_pcolours(); /* - * eight2sixteen - * Convert an 8-bit RGB component value to a 16-bit one. - * Will convert 00h to 0000h, 80h to 8080h and FFh to FFFFh. + * eight2sixteen + * Convert an 8-bit RGB component value to a 16-bit one. + * Will convert 00h to 0000h, 80h to 8080h and FFh to FFFFh. */ inline u16 eight2sixteen(u8 v) { @@ -65,9 +65,9 @@ /* - * alloc_colours - * Allocate a group of rgb values and return an array of - * physical colour numbers. + * alloc_colours + * Allocate a group of rgb values and return an array of + * physical colour numbers. */ pcolour_t *alloc_colours(rgb_c rgb_values[], size_t count) { @@ -75,122 +75,122 @@ pcolour_t *pcn_table = (pcolour_t *) malloc(count * sizeof *pcn_table); if (pcn_table == NULL) - fatal_error(msg_nomem); + fatal_error(msg_nomem); /* Allocate the physical colours if necessary. Should not do it for static visuals (StaticColor, TrueColor). It does no harm but it's useless. */ for (size_t n = 0; n < count; n++) { - // Is there already a physical colour for this RGB value ? - pcn_table[n] = PCOLOUR_NONE; - for (size_t i = 0; i < physical_colours; i++) - { - if (pcolours[i].rgb == rgb_values[n]) - { - // There is. Reuse it. - pcn_table[n] = pcolours[i].pcn; - pcolours[i].usage_count++; - break; - } - } + // Is there already a physical colour for this RGB value ? + pcn_table[n] = PCOLOUR_NONE; + for (size_t i = 0; i < physical_colours; i++) + { + if (pcolours[i].rgb == rgb_values[n]) + { + // There is. Reuse it. + pcn_table[n] = pcolours[i].pcn; + pcolours[i].usage_count++; + break; + } + } - // There isn't. Try to create a new physical colour. - if (pcn_table[n] == PCOLOUR_NONE) - { - XColor xc; - xc.red = eight2sixteen(rgb_values[n].r); - xc.green = eight2sixteen(rgb_values[n].g); - xc.blue = eight2sixteen(rgb_values[n].b); - Status r = XAllocColor(dpy, cmap, &xc); + // There isn't. Try to create a new physical colour. + if (pcn_table[n] == PCOLOUR_NONE) + { + XColor xc; + xc.red = eight2sixteen(rgb_values[n].r); + xc.green = eight2sixteen(rgb_values[n].g); + xc.blue = eight2sixteen(rgb_values[n].b); + Status r = XAllocColor(dpy, cmap, &xc); - /* Allocation successful. Add a new entry to - the table of physical colours. */ - if (r != 0) - { - pcn_table[n] = (pcolour_t) xc.pixel; - physical_colours++; - pcolours = (pcolours_table_entry_t *) - realloc(pcolours, physical_colours * sizeof *pcolours); - if (pcolours == NULL) - fatal_error(msg_nomem); - pcolours[physical_colours - 1].pcn = (pcolour_t) xc.pixel; - pcolours[physical_colours - 1].rgb = rgb_values[n]; - pcolours[physical_colours - 1].usage_count = 1; - } + /* Allocation successful. Add a new entry to + the table of physical colours. */ + if (r != 0) + { + pcn_table[n] = (pcolour_t) xc.pixel; + physical_colours++; + pcolours = (pcolours_table_entry_t *) + realloc(pcolours, physical_colours * sizeof *pcolours); + if (pcolours == NULL) + fatal_error(msg_nomem); + pcolours[physical_colours - 1].pcn = (pcolour_t) xc.pixel; + pcolours[physical_colours - 1].rgb = rgb_values[n]; + pcolours[physical_colours - 1].usage_count = 1; + } - /* Couldn't allocate (the colormap is full). - Reuse the nearest existing physical colour. */ - else - { - size_t best_fit = 0; - int best_delta = INT_MAX; + /* Couldn't allocate (the colormap is full). + Reuse the nearest existing physical colour. */ + else + { + size_t best_fit = 0; + int best_delta = INT_MAX; - for (size_t m = 0; m < physical_colours; m++) - { - int delta = pcolours[m].rgb - rgb_values[n]; - if (delta < best_delta) - { - best_fit = m; - best_delta = delta; - } - } - verbmsg - ("colours: alloc_colours %d/%d/%d: reused %d/%d/%d, delta=%d\n", - rgb_values[n].r, rgb_values[n].g, rgb_values[n].b, - pcolours[best_fit].rgb.r, pcolours[best_fit].rgb.g, - pcolours[best_fit].rgb.b, best_delta); - pcn_table[n] = pcolours[best_fit].pcn; - pcolours[best_fit].usage_count++; - } - } + for (size_t m = 0; m < physical_colours; m++) + { + int delta = pcolours[m].rgb - rgb_values[n]; + if (delta < best_delta) + { + best_fit = m; + best_delta = delta; + } + } + verbmsg + ("colours: alloc_colours %d/%d/%d: reused %d/%d/%d, delta=%d\n", + rgb_values[n].r, rgb_values[n].g, rgb_values[n].b, + pcolours[best_fit].rgb.r, pcolours[best_fit].rgb.g, + pcolours[best_fit].rgb.b, best_delta); + pcn_table[n] = pcolours[best_fit].pcn; + pcolours[best_fit].usage_count++; + } + } } return pcn_table; } /* - * free_colours - * Free the physical colours in . + * free_colours + * Free the physical colours in . */ void free_colours(pcolour_t * pcn_table, size_t count) { verbmsg("colours: free_colours: count %d\n", count); if (verbose) - dump_pcolours(); + dump_pcolours(); - if (pcn_table == NULL) // Sanity - return; + if (pcn_table == NULL) // Sanity + return; /* Decrement the usage count for all those physical colours. If the usage count reaches 0, actually free them. */ for (pcolour_t * pcn = pcn_table; count; count--, pcn++) { - size_t i; + size_t i; - for (i = 0; i < physical_colours; i++) - if (pcolours[i].pcn == *pcn) - break; + for (i = 0; i < physical_colours; i++) + if (pcolours[i].pcn == *pcn) + break; - if (i == physical_colours) - fatal_error("Trying to free pc[%d]=%ld that does not exist", - (int) i, (long) *pcn); + if (i == physical_colours) + fatal_error("Trying to free pc[%d]=%ld that does not exist", + (int) i, (long) *pcn); - if (pcolours[i].usage_count < 1) - fatal_error("Freeing unused colour %ld", (long) *pcn); + if (pcolours[i].usage_count < 1) + fatal_error("Freeing unused colour %ld", (long) *pcn); - pcolours[i].usage_count--; - if (pcolours[i].usage_count == 0) - { - unsigned long pixel = (unsigned long) *pcn; - x_catch_on(); - XFreeColors(dpy, cmap, &pixel, 1, 0); - // Should not happen but sometimes does (not reproducible) - if (const char *err_msg = x_error()) - warn("error freeing colour %08lXh (%s).\n", pixel, err_msg); - x_catch_off(); - pcolours[i].pcn = PCOLOUR_NONE; - } + pcolours[i].usage_count--; + if (pcolours[i].usage_count == 0) + { + unsigned long pixel = (unsigned long) *pcn; + x_catch_on(); + XFreeColors(dpy, cmap, &pixel, 1, 0); + // Should not happen but sometimes does (not reproducible) + if (const char *err_msg = x_error()) + warn("error freeing colour %08lXh (%s).\n", pixel, err_msg); + x_catch_off(); + pcolours[i].pcn = PCOLOUR_NONE; + } } /* If physical colours have actually been freed, @@ -198,32 +198,32 @@ size_t new_physical_colours = 0; { - for (size_t i = 0; i < physical_colours; i++) - if (pcolours[i].pcn != PCOLOUR_NONE) - new_physical_colours++; // Number of physical colours still in use. + for (size_t i = 0; i < physical_colours; i++) + if (pcolours[i].pcn != PCOLOUR_NONE) + new_physical_colours++; // Number of physical colours still in use. } verbmsg("colours: freed %d of %d physical colours\n", - physical_colours - new_physical_colours, physical_colours); + physical_colours - new_physical_colours, physical_colours); if (new_physical_colours == 0) { - free(pcolours); - pcolours = 0; + free(pcolours); + pcolours = 0; } else { - pcolours_table_entry_t *new_item; - pcolours_table_entry_t *new_pcolours = (pcolours_table_entry_t *) - malloc(new_physical_colours * sizeof *new_pcolours); - if (new_pcolours == NULL) - fatal_error(msg_nomem); - new_item = new_pcolours; - for (size_t i = 0; i < physical_colours; i++) - if (pcolours[i].pcn != PCOLOUR_NONE) - memcpy(new_item++, pcolours + i, sizeof *new_pcolours); - free(pcolours); - pcolours = new_pcolours; + pcolours_table_entry_t *new_item; + pcolours_table_entry_t *new_pcolours = (pcolours_table_entry_t *) + malloc(new_physical_colours * sizeof *new_pcolours); + if (new_pcolours == NULL) + fatal_error(msg_nomem); + new_item = new_pcolours; + for (size_t i = 0; i < physical_colours; i++) + if (pcolours[i].pcn != PCOLOUR_NONE) + memcpy(new_item++, pcolours + i, sizeof *new_pcolours); + free(pcolours); + pcolours = new_pcolours; } physical_colours = new_physical_colours; @@ -235,8 +235,8 @@ /* - * get_pcolours_count - * Return the number of physical colours allocated + * get_pcolours_count + * Return the number of physical colours allocated */ size_t get_pcolours_count() { @@ -245,24 +245,24 @@ /* - * get_pcolour_pcn - * Return the physical colour number (a.k.a. pixel value) - * for the th physical colour allocated. + * get_pcolour_pcn + * Return the physical colour number (a.k.a. pixel value) + * for the th physical colour allocated. */ pcolour_t get_pcolour_pcn(size_t i) { if (i >= physical_colours) { - nf_bug("get_pcolour_pcn: i=%d\n", (int) i); - return ULONG_MAX; + nf_bug("get_pcolour_pcn: i=%d\n", (int) i); + return ULONG_MAX; } return pcolours[i].pcn; } /* - * dump_pcolours - * For debugging purposes + * dump_pcolours + * For debugging purposes */ static void dump_pcolours() { @@ -271,28 +271,28 @@ for (size_t i = 0; i < physical_colours; i++) { #if 0 - printf("%02lX %02X/%02X/%02X %d", - pcolours[i].pcn, - pcolours[i].rgb.r, - pcolours[i].rgb.g, pcolours[i].rgb.b, pcolours[i].usage_count); - fputs(i % 5 == 4 ? "\n" : " ", stdout); + printf("%02lX %02X/%02X/%02X %d", + pcolours[i].pcn, + pcolours[i].rgb.r, + pcolours[i].rgb.g, pcolours[i].rgb.b, pcolours[i].usage_count); + fputs(i % 5 == 4 ? "\n" : " ", stdout); #endif - if (items_on_current_line == 0) - verbmsg("colours: "); - verbmsg("%c", - (pcolours[i].usage_count == - 1) ? '.' : '0' + pcolours[i].usage_count); - if (++items_on_current_line % 10 == 0) - { - if (items_on_current_line == 50) - { - items_on_current_line = 0; - verbmsg("\n"); - } - else - verbmsg(" "); - } + if (items_on_current_line == 0) + verbmsg("colours: "); + verbmsg("%c", + (pcolours[i].usage_count == + 1) ? '.' : '0' + pcolours[i].usage_count); + if (++items_on_current_line % 10 == 0) + { + if (items_on_current_line == 50) + { + items_on_current_line = 0; + verbmsg("\n"); + } + else + verbmsg(" "); + } } if (items_on_current_line != 0) - verbmsg("\n"); + verbmsg("\n"); } diff -r 594dea11ccd9 -r a68786b9c74b src/dependcy.cc --- a/src/dependcy.cc Sat Sep 24 15:01:56 2011 +0300 +++ b/src/dependcy.cc Sat Sep 24 15:59:33 2011 +0300 @@ -1,7 +1,7 @@ /* - * dependcy.cc - * Dependency class - * AYM 2000-04-09 + * dependcy.cc + * Dependency class + * AYM 2000-04-09 */ @@ -28,7 +28,7 @@ */ -#include "yadex.h" /* Just to force a recompile when you ./configure again */ +#include "yadex.h" /* Just to force a recompile when you ./configure again */ #include "dependcy.h" #include "serialnum.h" @@ -43,7 +43,7 @@ bool Dependency::outdated() { if (!token_valid) - return true; + return true; return serial_num->outdated(token); } diff -r 594dea11ccd9 -r a68786b9c74b src/dependcy.h --- a/src/dependcy.h Sat Sep 24 15:01:56 2011 +0300 +++ b/src/dependcy.h Sat Sep 24 15:59:33 2011 +0300 @@ -1,7 +1,7 @@ /* - * dependcy.h - * Dependency class - * AYM 2000-04-09 + * dependcy.h + * Dependency class + * AYM 2000-04-09 */ @@ -22,12 +22,12 @@ call Dependency::update(). */ -#ifndef YH_DEPENDCY /* DO NOT INSERT ANYTHING BEFORE THIS LINE */ +#ifndef YH_DEPENDCY /* DO NOT INSERT ANYTHING BEFORE THIS LINE */ #define YH_DEPENDCY -class Serial_num; // Defined in serialnum.h -typedef unsigned long serial_num_t; // Copied from serialnum.h +class Serial_num; // Defined in serialnum.h +typedef unsigned long serial_num_t; // Copied from serialnum.h class Dependency diff -r 594dea11ccd9 -r a68786b9c74b src/dialog.cc --- a/src/dialog.cc Sat Sep 24 15:01:56 2011 +0300 +++ b/src/dialog.cc Sat Sep 24 15:59:33 2011 +0300 @@ -1,7 +1,7 @@ /* - * dialog.cc - * Dialog boxes. - * AYM 1998-11-30 + * dialog.cc + * Dialog boxes. + * AYM 1998-11-30 */ @@ -35,11 +35,11 @@ /* - * Confirm - ask for confirmation + * Confirm - ask for confirmation * - * Ask for confirmation (prompt2 may be NULL). + * Ask for confirmation (prompt2 may be NULL). * - * Return zero for "no", non-zero for "yes". + * Return zero for "no", non-zero for "yes". */ bool Confirm(int x0, int y0, const char *prompt1, const char *prompt2) { @@ -58,17 +58,17 @@ maxlen = strlen(prompt3); if (strlen(prompt1) > maxlen) - maxlen = strlen(prompt1); + maxlen = strlen(prompt1); if (prompt2 != NULL && strlen(prompt2) > maxlen) - maxlen = strlen(prompt2); + maxlen = strlen(prompt2); n_lines_of_text = (prompt2 == NULL ? 2.5 : 3.5); width = 2 * BOX_BORDER + 2 * WIDE_HSPACING + maxlen * FONTW; height = - 2 * BOX_BORDER + 2 * WIDE_VSPACING + (int) (n_lines_of_text * FONTH); + 2 * BOX_BORDER + 2 * WIDE_VSPACING + (int) (n_lines_of_text * FONTH); if (x0 < 0) - x0 = (ScrMaxX - width) / 2; + x0 = (ScrMaxX - width) / 2; if (y0 < 0) - y0 = (ScrMaxY - height) / 2; + y0 = (ScrMaxY - height) / 2; text_x0 = x0 + BOX_BORDER + WIDE_HSPACING; text_x1 = text_x0 + maxlen * FONTW - 1; x1 = text_x1 + WIDE_HSPACING + BOX_BORDER; @@ -77,59 +77,59 @@ y1 = text_y1 + WIDE_HSPACING + BOX_BORDER; for (bool first_time = true;; first_time = false) { - if (first_time || is.key == YE_EXPOSE) - { - DrawScreenBox3D(x0, y0, x1, y1); - set_colour(WHITE); - DrawScreenText(text_x0, text_y0, prompt1); - if (prompt2 != NULL) - DrawScreenText(text_x0, text_y0 + FONTH, prompt2); - set_colour(WINTITLE); - DrawScreenText(text_x0, text_y1 - FONTH - 1, prompt3); - } - get_input_status(); - if (is.key == 'y' || is.key == 'Y' || is.key == YK_RETURN) - { - rc = true; - break; - } - if (is.key == 'n' || is.key == 'N' || is.key == YK_ESC) - { - rc = false; - break; - } + if (first_time || is.key == YE_EXPOSE) + { + DrawScreenBox3D(x0, y0, x1, y1); + set_colour(WHITE); + DrawScreenText(text_x0, text_y0, prompt1); + if (prompt2 != NULL) + DrawScreenText(text_x0, text_y0 + FONTH, prompt2); + set_colour(WINTITLE); + DrawScreenText(text_x0, text_y1 - FONTH - 1, prompt3); + } + get_input_status(); + if (is.key == 'y' || is.key == 'Y' || is.key == YK_RETURN) + { + rc = true; + break; + } + if (is.key == 'n' || is.key == 'N' || is.key == YK_ESC) + { + rc = false; + break; + } } - is.key = 0; // Shouldn't have to do that but EditorLoop() is broken + is.key = 0; // Shouldn't have to do that but EditorLoop() is broken return rc; } /* - * Confirm2 - ask for confirmation, in a smarter fashion + * Confirm2 - ask for confirmation, in a smarter fashion * - * Return zero for "no", non-zero for "yes". + * Return zero for "no", non-zero for "yes". */ int Confirm2(int x0, int y0, confirm_t * confirm_flag, - const char *prompt1, const char *prompt2) + const char *prompt1, const char *prompt2) { int r; if (*confirm_flag == YC_YES) - return 1; + return 1; if (*confirm_flag == YC_NO) - return 0; + return 0; r = Confirm(x0, y0, prompt1, prompt2); if (*confirm_flag == YC_ASK_ONCE) - *confirm_flag = r ? YC_YES : YC_NO; // We won't ask again + *confirm_flag = r ? YC_YES : YC_NO; // We won't ask again return r; } /* - * Notify - notification dialog box + * Notify - notification dialog box * - * Display a notification and wait for a key (prompt2 may - * be NULL) + * Display a notification and wait for a key (prompt2 may + * be NULL) */ void Notify(int x0, int y0, const char *prompt1, const char *prompt2) { @@ -147,17 +147,17 @@ maxlen = strlen(prompt3); if (strlen(prompt1) > maxlen) - maxlen = strlen(prompt1); + maxlen = strlen(prompt1); if (prompt2 != NULL && strlen(prompt2) > maxlen) - maxlen = strlen(prompt2); + maxlen = strlen(prompt2); n_lines_of_text = (prompt2 == NULL ? 2.5 : 3.5); width = 2 * BOX_BORDER + 2 * WIDE_HSPACING + maxlen * FONTW; height = - 2 * BOX_BORDER + 2 * WIDE_VSPACING + (int) (n_lines_of_text * FONTH); + 2 * BOX_BORDER + 2 * WIDE_VSPACING + (int) (n_lines_of_text * FONTH); if (x0 < 0) - x0 = (ScrMaxX - width) / 2; + x0 = (ScrMaxX - width) / 2; if (y0 < 0) - y0 = (ScrMaxY - height) / 2; + y0 = (ScrMaxY - height) / 2; text_x0 = x0 + BOX_BORDER + WIDE_HSPACING; text_x1 = text_x0 + maxlen * FONTW - 1; x1 = text_x1 + WIDE_HSPACING + BOX_BORDER; @@ -168,7 +168,7 @@ set_colour(WHITE); DrawScreenText(text_x0, text_y0, prompt1); if (prompt2 != NULL) - DrawScreenText(text_x0, text_y0 + FONTH, prompt2); + DrawScreenText(text_x0, text_y0 + FONTH, prompt2); set_colour(WINTITLE); DrawScreenText(text_x0, text_y1 - FONTH - 1, prompt3); get_key_or_click(); @@ -176,12 +176,12 @@ /* - * debmes - Display a message in a box only if in debug mode + * debmes - Display a message in a box only if in debug mode * - * Simple wrapper around Notify(). Don't try to make it display - * more than 200 characters or you'll crash the program. - * BUG: if result of formatting contains "%"'s, it will be - * formatted again... + * Simple wrapper around Notify(). Don't try to make it display + * more than 200 characters or you'll crash the program. + * BUG: if result of formatting contains "%"'s, it will be + * formatted again... */ void debmes(const char *fmt, ...) { @@ -189,7 +189,7 @@ va_list arglist; if (Debug != 1) - return; + return; va_start(arglist, fmt); y_vsnprintf(buf, sizeof buf, fmt, arglist); Notify(-1, -1, buf, NULL); @@ -197,7 +197,7 @@ /* - * DisplayMessage - clear the screen and display a message + * DisplayMessage - clear the screen and display a message */ void DisplayMessage(int x0, int y0, const char *msg, ...) { @@ -209,20 +209,20 @@ int width = 2 * BOX_BORDER + 2 * WIDE_HSPACING + FONTW * strlen(prompt); int height = 2 * BOX_BORDER + 2 * WIDE_VSPACING + FONTH; if (x0 < 0) - x0 = (ScrMaxX - width) / 2; + x0 = (ScrMaxX - width) / 2; if (y0 < 0) - y0 = (ScrMaxY - height) / 2; + y0 = (ScrMaxY - height) / 2; DrawScreenBox3D(x0, y0, x0 + width - 1, y0 + height - 1); push_colour(WINFG); DrawScreenText(x0 + BOX_BORDER + WIDE_HSPACING, - y0 + BOX_BORDER + WIDE_VSPACING, prompt); + y0 + BOX_BORDER + WIDE_VSPACING, prompt); pop_colour(); update_display(); } /* - * NotImplemented - make the user angry... + * NotImplemented - make the user angry... */ void NotImplemented(void) { diff -r 594dea11ccd9 -r a68786b9c74b src/dialog.h --- a/src/dialog.h Sat Sep 24 15:01:56 2011 +0300 +++ b/src/dialog.h Sat Sep 24 15:59:33 2011 +0300 @@ -1,13 +1,13 @@ /* - * dialog.h - * Dialog boxes - * AYM 1998-11-30 + * dialog.h + * Dialog boxes + * AYM 1998-11-30 */ bool Confirm(int, int, const char *, const char *); int Confirm2(int x0, int y0, confirm_t * confirm_flag, - const char *prompt1, const char *prompt2); + const char *prompt1, const char *prompt2); void Notify(int, int, const char *, const char *); void debmes(const char *fmt, ...); void DisplayMessage(int, int, const char *, ...); diff -r 594dea11ccd9 -r a68786b9c74b src/disppic.cc --- a/src/disppic.cc Sat Sep 24 15:01:56 2011 +0300 +++ b/src/disppic.cc Sat Sep 24 15:59:33 2011 +0300 @@ -1,6 +1,6 @@ /* - * disppic.cc - * AYM 1998-08-30 + * disppic.cc + * AYM 1998-08-30 */ @@ -41,9 +41,9 @@ /* - * display_pic() - load a picture and display it + * display_pic() - load a picture and display it * - * A wrapper for LoadPicture() and Sticker.load()/draw(). + * A wrapper for LoadPicture() and Sticker.load()/draw(). */ void display_pic(hookfunc_comm_t * c) { @@ -54,34 +54,34 @@ c->img.clear(); c->img.set_opaque(false); if (c->flags & HOOK_PATCH) - patch_dir.loc_by_name(c->name, loc); + patch_dir.loc_by_name(c->name, loc); else if ((c->flags & HOOK_SPRITE) && (c->flags & HOOK_ROOT)) - wad_res.sprites.loc_by_root(c->name, loc); + wad_res.sprites.loc_by_root(c->name, loc); else if ((c->flags & HOOK_SPRITE) && !(c->flags & HOOK_ROOT)) - wad_res.sprites.loc_by_name(c->name, loc); - if (!LoadPicture(c->img, c->name, loc, 0, // Not very clean, should use c->xofs but *WithFunc doesn't set it - 0, // Not very clean, should use c->yofs but *WithFunc doesn't set it - &c->width, &c->height)) + wad_res.sprites.loc_by_name(c->name, loc); + if (!LoadPicture(c->img, c->name, loc, 0, // Not very clean, should use c->xofs but *WithFunc doesn't set it + 0, // Not very clean, should use c->yofs but *WithFunc doesn't set it + &c->width, &c->height)) { - c->disp_x0 = c->x0 + (width - c->width) / 2; - c->disp_y0 = c->y0 + (height - c->height) / 2; - c->disp_x1 = c->disp_x0 + c->width - 1; - c->disp_y1 = c->disp_y0 + c->height - 1; - c->flags |= HOOK_SIZE_VALID; - c->lump_loc = loc; - c->flags |= HOOK_LOC_VALID; - if (c->flags & HOOK_SPECTRAL) - spectrify_img(c->img); - Sticker sticker(c->img, true); // Use opaque because it's faster - sticker.draw(drw, 't', c->disp_x0, c->disp_y0); - c->flags |= HOOK_DRAWN; + c->disp_x0 = c->x0 + (width - c->width) / 2; + c->disp_y0 = c->y0 + (height - c->height) / 2; + c->disp_x1 = c->disp_x0 + c->width - 1; + c->disp_y1 = c->disp_y0 + c->height - 1; + c->flags |= HOOK_SIZE_VALID; + c->lump_loc = loc; + c->flags |= HOOK_LOC_VALID; + if (c->flags & HOOK_SPECTRAL) + spectrify_img(c->img); + Sticker sticker(c->img, true); // Use opaque because it's faster + sticker.draw(drw, 't', c->disp_x0, c->disp_y0); + c->flags |= HOOK_DRAWN; } else { - // Drew nothing (negative width and height) - c->disp_x0 = c->x0 + 1; - c->disp_y0 = c->y0 + 1; - c->disp_x1 = c->x0; - c->disp_y1 = c->y0; + // Drew nothing (negative width and height) + c->disp_x0 = c->x0 + 1; + c->disp_y0 = c->y0 + 1; + c->disp_x1 = c->x0; + c->disp_y1 = c->y0; } } diff -r 594dea11ccd9 -r a68786b9c74b src/disppic.h --- a/src/disppic.h Sat Sep 24 15:01:56 2011 +0300 +++ b/src/disppic.h Sat Sep 24 15:59:33 2011 +0300 @@ -1,10 +1,10 @@ /* - * disppic.h - * AYM 1998-08-30 + * disppic.h + * AYM 1998-08-30 */ -#ifndef YH_DISPPIC /* DO NOT INSERT ANYTHING BEFORE THIS LINE */ +#ifndef YH_DISPPIC /* DO NOT INSERT ANYTHING BEFORE THIS LINE */ #define YH_DISPPIC diff -r 594dea11ccd9 -r a68786b9c74b src/drawmap.cc --- a/src/drawmap.cc Sat Sep 24 15:01:56 2011 +0300 +++ b/src/drawmap.cc Sat Sep 24 15:59:33 2011 +0300 @@ -1,6 +1,6 @@ /* - * drawmap.cc - * AYM 1998-09-06 + * drawmap.cc + * AYM 1998-09-06 */ @@ -36,9 +36,9 @@ #include #endif #include "_edit.h" -#include "disppic.h" /* Sprites */ +#include "disppic.h" /* Sprites */ #include "drawmap.h" -#include "game.h" /* Sprites */ +#include "game.h" /* Sprites */ #include "gfx.h" #include "imgscale.h" #include "imgspect.h" @@ -61,12 +61,12 @@ /* - * vertex_radius - apparent radius of a vertex, in pixels + * vertex_radius - apparent radius of a vertex, in pixels * - * Try this in Gnuplot : + * Try this in Gnuplot : * - * plot [0:10] x - * replot log(x+1.46)/log(1.5)-log(2.46)/log(1.5)+1 + * plot [0:10] x + * replot log(x+1.46)/log(1.5)-log(2.46)/log(1.5)+1 */ int vertex_radius(double scale) { @@ -75,7 +75,7 @@ static int last_result = 0; if (scale == last_scale) - return last_result; + return last_result; const int VERTEX_PIXELS = 5; @@ -92,10 +92,10 @@ double factor; if (scale <= crossover) - factor = scale; + factor = scale; else - factor = - crossover + log(scale - crossover + knee_x) / log(base) - knee_y; + factor = + crossover + log(scale - crossover + knee_x) / log(base) - knee_y; last_result = (int) (VERTEX_PIXELS * factor + 0.5); return last_result; #else @@ -109,7 +109,7 @@ draw the actual game map */ -void draw_map(edit_t * e) /* SWAP! */ +void draw_map(edit_t * e) /* SWAP! */ { int mapx0 = MAPX(0); int mapx9 = MAPX(ScrMaxX); @@ -123,195 +123,195 @@ if (e->global) { - draw_linedefs(e); - if (e->show_things_sprites) - draw_things_sprites(e); - else - draw_things_squares(e); - draw_vertices(e); + draw_linedefs(e); + if (e->show_things_sprites) + draw_things_sprites(e); + else + draw_things_squares(e); + draw_vertices(e); } else { - if (e->obj_type != OBJ_THINGS) - draw_things_squares(e); - draw_linedefs(e); - if (e->obj_type == OBJ_VERTICES) - draw_vertices(e); - if (e->obj_type == OBJ_THINGS) - { - if (e->show_things_sprites) - draw_things_sprites(e); - else - draw_things_squares(e); - } + if (e->obj_type != OBJ_THINGS) + draw_things_squares(e); + draw_linedefs(e); + if (e->obj_type == OBJ_VERTICES) + draw_vertices(e); + if (e->obj_type == OBJ_THINGS) + { + if (e->show_things_sprites) + draw_things_sprites(e); + else + draw_things_squares(e); + } } // Draw the things numbers if (e->obj_type == OBJ_THINGS && e->show_object_numbers) { - for (n = 0; n < NumThings; n++) - { - int mapx = Things[n].xpos; - int mapy = Things[n].ypos; - if (mapx < mapx0 || mapx > mapx9 || mapy < mapy0 || mapy > mapy9) - continue; - draw_obj_no(SCREENX(mapx) + FONTW, SCREENY(mapy) + 2, n, - THING_NO); - } + for (n = 0; n < NumThings; n++) + { + int mapx = Things[n].xpos; + int mapy = Things[n].ypos; + if (mapx < mapx0 || mapx > mapx9 || mapy < mapy0 || mapy > mapy9) + continue; + draw_obj_no(SCREENX(mapx) + FONTW, SCREENY(mapy) + 2, n, + THING_NO); + } } // Draw the sector numbers if (e->obj_type == OBJ_SECTORS && e->show_object_numbers) { - int xoffset = -FONTW / 2; + int xoffset = -FONTW / 2; - for (n = 0; n < NumSectors; n++) - { - int mapx; - int mapy; - centre_of_sector(n, &mapx, &mapy); - if (mapx >= mapx0 && mapx <= mapx9 && mapy >= mapy0 - && mapy <= mapy9) - draw_obj_no(SCREENX(mapx) + xoffset, - SCREENY(mapy) - FONTH / 2, n, SECTOR_NO); - if (n == 10 || n == 100 || n == 1000 || n == 10000) - xoffset -= FONTW / 2; - } + for (n = 0; n < NumSectors; n++) + { + int mapx; + int mapy; + centre_of_sector(n, &mapx, &mapy); + if (mapx >= mapx0 && mapx <= mapx9 && mapy >= mapy0 + && mapy <= mapy9) + draw_obj_no(SCREENX(mapx) + xoffset, + SCREENY(mapy) - FONTH / 2, n, SECTOR_NO); + if (n == 10 || n == 100 || n == 1000 || n == 10000) + xoffset -= FONTW / 2; + } } } /* - * draw_grid - draw the grid in the background of the edit window + * draw_grid - draw the grid in the background of the edit window */ static void draw_grid(edit_t * e) { if (!e->grid_shown) - return; + return; int mapx0 = MAPX(0); int mapx1 = MAPX(ScrMaxX); int mapy0 = MAPY(ScrMaxY); int mapy1 = MAPY(0); - int grid_step_1 = e->grid_step; // Map units between dots - int grid_step_2 = 4 * grid_step_1; // Map units between dim lines - int grid_step_3 = 4 * grid_step_2; // Map units between bright lines - int grid_step_4 = 4 * grid_step_3; // Map units between brighter lines + int grid_step_1 = e->grid_step; // Map units between dots + int grid_step_2 = 4 * grid_step_1; // Map units between dim lines + int grid_step_3 = 4 * grid_step_2; // Map units between bright lines + int grid_step_4 = 4 * grid_step_3; // Map units between brighter lines { - set_colour(GRID2V); - int mapx0_2 = (mapx0 / grid_step_2) * grid_step_2; - if (mapx0_2 < mapx0) - mapx0_2 += grid_step_2; - for (int i = mapx0_2; i <= mapx1; i += grid_step_2) - if (i % grid_step_3 != 0) - DrawMapLine(i, mapy0, i, mapy1); + set_colour(GRID2V); + int mapx0_2 = (mapx0 / grid_step_2) * grid_step_2; + if (mapx0_2 < mapx0) + mapx0_2 += grid_step_2; + for (int i = mapx0_2; i <= mapx1; i += grid_step_2) + if (i % grid_step_3 != 0) + DrawMapLine(i, mapy0, i, mapy1); } { - set_colour(GRID2H); - int mapy0_2 = (mapy0 / grid_step_2) * grid_step_2; - if (mapy0_2 < mapy0) - mapy0_2 += grid_step_2; - for (int j = mapy0_2; j <= mapy1; j += grid_step_2) - if (j % grid_step_3 != 0) - DrawMapLine(mapx0, j, mapx1, j); + set_colour(GRID2H); + int mapy0_2 = (mapy0 / grid_step_2) * grid_step_2; + if (mapy0_2 < mapy0) + mapy0_2 += grid_step_2; + for (int j = mapy0_2; j <= mapy1; j += grid_step_2) + if (j % grid_step_3 != 0) + DrawMapLine(mapx0, j, mapx1, j); } { - set_colour(GRID3V); - int mapx0_3 = (mapx0 / grid_step_3) * grid_step_3; - if (mapx0_3 < mapx0) - mapx0_3 += grid_step_3; - for (int i = mapx0_3; i <= mapx1; i += grid_step_3) - if (i % grid_step_4 != 0) - DrawMapLine(i, mapy0, i, mapy1); + set_colour(GRID3V); + int mapx0_3 = (mapx0 / grid_step_3) * grid_step_3; + if (mapx0_3 < mapx0) + mapx0_3 += grid_step_3; + for (int i = mapx0_3; i <= mapx1; i += grid_step_3) + if (i % grid_step_4 != 0) + DrawMapLine(i, mapy0, i, mapy1); } { - set_colour(GRID3H); - int mapy0_3 = (mapy0 / grid_step_3) * grid_step_3; - if (mapy0_3 < mapy0) - mapy0_3 += grid_step_3; - for (int j = mapy0_3; j <= mapy1; j += grid_step_3) - if (j % grid_step_4 != 0) - DrawMapLine(mapx0, j, mapx1, j); + set_colour(GRID3H); + int mapy0_3 = (mapy0 / grid_step_3) * grid_step_3; + if (mapy0_3 < mapy0) + mapy0_3 += grid_step_3; + for (int j = mapy0_3; j <= mapy1; j += grid_step_3) + if (j % grid_step_4 != 0) + DrawMapLine(mapx0, j, mapx1, j); } { - set_colour(GRID4V); - int mapx0_4 = (mapx0 / grid_step_4) * grid_step_4; - if (mapx0_4 < mapx0) - mapx0_4 += grid_step_4; - //printf ("MAPX(0): %d mapx0_4: %d\n", MAPX(0), mapx0_4); // DEBUG - for (int i = mapx0_4; i <= mapx1; i += grid_step_4) - DrawMapLine(i, mapy0, i, mapy1); + set_colour(GRID4V); + int mapx0_4 = (mapx0 / grid_step_4) * grid_step_4; + if (mapx0_4 < mapx0) + mapx0_4 += grid_step_4; + //printf ("MAPX(0): %d mapx0_4: %d\n", MAPX(0), mapx0_4); // DEBUG + for (int i = mapx0_4; i <= mapx1; i += grid_step_4) + DrawMapLine(i, mapy0, i, mapy1); } { - set_colour(GRID4H); - int mapy0_4 = (mapy0 / grid_step_4) * grid_step_4; - if (mapy0_4 < mapy0) - mapy0_4 += grid_step_4; - for (int j = mapy0_4; j <= mapy1; j += grid_step_4) - DrawMapLine(mapx0, j, mapx1, j); + set_colour(GRID4H); + int mapy0_4 = (mapy0 / grid_step_4) * grid_step_4; + if (mapy0_4 < mapy0) + mapy0_4 += grid_step_4; + for (int j = mapy0_4; j <= mapy1; j += grid_step_4) + DrawMapLine(mapx0, j, mapx1, j); } { - int mapx0_1 = (mapx0 / grid_step_1) * grid_step_1; - if (mapx0_1 < mapx0) - mapx0_1 += grid_step_1; - int mapy0_1 = (mapy0 / grid_step_1) * grid_step_1; - if (mapy0_1 < mapy0) - mapy0_1 += grid_step_1; + int mapx0_1 = (mapx0 / grid_step_1) * grid_step_1; + if (mapx0_1 < mapx0) + mapx0_1 += grid_step_1; + int mapy0_1 = (mapy0 / grid_step_1) * grid_step_1; + if (mapy0_1 < mapy0) + mapy0_1 += grid_step_1; #ifdef Y_X11 - // Optimisation for X: draw several points in one go - int npoints = (mapx1 - mapx0_1) / grid_step_1 + 1; - XPoint *points = (XPoint *) malloc(npoints * sizeof *points); - points[0].x = SCREENX(mapx0_1); - int n = 1; - int last_i = points[0].x; - for (int i = mapx0_1 + grid_step_1; i <= mapx1; i += grid_step_1) - { - if (n >= npoints) - nf_bug("%d >= %d", n, npoints); - points[n].x = SCREENX(i) - last_i; - points[n].y = 0; - n++; - last_i = SCREENX(i); - } - npoints = n; - set_colour(GRID1); - for (int j = mapy0_1; j <= mapy1; j += grid_step_1) - { - points[0].y = SCREENY(j); - XDrawPoints(dpy, drw, gc, points, npoints, CoordModePrevious); - } - free(points); + // Optimisation for X: draw several points in one go + int npoints = (mapx1 - mapx0_1) / grid_step_1 + 1; + XPoint *points = (XPoint *) malloc(npoints * sizeof *points); + points[0].x = SCREENX(mapx0_1); + int n = 1; + int last_i = points[0].x; + for (int i = mapx0_1 + grid_step_1; i <= mapx1; i += grid_step_1) + { + if (n >= npoints) + nf_bug("%d >= %d", n, npoints); + points[n].x = SCREENX(i) - last_i; + points[n].y = 0; + n++; + last_i = SCREENX(i); + } + npoints = n; + set_colour(GRID1); + for (int j = mapy0_1; j <= mapy1; j += grid_step_1) + { + points[0].y = SCREENY(j); + XDrawPoints(dpy, drw, gc, points, npoints, CoordModePrevious); + } + free(points); #else - // Generic code. Untested. - int npoints = (mapx1 - mapx0_1) / grid_step_1 + 1; - int dispx[npoints]; - for (int n = 0; n < npoints; n++) - dispx[n] = SCREENX(mapx0_1 + n * grid_step_1); - for (int j = mapy0_1; j <= mapy1; j += grid_step_1) - { - int dispy = SCREENY(j); - for (int n = 0; n < npoints; n++) - { - draw_point(dispx[n], dispy); - } - } + // Generic code. Untested. + int npoints = (mapx1 - mapx0_1) / grid_step_1 + 1; + int dispx[npoints]; + for (int n = 0; n < npoints; n++) + dispx[n] = SCREENX(mapx0_1 + n * grid_step_1); + for (int j = mapy0_1; j <= mapy1; j += grid_step_1) + { + int dispy = SCREENY(j); + for (int n = 0; n < npoints; n++) + { + draw_point(dispx[n], dispy); + } + } #endif } } /* - * draw_vertices - draw the vertices, and possibly their numbers + * draw_vertices - draw the vertices, and possibly their numbers */ static void draw_vertices(edit_t * e) { @@ -324,37 +324,37 @@ push_colour(LIGHTGREEN); for (int n = 0; n < NumVertices; n++) { - int mapx = Vertices[n].x; - int mapy = Vertices[n].y; - if (mapx >= mapx0 && mapx <= mapx9 && mapy >= mapy0 && mapy <= mapy9) - { - int scrx = SCREENX(mapx); - int scry = SCREENY(mapy); - DrawScreenLine(scrx - r, scry - r, scrx + r, scry + r); - DrawScreenLine(scrx + r, scry - r, scrx - r, scry + r); - } + int mapx = Vertices[n].x; + int mapy = Vertices[n].y; + if (mapx >= mapx0 && mapx <= mapx9 && mapy >= mapy0 && mapy <= mapy9) + { + int scrx = SCREENX(mapx); + int scry = SCREENY(mapy); + DrawScreenLine(scrx - r, scry - r, scrx + r, scry + r); + DrawScreenLine(scrx + r, scry - r, scrx - r, scry + r); + } } if (e->show_object_numbers) { - for (int n = 0; n < NumVertices; n++) - { - int mapx = Vertices[n].x; - int mapy = Vertices[n].y; - if (mapx >= mapx0 && mapx <= mapx9 && mapy >= mapy0 - && mapy <= mapy9) - { - int x = (int) (SCREENX(mapx) + 2 * r); - int y = SCREENY(mapy) + 2; - draw_obj_no(x, y, n, VERTEX_NO); - } - } + for (int n = 0; n < NumVertices; n++) + { + int mapx = Vertices[n].x; + int mapy = Vertices[n].y; + if (mapx >= mapx0 && mapx <= mapx9 && mapy >= mapy0 + && mapy <= mapy9) + { + int x = (int) (SCREENX(mapx) + 2 * r); + int y = SCREENY(mapy) + 2; + draw_obj_no(x, y, n, VERTEX_NO); + } + } } pop_colour(); } /* - * draw_linedefs - draw the linedefs + * draw_linedefs - draw the linedefs */ static int ld_check(int x1, int y1, int x2, int y2) { @@ -364,7 +364,7 @@ mapy9 = MAPY(0); return ((x1 < mapx0 && x2 < mapx0) || (x1 > mapx9 && x2 > mapx9) || - (y1 < mapy0 && y2 < mapy0) || (y1 > mapy9 && y2 > mapy9)); + (y1 < mapy0 && y2 < mapy0) || (y1 > mapy9 && y2 > mapy9)); } @@ -378,172 +378,172 @@ switch (e->obj_type) { case OBJ_THINGS: - { - int new_colour, current_colour = INT_MIN; /* Some impossible colour no. */ + { + int new_colour, current_colour = INT_MIN; /* Some impossible colour no. */ - for (int n = 0; n < NumLineDefs; n++) - { - int x1 = Vertices[LineDefs[n].start].x; - int x2 = Vertices[LineDefs[n].end].x; - int y1 = Vertices[LineDefs[n].start].y; - int y2 = Vertices[LineDefs[n].end].y; + for (int n = 0; n < NumLineDefs; n++) + { + int x1 = Vertices[LineDefs[n].start].x; + int x2 = Vertices[LineDefs[n].end].x; + int y1 = Vertices[LineDefs[n].start].y; + int y2 = Vertices[LineDefs[n].end].y; - if (ld_check(x1, y1, x2, y2)) - continue; + if (ld_check(x1, y1, x2, y2)) + continue; new_colour = (LineDefs[n].flags & 1) ? WHITE : LIGHTGREY; - if (new_colour != current_colour) - set_colour(current_colour = new_colour); - DrawMapLine(x1, y1, x2, y2); - } - break; - } + if (new_colour != current_colour) + set_colour(current_colour = new_colour); + DrawMapLine(x1, y1, x2, y2); + } + break; + } case OBJ_VERTICES: - set_colour(LIGHTGREY); - for (int n = 0; n < NumLineDefs; n++) - { - int x1 = Vertices[LineDefs[n].start].x; - int x2 = Vertices[LineDefs[n].end].x; - int y1 = Vertices[LineDefs[n].start].y; - int y2 = Vertices[LineDefs[n].end].y; + set_colour(LIGHTGREY); + for (int n = 0; n < NumLineDefs; n++) + { + int x1 = Vertices[LineDefs[n].start].x; + int x2 = Vertices[LineDefs[n].end].x; + int y1 = Vertices[LineDefs[n].start].y; + int y2 = Vertices[LineDefs[n].end].y; - if (ld_check(x1, y1, x2, y2)) - continue; + if (ld_check(x1, y1, x2, y2)) + continue; - DrawMapVector(x1, y1, x2, y2); - } - break; + DrawMapVector(x1, y1, x2, y2); + } + break; case OBJ_LINEDEFS: - { - int current_colour = INT_MIN; /* Some impossible colour no. */ - int new_colour; + { + int current_colour = INT_MIN; /* Some impossible colour no. */ + int new_colour; - for (int n = 0; n < NumLineDefs; n++) - { - int x1 = Vertices[LineDefs[n].start].x; - int x2 = Vertices[LineDefs[n].end].x; - int y1 = Vertices[LineDefs[n].start].y; - int y2 = Vertices[LineDefs[n].end].y; - if (x1 < mapx0 && x2 < mapx0 - || x1 > mapx9 && x2 > mapx9 - || y1 < mapy0 && y2 < mapy0 || y1 > mapy9 && y2 > mapy9) - continue; - if (LineDefs[n].type != 0) /* AYM 19980207: was "> 0" */ - { - if (LineDefs[n].tag != 0) /* AYM 19980207: was "> 0" */ - new_colour = LIGHTMAGENTA; - else - new_colour = LIGHTGREEN; - } - else if (LineDefs[n].flags & 1) - new_colour = WHITE; - else - new_colour = LIGHTGREY; + for (int n = 0; n < NumLineDefs; n++) + { + int x1 = Vertices[LineDefs[n].start].x; + int x2 = Vertices[LineDefs[n].end].x; + int y1 = Vertices[LineDefs[n].start].y; + int y2 = Vertices[LineDefs[n].end].y; + if (x1 < mapx0 && x2 < mapx0 + || x1 > mapx9 && x2 > mapx9 + || y1 < mapy0 && y2 < mapy0 || y1 > mapy9 && y2 > mapy9) + continue; + if (LineDefs[n].type != 0) /* AYM 19980207: was "> 0" */ + { + if (LineDefs[n].tag != 0) /* AYM 19980207: was "> 0" */ + new_colour = LIGHTMAGENTA; + else + new_colour = LIGHTGREEN; + } + else if (LineDefs[n].flags & 1) + new_colour = WHITE; + else + new_colour = LIGHTGREY; - // Signal errors by drawing the linedef in red. Needs work. - // Tag on a typeless linedef - if (LineDefs[n].type == 0 && LineDefs[n].tag != 0) - new_colour = LIGHTRED; - // No first sidedef - if (!is_sidedef(LineDefs[n].sidedef1)) - new_colour = LIGHTRED; - // Bad second sidedef - if (!is_sidedef(LineDefs[n].sidedef2) - && LineDefs[n].sidedef2 != -1) - new_colour = LIGHTRED; + // Signal errors by drawing the linedef in red. Needs work. + // Tag on a typeless linedef + if (LineDefs[n].type == 0 && LineDefs[n].tag != 0) + new_colour = LIGHTRED; + // No first sidedef + if (!is_sidedef(LineDefs[n].sidedef1)) + new_colour = LIGHTRED; + // Bad second sidedef + if (!is_sidedef(LineDefs[n].sidedef2) + && LineDefs[n].sidedef2 != -1) + new_colour = LIGHTRED; - if (new_colour != current_colour) - set_colour(current_colour = new_colour); - DrawMapLine(x1, y1, x2, y2); + if (new_colour != current_colour) + set_colour(current_colour = new_colour); + DrawMapLine(x1, y1, x2, y2); - if (e->show_object_numbers) - { - int scnx0 = SCREENX(x1); - int scnx1 = SCREENX(x2); - int scny0 = SCREENY(y1); - int scny1 = SCREENY(y2); - int label_width = ((int) log10(n) + 1) * FONTW; - if (abs(scnx1 - scnx0) > label_width + 4 - || abs(scny1 - scny0) > label_width + 4) - { - int scnx = (scnx0 + scnx1) / 2 - label_width / 2; - int scny = (scny0 + scny1) / 2 - FONTH / 2; - draw_obj_no(scnx, scny, n, LINEDEF_NO); - } - } - } - break; - } + if (e->show_object_numbers) + { + int scnx0 = SCREENX(x1); + int scnx1 = SCREENX(x2); + int scny0 = SCREENY(y1); + int scny1 = SCREENY(y2); + int label_width = ((int) log10(n) + 1) * FONTW; + if (abs(scnx1 - scnx0) > label_width + 4 + || abs(scny1 - scny0) > label_width + 4) + { + int scnx = (scnx0 + scnx1) / 2 - label_width / 2; + int scny = (scny0 + scny1) / 2 - FONTH / 2; + draw_obj_no(scnx, scny, n, LINEDEF_NO); + } + } + } + break; + } case OBJ_SECTORS: - { - int current_colour = INT_MIN; /* Some impossible colour no. */ - int new_colour; + { + int current_colour = INT_MIN; /* Some impossible colour no. */ + int new_colour; - for (int n = 0; n < NumLineDefs; n++) - { - int x1 = Vertices[LineDefs[n].start].x; - int x2 = Vertices[LineDefs[n].end].x; - int y1 = Vertices[LineDefs[n].start].y; - int y2 = Vertices[LineDefs[n].end].y; + for (int n = 0; n < NumLineDefs; n++) + { + int x1 = Vertices[LineDefs[n].start].x; + int x2 = Vertices[LineDefs[n].end].x; + int y1 = Vertices[LineDefs[n].start].y; + int y2 = Vertices[LineDefs[n].end].y; - if (ld_check(x1, y1, x2, y2)) - continue; + if (ld_check(x1, y1, x2, y2)) + continue; - int sd1 = OBJ_NO_NONE; - int sd2 = OBJ_NO_NONE; - int s1 = OBJ_NO_NONE; - int s2 = OBJ_NO_NONE; - // FIXME should flag negative sidedef numbers as errors - // FIXME should flag unused tag as errors - if ((sd1 = LineDefs[n].sidedef1) < 0 || sd1 >= NumSideDefs - || (s1 = SideDefs[sd1].sector) < 0 || s1 >= NumSectors - || (sd2 = LineDefs[n].sidedef2) >= NumSideDefs - || sd2 >= 0 && ((s2 = SideDefs[sd2].sector) < 0 - || s2 >= NumSectors)) - { - new_colour = LIGHTRED; - } - else - { - bool have_tag = false; - bool have_type = false; - if (Sectors[s1].tag != 0) - have_tag = true; - if (Sectors[s1].special != 0) - have_type = true; - if (sd2 >= 0) - { - if (Sectors[s2].tag != 0) - have_tag = true; - if (Sectors[s2].special != 0) - have_type = true; - } - if (have_tag && have_type) - new_colour = SECTOR_TAGTYPE; - else if (have_tag) - new_colour = SECTOR_TAG; - else if (have_type) - new_colour = SECTOR_TYPE; - else if (LineDefs[n].flags & 1) - new_colour = WHITE; - else - new_colour = LIGHTGREY; - } - if (new_colour != current_colour) - set_colour(current_colour = new_colour); - DrawMapLine(x1, y1, x2, y2); - } - break; - } + int sd1 = OBJ_NO_NONE; + int sd2 = OBJ_NO_NONE; + int s1 = OBJ_NO_NONE; + int s2 = OBJ_NO_NONE; + // FIXME should flag negative sidedef numbers as errors + // FIXME should flag unused tag as errors + if ((sd1 = LineDefs[n].sidedef1) < 0 || sd1 >= NumSideDefs + || (s1 = SideDefs[sd1].sector) < 0 || s1 >= NumSectors + || (sd2 = LineDefs[n].sidedef2) >= NumSideDefs + || sd2 >= 0 && ((s2 = SideDefs[sd2].sector) < 0 + || s2 >= NumSectors)) + { + new_colour = LIGHTRED; + } + else + { + bool have_tag = false; + bool have_type = false; + if (Sectors[s1].tag != 0) + have_tag = true; + if (Sectors[s1].special != 0) + have_type = true; + if (sd2 >= 0) + { + if (Sectors[s2].tag != 0) + have_tag = true; + if (Sectors[s2].special != 0) + have_type = true; + } + if (have_tag && have_type) + new_colour = SECTOR_TAGTYPE; + else if (have_tag) + new_colour = SECTOR_TAG; + else if (have_type) + new_colour = SECTOR_TYPE; + else if (LineDefs[n].flags & 1) + new_colour = WHITE; + else + new_colour = LIGHTGREY; + } + if (new_colour != current_colour) + set_colour(current_colour = new_colour); + DrawMapLine(x1, y1, x2, y2); + } + break; + } } } /* - * draw_things_squares - the obvious + * draw_things_squares - the obvious */ static void draw_things_squares(edit_t * e) { @@ -561,33 +561,33 @@ push_colour(THING_REM); for (int n = 0; n < NumThings; n++) { - int mapx = Things[n].xpos; - int mapy = Things[n].ypos; - int corner_x; - int corner_y; - if (mapx < mapx0 || mapx > mapx9 || mapy < mapy0 || mapy > mapy9) - continue; - int m = get_thing_radius(Things[n].type); - if (e->obj_type == OBJ_THINGS) - set_colour(get_thing_colour(Things[n].type)); + int mapx = Things[n].xpos; + int mapy = Things[n].ypos; + int corner_x; + int corner_y; + if (mapx < mapx0 || mapx > mapx9 || mapy < mapy0 || mapy > mapy9) + continue; + int m = get_thing_radius(Things[n].type); + if (e->obj_type == OBJ_THINGS) + set_colour(get_thing_colour(Things[n].type)); #ifdef ROUND_THINGS - DrawMapLine(mapx - m, mapy, mapx + m, mapy); - DrawMapLine(mapx, mapy - m, mapx, mapy + m); - DrawMapCircle(mapx, mapy, m); + DrawMapLine(mapx - m, mapy, mapx + m, mapy); + DrawMapLine(mapx, mapy - m, mapx, mapy + m); + DrawMapCircle(mapx, mapy, m); #else - DrawMapLine(mapx - m, mapy - m, mapx + m, mapy - m); - DrawMapLine(mapx + m, mapy - m, mapx + m, mapy + m); - DrawMapLine(mapx + m, mapy + m, mapx - m, mapy + m); - DrawMapLine(mapx - m, mapy + m, mapx - m, mapy - m); + DrawMapLine(mapx - m, mapy - m, mapx + m, mapy - m); + DrawMapLine(mapx + m, mapy - m, mapx + m, mapy + m); + DrawMapLine(mapx + m, mapy + m, mapx - m, mapy + m); + DrawMapLine(mapx - m, mapy + m, mapx - m, mapy - m); #endif - { - size_t direction = angle_to_direction(Things[n].angle); - static const short xsign[] = { 1, 1, 0, -1, -1, -1, 0, 1, 0 }; - static const short ysign[] = { 0, 1, 1, 1, 0, -1, -1, -1, 0 }; - corner_x = m * xsign[direction]; - corner_y = m * ysign[direction]; - } - DrawMapLine(mapx, mapy, mapx + corner_x, mapy + corner_y); + { + size_t direction = angle_to_direction(Things[n].angle); + static const short xsign[] = { 1, 1, 0, -1, -1, -1, 0, 1, 0 }; + static const short ysign[] = { 0, 1, 1, 1, 0, -1, -1, -1, 0 }; + corner_x = m * xsign[direction]; + corner_y = m * ysign[direction]; + } + DrawMapLine(mapx, mapy, mapx + corner_x, mapy + corner_y); } pop_colour(); } @@ -628,18 +628,18 @@ class Thing_npixels { public: - Thing_npixels(i16 thing_no, unsigned long npixels, - wad_ttype_t type):thing_no(thing_no), npixels(npixels), - type(type) + Thing_npixels(i16 thing_no, unsigned long npixels, + wad_ttype_t type):thing_no(thing_no), npixels(npixels), + type(type) { } bool operator<(const Thing_npixels & other) const { - if (this->npixels > other.npixels // Decreasing npixels major - || this->npixels == other.npixels // Increasing type minor - && this->type < other.type) - return true; - return false; + if (this->npixels > other.npixels // Decreasing npixels major + || this->npixels == other.npixels // Increasing type minor + && this->type < other.type) + return true; + return false; } i16 thing_no; unsigned long npixels; @@ -657,23 +657,23 @@ } const Thing_npixels & operator[] (int n) { - return a[n]; + return a[n]; } void refresh() { - a.clear(); - a.reserve(NumThings); - for (int n = 0; n < NumThings; n++) - { - Lump_loc loc; - const char *sprite_root = get_thing_sprite(Things[n].type); - if (sprite_root != NULL) - wad_res.sprites.loc_by_root(sprite_root, loc); - else - loc.len = 0; - a.push_back(Thing_npixels((i16) n, loc.len, Things[n].type)); - } - sort(a.begin(), a.end()); + a.clear(); + a.reserve(NumThings); + for (int n = 0; n < NumThings; n++) + { + Lump_loc loc; + const char *sprite_root = get_thing_sprite(Things[n].type); + if (sprite_root != NULL) + wad_res.sprites.loc_by_root(sprite_root, loc); + else + loc.len = 0; + a.push_back(Thing_npixels((i16) n, loc.len, Things[n].type)); + } + sort(a.begin(), a.end()); } private: std::vector < Thing_npixels > a; @@ -701,11 +701,11 @@ }; typedef std::map < i16, sprite_dim_t > dim_map_t; -static dim_map_t dim_map; // FIXME there should be one for each game +static dim_map_t dim_map; // FIXME there should be one for each game /* - * draw_things_sprites - the obvious + * draw_things_sprites - the obvious */ static void draw_things_sprites(edit_t * e) { @@ -713,9 +713,9 @@ static #endif Sticker sticker; - wad_ttype_t last_type = -1; // Type of last thing displayed + wad_ttype_t last_type = -1; // Type of last thing displayed dim_map_t::iterator dim = dim_map.end(); - bool set_dim = true; // Init to avoid warning + bool set_dim = true; // Init to avoid warning const unsigned short max_width = 1000; const unsigned short max_height = 1000; int mapx0 = 0; @@ -725,104 +725,104 @@ if (things_types_prev != things_types) { - list.refresh(); - things_types_prev = things_types; + list.refresh(); + things_types_prev = things_types; } #ifdef NO_RENDER static double last_scale = 0; if (last_scale != Scale) { - Lump_loc loc; - wad_res.sprites.loc_by_root("PLAY", loc); - Img img; - LoadPicture(img, "PLAYA0", loc, 0, 0); - Img img_scaled; - scale_img(img, Scale * sprite_scale / 100, img_scaled); - sprite.load(img_scaled, false); - last_scale = Scale; + Lump_loc loc; + wad_res.sprites.loc_by_root("PLAY", loc); + Img img; + LoadPicture(img, "PLAYA0", loc, 0, 0); + Img img_scaled; + scale_img(img, Scale * sprite_scale / 100, img_scaled); + sprite.load(img_scaled, false); + last_scale = Scale; } #endif push_colour(CYAN); for (int n = 0; n < NumThings; n++) { - const Thing_npixels & t = list[n]; + const Thing_npixels & t = list[n]; - // Skip off-screen things - if (t.type != last_type) - { - dim = dim_map.find(t.type); - if (dim == dim_map.end()) - { - set_dim = true; - mapx0 = MAPX(0) - max_width / 2; - mapx9 = MAPX(ScrMaxX) + max_width / 2; - mapy0 = MAPY(ScrMaxY) - max_height / 2; - mapy9 = MAPY(0) + max_height / 2; - } - else - { - mapx0 = MAPX(0) - dim->second.width / 2; - mapx9 = MAPX(ScrMaxX) + dim->second.width / 2; - mapy0 = MAPY(ScrMaxY) - dim->second.height / 2; - mapy9 = MAPY(0) + dim->second.height / 2; - } - } - int mapx = Things[t.thing_no].xpos; - int mapy = Things[t.thing_no].ypos; - if (mapx < mapx0 || mapx > mapx9 || mapy < mapy0 || mapy > mapy9) - continue; + // Skip off-screen things + if (t.type != last_type) + { + dim = dim_map.find(t.type); + if (dim == dim_map.end()) + { + set_dim = true; + mapx0 = MAPX(0) - max_width / 2; + mapx9 = MAPX(ScrMaxX) + max_width / 2; + mapy0 = MAPY(ScrMaxY) - max_height / 2; + mapy9 = MAPY(0) + max_height / 2; + } + else + { + mapx0 = MAPX(0) - dim->second.width / 2; + mapx9 = MAPX(ScrMaxX) + dim->second.width / 2; + mapy0 = MAPY(ScrMaxY) - dim->second.height / 2; + mapy9 = MAPY(0) + dim->second.height / 2; + } + } + int mapx = Things[t.thing_no].xpos; + int mapy = Things[t.thing_no].ypos; + if (mapx < mapx0 || mapx > mapx9 || mapy < mapy0 || mapy > mapy9) + continue; #ifndef NO_RENDER - // If not the same as the last thing displayed, rasterize it - if (t.type != last_type) - { - last_type = t.type; + // If not the same as the last thing displayed, rasterize it + if (t.type != last_type) + { + last_type = t.type; - const char *sprite_root = get_thing_sprite(t.type); - if (sprite_root != NULL) - { - Lump_loc loc; - wad_res.sprites.loc_by_root(sprite_root, loc); - Img img_raw, img_scaled; - if (LoadPicture(img_raw, sprite_root, loc, 0, 0)) - { - sticker.clear(); // We'll display the thing type instead - } - else - { - if (set_dim) - { - dim_map[t.type] = - sprite_dim_t(img_raw.width(), img_raw.height()); - set_dim = false; - } - scale_img(img_raw, Scale * sprite_scale / 100, - img_scaled); - if (get_thing_flags(t.type) & THINGDEF_SPECTRAL) - spectrify_img(img_scaled); - sticker.load(img_scaled, false); - } - } - else - sticker.clear(); // We'll display the thing type instead - } + const char *sprite_root = get_thing_sprite(t.type); + if (sprite_root != NULL) + { + Lump_loc loc; + wad_res.sprites.loc_by_root(sprite_root, loc); + Img img_raw, img_scaled; + if (LoadPicture(img_raw, sprite_root, loc, 0, 0)) + { + sticker.clear(); // We'll display the thing type instead + } + else + { + if (set_dim) + { + dim_map[t.type] = + sprite_dim_t(img_raw.width(), img_raw.height()); + set_dim = false; + } + scale_img(img_raw, Scale * sprite_scale / 100, + img_scaled); + if (get_thing_flags(t.type) & THINGDEF_SPECTRAL) + spectrify_img(img_scaled); + sticker.load(img_scaled, false); + } + } + else + sticker.clear(); // We'll display the thing type instead + } #endif - // Display it - if (sticker.is_clear()) - draw_vint(t.type, SCREENX(mapx), SCREENY(mapy), Scale); - else - sticker.draw(drw, 'c', SCREENX(mapx), SCREENY(mapy)); + // Display it + if (sticker.is_clear()) + draw_vint(t.type, SCREENX(mapx), SCREENY(mapy), Scale); + else + sticker.draw(drw, 'c', SCREENX(mapx), SCREENY(mapy)); } pop_colour(); } /* - * draw_obj_no - draw a number at screen coordinates (x, y) + * draw_obj_no - draw a number at screen coordinates (x, y) * - * FIXME too slow. + * FIXME too slow. */ static void draw_obj_no(int x, int y, int obj_no, acolour_t c) { diff -r 594dea11ccd9 -r a68786b9c74b src/drawmap.h --- a/src/drawmap.h Sat Sep 24 15:01:56 2011 +0300 +++ b/src/drawmap.h Sat Sep 24 15:59:33 2011 +0300 @@ -1,6 +1,6 @@ /* - * drawmap.h - * AYM 1998-09-06 + * drawmap.h + * AYM 1998-09-06 */ diff -r 594dea11ccd9 -r a68786b9c74b src/edisplay.cc --- a/src/edisplay.cc Sat Sep 24 15:01:56 2011 +0300 +++ b/src/edisplay.cc Sat Sep 24 15:59:33 2011 +0300 @@ -1,7 +1,7 @@ /* - * edisplay.cc - * The edisplay_c (edit window display) class - * AYM 1998-09-16 + * edisplay.cc + * The edisplay_c (edit window display) class + * AYM 1998-09-16 */ @@ -60,7 +60,7 @@ #include "gfx.h" #include "highlt.h" #include "infobar.h" -#include "levels.h" // Level +#include "levels.h" // Level #include "menu.h" #include "menubar.h" #include "modpopup.h" @@ -138,32 +138,32 @@ infobar->set_scale(Scale); infobar->set_grid_step(e->grid_step); if (e->pointer_in_window) - infobar->set_pointer(e->pointer_x, e->pointer_y); + infobar->set_pointer(e->pointer_x, e->pointer_y); else - infobar->unset_pointer(); + infobar->unset_pointer(); redraw_from_scratch = - refresh_needed - || e->selbox->need_to_clear() - || e->spot->need_to_clear() - || highlight->need_to_clear() - || objinfo->need_to_clear() - || infobar->need_to_clear() - || e->menubar->need_to_clear() || e->modpopup->need_to_clear(); + refresh_needed + || e->selbox->need_to_clear() + || e->spot->need_to_clear() + || highlight->need_to_clear() + || objinfo->need_to_clear() + || infobar->need_to_clear() + || e->menubar->need_to_clear() || e->modpopup->need_to_clear(); /* If we can update the display in an incremental fashion (not from scratch), do it by telling all widgets, from the top to the bottom, to undraw themselves if necessary. */ if (!redraw_from_scratch) { - e->modpopup->undraw(); - e->menubar->undraw(); - infobar->undraw(); - objinfo->undraw(); - highlight->undraw(); - e->spot->undraw(); - e->selbox->undraw(); + e->modpopup->undraw(); + e->menubar->undraw(); + infobar->undraw(); + objinfo->undraw(); + highlight->undraw(); + e->spot->undraw(); + e->selbox->undraw(); } /* If a complete refresh is required, call the clear() @@ -171,23 +171,23 @@ not visible anymore. */ else { - e->selbox->clear(); - e->spot->clear(); - highlight->clear(); - objinfo->clear(); - infobar->clear(); - e->menubar->clear(); - e->modpopup->clear(); + e->selbox->clear(); + e->spot->clear(); + highlight->clear(); + objinfo->clear(); + infobar->clear(); + e->menubar->clear(); + e->modpopup->clear(); - // A piece of ad-hockery - objinfo->unset(); + // A piece of ad-hockery + objinfo->unset(); - // As we said, "from scratch". - ClearScreen(); - draw_map(e); // FIXME should be widgetized - // draw_menubar (); // FIXME should be widgetized - HighlightSelection(e->obj_type, e->Selected); // FIXME should be widgetized - refresh_needed = 0; + // As we said, "from scratch". + ClearScreen(); + draw_map(e); // FIXME should be widgetized + // draw_menubar (); // FIXME should be widgetized + HighlightSelection(e->obj_type, e->Selected); // FIXME should be widgetized + refresh_needed = 0; } /* Tell all widgets from to bottom to the top @@ -196,7 +196,7 @@ e->spot->draw(); highlight->draw(); if (e->objinfo_shown) - objinfo->draw(); + objinfo->draw(); infobar->draw(); e->menubar->draw(); e->modpopup->draw(); diff -r 594dea11ccd9 -r a68786b9c74b src/edisplay.h --- a/src/edisplay.h Sat Sep 24 15:01:56 2011 +0300 +++ b/src/edisplay.h Sat Sep 24 15:59:33 2011 +0300 @@ -1,6 +1,6 @@ /* - * edisplay.h - * AYM 1998-09-16 + * edisplay.h + * AYM 1998-09-16 */ @@ -18,12 +18,12 @@ void highlight_object(Objid & obj); void forget_highlight(); - private: edit_t * e; /* Parent editing window */ - int requested_highlight; /* No. of object that should be highlighted */ - int actual_highlight; /* No. of object that really is highlighted */ - int pointer_scnx; /* Physical position of the pointer */ + private: edit_t * e; /* Parent editing window */ + int requested_highlight; /* No. of object that should be highlighted */ + int actual_highlight; /* No. of object that really is highlighted */ + int pointer_scnx; /* Physical position of the pointer */ int pointer_scny; - int refresh_needed; /* If true, the display needs to be refreshed */ + int refresh_needed; /* If true, the display needs to be refreshed */ highlight_c *highlight; objinfo_c *objinfo; infobar_c *infobar; diff -r 594dea11ccd9 -r a68786b9c74b src/editgrid.cc --- a/src/editgrid.cc Sat Sep 24 15:01:56 2011 +0300 +++ b/src/editgrid.cc Sat Sep 24 15:59:33 2011 +0300 @@ -1,6 +1,6 @@ /* - * editgrid.cc - * AYM 1998-11-09 + * editgrid.cc + * AYM 1998-11-09 */ @@ -35,7 +35,7 @@ void edit_grid_adapt(edit_t * e) { if (!e->grid_step_locked) - for (e->grid_step = e->grid_step_max; - e->grid_step * Scale / 2 >= grid_pixels_min; e->grid_step /= 2) - ; + for (e->grid_step = e->grid_step_max; + e->grid_step * Scale / 2 >= grid_pixels_min; e->grid_step /= 2) + ; } diff -r 594dea11ccd9 -r a68786b9c74b src/editgrid.h --- a/src/editgrid.h Sat Sep 24 15:01:56 2011 +0300 +++ b/src/editgrid.h Sat Sep 24 15:59:33 2011 +0300 @@ -1,6 +1,6 @@ /* - * editgrid.h - * AYM 1998-11-09 + * editgrid.h + * AYM 1998-11-09 */ @@ -31,32 +31,32 @@ /* - * edit_mapx_snapped - * Return snapped to grid - * (or unchanged is snap_to_grid is off) + * edit_mapx_snapped + * Return snapped to grid + * (or unchanged is snap_to_grid is off) */ inline int edit_mapx_snapped(const edit_t * e, int mapx) { if (!e->grid_snap || e->grid_step == 0) - return mapx; + return mapx; if (mapx >= 0) - return e->grid_step * ((mapx + e->grid_step / 2) / e->grid_step); + return e->grid_step * ((mapx + e->grid_step / 2) / e->grid_step); else - return e->grid_step * ((mapx - e->grid_step / 2) / e->grid_step); + return e->grid_step * ((mapx - e->grid_step / 2) / e->grid_step); } /* - * edit_mapy_snapped - * Return snapped to grid - * (or unchanged is snap_to_grid is off) + * edit_mapy_snapped + * Return snapped to grid + * (or unchanged is snap_to_grid is off) */ inline int edit_mapy_snapped(const edit_t * e, int mapy) { if (!e->grid_snap || e->grid_step == 0) - return mapy; + return mapy; if (mapy >= 0) - return e->grid_step * ((mapy + e->grid_step / 2) / e->grid_step); + return e->grid_step * ((mapy + e->grid_step / 2) / e->grid_step); else - return e->grid_step * ((mapy - e->grid_step / 2) / e->grid_step); + return e->grid_step * ((mapy - e->grid_step / 2) / e->grid_step); } diff -r 594dea11ccd9 -r a68786b9c74b src/editlev.cc --- a/src/editlev.cc Sat Sep 24 15:01:56 2011 +0300 +++ b/src/editlev.cc Sat Sep 24 15:59:33 2011 +0300 @@ -1,6 +1,6 @@ /* - * editlev.cc - * AYM 1998-09-06 + * editlev.cc + * AYM 1998-09-06 */ @@ -43,100 +43,100 @@ static void WriteYadexLog(const char *file, const char *level, - time_t * t0, time_t * t1); + time_t * t0, time_t * t1); /* - * find_level - * Look in the master directory for levels that match - * the name in . + * find_level + * Look in the master directory for levels that match + * the name in . * - * can have one of the following formats : - * - * [Ee]n[Mm]m EnMm - * [Mm][Aa][Pp]nm MAPnm - * n MAP0n - * nm Either EnMn or MAPnm - * ijk EiMjk (Doom alpha 0.4 and 0.5) + * can have one of the following formats : + * + * [Ee]n[Mm]m EnMm + * [Mm][Aa][Pp]nm MAPnm + * n MAP0n + * nm Either EnMn or MAPnm + * ijk EiMjk (Doom alpha 0.4 and 0.5) * - * Return: - * - If is either [Ee]n[Mm]m or [Mm][Aa][Pp]nm, - * - if the level was found, its canonical (uppercased) - * name in a freshly malloc'd buffer, - * - else, NULL. - * - If is either n or nm, - * - if either EnMn or MAPnm was found, the canonical name - * of the level found, in a freshly malloc'd buffer, - * - if none was found, , - * - if the is invalid, , - * - if several were found, . + * Return: + * - If is either [Ee]n[Mm]m or [Mm][Aa][Pp]nm, + * - if the level was found, its canonical (uppercased) + * name in a freshly malloc'd buffer, + * - else, NULL. + * - If is either n or nm, + * - if either EnMn or MAPnm was found, the canonical name + * of the level found, in a freshly malloc'd buffer, + * - if none was found, , + * - if the is invalid, , + * - if several were found, . */ char *find_level(const char *name_given) { // Is it a shorthand name ? ("1", "23", ...) if (al_sisnum(name_given) - && (atoi(name_given) <= 99 - || atoi(name_given) <= 999 && yg_level_name == YGLN_E1M10)) + && (atoi(name_given) <= 99 + || atoi(name_given) <= 999 && yg_level_name == YGLN_E1M10)) { - int n = atoi(name_given); - char *name1 = (char *) malloc(7); - char *name2 = (char *) malloc(6); - if (n > 99) - sprintf(name1, "E%dM%02d", n / 100, n % 100); - else - sprintf(name1, "E%dM%d", n / 10, n % 10); - sprintf(name2, "MAP%02d", n); - int match1 = FindMasterDir(MasterDir, name1) != NULL; - int match2 = FindMasterDir(MasterDir, name2) != NULL; - if (match1 && !match2) // Found only ExMy - { - free(name2); - return name1; - } - else if (match2 && !match1) // Found only MAPxy - { - free(name1); - return name2; - } - else if (match1 && match2) // Found both - { - free(name1); - free(name2); - return error_non_unique; - } - else // Found none - { - free(name1); - free(name2); - return error_none; - } + int n = atoi(name_given); + char *name1 = (char *) malloc(7); + char *name2 = (char *) malloc(6); + if (n > 99) + sprintf(name1, "E%dM%02d", n / 100, n % 100); + else + sprintf(name1, "E%dM%d", n / 10, n % 10); + sprintf(name2, "MAP%02d", n); + int match1 = FindMasterDir(MasterDir, name1) != NULL; + int match2 = FindMasterDir(MasterDir, name2) != NULL; + if (match1 && !match2) // Found only ExMy + { + free(name2); + return name1; + } + else if (match2 && !match1) // Found only MAPxy + { + free(name1); + return name2; + } + else if (match1 && match2) // Found both + { + free(name1); + free(name2); + return error_non_unique; + } + else // Found none + { + free(name1); + free(name2); + return error_none; + } } #if 1 // Else look for if (FindMasterDir(MasterDir, name_given)) - return al_sdup(name_given); + return al_sdup(name_given); else { - if (levelname2levelno(name_given)) - return NULL; - else - return error_invalid; + if (levelname2levelno(name_given)) + return NULL; + else + return error_invalid; } #else // If is "[Ee]n[Mm]m" or "[Mm][Aa][Pp]nm", look for that if (levelname2levelno(name_given)) { - char *canonical_name = strdup(name_given); - for (char *p = canonical_name; *p; p++) - *p = toupper(*p); // But shouldn't FindMasterDir() be case-insensitive ? - if (FindMasterDir(MasterDir, canonical_name)) - return canonical_name; - else - { - free(canonical_name); - return NULL; - } + char *canonical_name = strdup(name_given); + for (char *p = canonical_name; *p; p++) + *p = toupper(*p); // But shouldn't FindMasterDir() be case-insensitive ? + if (FindMasterDir(MasterDir, canonical_name)) + return canonical_name; + else + { + free(canonical_name); + return NULL; + } } return error_invalid; #endif @@ -153,44 +153,44 @@ ReadFTextureNames(); patch_dir.refresh(MasterDir); if (InitGfx()) - return; + return; /* Call init_input_status() as shortly as possible after the creation of the window to minimize the risk of calling get_input_status(), get_key(), have_key(), etc. with still uninitialized. */ init_input_status(); init_event(); - if (newlevel && !levelname) // "create" + if (newlevel && !levelname) // "create" { - EmptyLevelData(levelname); - MapMinX = -2000; - MapMinY = -2000; - MapMaxX = 2000; - MapMaxY = 2000; - Level = 0; + EmptyLevelData(levelname); + MapMinX = -2000; + MapMinY = -2000; + MapMaxX = 2000; + MapMaxY = 2000; + Level = 0; } - else if (newlevel && levelname) // "create " + else if (newlevel && levelname) // "create " { - printf("Sorry, \"create \" is not implemented." - " Try \"create\" without argument.\n"); - TermGfx(); - return; + printf("Sorry, \"create \" is not implemented." + " Try \"create\" without argument.\n"); + TermGfx(); + return; } - else // "edit " or "edit" + else // "edit " or "edit" { #if 0 - if (levelname == 0 || !levelname2levelno(levelname) - || !FindMasterDir(MasterDir, levelname)) - levelname = SelectLevel(atoi(levelname)); /* returns "" on Esc */ - if (levelname2levelno(levelname)) - { + if (levelname == 0 || !levelname2levelno(levelname) + || !FindMasterDir(MasterDir, levelname)) + levelname = SelectLevel(atoi(levelname)); /* returns "" on Esc */ + if (levelname2levelno(levelname)) + { #endif - ClearScreen(); - if (ReadLevelData(levelname)) - { - goto done; // Failure! - } + ClearScreen(); + if (ReadLevelData(levelname)) + { + goto done; // Failure! + } #if 0 - } + } #endif } LogMessage(": Editing %s...\n", levelname ? levelname : "new level"); @@ -198,51 +198,51 @@ // Set the name of the window { #define BUFSZ 100 - char buf[BUFSZ + 1]; + char buf[BUFSZ + 1]; #ifdef OLD_TITLE - al_scps(buf, "Yadex - ", BUFSZ); - if (Level && Level->wadfile) - al_saps(buf, Level->wadfile->filename, BUFSZ); - else - al_saps(buf, "New level", BUFSZ); - if (Level) - { - al_saps(buf, " - ", BUFSZ); - al_saps(buf, Level->dir.name, BUFSZ); - } - else if (levelname) - { - al_saps(buf, " - ", BUFSZ); - al_saps(buf, levelname, BUFSZ); - } + al_scps(buf, "Yadex - ", BUFSZ); + if (Level && Level->wadfile) + al_saps(buf, Level->wadfile->filename, BUFSZ); + else + al_saps(buf, "New level", BUFSZ); + if (Level) + { + al_saps(buf, " - ", BUFSZ); + al_saps(buf, Level->dir.name, BUFSZ); + } + else if (levelname) + { + al_saps(buf, " - ", BUFSZ); + al_saps(buf, levelname, BUFSZ); + } #else - al_scps(buf, "Yadex: ", BUFSZ); - al_saps(buf, (levelname) ? levelname : "(null)", BUFSZ); + al_scps(buf, "Yadex: ", BUFSZ); + al_saps(buf, (levelname) ? levelname : "(null)", BUFSZ); #endif - XStoreName(dpy, win, buf); + XStoreName(dpy, win, buf); #undef BUFSZ } { - time_t t0, t1; - time(&t0); - EditorLoop(levelname); - time(&t1); - LogMessage(": Finished editing %s...\n", - levelname ? levelname : "new level"); - if (Level && Level->wadfile) - { - const char *const file_name = - Level->wadfile ? Level->wadfile->pathname() : "(New level)"; - WriteYadexLog(file_name, levelname, &t0, &t1); - } + time_t t0, t1; + time(&t0); + EditorLoop(levelname); + time(&t1); + LogMessage(": Finished editing %s...\n", + levelname ? levelname : "new level"); + if (Level && Level->wadfile) + { + const char *const file_name = + Level->wadfile ? Level->wadfile->pathname() : "(New level)"; + WriteYadexLog(file_name, levelname, &t0, &t1); + } } done: TermGfx(); if (!Registered) - printf("Please register the game" - " if you want to be able to save your changes.\n"); + printf("Please register the game" + " if you want to be able to save your changes.\n"); ForgetLevelData(); /* forget the level pointer */ @@ -253,11 +253,11 @@ /* - * WriteYadexLog - Keep track of time spent editing that wad file - * FIXME should be in a separate module + * WriteYadexLog - Keep track of time spent editing that wad file + * FIXME should be in a separate module */ static void WriteYadexLog(const char *file, const char *level, time_t * t0, - time_t * t1) + time_t * t1) { al_fspec_t logname; al_fdrv_t drive; @@ -270,15 +270,15 @@ /* if log file does not already exist, do _not_ create it */ if (al_fnature(logname) == 1) { - FILE *logfd; - logfd = fopen(logname, "a"); - if (logfd) - { - struct tm *tm = localtime(t0); - fprintf(logfd, "%04d%02d%02d\tedit\t%s\t%ld\n", - tm->tm_year + 1900, tm->tm_mon + 1, tm->tm_mday, level, - (long) (*t1 - *t0) / 60); - fclose(logfd); - } + FILE *logfd; + logfd = fopen(logname, "a"); + if (logfd) + { + struct tm *tm = localtime(t0); + fprintf(logfd, "%04d%02d%02d\tedit\t%s\t%ld\n", + tm->tm_year + 1900, tm->tm_mon + 1, tm->tm_mday, level, + (long) (*t1 - *t0) / 60); + fclose(logfd); + } } } diff -r 594dea11ccd9 -r a68786b9c74b src/editlev.h --- a/src/editlev.h Sat Sep 24 15:01:56 2011 +0300 +++ b/src/editlev.h Sat Sep 24 15:59:33 2011 +0300 @@ -1,6 +1,6 @@ /* - * editlev.h - * AYM 1998-09-06 + * editlev.h + * AYM 1998-09-06 */ diff -r 594dea11ccd9 -r a68786b9c74b src/editloop.cc --- a/src/editloop.cc Sat Sep 24 15:01:56 2011 +0300 +++ b/src/editloop.cc Sat Sep 24 15:59:33 2011 +0300 @@ -1,7 +1,7 @@ /* - * editloop.cc - * The main loop of the editor. - * BW & RQ sometime in 1993 or 1994. + * editloop.cc + * The main loop of the editor. + * BW & RQ sometime in 1993 or 1994. */ @@ -73,63 +73,63 @@ static int zoom_fit(edit_t &); -extern bool InfoShown; /* should we display the info bar? */ -static int menubar_out_y1; /* FIXME */ +extern bool InfoShown; /* should we display the info bar? */ +static int menubar_out_y1; /* FIXME */ /* prototypes of private functions */ static int SortLevels(const void *item1, const void *item2); /* - * SelectLevel - * Prompt the user for a level name (EnMn or MAPnm). The - * name chosen must be present in the master directory - * (iwad or pwads). + * SelectLevel + * Prompt the user for a level name (EnMn or MAPnm). The + * name chosen must be present in the master directory + * (iwad or pwads). * - * If is 0, the level name can be picked from all - * levels present in the master directory. If is - * non-zero, the level name can be picked only from those - * levels in the master directory for which - * levelname2levelno() % 1000 is equal to . For - * example, if is equal to 12, only E1M2 and - * MAP12 would be listed. This feature is not used anymore - * because "e" now requires an argument and tends to deal - * with ambiguous level names (like "12") itself. + * If is 0, the level name can be picked from all + * levels present in the master directory. If is + * non-zero, the level name can be picked only from those + * levels in the master directory for which + * levelname2levelno() % 1000 is equal to . For + * example, if is equal to 12, only E1M2 and + * MAP12 would be listed. This feature is not used anymore + * because "e" now requires an argument and tends to deal + * with ambiguous level names (like "12") itself. */ const char *SelectLevel(int levelno) { MDirPtr dir; - static char name[WAD_NAME + 1]; /* AYM it was [7] previously */ + static char name[WAD_NAME + 1]; /* AYM it was [7] previously */ char **levels = 0; - int n = 0; /* number of levels in the dir. that match */ + int n = 0; /* number of levels in the dir. that match */ get_levels_that_match: for (dir = MasterDir; dir; dir = dir->next) { - if (levelname2levelno(dir->dir.name) > 0 - && (levelno == 0 - || levelname2levelno(dir->dir.name) % 1000 == levelno)) - { - if (n == 0) - levels = (char **) GetMemory(sizeof(char *)); - else - levels = - (char **) ResizeMemory(levels, (n + 1) * sizeof(char *)); - levels[n] = dir->dir.name; - n++; - } + if (levelname2levelno(dir->dir.name) > 0 + && (levelno == 0 + || levelname2levelno(dir->dir.name) % 1000 == levelno)) + { + if (n == 0) + levels = (char **) GetMemory(sizeof(char *)); + else + levels = + (char **) ResizeMemory(levels, (n + 1) * sizeof(char *)); + levels[n] = dir->dir.name; + n++; + } } - if (n == 0 && levelno != 0) /* In case no level matched levelno */ + if (n == 0 && levelno != 0) /* In case no level matched levelno */ { - levelno = 0; /* List ALL levels instead */ - goto get_levels_that_match; + levelno = 0; /* List ALL levels instead */ + goto get_levels_that_match; } /* So that InputNameFromList doesn't fail if you have both EnMn's and MAPnn's in the master dir. */ qsort(levels, n, sizeof(char *), SortLevels); al_scps(name, levels[0], sizeof name - 1); if (n == 1) - return name; + return name; InputNameFromList(-1, -1, "Level name :", n, levels, name); FreeMemory(levels); return name; @@ -144,16 +144,16 @@ { /* FIXME should probably use y_stricmp() instead */ return strcmp(*((const char *const *) item1), - *((const char *const *) item2)); + *((const char *const *) item2)); } // A table of the modes in the editor. typedef struct { - i8 obj_type; // Corresponding object type - i8 item_no; // # of item to tick in the "View" menu - i8 menu_no; // # of flavour of the "Misc op." menu + i8 obj_type; // Corresponding object type + i8 item_no; // # of item to tick in the "View" menu + i8 menu_no; // # of flavour of the "Misc op." menu } editmode_t; const int NB_MODES = 4; @@ -167,17 +167,17 @@ /* - * obj_type_to_mode_no - * Return the # of the mode that has this + * obj_type_to_mode_no + * Return the # of the mode that has this */ static int obj_type_to_mode_no(int obj_type) { int n; for (n = 0; n < NB_MODES; n++) - if (modes[n].obj_type == obj_type) - break; + if (modes[n].obj_type == obj_type) + break; if (n == NB_MODES) - fatal_error("no mode for obj_type %d", obj_type); + fatal_error("no mode for obj_type %d", obj_type); return n; } @@ -208,7 +208,7 @@ the editor main loop */ -void EditorLoop(const char *levelname) /* SWAP! */ +void EditorLoop(const char *levelname) /* SWAP! */ { edit_t e; /* FIXME : all these variables should be moved to edit_t : */ @@ -216,12 +216,12 @@ bool DragObject = false, DragMapMove = false; int oldbuttons, DragMapMoveX, DragMapMoveY; - bool StretchSelBox = false; // FIXME apparently not used anymore... + bool StretchSelBox = false; // FIXME apparently not used anymore... - Objid object; // The object under the pointer + Objid object; // The object under the pointer const Objid CANVAS(OBJ_NONE, OBJ_NO_CANVAS); - memset(&e, 0, sizeof e); /* Catch-all */ + memset(&e, 0, sizeof e); /* Catch-all */ e.move_speed = 20; e.extra_zoom = 0; // If you change this, don't forget to change @@ -268,222 +268,222 @@ if (zoom_default == 0) { - zoom_fit(e); + zoom_fit(e); } else { - int r = edit_set_zoom(&e, zoom_default / 100.0); - if (r == 0) - CenterMapAroundCoords((MapMinX + MapMaxX) / 2, - (MapMinY + MapMaxY) / 2); + int r = edit_set_zoom(&e, zoom_default / 100.0); + if (r == 0) + CenterMapAroundCoords((MapMinX + MapMaxX) / 2, + (MapMinY + MapMaxY) / 2); } oldbuttons = 0; /* Create the menu bar */ { - e.menubar->compute_menubar_coords(0, 0, ScrMaxX, ScrMaxY); + e.menubar->compute_menubar_coords(0, 0, ScrMaxX, ScrMaxY); - e.mb_menu[MBM_FILE] = new Menu(NULL, - "~Save", YK_F2, 0, - "Save ~as...", YK_F3, 0, + e.mb_menu[MBM_FILE] = new Menu(NULL, + "~Save", YK_F2, 0, + "Save ~as...", YK_F3, 0, // "~Print", YK_, MIF_SACTIVE, false, 0, - "~Quit", 'q', 0, NULL); + "~Quit", 'q', 0, NULL); - e.mb_menu[MBM_EDIT] = new Menu(NULL, - "~Copy object(s)", 'o', 0, - "~Add object", YK_INS, 0, - "~Delete object(s)", YK_DEL, 0, - "~Exchange object numbers", 24, 0, - "~Preferences...", YK_F5, 0, - "~Snap to grid", 'y', MIF_VTICK, - &e.grid_snap, 0, "~Lock grid step", - 'z', MIF_VTICK, &e.grid_step_locked, 0, - NULL); + e.mb_menu[MBM_EDIT] = new Menu(NULL, + "~Copy object(s)", 'o', 0, + "~Add object", YK_INS, 0, + "~Delete object(s)", YK_DEL, 0, + "~Exchange object numbers", 24, 0, + "~Preferences...", YK_F5, 0, + "~Snap to grid", 'y', MIF_VTICK, + &e.grid_snap, 0, "~Lock grid step", + 'z', MIF_VTICK, &e.grid_step_locked, 0, + NULL); // If you change the order of modes here, don't forget // to modify the array. - e.mb_menu[MBM_VIEW] = new Menu(NULL, - "~Things", 't', MIF_FTICK, mode_th, - (micbarg_t) & e, 0, - "~Linedefs & sidedefs", 'l', MIF_FTICK, - mode_l, (micbarg_t) & e, 0, - "~Vertices", 'v', MIF_FTICK, mode_v, - (micbarg_t) & e, 0, "~Sectors", 's', - MIF_FTICK, mode_s, (micbarg_t) & e, 0, - "Global", '\7', MIF_VTICK, &e.global, - 0, "~Next mode", YK_TAB, 0, - "~Prev mode", YK_BACKTAB, 0, - MI_SEPARATION, "Zoom ~in", '+', 0, - "Zoom ~out", '-', 0, "Extra ~zoom", - ' ', MIF_VTICK, &e.extra_zoom, 0, - "~Whole level", '`', 0, MI_SEPARATION, - "Show object numbers", '&', MIF_VTICK, - &e.show_object_numbers, 0, - "Show sprites", '%', MIF_VTICK, - &e.show_things_sprites, 0, - "Show ~grid", 'h', MIF_VTICK, - &e.grid_shown, 0, "Info bar", - YK_ALT + 'i', MIF_VTICK, - &e.infobar_shown, 0, - "Object info boxes", 'i', MIF_VTICK, - &e.objinfo_shown, 0, + e.mb_menu[MBM_VIEW] = new Menu(NULL, + "~Things", 't', MIF_FTICK, mode_th, + (micbarg_t) & e, 0, + "~Linedefs & sidedefs", 'l', MIF_FTICK, + mode_l, (micbarg_t) & e, 0, + "~Vertices", 'v', MIF_FTICK, mode_v, + (micbarg_t) & e, 0, "~Sectors", 's', + MIF_FTICK, mode_s, (micbarg_t) & e, 0, + "Global", '\7', MIF_VTICK, &e.global, + 0, "~Next mode", YK_TAB, 0, + "~Prev mode", YK_BACKTAB, 0, + MI_SEPARATION, "Zoom ~in", '+', 0, + "Zoom ~out", '-', 0, "Extra ~zoom", + ' ', MIF_VTICK, &e.extra_zoom, 0, + "~Whole level", '`', 0, MI_SEPARATION, + "Show object numbers", '&', MIF_VTICK, + &e.show_object_numbers, 0, + "Show sprites", '%', MIF_VTICK, + &e.show_things_sprites, 0, + "Show ~grid", 'h', MIF_VTICK, + &e.grid_shown, 0, "Info bar", + YK_ALT + 'i', MIF_VTICK, + &e.infobar_shown, 0, + "Object info boxes", 'i', MIF_VTICK, + &e.objinfo_shown, 0, // "3D preview", '3', MIF_SACTIVE, false, 0, - NULL); + NULL); - e.mb_menu[MBM_SEARCH] = new Menu(NULL, + e.mb_menu[MBM_SEARCH] = new Menu(NULL, // "~Find/change", YK_F4, MIF_SACTIVE, false, 0, // "~Repeat last find", -1, MIF_SACTIVE, false, 0, - "~Next object", 'n', 0, - "~Prev object", 'p', 0, - "~Jump to object...", 'j', 0, - "~Find by type", 'f', 0, NULL); + "~Next object", 'n', 0, + "~Prev object", 'p', 0, + "~Jump to object...", 'j', 0, + "~Find by type", 'f', 0, NULL); - e.mb_menu[MBM_MISC_L] = new Menu("Misc. operations", - "Find first free ~tag number", YK_, - 0, "~Rotate and scale linedefs...", - YK_, 0, - "Split linedefs (add new ~vertex)", - YK_, 0, "~Split linedefs and sector", - YK_, 0, - "~Delete linedefs and join sectors", - YK_, 0, "~Flip linedefs", YK_, 0, - "S~wap sidedefs", YK_, 0, - "Align textures (~Y offset)", YK_, 0, - "Align textures (~X offset)...", YK_, - 0, - "Remove ~2nd sidedef (make single-sided)", - YK_, 0, - "Make rectangular ~nook (32x16)", - YK_, 0, - "Make rectangular ~boss (32x16)", - YK_, 0, - "Set ~length (move 1st vertex)...", - YK_, 0, - "Set length (move 2nd vertex)...", - YK_, 0, "~Unlink 1st sidedef", YK_, - 0, "Unlink 2nd sidedef", YK_, 0, - "~Mirror horizontally", YK_, 0, - "Mirror v~ertically", YK_, 0, - "~Cut a slice out of a sector", YK_, - 0, NULL); + e.mb_menu[MBM_MISC_L] = new Menu("Misc. operations", + "Find first free ~tag number", YK_, + 0, "~Rotate and scale linedefs...", + YK_, 0, + "Split linedefs (add new ~vertex)", + YK_, 0, "~Split linedefs and sector", + YK_, 0, + "~Delete linedefs and join sectors", + YK_, 0, "~Flip linedefs", YK_, 0, + "S~wap sidedefs", YK_, 0, + "Align textures (~Y offset)", YK_, 0, + "Align textures (~X offset)...", YK_, + 0, + "Remove ~2nd sidedef (make single-sided)", + YK_, 0, + "Make rectangular ~nook (32x16)", + YK_, 0, + "Make rectangular ~boss (32x16)", + YK_, 0, + "Set ~length (move 1st vertex)...", + YK_, 0, + "Set length (move 2nd vertex)...", + YK_, 0, "~Unlink 1st sidedef", YK_, + 0, "Unlink 2nd sidedef", YK_, 0, + "~Mirror horizontally", YK_, 0, + "Mirror v~ertically", YK_, 0, + "~Cut a slice out of a sector", YK_, + 0, NULL); - e.mb_menu[MBM_MISC_S] = new Menu("Misc. operations", - "Find first free ~tag number", YK_, - 0, "~Rotate and scale sectors...", - YK_, 0, "Make ~door from sector", - YK_, 0, "Make ~lift from sector", - YK_, 0, - "Distribute sector ~floor heights", - YK_, 0, - "Distribute sector ~ceiling heights", - YK_, 0, "R~aise or lower sectors...", - YK_, 0, - "~Brighten or darken sectors...", - YK_, 0, "~Unlink room", YK_, 0, - "~Mirror horizontally", YK_, 0, - "Mirror ~vertically", YK_, 0, - "~Swap flats", YK_, 0, NULL); + e.mb_menu[MBM_MISC_S] = new Menu("Misc. operations", + "Find first free ~tag number", YK_, + 0, "~Rotate and scale sectors...", + YK_, 0, "Make ~door from sector", + YK_, 0, "Make ~lift from sector", + YK_, 0, + "Distribute sector ~floor heights", + YK_, 0, + "Distribute sector ~ceiling heights", + YK_, 0, "R~aise or lower sectors...", + YK_, 0, + "~Brighten or darken sectors...", + YK_, 0, "~Unlink room", YK_, 0, + "~Mirror horizontally", YK_, 0, + "Mirror ~vertically", YK_, 0, + "~Swap flats", YK_, 0, NULL); - e.mb_menu[MBM_MISC_T] = new Menu("Misc. operations", - "Find first free ~tag number", YK_, - 0, "~Rotate and scale things...", - YK_, 0, "~Spin things 45° clockwise", - 'x', 0, - "Spin things 45° ~counter-clockwise", - 'w', 0, "~Mirror horizontally", YK_, - 0, "Mirror ~vertically", YK_, 0, - NULL); + e.mb_menu[MBM_MISC_T] = new Menu("Misc. operations", + "Find first free ~tag number", YK_, + 0, "~Rotate and scale things...", + YK_, 0, "~Spin things 45° clockwise", + 'x', 0, + "Spin things 45° ~counter-clockwise", + 'w', 0, "~Mirror horizontally", YK_, + 0, "Mirror ~vertically", YK_, 0, + NULL); - e.mb_menu[MBM_MISC_V] = new Menu("Misc. operations", - "Find first free ~tag number", YK_, - 0, "~Rotate and scale vertices...", - YK_, 0, - "~Delete vertex and join linedefs", - YK_, 0, - "~Merge several vertices into one", - YK_, 0, - "Add a linedef and ~split sector", - YK_, 0, "Mirror ~horizontally", YK_, - 0, "Mirror ~vertically", YK_, 0, - NULL); + e.mb_menu[MBM_MISC_V] = new Menu("Misc. operations", + "Find first free ~tag number", YK_, + 0, "~Rotate and scale vertices...", + YK_, 0, + "~Delete vertex and join linedefs", + YK_, 0, + "~Merge several vertices into one", + YK_, 0, + "Add a linedef and ~split sector", + YK_, 0, "Mirror ~horizontally", YK_, + 0, "Mirror ~vertically", YK_, 0, + NULL); - e.mb_menu[MBM_OBJECTS] = new Menu("Insert a pre-defined object", - "~Rectangle...", YK_, 0, - "~Polygon (N sides)...", YK_, 0, - NULL); + e.mb_menu[MBM_OBJECTS] = new Menu("Insert a pre-defined object", + "~Rectangle...", YK_, 0, + "~Polygon (N sides)...", YK_, 0, + NULL); - e.mb_menu[MBM_CHECK] = new Menu("Check level consistency", - "~Number of objects", YK_, 0, - "Check if all ~sectors are closed", - YK_, 0, "Check all ~cross-references", - YK_, 0, "Check for ~missing textures", - YK_, 0, "Check ~texture names", YK_, - 0, NULL); + e.mb_menu[MBM_CHECK] = new Menu("Check level consistency", + "~Number of objects", YK_, 0, + "Check if all ~sectors are closed", + YK_, 0, "Check all ~cross-references", + YK_, 0, "Check for ~missing textures", + YK_, 0, "Check ~texture names", YK_, + 0, NULL); - e.mb_menu[MBM_HELP] = new Menu(NULL, - "~Keyboard & mouse...", YK_F1, 0, - "~About Yadex...", YK_ALT + 'a', 0, - NULL); + e.mb_menu[MBM_HELP] = new Menu(NULL, + "~Keyboard & mouse...", YK_F1, 0, + "~About Yadex...", YK_ALT + 'a', 0, + NULL); - e.mb_ino[MBI_FILE] = - e.menubar->add_item("File", 0, 0, e.mb_menu[MBM_FILE]); - e.mb_ino[MBI_EDIT] = - e.menubar->add_item("Edit", 0, 0, e.mb_menu[MBM_EDIT]); - e.mb_ino[MBI_VIEW] = - e.menubar->add_item("View", 0, 0, e.mb_menu[MBM_VIEW]); - e.mb_ino[MBI_SEARCH] = - e.menubar->add_item("Search", 0, 0, e.mb_menu[MBM_SEARCH]); - e.mb_ino[MBI_MISC] = - e.menubar->add_item("Misc", 0, 0, e.mb_menu[MBM_MISC_T]); - e.mb_ino[MBI_OBJECTS] = - e.menubar->add_item("Objects", 0, 0, e.mb_menu[MBM_OBJECTS]); - e.mb_ino[MBI_CHECK] = - e.menubar->add_item("Check", 0, 0, e.mb_menu[MBM_CHECK]); - e.mb_ino[MBI_HELP] = - e.menubar->add_item("Help", 0, 1, e.mb_menu[MBM_HELP]); + e.mb_ino[MBI_FILE] = + e.menubar->add_item("File", 0, 0, e.mb_menu[MBM_FILE]); + e.mb_ino[MBI_EDIT] = + e.menubar->add_item("Edit", 0, 0, e.mb_menu[MBM_EDIT]); + e.mb_ino[MBI_VIEW] = + e.menubar->add_item("View", 0, 0, e.mb_menu[MBM_VIEW]); + e.mb_ino[MBI_SEARCH] = + e.menubar->add_item("Search", 0, 0, e.mb_menu[MBM_SEARCH]); + e.mb_ino[MBI_MISC] = + e.menubar->add_item("Misc", 0, 0, e.mb_menu[MBM_MISC_T]); + e.mb_ino[MBI_OBJECTS] = + e.menubar->add_item("Objects", 0, 0, e.mb_menu[MBM_OBJECTS]); + e.mb_ino[MBI_CHECK] = + e.menubar->add_item("Check", 0, 0, e.mb_menu[MBM_CHECK]); + e.mb_ino[MBI_HELP] = + e.menubar->add_item("Help", 0, 1, e.mb_menu[MBM_HELP]); - menubar_out_y1 = 2 * BOX_BORDER + 2 * NARROW_VSPACING + FONTH - 1; // FIXME + menubar_out_y1 = 2 * BOX_BORDER + 2 * NARROW_VSPACING + FONTH - 1; // FIXME } // FIXME this should come from the .ygd // instead of being hard-coded. Menu *menu_linedef_flags = new Menu(NULL, - "~Impassable", YK_, 0, - "~Monsters cannot cross", YK_, 0, - "~Double-sided", YK_, 0, - "~Upper texture unpegged", YK_, 0, - "~Lower texture unpegged", YK_, 0, - "~Secret (shown as normal)", YK_, 0, - "~Blocks sound", YK_, 0, - "~Never shown on the map", YK_, 0, - "~Always shown on the map", YK_, 0, - "~Pass through [Boom]", YK_, 0, // Boom extension - "b1~0 0400h", YK_, 0, // Undefined - "b1~1 0800h", YK_, 0, // Undefined - "~Translucent [Strife]", YK_, 0, // Strife - "b1~3 2000h", YK_, 0, // Undefined - "b1~4 4000h", YK_, 0, // Undefined - "b1~5 8000h", YK_, 0, // Undefined - NULL); + "~Impassable", YK_, 0, + "~Monsters cannot cross", YK_, 0, + "~Double-sided", YK_, 0, + "~Upper texture unpegged", YK_, 0, + "~Lower texture unpegged", YK_, 0, + "~Secret (shown as normal)", YK_, 0, + "~Blocks sound", YK_, 0, + "~Never shown on the map", YK_, 0, + "~Always shown on the map", YK_, 0, + "~Pass through [Boom]", YK_, 0, // Boom extension + "b1~0 0400h", YK_, 0, // Undefined + "b1~1 0800h", YK_, 0, // Undefined + "~Translucent [Strife]", YK_, 0, // Strife + "b1~3 2000h", YK_, 0, // Undefined + "b1~4 4000h", YK_, 0, // Undefined + "b1~5 8000h", YK_, 0, // Undefined + NULL); Menu *menu_thing_flags = new Menu(NULL, - "~Easy", YK_, 0, - "Medi~um", YK_, 0, - "~Hard", YK_, 0, - "~Deaf", YK_, 0, - "~Multiplayer", YK_, 0, - "~Not in DM [Boom]", YK_, 0, // Boom extension - "Not in ~coop [Boom]", YK_, 0, // Boom extension - "F~riendly [MBF]", YK_, 0, // MBF extension - "b~8 0100h", YK_, 0, // Undefined - "b~9 0200h", YK_, 0, // Undefined - "b1~0 0400h", YK_, 0, // Undefined - "b1~1 0800h", YK_, 0, // Undefined - "b1~2 1000h", YK_, 0, // Undefined - "b1~3 2000h", YK_, 0, // Undefined - "b1~4 4000h", YK_, 0, // Undefined - "b1~5 8000h", YK_, 0, // Undefined - NULL); + "~Easy", YK_, 0, + "Medi~um", YK_, 0, + "~Hard", YK_, 0, + "~Deaf", YK_, 0, + "~Multiplayer", YK_, 0, + "~Not in DM [Boom]", YK_, 0, // Boom extension + "Not in ~coop [Boom]", YK_, 0, // Boom extension + "F~riendly [MBF]", YK_, 0, // MBF extension + "b~8 0100h", YK_, 0, // Undefined + "b~9 0200h", YK_, 0, // Undefined + "b1~0 0400h", YK_, 0, // Undefined + "b1~1 0800h", YK_, 0, // Undefined + "b1~2 1000h", YK_, 0, // Undefined + "b1~3 2000h", YK_, 0, // Undefined + "b1~4 4000h", YK_, 0, // Undefined + "b1~5 8000h", YK_, 0, // Undefined + NULL); /* AYM 1998-06-22 This is the big mean loop. I organized it in three main steps : @@ -499,2037 +499,2037 @@ for (RedrawMap = 1;; RedrawMap = 0) { - int motion = 0; // Initialized to silence GCC warning + int motion = 0; // Initialized to silence GCC warning - /* - * Step 1 -- Do all the displaying work - */ + /* + * Step 1 -- Do all the displaying work + */ #ifdef Y_BATCH - // Hold refresh until all events are processed - if (!has_event() && !has_input_event()) - { + // Hold refresh until all events are processed + if (!has_event() && !has_input_event()) + { #endif - if (e.highlighted()) // FIXME - e.edisplay->highlight_object(e.highlighted); // Should - else // be in - e.edisplay->forget_highlight(); // edisplay_c ! + if (e.highlighted()) // FIXME + e.edisplay->highlight_object(e.highlighted); // Should + else // be in + e.edisplay->forget_highlight(); // edisplay_c ! - if (is.in_window) - e.spot->set(edit_mapx_snapped(&e, e.pointer_x), - edit_mapy_snapped(&e, e.pointer_y)); - else - e.spot->unset(); + if (is.in_window) + e.spot->set(edit_mapx_snapped(&e, e.pointer_x), + edit_mapy_snapped(&e, e.pointer_y)); + else + e.spot->unset(); - e.edisplay->refresh(); - /* The display is now up to date */ + e.edisplay->refresh(); + /* The display is now up to date */ #ifdef Y_BATCH - } + } #endif - /* - * Step 2 -- Get the next event - */ + /* + * Step 2 -- Get the next event + */ - if (has_key_press_event()) - is.key = get_event(); - else - get_input_status(); - e.pointer_in_window = is.in_window; - if (is.in_window) - { - /* AYM 1998-07-04 - If the map coordinates of the pointer have changed, - generate a pointer motion event. I don't like to do - that but it makes things much simpler elsewhere. */ - if (MAPX(is.x) != e.pointer_x || MAPY(is.y) != e.pointer_y) - motion = 1; - else - motion = 0; + if (has_key_press_event()) + is.key = get_event(); + else + get_input_status(); + e.pointer_in_window = is.in_window; + if (is.in_window) + { + /* AYM 1998-07-04 + If the map coordinates of the pointer have changed, + generate a pointer motion event. I don't like to do + that but it makes things much simpler elsewhere. */ + if (MAPX(is.x) != e.pointer_x || MAPY(is.y) != e.pointer_y) + motion = 1; + else + motion = 0; - e.pointer_x = MAPX(is.x); - e.pointer_y = MAPY(is.y); - obj_type_t t = e.global ? OBJ_ANY : e.obj_type; - GetCurObject(object, t, e.pointer_x, e.pointer_y); - } + e.pointer_x = MAPX(is.x); + e.pointer_y = MAPY(is.y); + obj_type_t t = e.global ? OBJ_ANY : e.obj_type; + GetCurObject(object, t, e.pointer_x, e.pointer_y); + } - /* - * Step 3 -- Process the event - * This section is (should be) a long list of elif's - */ + /* + * Step 3 -- Process the event + * This section is (should be) a long list of elif's + */ - /* - * Step 3.1A -- If a pull-down menu is "on", - * try to make it process the event. - */ + /* + * Step 3.1A -- If a pull-down menu is "on", + * try to make it process the event. + */ - if (e.menubar->pulled_down() >= 0) - { - int menu_no = e.menubar->pulled_down(); - Menu *menu = e.menubar->get_menu(menu_no); - int r = menu->process_event(&is); + if (e.menubar->pulled_down() >= 0) + { + int menu_no = e.menubar->pulled_down(); + Menu *menu = e.menubar->get_menu(menu_no); + int r = menu->process_event(&is); - if (r == MEN_CANCEL) - { - e.menubar->pull_down(-1); - e.menubar->highlight(-1); - goto done; - } + if (r == MEN_CANCEL) + { + e.menubar->pull_down(-1); + e.menubar->highlight(-1); + goto done; + } - // The event was understood and processed normally - // by the menu event handler so we're done. - else if (r == MEN_OTHER) - goto done; + // The event was understood and processed normally + // by the menu event handler so we're done. + else if (r == MEN_OTHER) + goto done; - // The event was not understood by the menu event - // handler so let's see what the normal event handler - // can do with it. - else if (r == MEN_INVALID) - ; + // The event was not understood by the menu event + // handler so let's see what the normal event handler + // can do with it. + else if (r == MEN_INVALID) + ; - else - { - e.menubar->pull_down(-1); - e.menubar->highlight(-1); - if (menu_no == e.mb_ino[MBI_MISC]) - { - if (e.Selected) - MiscOperations(e.obj_type, &e.Selected, r + 1); - else - { - if (e.highlighted()) - SelectObject(&e.Selected, e.highlighted.num); - MiscOperations(e.obj_type, &e.Selected, r + 1); - if (e.highlighted()) - UnSelectObject(&e.Selected, e.highlighted.num); - } - e.highlighted.nil(); - DragObject = false; - StretchSelBox = false; - RedrawMap = 1; - } - else if (menu_no == e.mb_ino[MBI_OBJECTS]) - { - /* code duplicated from 'F9' - I hate to do that */ - int savednum = NumLineDefs; - InsertStandardObject(e.pointer_x, e.pointer_y, r + 1); - if (NumLineDefs > savednum) - { - ForgetSelection(&e.Selected); - e.obj_type = OBJ_LINEDEFS; - for (int i = savednum; i < NumLineDefs; i++) - SelectObject(&e.Selected, i); - e.highlighted.nil(); - DragObject = false; - StretchSelBox = false; - } - RedrawMap = 1; - } - else if (menu_no == e.mb_ino[MBI_CHECK]) - { - if (r == 0) - Statistics(); - else if (r == 1) - CheckSectors(); - else if (r == 2) - CheckCrossReferences(); - else if (r == 3) - CheckTextures(); - else if (r == 4) - CheckTextureNames(); - } - else - send_event(menu->last_shortcut_key()); - goto done; - } - } + else + { + e.menubar->pull_down(-1); + e.menubar->highlight(-1); + if (menu_no == e.mb_ino[MBI_MISC]) + { + if (e.Selected) + MiscOperations(e.obj_type, &e.Selected, r + 1); + else + { + if (e.highlighted()) + SelectObject(&e.Selected, e.highlighted.num); + MiscOperations(e.obj_type, &e.Selected, r + 1); + if (e.highlighted()) + UnSelectObject(&e.Selected, e.highlighted.num); + } + e.highlighted.nil(); + DragObject = false; + StretchSelBox = false; + RedrawMap = 1; + } + else if (menu_no == e.mb_ino[MBI_OBJECTS]) + { + /* code duplicated from 'F9' - I hate to do that */ + int savednum = NumLineDefs; + InsertStandardObject(e.pointer_x, e.pointer_y, r + 1); + if (NumLineDefs > savednum) + { + ForgetSelection(&e.Selected); + e.obj_type = OBJ_LINEDEFS; + for (int i = savednum; i < NumLineDefs; i++) + SelectObject(&e.Selected, i); + e.highlighted.nil(); + DragObject = false; + StretchSelBox = false; + } + RedrawMap = 1; + } + else if (menu_no == e.mb_ino[MBI_CHECK]) + { + if (r == 0) + Statistics(); + else if (r == 1) + CheckSectors(); + else if (r == 2) + CheckCrossReferences(); + else if (r == 3) + CheckTextures(); + else if (r == 4) + CheckTextureNames(); + } + else + send_event(menu->last_shortcut_key()); + goto done; + } + } - /* - * Step 3.1B -- If the "Misc operations" popup is on, - * try to make it process the event. - */ + /* + * Step 3.1B -- If the "Misc operations" popup is on, + * try to make it process the event. + */ - else if (e.modpopup->get() == e.mb_menu[MBM_MISC_L] - || e.modpopup->get() == e.mb_menu[MBM_MISC_S] - || e.modpopup->get() == e.mb_menu[MBM_MISC_T] - || e.modpopup->get() == e.mb_menu[MBM_MISC_V]) - { - int r = (e.modpopup->get())->process_event(&is); + else if (e.modpopup->get() == e.mb_menu[MBM_MISC_L] + || e.modpopup->get() == e.mb_menu[MBM_MISC_S] + || e.modpopup->get() == e.mb_menu[MBM_MISC_T] + || e.modpopup->get() == e.mb_menu[MBM_MISC_V]) + { + int r = (e.modpopup->get())->process_event(&is); - // [Esc] or click outside the popup menu. Close it. - if (r == MEN_CANCEL - || r == MEN_INVALID && is.key == YE_BUTL_PRESS) - { - e.modpopup->unset(); - goto done2; - } + // [Esc] or click outside the popup menu. Close it. + if (r == MEN_CANCEL + || r == MEN_INVALID && is.key == YE_BUTL_PRESS) + { + e.modpopup->unset(); + goto done2; + } - // The event was understood and processed normally - // by the menu event handler so we're done. - else if (r == MEN_OTHER) - goto done2; + // The event was understood and processed normally + // by the menu event handler so we're done. + else if (r == MEN_OTHER) + goto done2; - // The event was not understood by the menu event - // handler so let's see what the normal event handler - // can do with it. - else if (r == MEN_INVALID) - ; + // The event was not understood by the menu event + // handler so let's see what the normal event handler + // can do with it. + else if (r == MEN_INVALID) + ; - else - { - e.modpopup->unset(); - if (e.Selected) - MiscOperations(e.obj_type, &e.Selected, r + 1); - else - { - if (e.highlighted()) - SelectObject(&e.Selected, e.highlighted.num); - MiscOperations(e.obj_type, &e.Selected, r + 1); - if (e.highlighted()) - UnSelectObject(&e.Selected, e.highlighted.num); - } - e.highlighted.nil(); - DragObject = false; - StretchSelBox = false; - goto done2; - } - } + else + { + e.modpopup->unset(); + if (e.Selected) + MiscOperations(e.obj_type, &e.Selected, r + 1); + else + { + if (e.highlighted()) + SelectObject(&e.Selected, e.highlighted.num); + MiscOperations(e.obj_type, &e.Selected, r + 1); + if (e.highlighted()) + UnSelectObject(&e.Selected, e.highlighted.num); + } + e.highlighted.nil(); + DragObject = false; + StretchSelBox = false; + goto done2; + } + } - /* - * Step 3.1C -- If the "Insert standard object" popup is on, - * try to make it process the event. - */ + /* + * Step 3.1C -- If the "Insert standard object" popup is on, + * try to make it process the event. + */ - else if (e.modpopup->get() == e.mb_menu[MBM_OBJECTS]) - { - int r = (e.modpopup->get())->process_event(&is); + else if (e.modpopup->get() == e.mb_menu[MBM_OBJECTS]) + { + int r = (e.modpopup->get())->process_event(&is); - // [Esc] or click outside the popup menu. Close it. - if (r == MEN_CANCEL - || r == MEN_INVALID && is.key == YE_BUTL_PRESS) - { - e.modpopup->unset(); - goto done2; - } + // [Esc] or click outside the popup menu. Close it. + if (r == MEN_CANCEL + || r == MEN_INVALID && is.key == YE_BUTL_PRESS) + { + e.modpopup->unset(); + goto done2; + } - // The event was understood and processed normally - // by the menu event handler so we're done. - else if (r == MEN_OTHER) - goto done2; + // The event was understood and processed normally + // by the menu event handler so we're done. + else if (r == MEN_OTHER) + goto done2; - // The event was not understood by the menu event - // handler so let's see what the normal event handler - // can do with it. - else if (r == MEN_INVALID) - ; + // The event was not understood by the menu event + // handler so let's see what the normal event handler + // can do with it. + else if (r == MEN_INVALID) + ; - else - { - e.modpopup->unset(); - int savednum = NumLineDefs; - InsertStandardObject(e.pointer_x, e.pointer_y, r + 1); - if (NumLineDefs > savednum) - { - ForgetSelection(&e.Selected); - e.obj_type = OBJ_LINEDEFS; - for (int i = savednum; i < NumLineDefs; i++) - SelectObject(&e.Selected, i); - e.highlighted.nil(); - DragObject = false; - StretchSelBox = false; - } - goto done2; - } - } + else + { + e.modpopup->unset(); + int savednum = NumLineDefs; + InsertStandardObject(e.pointer_x, e.pointer_y, r + 1); + if (NumLineDefs > savednum) + { + ForgetSelection(&e.Selected); + e.obj_type = OBJ_LINEDEFS; + for (int i = savednum; i < NumLineDefs; i++) + SelectObject(&e.Selected, i); + e.highlighted.nil(); + DragObject = false; + StretchSelBox = false; + } + goto done2; + } + } - /* - * Step 3.1D -- if the "Set/toggle/clear" linedef flag popup - * is on, try to make it process the event. - */ - else if (e.modpopup->get() == menu_linedef_flags) - { - int r = (e.modpopup->get())->process_event(&is); + /* + * Step 3.1D -- if the "Set/toggle/clear" linedef flag popup + * is on, try to make it process the event. + */ + else if (e.modpopup->get() == menu_linedef_flags) + { + int r = (e.modpopup->get())->process_event(&is); - // [Esc] or click outside the popup menu. Close it. - if (r == MEN_CANCEL - || r == MEN_INVALID && is.key == YE_BUTL_PRESS) - { - e.modpopup->unset(); - goto done2; - } + // [Esc] or click outside the popup menu. Close it. + if (r == MEN_CANCEL + || r == MEN_INVALID && is.key == YE_BUTL_PRESS) + { + e.modpopup->unset(); + goto done2; + } - // The event was understood and processed normally - // by the menu event handler so we're done. - else if (r == MEN_OTHER) - goto done2; + // The event was understood and processed normally + // by the menu event handler so we're done. + else if (r == MEN_OTHER) + goto done2; - // The event was not understood by the menu event - // handler so let's see what the normal event handler - // can do with it. - else if (r == MEN_INVALID) - ; + // The event was not understood by the menu event + // handler so let's see what the normal event handler + // can do with it. + else if (r == MEN_INVALID) + ; - else - { - int op = -1; - e.modpopup->unset(); - if (e.modal == 's') - op = YO_SET; - else if (e.modal == 't') - op = YO_TOGGLE; - else if (e.modal == 'c') - op = YO_CLEAR; - else - fatal_error("modal=%02X", e.modal); - if (!e.Selected) - { - SelectObject(&e.Selected, e.highlighted.num); - frob_linedefs_flags(e.Selected, op, r); - UnSelectObject(&e.Selected, e.highlighted.num); - } - else - { - frob_linedefs_flags(e.Selected, op, r); - } - goto done2; - } - } + else + { + int op = -1; + e.modpopup->unset(); + if (e.modal == 's') + op = YO_SET; + else if (e.modal == 't') + op = YO_TOGGLE; + else if (e.modal == 'c') + op = YO_CLEAR; + else + fatal_error("modal=%02X", e.modal); + if (!e.Selected) + { + SelectObject(&e.Selected, e.highlighted.num); + frob_linedefs_flags(e.Selected, op, r); + UnSelectObject(&e.Selected, e.highlighted.num); + } + else + { + frob_linedefs_flags(e.Selected, op, r); + } + goto done2; + } + } - /* - * Step 3.1E -- if the "Set/toggle/clear" thing flag popup - * is on, try to make it process the event. - */ - else if (e.modpopup->get() == menu_thing_flags) - { - int r = (e.modpopup->get())->process_event(&is); + /* + * Step 3.1E -- if the "Set/toggle/clear" thing flag popup + * is on, try to make it process the event. + */ + else if (e.modpopup->get() == menu_thing_flags) + { + int r = (e.modpopup->get())->process_event(&is); - // [Esc] or click outside the popup menu. Close it. - if (r == MEN_CANCEL - || r == MEN_INVALID && is.key == YE_BUTL_PRESS) - { - e.modpopup->unset(); - goto done2; - } + // [Esc] or click outside the popup menu. Close it. + if (r == MEN_CANCEL + || r == MEN_INVALID && is.key == YE_BUTL_PRESS) + { + e.modpopup->unset(); + goto done2; + } - // The event was understood and processed normally - // by the menu event handler so we're done. - else if (r == MEN_OTHER) - goto done2; + // The event was understood and processed normally + // by the menu event handler so we're done. + else if (r == MEN_OTHER) + goto done2; - // The event was not understood by the menu event - // handler so let's see what the normal event handler - // can do with it. - else if (r == MEN_INVALID) - ; + // The event was not understood by the menu event + // handler so let's see what the normal event handler + // can do with it. + else if (r == MEN_INVALID) + ; - else - { - int op = -1; - e.modpopup->unset(); - if (e.modal == 's') - op = YO_SET; - else if (e.modal == 't') - op = YO_TOGGLE; - else if (e.modal == 'c') - op = YO_CLEAR; - else - fatal_error("modal=%02X", e.modal); - if (!e.Selected) - { - SelectObject(&e.Selected, e.highlighted.num); - frob_things_flags(e.Selected, op, r); - UnSelectObject(&e.Selected, e.highlighted.num); - } - else - { - frob_things_flags(e.Selected, op, r); - } - goto done2; - } - } + else + { + int op = -1; + e.modpopup->unset(); + if (e.modal == 's') + op = YO_SET; + else if (e.modal == 't') + op = YO_TOGGLE; + else if (e.modal == 'c') + op = YO_CLEAR; + else + fatal_error("modal=%02X", e.modal); + if (!e.Selected) + { + SelectObject(&e.Selected, e.highlighted.num); + frob_things_flags(e.Selected, op, r); + UnSelectObject(&e.Selected, e.highlighted.num); + } + else + { + frob_things_flags(e.Selected, op, r); + } + goto done2; + } + } - /* - * Step 3.2 -- "Normal" event handling - */ + /* + * Step 3.2 -- "Normal" event handling + */ - /* - * Step 3.2.1 -- Non keyboard events - */ + /* + * Step 3.2.1 -- Non keyboard events + */ - if (is.key == YE_EXPOSE) - { - RedrawMap = 1; - goto done2; - } + if (is.key == YE_EXPOSE) + { + RedrawMap = 1; + goto done2; + } - else if (is.key == YE_RESIZE) - { - SetWindowSize(is.width, is.height); - e.menubar->compute_menubar_coords(0, 0, ScrMaxX, ScrMaxY); - RedrawMap = 1; - goto done2; - } + else if (is.key == YE_RESIZE) + { + SetWindowSize(is.width, is.height); + e.menubar->compute_menubar_coords(0, 0, ScrMaxX, ScrMaxY); + RedrawMap = 1; + goto done2; + } - // To prevent normal handling when a popup menu is on. - if (e.modpopup->get() != 0) - { - goto done2; - } + // To prevent normal handling when a popup menu is on. + if (e.modpopup->get() != 0) + { + goto done2; + } - /* - * Step 3.2.2 -- Mouse events - */ - if (DragMapMove && is.key == YE_MOTION) - { - int deltaX = DragMapMoveX - is.x, deltaY = DragMapMoveY - is.y; + /* + * Step 3.2.2 -- Mouse events + */ + if (DragMapMove && is.key == YE_MOTION) + { + int deltaX = DragMapMoveX - is.x, deltaY = DragMapMoveY - is.y; - if (deltaX != 0 || deltaY != 0) - { - OrigX += (deltaX / Scale); - OrigY -= (deltaY / Scale); - RedrawMap = 1; - DragMapMoveX = is.x; - DragMapMoveY = is.y; - goto done2; - } - } + if (deltaX != 0 || deltaY != 0) + { + OrigX += (deltaX / Scale); + OrigY -= (deltaY / Scale); + RedrawMap = 1; + DragMapMoveX = is.x; + DragMapMoveY = is.y; + goto done2; + } + } - else if (is.key == YE_BUTM_PRESS) - { - DragMapMove = true; - DragMapMoveX = is.x; - DragMapMoveY = is.y; - goto done; - } + else if (is.key == YE_BUTM_PRESS) + { + DragMapMove = true; + DragMapMoveX = is.x; + DragMapMoveY = is.y; + goto done; + } - else if (is.key == YE_BUTM_RELEASE) - { - DragMapMove = false; - goto done; - } + else if (is.key == YE_BUTM_RELEASE) + { + DragMapMove = false; + goto done; + } - // Clicking on an item of the menu bar - // pulls down the corresponding menu. - else if (is.key == YE_BUTL_PRESS - && e.menubar->is_on_menubar_item(is.x, is.y) >= 0) - { - int itemno; + // Clicking on an item of the menu bar + // pulls down the corresponding menu. + else if (is.key == YE_BUTL_PRESS + && e.menubar->is_on_menubar_item(is.x, is.y) >= 0) + { + int itemno; - e.clicked.nil(); - itemno = e.menubar->is_on_menubar_item(is.x, is.y); - if (itemno >= 0) - e.menubar->pull_down(itemno); - else - Beep(); - goto done; - } + e.clicked.nil(); + itemno = e.menubar->is_on_menubar_item(is.x, is.y); + if (itemno >= 0) + e.menubar->pull_down(itemno); + else + Beep(); + goto done; + } - /* Clicking on an empty space starts a new selection box. - Unless [Ctrl] is pressed, it also clears the current selection. */ - else if (is.key == YE_BUTL_PRESS - && e.tool == TOOL_NORMAL && object.is_nil()) - { - e.menubar->highlight(-1); // Close any open menu - e.clicked = CANVAS; - e.click_ctrl = is.ctrl; - if (!is.ctrl) - { - ForgetSelection(&e.Selected); - RedrawMap = 1; - } - e.selbox->set_1st_corner(e.pointer_x, e.pointer_y); - e.selbox->set_2nd_corner(e.pointer_x, e.pointer_y); - } + /* Clicking on an empty space starts a new selection box. + Unless [Ctrl] is pressed, it also clears the current selection. */ + else if (is.key == YE_BUTL_PRESS + && e.tool == TOOL_NORMAL && object.is_nil()) + { + e.menubar->highlight(-1); // Close any open menu + e.clicked = CANVAS; + e.click_ctrl = is.ctrl; + if (!is.ctrl) + { + ForgetSelection(&e.Selected); + RedrawMap = 1; + } + e.selbox->set_1st_corner(e.pointer_x, e.pointer_y); + e.selbox->set_2nd_corner(e.pointer_x, e.pointer_y); + } - /* Clicking on an unselected object unselects - everything but that object. Additionally, - we write the number of the object in case - the user is about to drag it. */ - else if (is.key == YE_BUTL_PRESS && !is.ctrl - && e.tool == TOOL_NORMAL - && !IsSelected(e.Selected, object.num)) - { - e.menubar->highlight(-1); // Close any open menu - e.clicked = object; - e.click_ctrl = 0; - e.click_time = is.time; - ForgetSelection(&e.Selected); - SelectObject(&e.Selected, object.num); - /* I don't like having to do that */ - if (object.type == OBJ_THINGS && object()) - MoveObjectsToCoords(object.type, 0, - Things[object.num].xpos, - Things[object.num].ypos, 0); - else if (object.type == OBJ_VERTICES && object()) - MoveObjectsToCoords(object.type, 0, - Vertices[object.num].x, - Vertices[object.num].y, 0); - else - MoveObjectsToCoords(object.type, 0, - e.pointer_x, e.pointer_y, - e.grid_snap ? e.grid_step : 0); - RedrawMap = 1; - } + /* Clicking on an unselected object unselects + everything but that object. Additionally, + we write the number of the object in case + the user is about to drag it. */ + else if (is.key == YE_BUTL_PRESS && !is.ctrl + && e.tool == TOOL_NORMAL + && !IsSelected(e.Selected, object.num)) + { + e.menubar->highlight(-1); // Close any open menu + e.clicked = object; + e.click_ctrl = 0; + e.click_time = is.time; + ForgetSelection(&e.Selected); + SelectObject(&e.Selected, object.num); + /* I don't like having to do that */ + if (object.type == OBJ_THINGS && object()) + MoveObjectsToCoords(object.type, 0, + Things[object.num].xpos, + Things[object.num].ypos, 0); + else if (object.type == OBJ_VERTICES && object()) + MoveObjectsToCoords(object.type, 0, + Vertices[object.num].x, + Vertices[object.num].y, 0); + else + MoveObjectsToCoords(object.type, 0, + e.pointer_x, e.pointer_y, + e.grid_snap ? e.grid_step : 0); + RedrawMap = 1; + } - /* Second click of a double click on an object */ - else if (is.key == YE_BUTL_PRESS && !is.ctrl - && e.tool == TOOL_NORMAL - && IsSelected(e.Selected, object.num) - && object == e.clicked - && is.time - e.click_time <= - (unsigned long) double_click_timeout) - { - // Very important! If you don't do that, the release of the - // click that closed the properties menu will drag the object. - e.clicked.nil(); - send_event(YK_RETURN); - goto done; - } + /* Second click of a double click on an object */ + else if (is.key == YE_BUTL_PRESS && !is.ctrl + && e.tool == TOOL_NORMAL + && IsSelected(e.Selected, object.num) + && object == e.clicked + && is.time - e.click_time <= + (unsigned long) double_click_timeout) + { + // Very important! If you don't do that, the release of the + // click that closed the properties menu will drag the object. + e.clicked.nil(); + send_event(YK_RETURN); + goto done; + } - /* Clicking on a selected object does nothing ; - the user might want to drag the selection. */ - else if (is.key == YE_BUTL_PRESS && !is.ctrl - && e.tool == TOOL_NORMAL - && IsSelected(e.Selected, object.num)) - { - e.menubar->highlight(-1); // Close any open menu - e.clicked = object; - e.click_ctrl = 0; - e.click_time = is.time; - /* I don't like having to do that */ - if (object.type == OBJ_THINGS && object()) - MoveObjectsToCoords(object.type, 0, - Things[object.num].xpos, - Things[object.num].ypos, 0); - else if (object.type == OBJ_VERTICES && object()) - MoveObjectsToCoords(object.type, 0, - Vertices[object.num].x, - Vertices[object.num].y, 0); - else - MoveObjectsToCoords(object.type, 0, - e.pointer_x, e.pointer_y, - e.grid_snap ? e.grid_step : 0); - } + /* Clicking on a selected object does nothing ; + the user might want to drag the selection. */ + else if (is.key == YE_BUTL_PRESS && !is.ctrl + && e.tool == TOOL_NORMAL + && IsSelected(e.Selected, object.num)) + { + e.menubar->highlight(-1); // Close any open menu + e.clicked = object; + e.click_ctrl = 0; + e.click_time = is.time; + /* I don't like having to do that */ + if (object.type == OBJ_THINGS && object()) + MoveObjectsToCoords(object.type, 0, + Things[object.num].xpos, + Things[object.num].ypos, 0); + else if (object.type == OBJ_VERTICES && object()) + MoveObjectsToCoords(object.type, 0, + Vertices[object.num].x, + Vertices[object.num].y, 0); + else + MoveObjectsToCoords(object.type, 0, + e.pointer_x, e.pointer_y, + e.grid_snap ? e.grid_step : 0); + } - /* Clicking on selected object with [Ctrl] pressed unselects it. - Clicking on unselected object with [Ctrl] pressed selects it. */ - else if (((is.key == YE_BUTL_PRESS && is.ctrl) - || is.key == YE_BUTR_PRESS) && e.tool == TOOL_NORMAL - && object()) - { - e.menubar->highlight(-1); // Close any open menu - e.clicked = object; - e.click_ctrl = 1; - if (IsSelected(e.Selected, object.num)) - UnSelectObject(&e.Selected, object.num); - else - SelectObject(&e.Selected, object.num); - RedrawMap = 1; - } + /* Clicking on selected object with [Ctrl] pressed unselects it. + Clicking on unselected object with [Ctrl] pressed selects it. */ + else if (((is.key == YE_BUTL_PRESS && is.ctrl) + || is.key == YE_BUTR_PRESS) && e.tool == TOOL_NORMAL + && object()) + { + e.menubar->highlight(-1); // Close any open menu + e.clicked = object; + e.click_ctrl = 1; + if (IsSelected(e.Selected, object.num)) + UnSelectObject(&e.Selected, object.num); + else + SelectObject(&e.Selected, object.num); + RedrawMap = 1; + } - /* TOOL_SNAP_VERTEX */ - else if (is.key == YE_BUTL_PRESS - && e.tool == TOOL_SNAP_VERTEX - && e.obj_type == OBJ_VERTICES && object() - // Can't delete vertex that is referenced by the selection - && !IsSelected(e.Selected, object.num)) - { - printf("SNAP %d\n", (int) object.num); - SelPtr list = 0; - SelectObject(&list, object.num); - DeleteVerticesJoinLineDefs(list); - ForgetSelection(&list); - RedrawMap = 1; - } + /* TOOL_SNAP_VERTEX */ + else if (is.key == YE_BUTL_PRESS + && e.tool == TOOL_SNAP_VERTEX + && e.obj_type == OBJ_VERTICES && object() + // Can't delete vertex that is referenced by the selection + && !IsSelected(e.Selected, object.num)) + { + printf("SNAP %d\n", (int) object.num); + SelPtr list = 0; + SelectObject(&list, object.num); + DeleteVerticesJoinLineDefs(list); + ForgetSelection(&list); + RedrawMap = 1; + } - /* Clicking anywhere else closes the pull-down menus. */ - else if (is.key == YE_BUTL_PRESS) - e.menubar->highlight(-1); // Close any open menu + /* Clicking anywhere else closes the pull-down menus. */ + else if (is.key == YE_BUTL_PRESS) + e.menubar->highlight(-1); // Close any open menu - /* Releasing the button while there was a selection box - causes all the objects within the box to be selected. */ - // FIXME : should call this automatically when switching tool - else if (is.key == YE_BUTL_RELEASE - && e.tool == TOOL_NORMAL && e.clicked == CANVAS) - { - int x1, y1, x2, y2; - e.selbox->get_corners(&x1, &y1, &x2, &y2); - SelectObjectsInBox(&e.Selected, e.obj_type, x1, y1, x2, y2); - e.selbox->unset_corners(); - RedrawMap = 1; - } + /* Releasing the button while there was a selection box + causes all the objects within the box to be selected. */ + // FIXME : should call this automatically when switching tool + else if (is.key == YE_BUTL_RELEASE + && e.tool == TOOL_NORMAL && e.clicked == CANVAS) + { + int x1, y1, x2, y2; + e.selbox->get_corners(&x1, &y1, &x2, &y2); + SelectObjectsInBox(&e.Selected, e.obj_type, x1, y1, x2, y2); + e.selbox->unset_corners(); + RedrawMap = 1; + } - /* Releasing the button while dragging : drop the selection. */ - // FIXME : should call this automatically when switching tool - else if (is.key == YE_BUTL_RELEASE - && e.tool == TOOL_NORMAL && e.clicked()) - { - if (AutoMergeVertices(&e.Selected, e.obj_type, 'm')) - RedrawMap = 1; - } + /* Releasing the button while dragging : drop the selection. */ + // FIXME : should call this automatically when switching tool + else if (is.key == YE_BUTL_RELEASE + && e.tool == TOOL_NORMAL && e.clicked()) + { + if (AutoMergeVertices(&e.Selected, e.obj_type, 'm')) + RedrawMap = 1; + } - // Moving the pointer with the left button pressed - // after clicking on an item of the menu bar : pull - // down menus as the pointer passes over them. - else if (is.key == YE_MOTION - && e.tool == TOOL_NORMAL - && is.butl && !e.clicked() && !(e.clicked == CANVAS)) - { - int itemno = e.menubar->is_on_menubar_item(is.x, is.y); - if (itemno >= 0) - e.menubar->pull_down(itemno); - goto done; - } + // Moving the pointer with the left button pressed + // after clicking on an item of the menu bar : pull + // down menus as the pointer passes over them. + else if (is.key == YE_MOTION + && e.tool == TOOL_NORMAL + && is.butl && !e.clicked() && !(e.clicked == CANVAS)) + { + int itemno = e.menubar->is_on_menubar_item(is.x, is.y); + if (itemno >= 0) + e.menubar->pull_down(itemno); + goto done; + } - /* Moving the pointer with the left button pressed - and a selection box exists : move the second - corner of the selection box. */ - else if ((is.key == YE_MOTION || motion) - && e.tool == TOOL_NORMAL && is.butl && e.clicked == CANVAS) - { - e.selbox->set_2nd_corner(e.pointer_x, e.pointer_y); - } + /* Moving the pointer with the left button pressed + and a selection box exists : move the second + corner of the selection box. */ + else if ((is.key == YE_MOTION || motion) + && e.tool == TOOL_NORMAL && is.butl && e.clicked == CANVAS) + { + e.selbox->set_2nd_corner(e.pointer_x, e.pointer_y); + } - /* Moving the pointer with the left button pressed - but no selection box exists and [Ctrl] was not - pressed when the button was pressed : - drag the selection. */ - else if (motion - && e.tool == TOOL_NORMAL - && is.butl && e.clicked() && !e.click_ctrl) - { - if (!e.Selected) - { - SelectObject(&e.Selected, e.clicked.num); - if (MoveObjectsToCoords(e.clicked.type, e.Selected, - e.pointer_x, e.pointer_y, - e.grid_snap ? e.grid_step : 0)) - RedrawMap = 1; - ForgetSelection(&e.Selected); - } - else if (MoveObjectsToCoords(e.clicked.type, e.Selected, - e.pointer_x, e.pointer_y, - e.grid_snap ? e.grid_step : 0)) - RedrawMap = 1; - } + /* Moving the pointer with the left button pressed + but no selection box exists and [Ctrl] was not + pressed when the button was pressed : + drag the selection. */ + else if (motion + && e.tool == TOOL_NORMAL + && is.butl && e.clicked() && !e.click_ctrl) + { + if (!e.Selected) + { + SelectObject(&e.Selected, e.clicked.num); + if (MoveObjectsToCoords(e.clicked.type, e.Selected, + e.pointer_x, e.pointer_y, + e.grid_snap ? e.grid_step : 0)) + RedrawMap = 1; + ForgetSelection(&e.Selected); + } + else if (MoveObjectsToCoords(e.clicked.type, e.Selected, + e.pointer_x, e.pointer_y, + e.grid_snap ? e.grid_step : 0)) + RedrawMap = 1; + } - /* AYM : added is.in_window */ - if (is.in_window && !is.butl && !is.shift) - { - /* Check if there is something near the pointer */ - e.highlighted = object; - } + /* AYM : added is.in_window */ + if (is.in_window && !is.butl && !is.shift) + { + /* Check if there is something near the pointer */ + e.highlighted = object; + } - /* - * Step 3.2.3 -- Keyboard events - */ + /* + * Step 3.2.3 -- Keyboard events + */ - if (event_is_key(is.key) - || is.key == YE_WHEEL_UP || is.key == YE_WHEEL_DOWN) - { - if (is.key == YK_LEFT && e.menubar->highlighted() >= 0) - { - int new_item = e.menubar->highlighted() - 1; - if (new_item < 0) - new_item = e.mb_ino[MBI_HELP]; - e.menubar->pull_down(new_item); - RedrawMap = 1; - } + if (event_is_key(is.key) + || is.key == YE_WHEEL_UP || is.key == YE_WHEEL_DOWN) + { + if (is.key == YK_LEFT && e.menubar->highlighted() >= 0) + { + int new_item = e.menubar->highlighted() - 1; + if (new_item < 0) + new_item = e.mb_ino[MBI_HELP]; + e.menubar->pull_down(new_item); + RedrawMap = 1; + } - else if (is.key == YK_RIGHT && e.menubar->highlighted() >= 0) - { - int new_item = e.menubar->highlighted() + 1; - if (new_item > e.mb_ino[MBI_HELP]) - new_item = 0; - e.menubar->pull_down(new_item); - RedrawMap = 1; - } + else if (is.key == YK_RIGHT && e.menubar->highlighted() >= 0) + { + int new_item = e.menubar->highlighted() + 1; + if (new_item > e.mb_ino[MBI_HELP]) + new_item = 0; + e.menubar->pull_down(new_item); + RedrawMap = 1; + } - else if (is.key == YK_ALT + 'f') - e.menubar->pull_down(e.mb_ino[MBI_FILE]); + else if (is.key == YK_ALT + 'f') + e.menubar->pull_down(e.mb_ino[MBI_FILE]); - else if (is.key == YK_ALT + 'e') - e.menubar->pull_down(e.mb_ino[MBI_EDIT]); + else if (is.key == YK_ALT + 'e') + e.menubar->pull_down(e.mb_ino[MBI_EDIT]); - else if (is.key == YK_ALT + 's') - e.menubar->pull_down(e.mb_ino[MBI_SEARCH]); + else if (is.key == YK_ALT + 's') + e.menubar->pull_down(e.mb_ino[MBI_SEARCH]); - else if (is.key == YK_ALT + 'v') - e.menubar->pull_down(e.mb_ino[MBI_VIEW]); + else if (is.key == YK_ALT + 'v') + e.menubar->pull_down(e.mb_ino[MBI_VIEW]); - else if (is.key == YK_ALT + 'm') - e.menubar->pull_down(e.mb_ino[MBI_MISC]); + else if (is.key == YK_ALT + 'm') + e.menubar->pull_down(e.mb_ino[MBI_MISC]); - else if (is.key == YK_ALT + 'o') - e.menubar->pull_down(e.mb_ino[MBI_OBJECTS]); + else if (is.key == YK_ALT + 'o') + e.menubar->pull_down(e.mb_ino[MBI_OBJECTS]); - else if (is.key == YK_ALT + 'c') - e.menubar->pull_down(e.mb_ino[MBI_CHECK]); + else if (is.key == YK_ALT + 'c') + e.menubar->pull_down(e.mb_ino[MBI_CHECK]); - else if (is.key == YK_ALT + 'h') - e.menubar->pull_down(e.mb_ino[MBI_HELP]); + else if (is.key == YK_ALT + 'h') + e.menubar->pull_down(e.mb_ino[MBI_HELP]); - // [Ctrl][L]: force redraw - else if (is.key == '\f') - { - RedrawMap = 1; - } + // [Ctrl][L]: force redraw + else if (is.key == '\f') + { + RedrawMap = 1; + } - // [Esc], [q]: close - else if (is.key == YK_ESC || is.key == 'q') - { - if (DragObject) - DragObject = false; - else if (StretchSelBox) - StretchSelBox = false; - else - { - ForgetSelection(&e.Selected); - if (!MadeChanges - || Confirm(-1, -1, "You have unsaved changes." - " Do you really want to quit?", 0)) - break; - RedrawMap = 1; - } - } + // [Esc], [q]: close + else if (is.key == YK_ESC || is.key == 'q') + { + if (DragObject) + DragObject = false; + else if (StretchSelBox) + StretchSelBox = false; + else + { + ForgetSelection(&e.Selected); + if (!MadeChanges + || Confirm(-1, -1, "You have unsaved changes." + " Do you really want to quit?", 0)) + break; + RedrawMap = 1; + } + } - // [F1]: pop up "Help" window - else if (is.key == YK_F1) /* 'F1' */ - { - DisplayHelp(); - RedrawMap = 1; - } + // [F1]: pop up "Help" window + else if (is.key == YK_F1) /* 'F1' */ + { + DisplayHelp(); + RedrawMap = 1; + } - // [Alt][a]: pop up the "About..." window - else if (is.key == YK_ALT + 'a') - { - about_yadex(); - RedrawMap = 1; - } + // [Alt][a]: pop up the "About..." window + else if (is.key == YK_ALT + 'a') + { + about_yadex(); + RedrawMap = 1; + } - // [Shift][F1]: save a screen shot into yadex.gif. - // FIXME doesn't work in the Unix port - else if (is.key == YK_F1 + YK_SHIFT) - { - Rgbbmp b; - window_to_rgbbmp(0, 0, (int) ScrMaxX + 1, (int) ScrMaxY + 1, - b); - rgbbmp_to_rawppm(b, "yadex.ppm"); - //ScreenShot (); - } + // [Shift][F1]: save a screen shot into yadex.gif. + // FIXME doesn't work in the Unix port + else if (is.key == YK_F1 + YK_SHIFT) + { + Rgbbmp b; + window_to_rgbbmp(0, 0, (int) ScrMaxX + 1, (int) ScrMaxY + 1, + b); + rgbbmp_to_rawppm(b, "yadex.ppm"); + //ScreenShot (); + } - // [Shift][F2]: undocumented--test of Entry2 - else if (is.key == YK_F2 + YK_SHIFT) - { - char buf1[10]; - char buf2[30]; - char buf3[20]; - strcpy(buf1, "buf1"); - strcpy(buf2, "buf2"); - strcpy(buf3, "buf3"); - Entry2 e("Title of window", "Buf 1%*sBuf 2%*sBuf 3%*s", - sizeof buf1 - 1, buf1, - sizeof buf2 - 1, buf2, sizeof buf3 - 1, buf3); - e.loop(); - printf("bufs: \"%s\", \"%s\", \"%s\"\n", buf1, buf2, buf3); - RedrawMap = 1; - } + // [Shift][F2]: undocumented--test of Entry2 + else if (is.key == YK_F2 + YK_SHIFT) + { + char buf1[10]; + char buf2[30]; + char buf3[20]; + strcpy(buf1, "buf1"); + strcpy(buf2, "buf2"); + strcpy(buf3, "buf3"); + Entry2 e("Title of window", "Buf 1%*sBuf 2%*sBuf 3%*s", + sizeof buf1 - 1, buf1, + sizeof buf2 - 1, buf2, sizeof buf3 - 1, buf3); + e.loop(); + printf("bufs: \"%s\", \"%s\", \"%s\"\n", buf1, buf2, buf3); + RedrawMap = 1; + } - /* [F2] save level into pwad, prompt for the file name - every time but keep the same level name. */ - else if (is.key == YK_F2 && Registered) - { - if (!CheckStartingPos()) - goto cancel_save; - char *outfile; - const char *newlevelname; - if (levelname) - newlevelname = levelname; - else - { - newlevelname = SelectLevel(0); - if (!*newlevelname) - goto cancel_save; - } - outfile = GetWadFileName(newlevelname); - if (!outfile) - goto cancel_save; - SaveLevelData(outfile, newlevelname); - levelname = newlevelname; - // Sigh. Shouldn't have to do that. Level must die ! - Level = FindMasterDir(MasterDir, levelname); - cancel_save: - RedrawMap = 1; - } + /* [F2] save level into pwad, prompt for the file name + every time but keep the same level name. */ + else if (is.key == YK_F2 && Registered) + { + if (!CheckStartingPos()) + goto cancel_save; + char *outfile; + const char *newlevelname; + if (levelname) + newlevelname = levelname; + else + { + newlevelname = SelectLevel(0); + if (!*newlevelname) + goto cancel_save; + } + outfile = GetWadFileName(newlevelname); + if (!outfile) + goto cancel_save; + SaveLevelData(outfile, newlevelname); + levelname = newlevelname; + // Sigh. Shouldn't have to do that. Level must die ! + Level = FindMasterDir(MasterDir, levelname); + cancel_save: + RedrawMap = 1; + } - /* [F3] save level into pwad, prompt for the file name and - level name. */ - else if (is.key == YK_F3 && Registered) - { - char *outfile; - const char *newlevelname; - MDirPtr newLevel, oldl, newl; + /* [F3] save level into pwad, prompt for the file name and + level name. */ + else if (is.key == YK_F3 && Registered) + { + char *outfile; + const char *newlevelname; + MDirPtr newLevel, oldl, newl; - if (!CheckStartingPos()) - goto cancel_save_as; - newlevelname = SelectLevel(0); - if (!*newlevelname) - goto cancel_save_as; - if (!levelname || y_stricmp(newlevelname, levelname)) - { - /* horrible but it works... */ - // Horrible indeed -- AYM 1999-07-30 - newLevel = FindMasterDir(MasterDir, newlevelname); - if (!newLevel) - nf_bug("newLevel is NULL"); // Debatable ! -- AYM 2001-05-29 - if (Level) // If new level ("create" command), Level is NULL - { - oldl = Level; - newl = newLevel; - for (int m = 0; m < 11; m++) - { - newl->wadfile = oldl->wadfile; - if (m > 0) - newl->dir = oldl->dir; - /* - if (!fncmp (outfile, oldl->wadfile->filename)) - { - oldl->wadfile = WadFileList; - oldl->dir = lost... - } - */ - oldl = oldl->next; - newl = newl->next; - } - } - Level = newLevel; - } - outfile = GetWadFileName(newlevelname); - if (!outfile) - goto cancel_save_as; - SaveLevelData(outfile, newlevelname); - levelname = newlevelname; - cancel_save_as: - RedrawMap = 1; - } + if (!CheckStartingPos()) + goto cancel_save_as; + newlevelname = SelectLevel(0); + if (!*newlevelname) + goto cancel_save_as; + if (!levelname || y_stricmp(newlevelname, levelname)) + { + /* horrible but it works... */ + // Horrible indeed -- AYM 1999-07-30 + newLevel = FindMasterDir(MasterDir, newlevelname); + if (!newLevel) + nf_bug("newLevel is NULL"); // Debatable ! -- AYM 2001-05-29 + if (Level) // If new level ("create" command), Level is NULL + { + oldl = Level; + newl = newLevel; + for (int m = 0; m < 11; m++) + { + newl->wadfile = oldl->wadfile; + if (m > 0) + newl->dir = oldl->dir; + /* + if (!fncmp (outfile, oldl->wadfile->filename)) + { + oldl->wadfile = WadFileList; + oldl->dir = lost... + } + */ + oldl = oldl->next; + newl = newl->next; + } + } + Level = newLevel; + } + outfile = GetWadFileName(newlevelname); + if (!outfile) + goto cancel_save_as; + SaveLevelData(outfile, newlevelname); + levelname = newlevelname; + cancel_save_as: + RedrawMap = 1; + } - // [F5]: pop up the "Preferences" menu - else if (is.key == YK_F5 && e.menubar->highlighted() < 0) - { - Preferences(-1, -1); - RedrawMap = 1; - } + // [F5]: pop up the "Preferences" menu + else if (is.key == YK_F5 && e.menubar->highlighted() < 0) + { + Preferences(-1, -1); + RedrawMap = 1; + } - // [a]: pop up the "Set flag" menu - else if (is.key == 'a' - && e.menubar->highlighted() < 0 - && (e.Selected || e.highlighted())) - { - e.modal = 's'; // Set - if (e.obj_type == OBJ_LINEDEFS) - { - menu_linedef_flags->set_title("Set linedef flag"); - e.modpopup->set(menu_linedef_flags, 0); - } - else if (e.obj_type == OBJ_THINGS) - { - menu_thing_flags->set_title("Set thing flag"); - e.modpopup->set(menu_thing_flags, 0); - } - } + // [a]: pop up the "Set flag" menu + else if (is.key == 'a' + && e.menubar->highlighted() < 0 + && (e.Selected || e.highlighted())) + { + e.modal = 's'; // Set + if (e.obj_type == OBJ_LINEDEFS) + { + menu_linedef_flags->set_title("Set linedef flag"); + e.modpopup->set(menu_linedef_flags, 0); + } + else if (e.obj_type == OBJ_THINGS) + { + menu_thing_flags->set_title("Set thing flag"); + e.modpopup->set(menu_thing_flags, 0); + } + } - // [b]: pop up the "Toggle flag" menu - else if (is.key == 'b' - && e.menubar->highlighted() < 0 - && (e.Selected || e.highlighted())) - { - e.modal = 't'; // Toggle - if (e.obj_type == OBJ_LINEDEFS) - { - menu_linedef_flags->set_title("Toggle linedef flag"); - e.modpopup->set(menu_linedef_flags, 0); - } - else if (e.obj_type == OBJ_THINGS) - { - menu_thing_flags->set_title("Toggle thing flag"); - e.modpopup->set(menu_thing_flags, 0); - } - } + // [b]: pop up the "Toggle flag" menu + else if (is.key == 'b' + && e.menubar->highlighted() < 0 + && (e.Selected || e.highlighted())) + { + e.modal = 't'; // Toggle + if (e.obj_type == OBJ_LINEDEFS) + { + menu_linedef_flags->set_title("Toggle linedef flag"); + e.modpopup->set(menu_linedef_flags, 0); + } + else if (e.obj_type == OBJ_THINGS) + { + menu_thing_flags->set_title("Toggle thing flag"); + e.modpopup->set(menu_thing_flags, 0); + } + } - // [c]: pop up the "Clear flag" menu - else if (is.key == 'c' - && e.menubar->highlighted() < 0 - && (e.Selected || e.highlighted())) - { - e.modal = 'c'; // Clear; - if (e.obj_type == OBJ_LINEDEFS) - { - menu_linedef_flags->set_title("Clear linedef flag"); - e.modpopup->set(menu_linedef_flags, 0); - } - else if (e.obj_type == OBJ_THINGS) - { - menu_thing_flags->set_title("Clear thing flag"); - e.modpopup->set(menu_thing_flags, 0); - } - } + // [c]: pop up the "Clear flag" menu + else if (is.key == 'c' + && e.menubar->highlighted() < 0 + && (e.Selected || e.highlighted())) + { + e.modal = 'c'; // Clear; + if (e.obj_type == OBJ_LINEDEFS) + { + menu_linedef_flags->set_title("Clear linedef flag"); + e.modpopup->set(menu_linedef_flags, 0); + } + else if (e.obj_type == OBJ_THINGS) + { + menu_thing_flags->set_title("Clear thing flag"); + e.modpopup->set(menu_thing_flags, 0); + } + } - // [F8]: pop up the "Misc. operations" menu - else if (is.key == YK_F8 && e.menubar->highlighted() < 0) - { - e.modpopup->set(e.menubar->get_menu(MBI_MISC), 1); - } + // [F8]: pop up the "Misc. operations" menu + else if (is.key == YK_F8 && e.menubar->highlighted() < 0) + { + e.modpopup->set(e.menubar->get_menu(MBI_MISC), 1); + } - // [F9]: pop up the "Insert a standard object" menu - else if (is.key == YK_F9 && e.menubar->highlighted() < 0) - { - e.modpopup->set(e.menubar->get_menu(MBI_OBJECTS), 1); - } + // [F9]: pop up the "Insert a standard object" menu + else if (is.key == YK_F9 && e.menubar->highlighted() < 0) + { + e.modpopup->set(e.menubar->get_menu(MBI_OBJECTS), 1); + } - // [F10]: pop up the "Checks" menu - else if (is.key == YK_F10 && e.menubar->highlighted() < 0) - { - CheckLevel(-1, -1); - RedrawMap = 1; - } + // [F10]: pop up the "Checks" menu + else if (is.key == YK_F10 && e.menubar->highlighted() < 0) + { + CheckLevel(-1, -1); + RedrawMap = 1; + } - // [Alt][i]: show/hide the info bar - else if (is.key == YK_ALT + 'i') - { - e.infobar_shown = !e.infobar_shown; - RedrawMap = 1; - } + // [Alt][i]: show/hide the info bar + else if (is.key == YK_ALT + 'i') + { + e.infobar_shown = !e.infobar_shown; + RedrawMap = 1; + } - // [i]: show/hide the object info boxes - else if (is.key == 'i') - { - e.objinfo_shown = !e.objinfo_shown; - RedrawMap = 1; - } + // [i]: show/hide the object info boxes + else if (is.key == 'i') + { + e.objinfo_shown = !e.objinfo_shown; + RedrawMap = 1; + } - // [+], [=], wheel: zooming in - else if (is.key == '+' || is.key == '=' || is.key == YE_WHEEL_UP) - { - int r = edit_zoom_in(&e); - if (r == 0) - RedrawMap = 1; - } + // [+], [=], wheel: zooming in + else if (is.key == '+' || is.key == '=' || is.key == YE_WHEEL_UP) + { + int r = edit_zoom_in(&e); + if (r == 0) + RedrawMap = 1; + } - // [-], [_], wheel: zooming out - else if (is.key == '-' || is.key == '_' - || is.key == YE_WHEEL_DOWN) - { - int r = edit_zoom_out(&e); - if (r == 0) - RedrawMap = 1; - } + // [-], [_], wheel: zooming out + else if (is.key == '-' || is.key == '_' + || is.key == YE_WHEEL_DOWN) + { + int r = edit_zoom_out(&e); + if (r == 0) + RedrawMap = 1; + } - // [1] - [9], [0]: set the zoom factor - else if (is.key >= '0' && is.key <= '9') - { - int r = edit_set_zoom(&e, digit_zoom_factors[dectoi(is.key)]); - if (r == 0) - RedrawMap = 1; - } + // [1] - [9], [0]: set the zoom factor + else if (is.key >= '0' && is.key <= '9') + { + int r = edit_set_zoom(&e, digit_zoom_factors[dectoi(is.key)]); + if (r == 0) + RedrawMap = 1; + } - // [']: centre window on centre of map - else if (is.key == '\'') - { - update_level_bounds(); - CenterMapAroundCoords((MapMinX + MapMaxX) / 2, - (MapMinY + MapMaxY) / 2); - RedrawMap = 1; - } + // [']: centre window on centre of map + else if (is.key == '\'') + { + update_level_bounds(); + CenterMapAroundCoords((MapMinX + MapMaxX) / 2, + (MapMinY + MapMaxY) / 2); + RedrawMap = 1; + } - // [`]: centre window on centre of map - // and set zoom to view the entire map - else if (is.key == '`') - { - int r = zoom_fit(e); - if (r == 0) - RedrawMap = 1; - } + // [`]: centre window on centre of map + // and set zoom to view the entire map + else if (is.key == '`') + { + int r = zoom_fit(e); + if (r == 0) + RedrawMap = 1; + } - // [Left], [Right], [Up], [Down]: - // scroll percents of a screenful. - else if (is.key == YK_LEFT && MAPX(ScrCenterX) > -20000) - { - OrigX -= (int) ((double) ScrMaxX * scroll_less / 100 / Scale); - RedrawMap = 1; - } - else if (is.key == YK_RIGHT && MAPX(ScrCenterX) < 20000) - { - OrigX += (int) ((double) ScrMaxX * scroll_less / 100 / Scale); - RedrawMap = 1; - } - else if (is.key == YK_UP && MAPY(ScrCenterY) < 20000) - { - OrigY += (int) ((double) ScrMaxY * scroll_less / 100 / Scale); - RedrawMap = 1; - } - else if (is.key == YK_DOWN && MAPY(ScrCenterY) > -20000) - { - OrigY -= (int) ((double) ScrMaxY * scroll_less / 100 / Scale); - RedrawMap = 1; - } + // [Left], [Right], [Up], [Down]: + // scroll percents of a screenful. + else if (is.key == YK_LEFT && MAPX(ScrCenterX) > -20000) + { + OrigX -= (int) ((double) ScrMaxX * scroll_less / 100 / Scale); + RedrawMap = 1; + } + else if (is.key == YK_RIGHT && MAPX(ScrCenterX) < 20000) + { + OrigX += (int) ((double) ScrMaxX * scroll_less / 100 / Scale); + RedrawMap = 1; + } + else if (is.key == YK_UP && MAPY(ScrCenterY) < 20000) + { + OrigY += (int) ((double) ScrMaxY * scroll_less / 100 / Scale); + RedrawMap = 1; + } + else if (is.key == YK_DOWN && MAPY(ScrCenterY) > -20000) + { + OrigY -= (int) ((double) ScrMaxY * scroll_less / 100 / Scale); + RedrawMap = 1; + } - // [Pgup], [Pgdn], [Home], [End]: - // scroll percents of a screenful. - else if (is.key == YK_PU && MAPY(ScrCenterY) < /*MapMaxY */ 20000) - { - OrigY += (int) ((double) ScrMaxY * scroll_more / 100 / Scale); - RedrawMap = 1; - } - else if (is.key == YK_PD - && MAPY(ScrCenterY) > /*MapMinY */ -20000) - { - OrigY -= (int) ((double) ScrMaxY * scroll_more / 100 / Scale); - RedrawMap = 1; - } - else if (is.key == YK_HOME - && MAPX(ScrCenterX) > /*MapMinX */ -20000) - { - OrigX -= (int) ((double) ScrMaxX * scroll_more / 100 / Scale); - RedrawMap = 1; - } - else if (is.key == YK_END - && MAPX(ScrCenterX) < /*MapMaxX */ 20000) - { - OrigX += (int) ((double) ScrMaxX * scroll_more / 100 / Scale); - RedrawMap = 1; - } + // [Pgup], [Pgdn], [Home], [End]: + // scroll percents of a screenful. + else if (is.key == YK_PU && MAPY(ScrCenterY) < /*MapMaxY */ 20000) + { + OrigY += (int) ((double) ScrMaxY * scroll_more / 100 / Scale); + RedrawMap = 1; + } + else if (is.key == YK_PD + && MAPY(ScrCenterY) > /*MapMinY */ -20000) + { + OrigY -= (int) ((double) ScrMaxY * scroll_more / 100 / Scale); + RedrawMap = 1; + } + else if (is.key == YK_HOME + && MAPX(ScrCenterX) > /*MapMinX */ -20000) + { + OrigX -= (int) ((double) ScrMaxX * scroll_more / 100 / Scale); + RedrawMap = 1; + } + else if (is.key == YK_END + && MAPX(ScrCenterX) < /*MapMaxX */ 20000) + { + OrigX += (int) ((double) ScrMaxX * scroll_more / 100 / Scale); + RedrawMap = 1; + } - else if (is.key == ' ') - { - e.extra_zoom = !e.extra_zoom; - edit_set_zoom(&e, Scale * (e.extra_zoom ? 4 : 0.25)); - RedrawMap = 1; - } + else if (is.key == ' ') + { + e.extra_zoom = !e.extra_zoom; + edit_set_zoom(&e, Scale * (e.extra_zoom ? 4 : 0.25)); + RedrawMap = 1; + } - // [Tab], [l], [s], [t], [v]: switch mode - else if (is.key == YK_TAB || is.key == YK_BACKTAB - || is.key == 't' || is.key == 'v' || is.key == 'l' - || is.key == 's') - { - int old_mode; - int new_mode = -1; - int PrevMode = e.obj_type; - SelPtr NewSel; + // [Tab], [l], [s], [t], [v]: switch mode + else if (is.key == YK_TAB || is.key == YK_BACKTAB + || is.key == 't' || is.key == 'v' || is.key == 'l' + || is.key == 's') + { + int old_mode; + int new_mode = -1; + int PrevMode = e.obj_type; + SelPtr NewSel; - // What's the number of the current mode ? - old_mode = obj_type_to_mode_no(e.obj_type); + // What's the number of the current mode ? + old_mode = obj_type_to_mode_no(e.obj_type); - // What's the number of the new mode ? - if (is.key == YK_TAB) // [Tab] - new_mode = (old_mode + 1) % NB_MODES; - else if (is.key == YK_BACKTAB) // [Shift]-[Tab] - new_mode = old_mode == 0 ? NB_MODES - 1 : old_mode - 1; - else - { - if (is.key == 't') - new_mode = obj_type_to_mode_no(OBJ_THINGS); - else if (is.key == 'v') - new_mode = obj_type_to_mode_no(OBJ_VERTICES); - else if (is.key == 'l') - new_mode = obj_type_to_mode_no(OBJ_LINEDEFS); - else if (is.key == 's') - new_mode = obj_type_to_mode_no(OBJ_SECTORS); - else - fatal_error("changing mode with %04X", is.key); - /* unselect all */ - ForgetSelection(&e.Selected); - } + // What's the number of the new mode ? + if (is.key == YK_TAB) // [Tab] + new_mode = (old_mode + 1) % NB_MODES; + else if (is.key == YK_BACKTAB) // [Shift]-[Tab] + new_mode = old_mode == 0 ? NB_MODES - 1 : old_mode - 1; + else + { + if (is.key == 't') + new_mode = obj_type_to_mode_no(OBJ_THINGS); + else if (is.key == 'v') + new_mode = obj_type_to_mode_no(OBJ_VERTICES); + else if (is.key == 'l') + new_mode = obj_type_to_mode_no(OBJ_LINEDEFS); + else if (is.key == 's') + new_mode = obj_type_to_mode_no(OBJ_SECTORS); + else + fatal_error("changing mode with %04X", is.key); + /* unselect all */ + ForgetSelection(&e.Selected); + } - // Set the object type according to the new mode. - e.obj_type = modes[new_mode].obj_type; + // Set the object type according to the new mode. + e.obj_type = modes[new_mode].obj_type; - // Change the flavour of the "Misc" menu. - e.menubar->set_menu(e.mb_ino[MBI_MISC], - e.mb_menu[modes[new_mode].menu_no]); + // Change the flavour of the "Misc" menu. + e.menubar->set_menu(e.mb_ino[MBI_MISC], + e.mb_menu[modes[new_mode].menu_no]); - /* special cases for the selection list... */ - if (e.Selected) - { - /* select all linedefs bound to the selected sectors */ - if (PrevMode == OBJ_SECTORS && e.obj_type == OBJ_LINEDEFS) - { - int l, sd; + /* special cases for the selection list... */ + if (e.Selected) + { + /* select all linedefs bound to the selected sectors */ + if (PrevMode == OBJ_SECTORS && e.obj_type == OBJ_LINEDEFS) + { + int l, sd; - NewSel = 0; - for (l = 0; l < NumLineDefs; l++) - { - sd = LineDefs[l].sidedef1; - if (sd >= 0 - && IsSelected(e.Selected, - SideDefs[sd].sector)) - SelectObject(&NewSel, l); - else - { - sd = LineDefs[l].sidedef2; - if (sd >= 0 - && IsSelected(e.Selected, - SideDefs[sd].sector)) - SelectObject(&NewSel, l); - } - } - ForgetSelection(&e.Selected); - e.Selected = NewSel; - } - /* select all Vertices bound to the selected linedefs */ - else if (PrevMode == OBJ_LINEDEFS - && e.obj_type == OBJ_VERTICES) - { - NewSel = 0; - while (e.Selected) - { - if (!IsSelected - (NewSel, LineDefs[e.Selected->objnum].start)) - SelectObject(&NewSel, - LineDefs[e.Selected->objnum]. - start); - if (!IsSelected - (NewSel, LineDefs[e.Selected->objnum].end)) - SelectObject(&NewSel, - LineDefs[e.Selected->objnum]. - end); - UnSelectObject(&e.Selected, e.Selected->objnum); - } - e.Selected = NewSel; - } - /* select all sectors that have their linedefs selected */ - else if (PrevMode == OBJ_LINEDEFS - && e.obj_type == OBJ_SECTORS) - { - int l, sd; + NewSel = 0; + for (l = 0; l < NumLineDefs; l++) + { + sd = LineDefs[l].sidedef1; + if (sd >= 0 + && IsSelected(e.Selected, + SideDefs[sd].sector)) + SelectObject(&NewSel, l); + else + { + sd = LineDefs[l].sidedef2; + if (sd >= 0 + && IsSelected(e.Selected, + SideDefs[sd].sector)) + SelectObject(&NewSel, l); + } + } + ForgetSelection(&e.Selected); + e.Selected = NewSel; + } + /* select all Vertices bound to the selected linedefs */ + else if (PrevMode == OBJ_LINEDEFS + && e.obj_type == OBJ_VERTICES) + { + NewSel = 0; + while (e.Selected) + { + if (!IsSelected + (NewSel, LineDefs[e.Selected->objnum].start)) + SelectObject(&NewSel, + LineDefs[e.Selected->objnum]. + start); + if (!IsSelected + (NewSel, LineDefs[e.Selected->objnum].end)) + SelectObject(&NewSel, + LineDefs[e.Selected->objnum]. + end); + UnSelectObject(&e.Selected, e.Selected->objnum); + } + e.Selected = NewSel; + } + /* select all sectors that have their linedefs selected */ + else if (PrevMode == OBJ_LINEDEFS + && e.obj_type == OBJ_SECTORS) + { + int l, sd; - NewSel = 0; - /* select all sectors... */ - for (l = 0; l < NumSectors; l++) - SelectObject(&NewSel, l); - /* ... then unselect those that should not be in the list */ - for (l = 0; l < NumLineDefs; l++) - if (!IsSelected(e.Selected, l)) - { - sd = LineDefs[l].sidedef1; - if (sd >= 0) - UnSelectObject(&NewSel, - SideDefs[sd].sector); - sd = LineDefs[l].sidedef2; - if (sd >= 0) - UnSelectObject(&NewSel, - SideDefs[sd].sector); - } - ForgetSelection(&e.Selected); - e.Selected = NewSel; - } - /* select all linedefs that have both ends selected */ - else if (PrevMode == OBJ_VERTICES - && e.obj_type == OBJ_LINEDEFS) - { - int l; + NewSel = 0; + /* select all sectors... */ + for (l = 0; l < NumSectors; l++) + SelectObject(&NewSel, l); + /* ... then unselect those that should not be in the list */ + for (l = 0; l < NumLineDefs; l++) + if (!IsSelected(e.Selected, l)) + { + sd = LineDefs[l].sidedef1; + if (sd >= 0) + UnSelectObject(&NewSel, + SideDefs[sd].sector); + sd = LineDefs[l].sidedef2; + if (sd >= 0) + UnSelectObject(&NewSel, + SideDefs[sd].sector); + } + ForgetSelection(&e.Selected); + e.Selected = NewSel; + } + /* select all linedefs that have both ends selected */ + else if (PrevMode == OBJ_VERTICES + && e.obj_type == OBJ_LINEDEFS) + { + int l; - NewSel = 0; - for (l = 0; l < NumLineDefs; l++) - if (IsSelected(e.Selected, LineDefs[l].start) - && IsSelected(e.Selected, LineDefs[l].end)) - SelectObject(&NewSel, l); - ForgetSelection(&e.Selected); - e.Selected = NewSel; - } - /* unselect all */ - else - ForgetSelection(&e.Selected); - } - if (GetMaxObjectNum(e.obj_type) >= 0 && Select0 && !e.global) - { - e.highlighted.type = e.obj_type; - e.highlighted.num = 0; - } - else - e.highlighted.nil(); + NewSel = 0; + for (l = 0; l < NumLineDefs; l++) + if (IsSelected(e.Selected, LineDefs[l].start) + && IsSelected(e.Selected, LineDefs[l].end)) + SelectObject(&NewSel, l); + ForgetSelection(&e.Selected); + e.Selected = NewSel; + } + /* unselect all */ + else + ForgetSelection(&e.Selected); + } + if (GetMaxObjectNum(e.obj_type) >= 0 && Select0 && !e.global) + { + e.highlighted.type = e.obj_type; + e.highlighted.num = 0; + } + else + e.highlighted.nil(); - DragObject = false; - StretchSelBox = false; - RedrawMap = 1; - } + DragObject = false; + StretchSelBox = false; + RedrawMap = 1; + } - // [Ctrl][g]: toggle global mode - else if (is.key == '\7') - { - static bool dont_warn = false; - bool ok = false; - if (e.global) - ok = true; // No confirmation needed to switch off - else if (dont_warn) - ok = true; - else - { - ok = Confirm(-1, -1, - "Global mode is experimental and probably highly", - "unstable. This means crashes. Are you sure ?"); - RedrawMap = 1; - if (ok) - { - dont_warn = true; // User is sure. Won't ask again - Notify(-1, -1, - "Selection does not work in global mode. Don't", - "bother reporting it, I'm aware of it already."); - } - } - if (ok) - { - ForgetSelection(&e.Selected); - e.global = !e.global; - RedrawMap = 1; - } - } + // [Ctrl][g]: toggle global mode + else if (is.key == '\7') + { + static bool dont_warn = false; + bool ok = false; + if (e.global) + ok = true; // No confirmation needed to switch off + else if (dont_warn) + ok = true; + else + { + ok = Confirm(-1, -1, + "Global mode is experimental and probably highly", + "unstable. This means crashes. Are you sure ?"); + RedrawMap = 1; + if (ok) + { + dont_warn = true; // User is sure. Won't ask again + Notify(-1, -1, + "Selection does not work in global mode. Don't", + "bother reporting it, I'm aware of it already."); + } + } + if (ok) + { + ForgetSelection(&e.Selected); + e.global = !e.global; + RedrawMap = 1; + } + } - // [e]: Select/unselect all linedefs in non-forked path - else if (is.key == 'e' && e.highlighted._is_linedef()) - { - ForgetSelection(&e.Selected); - select_linedefs_path(&e.Selected, e.highlighted.num, YS_ADD); - RedrawMap = 1; - } + // [e]: Select/unselect all linedefs in non-forked path + else if (is.key == 'e' && e.highlighted._is_linedef()) + { + ForgetSelection(&e.Selected); + select_linedefs_path(&e.Selected, e.highlighted.num, YS_ADD); + RedrawMap = 1; + } - // [Ctrl][e] Select/unselect all linedefs in path - else if (is.key == '\5' && !is.shift - && e.highlighted._is_linedef()) - { - select_linedefs_path(&e.Selected, e.highlighted.num, - YS_TOGGLE); - RedrawMap = 1; - } - // [E]: add linedef and split sector -- [AJA] - else if (is.key == 'E' && e.obj_type == OBJ_VERTICES) - { - if (e.Selected) - { - MiscOperations(e.obj_type, &e.Selected, 5); - RedrawMap = 1; - } - } - // [E]: Select/unselect all 1s linedefs in path - else if (is.key == 'E' && e.highlighted._is_linedef()) - { - ForgetSelection(&e.Selected); - select_1s_linedefs_path(&e.Selected, e.highlighted.num, - YS_ADD); - RedrawMap = 1; - } + // [Ctrl][e] Select/unselect all linedefs in path + else if (is.key == '\5' && !is.shift + && e.highlighted._is_linedef()) + { + select_linedefs_path(&e.Selected, e.highlighted.num, + YS_TOGGLE); + RedrawMap = 1; + } + // [E]: add linedef and split sector -- [AJA] + else if (is.key == 'E' && e.obj_type == OBJ_VERTICES) + { + if (e.Selected) + { + MiscOperations(e.obj_type, &e.Selected, 5); + RedrawMap = 1; + } + } + // [E]: Select/unselect all 1s linedefs in path + else if (is.key == 'E' && e.highlighted._is_linedef()) + { + ForgetSelection(&e.Selected); + select_1s_linedefs_path(&e.Selected, e.highlighted.num, + YS_ADD); + RedrawMap = 1; + } - // [Ctrl][Shift][e]: Select/unselect all 1s linedefs in path - else if (is.key == '\5' && is.shift - && e.highlighted._is_linedef()) - { - select_1s_linedefs_path(&e.Selected, e.highlighted.num, - YS_TOGGLE); - RedrawMap = 1; - } + // [Ctrl][Shift][e]: Select/unselect all 1s linedefs in path + else if (is.key == '\5' && is.shift + && e.highlighted._is_linedef()) + { + select_1s_linedefs_path(&e.Selected, e.highlighted.num, + YS_TOGGLE); + RedrawMap = 1; + } - // [G]: to increase the grid step - else if (is.key == 'G') - { - if (e.grid_step < e.grid_step_max) - e.grid_step *= 2; - else - e.grid_step = e.grid_step_min; - RedrawMap = 1; - } + // [G]: to increase the grid step + else if (is.key == 'G') + { + if (e.grid_step < e.grid_step_max) + e.grid_step *= 2; + else + e.grid_step = e.grid_step_min; + RedrawMap = 1; + } - // [g]: decrease the grid step - else if (is.key == 'g') - { - if (e.grid_step > e.grid_step_min) - e.grid_step /= 2; - else - e.grid_step = e.grid_step_max; - RedrawMap = 1; - } + // [g]: decrease the grid step + else if (is.key == 'g') + { + if (e.grid_step > e.grid_step_min) + e.grid_step /= 2; + else + e.grid_step = e.grid_step_max; + RedrawMap = 1; + } - // [h]: display or hide the grid - else if (is.key == 'h') - { - e.grid_shown = !e.grid_shown; - RedrawMap = 1; - } + // [h]: display or hide the grid + else if (is.key == 'h') + { + e.grid_shown = !e.grid_shown; + RedrawMap = 1; + } - // [H]: reset the grid to grid_step_max - else if (is.key == 'H') - { - e.grid_step = e.grid_step_max; - RedrawMap = 1; - } + // [H]: reset the grid to grid_step_max + else if (is.key == 'H') + { + e.grid_step = e.grid_step_max; + RedrawMap = 1; + } - // [y]: toggle the snap_to_grid flag - else if (is.key == 'y') - { - e.grid_snap = !e.grid_snap; - } + // [y]: toggle the snap_to_grid flag + else if (is.key == 'y') + { + e.grid_snap = !e.grid_snap; + } - // [z]: toggle the lock_grip_step flag - else if (is.key == 'z') - { - e.grid_step_locked = !e.grid_step_locked; - } + // [z]: toggle the lock_grip_step flag + else if (is.key == 'z') + { + e.grid_step_locked = !e.grid_step_locked; + } - // [r]: toggle the rulers - else if (is.key == 'r') - e.rulers_shown = !e.rulers_shown; + // [r]: toggle the rulers + else if (is.key == 'r') + e.rulers_shown = !e.rulers_shown; - // [n], [>]: highlight the next object - else if ((is.key == 'n' || is.key == '>') - && (!e.global ||e.highlighted())) - { - obj_type_t t = - e.highlighted()? e.highlighted.type : e.obj_type; - obj_no_t nmax = GetMaxObjectNum(t); - if (is_obj(nmax)) - { - if (e.highlighted.is_nil()) - { - e.highlighted.type = t; - e.highlighted.num = 0; - } - else - { - e.highlighted.num++; - if (e.highlighted.num > nmax) - e.highlighted.num = 0; - } - GoToObject(e.highlighted); - RedrawMap = 1; - } - } + // [n], [>]: highlight the next object + else if ((is.key == 'n' || is.key == '>') + && (!e.global ||e.highlighted())) + { + obj_type_t t = + e.highlighted()? e.highlighted.type : e.obj_type; + obj_no_t nmax = GetMaxObjectNum(t); + if (is_obj(nmax)) + { + if (e.highlighted.is_nil()) + { + e.highlighted.type = t; + e.highlighted.num = 0; + } + else + { + e.highlighted.num++; + if (e.highlighted.num > nmax) + e.highlighted.num = 0; + } + GoToObject(e.highlighted); + RedrawMap = 1; + } + } - // [p], [<]: highlight the previous object - else if ((is.key == 'p' || is.key == '<') - && (!e.global ||e.highlighted())) - { - obj_type_t t = - e.highlighted()? e.highlighted.type : e.obj_type; - obj_no_t nmax = GetMaxObjectNum(t); - if (is_obj(nmax)) - { - if (e.highlighted.is_nil()) - { - e.highlighted.type = t; - e.highlighted.num = nmax; - } - else - { - e.highlighted.num--; - if (e.highlighted.num < 0) - e.highlighted.num = nmax; - } - GoToObject(e.highlighted); - RedrawMap = 1; - } - } + // [p], [<]: highlight the previous object + else if ((is.key == 'p' || is.key == '<') + && (!e.global ||e.highlighted())) + { + obj_type_t t = + e.highlighted()? e.highlighted.type : e.obj_type; + obj_no_t nmax = GetMaxObjectNum(t); + if (is_obj(nmax)) + { + if (e.highlighted.is_nil()) + { + e.highlighted.type = t; + e.highlighted.num = nmax; + } + else + { + e.highlighted.num--; + if (e.highlighted.num < 0) + e.highlighted.num = nmax; + } + GoToObject(e.highlighted); + RedrawMap = 1; + } + } - // [j], [#]: jump to object by number - else if ((is.key == 'j' || is.key == '#') - && (!e.global ||e.highlighted())) - { - Objid default_obj; - default_obj.type = - e.highlighted()? e.highlighted.type : e.obj_type; - default_obj.num = e.highlighted()? e.highlighted.num : 0; - Objid target_obj; - input_objid(target_obj, default_obj, -1, -1); - if (target_obj()) - GoToObject(target_obj); - RedrawMap = 1; - } + // [j], [#]: jump to object by number + else if ((is.key == 'j' || is.key == '#') + && (!e.global ||e.highlighted())) + { + Objid default_obj; + default_obj.type = + e.highlighted()? e.highlighted.type : e.obj_type; + default_obj.num = e.highlighted()? e.highlighted.num : 0; + Objid target_obj; + input_objid(target_obj, default_obj, -1, -1); + if (target_obj()) + GoToObject(target_obj); + RedrawMap = 1; + } - // [f]: find object by type - else if (is.key == 'f' && (!e.global ||e.highlighted())) - { - Objid find_obj; - int otype; - obj_no_t omax, onum; - find_obj.type = - e.highlighted()? e.highlighted.type : e.obj_type; - onum = find_obj.num = e.highlighted()? e.highlighted.num : 0; - omax = GetMaxObjectNum(find_obj.type); - switch (find_obj.type) - { - case OBJ_SECTORS: - if (!InputSectorType(84, 21, &otype)) - { - for (onum = e.highlighted()? onum + 1 : onum; - onum <= omax; onum++) - if (Sectors[onum].special == (wad_stype_t) otype) - { - find_obj.num = onum; - GoToObject(find_obj); - break; - } - } - break; - case OBJ_THINGS: - if (!InputThingType(42, 21, &otype)) - { - for (onum = e.highlighted()? onum + 1 : onum; - onum <= omax; onum++) - if (Things[onum].type == (wad_ttype_t) otype) - { - find_obj.num = onum; - GoToObject(find_obj); - break; - } - } - break; - case OBJ_LINEDEFS: - if (!InputLinedefType(0, 21, &otype)) - { - for (onum = e.highlighted()? onum + 1 : onum; - onum <= omax; onum++) - if (LineDefs[onum].type == (wad_ldtype_t) otype) - { - find_obj.num = onum; - GoToObject(find_obj); - break; - } - } - break; - } - RedrawMap = 1; - } + // [f]: find object by type + else if (is.key == 'f' && (!e.global ||e.highlighted())) + { + Objid find_obj; + int otype; + obj_no_t omax, onum; + find_obj.type = + e.highlighted()? e.highlighted.type : e.obj_type; + onum = find_obj.num = e.highlighted()? e.highlighted.num : 0; + omax = GetMaxObjectNum(find_obj.type); + switch (find_obj.type) + { + case OBJ_SECTORS: + if (!InputSectorType(84, 21, &otype)) + { + for (onum = e.highlighted()? onum + 1 : onum; + onum <= omax; onum++) + if (Sectors[onum].special == (wad_stype_t) otype) + { + find_obj.num = onum; + GoToObject(find_obj); + break; + } + } + break; + case OBJ_THINGS: + if (!InputThingType(42, 21, &otype)) + { + for (onum = e.highlighted()? onum + 1 : onum; + onum <= omax; onum++) + if (Things[onum].type == (wad_ttype_t) otype) + { + find_obj.num = onum; + GoToObject(find_obj); + break; + } + } + break; + case OBJ_LINEDEFS: + if (!InputLinedefType(0, 21, &otype)) + { + for (onum = e.highlighted()? onum + 1 : onum; + onum <= omax; onum++) + if (LineDefs[onum].type == (wad_ldtype_t) otype) + { + find_obj.num = onum; + GoToObject(find_obj); + break; + } + } + break; + } + RedrawMap = 1; + } #if 0 - // [c]: clear selection and redraw the map - else if (is.key == 'c') - { - ForgetSelection(&e.Selected); - RedrawMap = 1; - DragObject = false; - StretchSelBox = false; - } + // [c]: clear selection and redraw the map + else if (is.key == 'c') + { + ForgetSelection(&e.Selected); + RedrawMap = 1; + DragObject = false; + StretchSelBox = false; + } #endif - // [o]: copy a group of objects - else if (is.key == 'o' && (e.Selected || e.highlighted())) - { - int x, y; + // [o]: copy a group of objects + else if (is.key == 'o' && (e.Selected || e.highlighted())) + { + int x, y; - /* copy the object(s) */ - if (!e.Selected) - SelectObject(&e.Selected, e.highlighted.num); - CopyObjects(e.obj_type, e.Selected); - /* enter drag mode */ - //DragObject = true; - /* AYM 19980619 : got to look into this!! */ - //e.highlight_obj_no = e.Selected->objnum; + /* copy the object(s) */ + if (!e.Selected) + SelectObject(&e.Selected, e.highlighted.num); + CopyObjects(e.obj_type, e.Selected); + /* enter drag mode */ + //DragObject = true; + /* AYM 19980619 : got to look into this!! */ + //e.highlight_obj_no = e.Selected->objnum; - // Find the "hotspot" in the object(s) - if (e.highlighted() && !e.Selected) - GetObjectCoords(e.highlighted.type, e.highlighted.num, &x, - &y); - else - centre_of_objects(e.obj_type, e.Selected, &x, &y); + // Find the "hotspot" in the object(s) + if (e.highlighted() && !e.Selected) + GetObjectCoords(e.highlighted.type, e.highlighted.num, &x, + &y); + else + centre_of_objects(e.obj_type, e.Selected, &x, &y); - // Drag the object(s) so that the "hotspot" is under the pointer - MoveObjectsToCoords(e.obj_type, 0, x, y, 0); - MoveObjectsToCoords(e.obj_type, e.Selected, - e.pointer_x, e.pointer_y, 0); - RedrawMap = 1; - StretchSelBox = false; - } + // Drag the object(s) so that the "hotspot" is under the pointer + MoveObjectsToCoords(e.obj_type, 0, x, y, 0); + MoveObjectsToCoords(e.obj_type, e.Selected, + e.pointer_x, e.pointer_y, 0); + RedrawMap = 1; + StretchSelBox = false; + } - // [Return]: edit the properties of the current object. - else if (is.key == YK_RETURN && (e.Selected || e.highlighted())) - { - if (e.Selected) - EditObjectsInfo(0, menubar_out_y1 + 1, e.obj_type, - e.Selected); - else - { - SelectObject(&e.Selected, e.highlighted.num); - EditObjectsInfo(0, menubar_out_y1 + 1, e.highlighted.type, - e.Selected); - UnSelectObject(&e.Selected, e.highlighted.num); - } - RedrawMap = 1; - DragObject = false; - StretchSelBox = false; - } + // [Return]: edit the properties of the current object. + else if (is.key == YK_RETURN && (e.Selected || e.highlighted())) + { + if (e.Selected) + EditObjectsInfo(0, menubar_out_y1 + 1, e.obj_type, + e.Selected); + else + { + SelectObject(&e.Selected, e.highlighted.num); + EditObjectsInfo(0, menubar_out_y1 + 1, e.highlighted.type, + e.Selected); + UnSelectObject(&e.Selected, e.highlighted.num); + } + RedrawMap = 1; + DragObject = false; + StretchSelBox = false; + } - // [w]: spin things 1/8 turn counter-clockwise - else if (is.key == 'w' && e.obj_type == OBJ_THINGS - && (e.Selected || e.highlighted())) - { - if (!e.Selected) - { - SelectObject(&e.Selected, e.highlighted.num); - spin_things(e.Selected, 45); - UnSelectObject(&e.Selected, e.highlighted.num); - } - else - { - spin_things(e.Selected, 45); - } - RedrawMap = 1; /* FIXME: should redraw only the things */ - DragObject = false; - StretchSelBox = false; - } + // [w]: spin things 1/8 turn counter-clockwise + else if (is.key == 'w' && e.obj_type == OBJ_THINGS + && (e.Selected || e.highlighted())) + { + if (!e.Selected) + { + SelectObject(&e.Selected, e.highlighted.num); + spin_things(e.Selected, 45); + UnSelectObject(&e.Selected, e.highlighted.num); + } + else + { + spin_things(e.Selected, 45); + } + RedrawMap = 1; /* FIXME: should redraw only the things */ + DragObject = false; + StretchSelBox = false; + } - // [w]: split linedefs and sectors - else if (is.key == 'w' && e.obj_type == OBJ_LINEDEFS - && e.Selected && e.Selected->next - && !e.Selected->next->next) - { - SplitLineDefsAndSector(e.Selected->next->objnum, - e.Selected->objnum); - ForgetSelection(&e.Selected); - RedrawMap = 1; - DragObject = false; - StretchSelBox = false; - } + // [w]: split linedefs and sectors + else if (is.key == 'w' && e.obj_type == OBJ_LINEDEFS + && e.Selected && e.Selected->next + && !e.Selected->next->next) + { + SplitLineDefsAndSector(e.Selected->next->objnum, + e.Selected->objnum); + ForgetSelection(&e.Selected); + RedrawMap = 1; + DragObject = false; + StretchSelBox = false; + } - // [w]: split sector between vertices - else if (is.key == 'w' && e.obj_type == OBJ_VERTICES - && e.Selected && e.Selected->next - && !e.Selected->next->next) - { - SplitSector(e.Selected->next->objnum, e.Selected->objnum); - ForgetSelection(&e.Selected); - RedrawMap = 1; - DragObject = false; - StretchSelBox = false; - } + // [w]: split sector between vertices + else if (is.key == 'w' && e.obj_type == OBJ_VERTICES + && e.Selected && e.Selected->next + && !e.Selected->next->next) + { + SplitSector(e.Selected->next->objnum, e.Selected->objnum); + ForgetSelection(&e.Selected); + RedrawMap = 1; + DragObject = false; + StretchSelBox = false; + } - // [x]: spin things 1/8 turn clockwise - else if (is.key == 'x' && e.obj_type == OBJ_THINGS - && (e.Selected || e.highlighted())) - { - if (!e.Selected) - { - SelectObject(&e.Selected, e.highlighted.num); - spin_things(e.Selected, -45); - UnSelectObject(&e.Selected, e.highlighted.num); - } - else - { - spin_things(e.Selected, -45); - } - RedrawMap = 1; /* FIXME: should redraw only the things */ - DragObject = false; - StretchSelBox = false; - } + // [x]: spin things 1/8 turn clockwise + else if (is.key == 'x' && e.obj_type == OBJ_THINGS + && (e.Selected || e.highlighted())) + { + if (!e.Selected) + { + SelectObject(&e.Selected, e.highlighted.num); + spin_things(e.Selected, -45); + UnSelectObject(&e.Selected, e.highlighted.num); + } + else + { + spin_things(e.Selected, -45); + } + RedrawMap = 1; /* FIXME: should redraw only the things */ + DragObject = false; + StretchSelBox = false; + } - // [x]: split linedefs - else if (is.key == 'x' && e.obj_type == OBJ_LINEDEFS - && (e.Selected || e.highlighted())) - { - if (!e.Selected) - { - SelectObject(&e.Selected, e.highlighted.num); - SplitLineDefs(e.Selected); - UnSelectObject(&e.Selected, e.highlighted.num); - } - else - SplitLineDefs(e.Selected); - RedrawMap = 1; - DragObject = false; - StretchSelBox = false; - } + // [x]: split linedefs + else if (is.key == 'x' && e.obj_type == OBJ_LINEDEFS + && (e.Selected || e.highlighted())) + { + if (!e.Selected) + { + SelectObject(&e.Selected, e.highlighted.num); + SplitLineDefs(e.Selected); + UnSelectObject(&e.Selected, e.highlighted.num); + } + else + SplitLineDefs(e.Selected); + RedrawMap = 1; + DragObject = false; + StretchSelBox = false; + } - // [Ctrl][x]: exchange objects numbers - else if (is.key == 24) - { - if (!e.Selected - || !e.Selected->next || (e.Selected->next)->next) - { - Beep(); - Notify(-1, -1, "You must select exactly two objects", 0); - RedrawMap = 1; - } - else - { - exchange_objects_numbers(e.obj_type, e.Selected, true); - RedrawMap = 1; - } - } + // [Ctrl][x]: exchange objects numbers + else if (is.key == 24) + { + if (!e.Selected + || !e.Selected->next || (e.Selected->next)->next) + { + Beep(); + Notify(-1, -1, "You must select exactly two objects", 0); + RedrawMap = 1; + } + else + { + exchange_objects_numbers(e.obj_type, e.Selected, true); + RedrawMap = 1; + } + } - // [Ctrl][k]: cut a slice out of a sector - else if (is.key == 11 && e.obj_type == OBJ_LINEDEFS - && e.Selected && e.Selected->next - && !e.Selected->next->next) - { - sector_slice(e.Selected->next->objnum, e.Selected->objnum); - ForgetSelection(&e.Selected); - RedrawMap = 1; - DragObject = false; - StretchSelBox = false; - } + // [Ctrl][k]: cut a slice out of a sector + else if (is.key == 11 && e.obj_type == OBJ_LINEDEFS + && e.Selected && e.Selected->next + && !e.Selected->next->next) + { + sector_slice(e.Selected->next->objnum, e.Selected->objnum); + ForgetSelection(&e.Selected); + RedrawMap = 1; + DragObject = false; + StretchSelBox = false; + } - // [Del]: delete the current object - else if (is.key == YK_DEL && (e.Selected || e.highlighted())) /* 'Del' */ - { - if (e.obj_type == OBJ_THINGS - || Expert - || Confirm(-1, -1, - (e.Selected && e.Selected->next ? - "Do you really want to delete these objects?" - : - "Do you really want to delete this object?"), - (e.Selected - && e.Selected-> - next ? - "This will also delete the objects bound to them." - : - "This will also delete the objects bound to it."))) - { - if (e.Selected) - DeleteObjects(e.obj_type, &e.Selected); - else - DeleteObject(e.highlighted); - } - // AYM 1998-09-20 I thought I'd add this - // (though it doesn't fix the problem : if the object has been - // deleted, HighlightObject is still called with a bad object#). - e.highlighted.nil(); - DragObject = false; - StretchSelBox = false; - RedrawMap = 1; - } + // [Del]: delete the current object + else if (is.key == YK_DEL && (e.Selected || e.highlighted())) /* 'Del' */ + { + if (e.obj_type == OBJ_THINGS + || Expert + || Confirm(-1, -1, + (e.Selected && e.Selected->next ? + "Do you really want to delete these objects?" + : + "Do you really want to delete this object?"), + (e.Selected + && e.Selected-> + next ? + "This will also delete the objects bound to them." + : + "This will also delete the objects bound to it."))) + { + if (e.Selected) + DeleteObjects(e.obj_type, &e.Selected); + else + DeleteObject(e.highlighted); + } + // AYM 1998-09-20 I thought I'd add this + // (though it doesn't fix the problem : if the object has been + // deleted, HighlightObject is still called with a bad object#). + e.highlighted.nil(); + DragObject = false; + StretchSelBox = false; + RedrawMap = 1; + } - // [Ins]: insert a new object - else if (is.key == YK_INS || is.key == YK_INS + YK_SHIFT) /* 'Ins' */ - { - SelPtr cur; - int prev_obj_type = e.obj_type; + // [Ins]: insert a new object + else if (is.key == YK_INS || is.key == YK_INS + YK_SHIFT) /* 'Ins' */ + { + SelPtr cur; + int prev_obj_type = e.obj_type; - /* first special case: if several vertices are - selected, add new linedefs */ - if (e.obj_type == OBJ_VERTICES - && e.Selected && e.Selected->next) - { - int firstv; - int obj_no = OBJ_NO_NONE; + /* first special case: if several vertices are + selected, add new linedefs */ + if (e.obj_type == OBJ_VERTICES + && e.Selected && e.Selected->next) + { + int firstv; + int obj_no = OBJ_NO_NONE; - if (e.Selected->next->next) - firstv = e.Selected->objnum; - else - firstv = -1; - e.obj_type = OBJ_LINEDEFS; - /* create linedefs between the vertices */ - for (cur = e.Selected; cur->next; cur = cur->next) - { - /* check if there is already a linedef between the two vertices */ - for (obj_no = 0; obj_no < NumLineDefs; obj_no++) - if ((LineDefs[obj_no].start == cur->next->objnum - && LineDefs[obj_no].end == cur->objnum) - || (LineDefs[obj_no].end == cur->next->objnum - && LineDefs[obj_no].start == cur->objnum)) - break; - if (obj_no < NumLineDefs) - cur->objnum = obj_no; - else - { - InsertObject(OBJ_LINEDEFS, -1, 0, 0); - e.highlighted.type = OBJ_LINEDEFS; - e.highlighted.num = NumLineDefs - 1; - LineDefs[e.highlighted.num].start = - cur->next->objnum; - LineDefs[e.highlighted.num].end = cur->objnum; - cur->objnum = e.highlighted.num; // FIXME cur = e.highlighted - } - } - /* close the polygon if there are more than 2 vertices */ - if (firstv >= 0 && is.shift) - { - e.highlighted.type = OBJ_LINEDEFS; - for (e.highlighted.num = 0; - e.highlighted.num < NumLineDefs; - e.highlighted.num++) - if ((LineDefs[e.highlighted.num].start == firstv - && LineDefs[e.highlighted.num].end == - cur->objnum) - || (LineDefs[e.highlighted.num].end == firstv - && LineDefs[e.highlighted.num].start == - cur->objnum)) - break; - if (e.highlighted.num < NumLineDefs) - cur->objnum = obj_no; - else - { - InsertObject(OBJ_LINEDEFS, -1, 0, 0); - e.highlighted.type = OBJ_LINEDEFS; - e.highlighted.num = NumLineDefs - 1; - LineDefs[e.highlighted.num].start = firstv; - LineDefs[e.highlighted.num].end = cur->objnum; - cur->objnum = e.highlighted.num; // FIXME cur = e.highlighted - } - } - else - UnSelectObject(&e.Selected, cur->objnum); - } - /* second special case: if several linedefs are selected, - add new sidedefs and one sector */ - else if (e.obj_type == OBJ_LINEDEFS && e.Selected) - { - for (cur = e.Selected; cur; cur = cur->next) - if (LineDefs[cur->objnum].sidedef1 >= 0 - && LineDefs[cur->objnum].sidedef2 >= 0) - { - char msg[80]; + if (e.Selected->next->next) + firstv = e.Selected->objnum; + else + firstv = -1; + e.obj_type = OBJ_LINEDEFS; + /* create linedefs between the vertices */ + for (cur = e.Selected; cur->next; cur = cur->next) + { + /* check if there is already a linedef between the two vertices */ + for (obj_no = 0; obj_no < NumLineDefs; obj_no++) + if ((LineDefs[obj_no].start == cur->next->objnum + && LineDefs[obj_no].end == cur->objnum) + || (LineDefs[obj_no].end == cur->next->objnum + && LineDefs[obj_no].start == cur->objnum)) + break; + if (obj_no < NumLineDefs) + cur->objnum = obj_no; + else + { + InsertObject(OBJ_LINEDEFS, -1, 0, 0); + e.highlighted.type = OBJ_LINEDEFS; + e.highlighted.num = NumLineDefs - 1; + LineDefs[e.highlighted.num].start = + cur->next->objnum; + LineDefs[e.highlighted.num].end = cur->objnum; + cur->objnum = e.highlighted.num; // FIXME cur = e.highlighted + } + } + /* close the polygon if there are more than 2 vertices */ + if (firstv >= 0 && is.shift) + { + e.highlighted.type = OBJ_LINEDEFS; + for (e.highlighted.num = 0; + e.highlighted.num < NumLineDefs; + e.highlighted.num++) + if ((LineDefs[e.highlighted.num].start == firstv + && LineDefs[e.highlighted.num].end == + cur->objnum) + || (LineDefs[e.highlighted.num].end == firstv + && LineDefs[e.highlighted.num].start == + cur->objnum)) + break; + if (e.highlighted.num < NumLineDefs) + cur->objnum = obj_no; + else + { + InsertObject(OBJ_LINEDEFS, -1, 0, 0); + e.highlighted.type = OBJ_LINEDEFS; + e.highlighted.num = NumLineDefs - 1; + LineDefs[e.highlighted.num].start = firstv; + LineDefs[e.highlighted.num].end = cur->objnum; + cur->objnum = e.highlighted.num; // FIXME cur = e.highlighted + } + } + else + UnSelectObject(&e.Selected, cur->objnum); + } + /* second special case: if several linedefs are selected, + add new sidedefs and one sector */ + else if (e.obj_type == OBJ_LINEDEFS && e.Selected) + { + for (cur = e.Selected; cur; cur = cur->next) + if (LineDefs[cur->objnum].sidedef1 >= 0 + && LineDefs[cur->objnum].sidedef2 >= 0) + { + char msg[80]; - Beep(); - sprintf(msg, - "Linedef #%d already has two sidedefs", - cur->objnum); - Notify(-1, -1, "Error: cannot add the new sector", - msg); - break; - } - if (!cur) - { - e.obj_type = OBJ_SECTORS; - InsertObject(OBJ_SECTORS, -1, 0, 0); - e.highlighted.type = OBJ_SECTORS; - e.highlighted.num = NumSectors - 1; - for (cur = e.Selected; cur; cur = cur->next) - { - InsertObject(OBJ_SIDEDEFS, -1, 0, 0); - SideDefs[NumSideDefs - 1].sector = - e.highlighted.num; - if (LineDefs[cur->objnum].sidedef1 >= 0) - { - int s; + Beep(); + sprintf(msg, + "Linedef #%d already has two sidedefs", + cur->objnum); + Notify(-1, -1, "Error: cannot add the new sector", + msg); + break; + } + if (!cur) + { + e.obj_type = OBJ_SECTORS; + InsertObject(OBJ_SECTORS, -1, 0, 0); + e.highlighted.type = OBJ_SECTORS; + e.highlighted.num = NumSectors - 1; + for (cur = e.Selected; cur; cur = cur->next) + { + InsertObject(OBJ_SIDEDEFS, -1, 0, 0); + SideDefs[NumSideDefs - 1].sector = + e.highlighted.num; + if (LineDefs[cur->objnum].sidedef1 >= 0) + { + int s; - s = SideDefs[LineDefs[cur->objnum].sidedef1]. - sector; - if (s >= 0) - { - Sectors[e.highlighted.num].floorh = - Sectors[s].floorh; - Sectors[e.highlighted.num].ceilh = - Sectors[s].ceilh; - strncpy(Sectors[e.highlighted.num].floort, - Sectors[s].floort, WAD_FLAT_NAME); - strncpy(Sectors[e.highlighted.num].ceilt, - Sectors[s].ceilt, WAD_FLAT_NAME); - Sectors[e.highlighted.num].light = - Sectors[s].light; - } - LineDefs[cur->objnum].sidedef2 = - NumSideDefs - 1; - LineDefs[cur->objnum].flags = 4; - strncpy(SideDefs[NumSideDefs - 1].tex3, - "-", WAD_TEX_NAME); - strncpy(SideDefs - [LineDefs[cur->objnum].sidedef1].tex3, - "-", WAD_TEX_NAME); - } - else - LineDefs[cur->objnum].sidedef1 = - NumSideDefs - 1; - } - ForgetSelection(&e.Selected); - SelectObject(&e.Selected, e.highlighted.num); - } - } - /* normal case: add a new object of the current type */ - else - { - ForgetSelection(&e.Selected); - /* FIXME how do you insert a new object of type T if - no object of that type already exists ? */ - obj_type_t t = - e.highlighted()? e.highlighted.type : e.obj_type; - InsertObject(t, e.highlighted.num, - edit_mapx_snapped(&e, e.pointer_x), - edit_mapy_snapped(&e, e.pointer_y)); - e.highlighted.type = t; - e.highlighted.num = GetMaxObjectNum(e.obj_type); - if (e.obj_type == OBJ_LINEDEFS) - { - int v1 = LineDefs[e.highlighted.num].start; - int v2 = LineDefs[e.highlighted.num].end; - if (!Input2VertexNumbers(-1, -1, - "Choose the two vertices for the new linedef", - &v1, &v2)) - { - DeleteObject(e.highlighted); - e.highlighted.nil(); - } - else - { - LineDefs[e.highlighted.num].start = v1; - LineDefs[e.highlighted.num].end = v2; - } - } - else if (e.obj_type == OBJ_VERTICES) - { - SelectObject(&e.Selected, e.highlighted.num); - if (AutoMergeVertices(&e.Selected, e.obj_type, 'i')) - RedrawMap = 1; - ForgetSelection(&e.Selected); - } - } + s = SideDefs[LineDefs[cur->objnum].sidedef1]. + sector; + if (s >= 0) + { + Sectors[e.highlighted.num].floorh = + Sectors[s].floorh; + Sectors[e.highlighted.num].ceilh = + Sectors[s].ceilh; + strncpy(Sectors[e.highlighted.num].floort, + Sectors[s].floort, WAD_FLAT_NAME); + strncpy(Sectors[e.highlighted.num].ceilt, + Sectors[s].ceilt, WAD_FLAT_NAME); + Sectors[e.highlighted.num].light = + Sectors[s].light; + } + LineDefs[cur->objnum].sidedef2 = + NumSideDefs - 1; + LineDefs[cur->objnum].flags = 4; + strncpy(SideDefs[NumSideDefs - 1].tex3, + "-", WAD_TEX_NAME); + strncpy(SideDefs + [LineDefs[cur->objnum].sidedef1].tex3, + "-", WAD_TEX_NAME); + } + else + LineDefs[cur->objnum].sidedef1 = + NumSideDefs - 1; + } + ForgetSelection(&e.Selected); + SelectObject(&e.Selected, e.highlighted.num); + } + } + /* normal case: add a new object of the current type */ + else + { + ForgetSelection(&e.Selected); + /* FIXME how do you insert a new object of type T if + no object of that type already exists ? */ + obj_type_t t = + e.highlighted()? e.highlighted.type : e.obj_type; + InsertObject(t, e.highlighted.num, + edit_mapx_snapped(&e, e.pointer_x), + edit_mapy_snapped(&e, e.pointer_y)); + e.highlighted.type = t; + e.highlighted.num = GetMaxObjectNum(e.obj_type); + if (e.obj_type == OBJ_LINEDEFS) + { + int v1 = LineDefs[e.highlighted.num].start; + int v2 = LineDefs[e.highlighted.num].end; + if (!Input2VertexNumbers(-1, -1, + "Choose the two vertices for the new linedef", + &v1, &v2)) + { + DeleteObject(e.highlighted); + e.highlighted.nil(); + } + else + { + LineDefs[e.highlighted.num].start = v1; + LineDefs[e.highlighted.num].end = v2; + } + } + else if (e.obj_type == OBJ_VERTICES) + { + SelectObject(&e.Selected, e.highlighted.num); + if (AutoMergeVertices(&e.Selected, e.obj_type, 'i')) + RedrawMap = 1; + ForgetSelection(&e.Selected); + } + } - // Mode-changing code, duplicated from above. - // As RQ would say: "I hate to do that". So do I. - // The best solution would be to have a mode - // changing function that only changes e.obj_type - // and emits a "mode change" message. Another part - // of the code, responsible for the menus, would - // intercept that message and update them. I don't - // have the time (as of 1998-12-14) to do it now. - if (e.obj_type != prev_obj_type) - { - int new_mode; + // Mode-changing code, duplicated from above. + // As RQ would say: "I hate to do that". So do I. + // The best solution would be to have a mode + // changing function that only changes e.obj_type + // and emits a "mode change" message. Another part + // of the code, responsible for the menus, would + // intercept that message and update them. I don't + // have the time (as of 1998-12-14) to do it now. + if (e.obj_type != prev_obj_type) + { + int new_mode; - // What's the number of the new mode ? - new_mode = obj_type_to_mode_no(e.obj_type); + // What's the number of the new mode ? + new_mode = obj_type_to_mode_no(e.obj_type); - // Change the flavour of the "Misc" menu. - e.menubar->set_menu(e.mb_ino[MBI_MISC], - e.mb_menu[modes[new_mode].menu_no]); - } + // Change the flavour of the "Misc" menu. + e.menubar->set_menu(e.mb_ino[MBI_MISC], + e.mb_menu[modes[new_mode].menu_no]); + } - DragObject = false; - StretchSelBox = false; - RedrawMap = 1; - } + DragObject = false; + StretchSelBox = false; + RedrawMap = 1; + } - // [Z] Set sector on surrounding linedefs (AJA) - else if (is.key == 'Z' && e.pointer_in_window) - { - if (e.obj_type == OBJ_SECTORS && e.Selected) - { - SuperSectorSelector(e.pointer_x, e.pointer_y, - e.Selected->objnum); - } - else - { - SuperSectorSelector(e.pointer_x, e.pointer_y, - OBJ_NO_NONE); - } - RedrawMap = 1; - } + // [Z] Set sector on surrounding linedefs (AJA) + else if (is.key == 'Z' && e.pointer_in_window) + { + if (e.obj_type == OBJ_SECTORS && e.Selected) + { + SuperSectorSelector(e.pointer_x, e.pointer_y, + e.Selected->objnum); + } + else + { + SuperSectorSelector(e.pointer_x, e.pointer_y, + OBJ_NO_NONE); + } + RedrawMap = 1; + } - // [!] Debug info (not documented) - else if (is.key == '!') - { - DumpSelection(e.Selected); - } + // [!] Debug info (not documented) + else if (is.key == '!') + { + DumpSelection(e.Selected); + } - // [R] Render 3D view (AJA) - else if (is.key == 'R') - { - Render3D(); - RedrawMap = 1; - } + // [R] Render 3D view (AJA) + else if (is.key == 'R') + { + Render3D(); + RedrawMap = 1; + } - // [T] Transfer properties to selected objects (AJA) - else if (is.key == 'T' && e.Selected && e.highlighted.num >= 0) - { - switch (e.obj_type) - { - case OBJ_SECTORS: - TransferSectorProperties(e.highlighted.num, e.Selected); - RedrawMap = 1; - break; - case OBJ_THINGS: - TransferThingProperties(e.highlighted.num, e.Selected); - RedrawMap = 1; - break; - case OBJ_LINEDEFS: - TransferLinedefProperties(e.highlighted.num, e.Selected); - RedrawMap = 1; - break; - default: - Beep(); - break; - } - } + // [T] Transfer properties to selected objects (AJA) + else if (is.key == 'T' && e.Selected && e.highlighted.num >= 0) + { + switch (e.obj_type) + { + case OBJ_SECTORS: + TransferSectorProperties(e.highlighted.num, e.Selected); + RedrawMap = 1; + break; + case OBJ_THINGS: + TransferThingProperties(e.highlighted.num, e.Selected); + RedrawMap = 1; + break; + case OBJ_LINEDEFS: + TransferLinedefProperties(e.highlighted.num, e.Selected); + RedrawMap = 1; + break; + default: + Beep(); + break; + } + } - // [Ctrl][b] Select linedefs whose sidedefs reference non-existant sectors - else if (is.key == 2) - { - bad_sector_number(&e.Selected); - RedrawMap = 1; - } + // [Ctrl][b] Select linedefs whose sidedefs reference non-existant sectors + else if (is.key == 2) + { + bad_sector_number(&e.Selected); + RedrawMap = 1; + } - // [Ctrl][p] Examine game palette (not documented) - else if (is.key == 16) - { - Palette_viewer pv; - pv.run(); - RedrawMap = 1; - } + // [Ctrl][p] Examine game palette (not documented) + else if (is.key == 16) + { + Palette_viewer pv; + pv.run(); + RedrawMap = 1; + } - // [Ctrl][r] Xref for sidedef (not documented) - else if (is.key == 18) - { - xref_sidedef(); - } + // [Ctrl][r] Xref for sidedef (not documented) + else if (is.key == 18) + { + xref_sidedef(); + } - // [Ctrl][s] List secret sectors (not documented) - else if (is.key == 19) - { - secret_sectors(); - } + // [Ctrl][s] List secret sectors (not documented) + else if (is.key == 19) + { + secret_sectors(); + } - // [Ctrl][t] List tagged linedefs or sectors - else if (is.key == 20) - { - if (e.highlighted._is_sector()) - list_tagged_linedefs(Sectors[e.highlighted.num].tag); - else if (e.highlighted._is_linedef()) - list_tagged_sectors(LineDefs[e.highlighted.num].tag); - else - Beep(); - } + // [Ctrl][t] List tagged linedefs or sectors + else if (is.key == 20) + { + if (e.highlighted._is_sector()) + list_tagged_linedefs(Sectors[e.highlighted.num].tag); + else if (e.highlighted._is_linedef()) + list_tagged_sectors(LineDefs[e.highlighted.num].tag); + else + Beep(); + } - // [Ctrl][u] Select linedefs with unknown type (not documented) - else if (is.key == 21) - { - unknown_linedef_type(&e.Selected); - RedrawMap = 1; - } + // [Ctrl][u] Select linedefs with unknown type (not documented) + else if (is.key == 21) + { + unknown_linedef_type(&e.Selected); + RedrawMap = 1; + } - // [Ctrl][v] Toggle between "snap vertex" tool and normal tool - // (not documented) - else if (is.key == 22) - { - if (e.tool == TOOL_NORMAL) - { - e.tool = TOOL_SNAP_VERTEX; - printf("Switched to snap vertex tool." - " Press [Ctrl][v] to switch back to normal tool.\n"); - } - else - { - e.tool = TOOL_NORMAL; - printf("Switched back to normal tool.\n"); - } - } + // [Ctrl][v] Toggle between "snap vertex" tool and normal tool + // (not documented) + else if (is.key == 22) + { + if (e.tool == TOOL_NORMAL) + { + e.tool = TOOL_SNAP_VERTEX; + printf("Switched to snap vertex tool." + " Press [Ctrl][v] to switch back to normal tool.\n"); + } + else + { + e.tool = TOOL_NORMAL; + printf("Switched back to normal tool.\n"); + } + } - // [&] Show object numbers - else if (is.key == '&') - { - e.show_object_numbers = !e.show_object_numbers; - RedrawMap = 1; - } + // [&] Show object numbers + else if (is.key == '&') + { + e.show_object_numbers = !e.show_object_numbers; + RedrawMap = 1; + } - // [%] Show things sprites - else if (is.key == '%') - { - e.show_things_sprites = !e.show_things_sprites; - e.show_things_squares = !e.show_things_sprites; // Not a typo ! - RedrawMap = 1; - } + // [%] Show things sprites + else if (is.key == '%') + { + e.show_things_sprites = !e.show_things_sprites; + e.show_things_squares = !e.show_things_sprites; // Not a typo ! + RedrawMap = 1; + } - /* user likes music */ - else if (is.key) - { - Beep(); - } - } + /* user likes music */ + else if (is.key) + { + Beep(); + } + } - /* - * Step 4 -- Misc. cruft - */ + /* + * Step 4 -- Misc. cruft + */ done: - // Auto-scrolling: scroll the map automatically - // when the mouse pointer rests near the edge - // of the window. - // Scrolling is disabled when a pull-down menu - // is visible because it would be annoying to see - // the map scrolling while you're searching - // through the menus. + // Auto-scrolling: scroll the map automatically + // when the mouse pointer rests near the edge + // of the window. + // Scrolling is disabled when a pull-down menu + // is visible because it would be annoying to see + // the map scrolling while you're searching + // through the menus. - if (is.in_window - && autoscroll && !is.scroll_lock && e.menubar->pulled_down() < 0) - { - unsigned distance; // In pixels + if (is.in_window + && autoscroll && !is.scroll_lock && e.menubar->pulled_down() < 0) + { + unsigned distance; // In pixels #define actual_move(total,dist) \ ((int) (((total * autoscroll_amp / 100)\ * ((double) (autoscroll_edge - dist) / autoscroll_edge))\ / Scale)) - distance = is.y; - // The reason for the second member of the condition - // is that we don't want to scroll when the user is - // simply reaching for a menu... - if (distance <= autoscroll_edge - && e.menubar->is_under_menubar_item(is.x) < 0) - { - if (MAPY(ScrCenterY) < /*MapMaxY */ 20000) - { - OrigY += actual_move(ScrMaxY, distance); - RedrawMap = 1; - } - } + distance = is.y; + // The reason for the second member of the condition + // is that we don't want to scroll when the user is + // simply reaching for a menu... + if (distance <= autoscroll_edge + && e.menubar->is_under_menubar_item(is.x) < 0) + { + if (MAPY(ScrCenterY) < /*MapMaxY */ 20000) + { + OrigY += actual_move(ScrMaxY, distance); + RedrawMap = 1; + } + } - distance = ScrMaxY - is.y; - if (distance <= autoscroll_edge) - { - if (MAPY(ScrCenterY) > /*MapMinY */ -20000) - { - OrigY -= actual_move(ScrMaxY, distance); - RedrawMap = 1; - } - } + distance = ScrMaxY - is.y; + if (distance <= autoscroll_edge) + { + if (MAPY(ScrCenterY) > /*MapMinY */ -20000) + { + OrigY -= actual_move(ScrMaxY, distance); + RedrawMap = 1; + } + } - distance = is.x; - if (distance <= autoscroll_edge) - { - if (MAPX(ScrCenterX) > /*MapMinX */ -20000) - { - OrigX -= actual_move(ScrMaxX, distance); - RedrawMap = 1; - } - } + distance = is.x; + if (distance <= autoscroll_edge) + { + if (MAPX(ScrCenterX) > /*MapMinX */ -20000) + { + OrigX -= actual_move(ScrMaxX, distance); + RedrawMap = 1; + } + } - // The reason for the second member of the condition - // is that we don't want to scroll when the user is - // simply reaching for the "Help" menu... - // Note: the ordinate "3 * FONTH" is of course not - // critical. It's just a rough approximation. - distance = ScrMaxX - is.x; - if (distance <= autoscroll_edge && (unsigned) is.y >= 3 * FONTH) - { - if (MAPX(ScrCenterX) < /*MapMaxX */ 20000) - { - OrigX += actual_move(ScrMaxX, distance); - RedrawMap = 1; - } - } - } + // The reason for the second member of the condition + // is that we don't want to scroll when the user is + // simply reaching for the "Help" menu... + // Note: the ordinate "3 * FONTH" is of course not + // critical. It's just a rough approximation. + distance = ScrMaxX - is.x; + if (distance <= autoscroll_edge && (unsigned) is.y >= 3 * FONTH) + { + if (MAPX(ScrCenterX) < /*MapMaxX */ 20000) + { + OrigX += actual_move(ScrMaxX, distance); + RedrawMap = 1; + } + } + } - /* - * Step 5 -- Process events that were generated - */ + /* + * Step 5 -- Process events that were generated + */ done2: - // Process events that were generated - if (has_event(YE_ZOOM_CHANGED) && !e.grid_step_locked) - { - get_event(); - edit_grid_adapt(&e); - RedrawMap = 1; - } + // Process events that were generated + if (has_event(YE_ZOOM_CHANGED) && !e.grid_step_locked) + { + get_event(); + edit_grid_adapt(&e); + RedrawMap = 1; + } - if (RedrawMap) - e.edisplay->need_refresh(); + if (RedrawMap) + e.edisplay->need_refresh(); } delete e.edisplay; delete e.selbox; delete e.menubar; for (size_t n = 0; n < MBM_HELP; n++) - delete e.mb_menu[n]; + delete e.mb_menu[n]; delete menu_linedef_flags; delete menu_thing_flags; @@ -2537,15 +2537,15 @@ /* - * zoom_fit - adjust zoom factor to make level fit in window + * zoom_fit - adjust zoom factor to make level fit in window * - * Return 0 on success, non-zero on failure. + * Return 0 on success, non-zero on failure. */ static int zoom_fit(edit_t & e) { // Empty level, 100% will be fine. if (NumVertices == 0) - return edit_set_zoom(&e, 1.0); + return edit_set_zoom(&e, 1.0); update_level_bounds(); @@ -2557,7 +2557,7 @@ int r = edit_set_zoom(&e, y_min(xzoom, yzoom)); if (r != 0) - return 1; + return 1; CenterMapAroundCoords((MapMinX + MapMaxX) / 2, (MapMinY + MapMaxY) / 2); return 0; diff -r 594dea11ccd9 -r a68786b9c74b src/editloop.h --- a/src/editloop.h Sat Sep 24 15:01:56 2011 +0300 +++ b/src/editloop.h Sat Sep 24 15:59:33 2011 +0300 @@ -1,10 +1,10 @@ /* - * editloop.h - * AYM 1998-09-06 + * editloop.h + * AYM 1998-09-06 */ -void EditorLoop(const char *); /* SWAP! */ +void EditorLoop(const char *); /* SWAP! */ const char *SelectLevel(int levelno); int InputSectorType(int x0, int y0, int *number); int InputLinedefType(int x0, int y0, int *number); diff -r 594dea11ccd9 -r a68786b9c74b src/editobj.cc --- a/src/editobj.cc Sat Sep 24 15:01:56 2011 +0300 +++ b/src/editobj.cc Sat Sep 24 15:59:33 2011 +0300 @@ -1,7 +1,7 @@ /* - * editobj.cc - * Object editing routines. - * BW & RQ sometime in 1993 or 1994. + * editobj.cc + * Object editing routines. + * BW & RQ sometime in 1993 or 1994. */ @@ -59,64 +59,64 @@ char prompt[80]; sprintf(prompt, "Enter a %s number between 0 and %d:", - GetObjectTypeName(objtype), GetMaxObjectNum(objtype)); + GetObjectTypeName(objtype), GetMaxObjectNum(objtype)); if (x0 < 0) - x0 = (ScrMaxX - 25 - 8 * strlen(prompt)) / 2; + x0 = (ScrMaxX - 25 - 8 * strlen(prompt)) / 2; if (y0 < 0) - y0 = (ScrMaxY - 55) / 2; + y0 = (ScrMaxY - 55) / 2; DrawScreenBox3D(x0, y0, x0 + 25 + 8 * strlen(prompt), y0 + 55); set_colour(WHITE); DrawScreenText(x0 + 10, y0 + 8, prompt); val = curobj; while ((key - = - InputInteger(x0 + 10, y0 + 28, &val, 0, - GetMaxObjectNum(objtype))) != YK_RETURN - && key != YK_ESC) - Beep(); + = + InputInteger(x0 + 10, y0 + 28, &val, 0, + GetMaxObjectNum(objtype))) != YK_RETURN + && key != YK_ESC) + Beep(); return val; } /* - * input_objid - ask for an object number of the specified type + * input_objid - ask for an object number of the specified type * - * If the user hit [Return], set objid.type to init.type - * and objid.num to whatever number the user entered. If - * the user hit [Esc], call nil() on objid. + * If the user hit [Return], set objid.type to init.type + * and objid.num to whatever number the user entered. If + * the user hit [Esc], call nil() on objid. */ void input_objid(Objid & objid, const Objid & init, int x0, int y0) { char prompt[80]; sprintf(prompt, "Enter a %s number between 0 and %d:", - GetObjectTypeName(init.type), GetMaxObjectNum(init.type)); + GetObjectTypeName(init.type), GetMaxObjectNum(init.type)); if (x0 < 0) - x0 = (ScrMaxX - 25 - 8 * strlen(prompt)) / 2; + x0 = (ScrMaxX - 25 - 8 * strlen(prompt)) / 2; if (y0 < 0) - y0 = (ScrMaxY - 55) / 2; + y0 = (ScrMaxY - 55) / 2; DrawScreenBox3D(x0, y0, x0 + 25 + 8 * strlen(prompt), y0 + 55); set_colour(WHITE); DrawScreenText(x0 + 10, y0 + 8, prompt); int num = init.num; int key; while ((key - = - InputInteger(x0 + 10, y0 + 28, &num, 0, - GetMaxObjectNum(init.type))) != YK_RETURN - && key != YK_ESC) - Beep(); + = + InputInteger(x0 + 10, y0 + 28, &num, 0, + GetMaxObjectNum(init.type))) != YK_RETURN + && key != YK_ESC) + Beep(); if (key == YK_ESC) - objid.nil(); + objid.nil(); else if (key == YK_RETURN) { - objid.type = init.type; - objid.num = num; + objid.type = init.type; + objid.num = num; } else { - nf_bug("input_objid: bad key %d", (int) key); // Can't happen - objid.nil(); + nf_bug("input_objid: bad key %d", (int) key); // Can't happen + objid.nil(); } } @@ -136,23 +136,23 @@ // Dimensions sprintf(prompt, "Enter a %s number between 0 and %d%c", - GetObjectTypeName(objtype), - GetMaxObjectNum(objtype), allownone ? ',' : ':'); - maxlen = 40; // Why 40 ? -- AYM 2002-04-17 + GetObjectTypeName(objtype), + GetMaxObjectNum(objtype), allownone ? ',' : ':'); + maxlen = 40; // Why 40 ? -- AYM 2002-04-17 if (strlen(prompt) > maxlen); maxlen = strlen(prompt); if (strlen(msg1) > maxlen) - maxlen = strlen(msg1); + maxlen = strlen(msg1); if (strlen(msg2) > maxlen) - maxlen = strlen(msg2); + maxlen = strlen(msg2); int ya = 0 + BOX_BORDER + WIDE_VSPACING; int yb = ya; if (allownone) - yb += FONTH; + yb += FONTH; int yc = yb + FONTH + WIDE_VSPACING; // FIXME should query InputInteger() instead int yd = - yc + 2 * HOLLOW_BORDER + 2 * NARROW_VSPACING + FONTH + WIDE_VSPACING; + yc + 2 * HOLLOW_BORDER + 2 * NARROW_VSPACING + FONTH + WIDE_VSPACING; int ye = yd + FONTH; int yf = ye + FONTH + WIDE_VSPACING + BOX_BORDER; width = 2 * BOX_BORDER + 2 * WIDE_HSPACING + maxlen * FONTW; @@ -160,16 +160,16 @@ // Position if (x0 < 0) - x0 = (ScrMaxX - width) / 2; + x0 = (ScrMaxX - width) / 2; if (y0 < 0) - y0 = (ScrMaxY - height) / 2; + y0 = (ScrMaxY - height) / 2; DrawScreenBox3D(x0, y0, x0 + width, y0 + height); set_colour(WHITE); int x = x0 + BOX_BORDER + WIDE_HSPACING; DrawScreenText(x, y0 + ya, prompt); if (allownone) - DrawScreenText(x, y0 + yb, "or -1 for none:"); + DrawScreenText(x, y0 + yb, "or -1 for none:"); set_colour(LIGHTRED); DrawScreenText(x, y0 + yd, msg1); DrawScreenText(x, y0 + ye, msg2); @@ -179,8 +179,8 @@ int min = allownone ? -1 : 0; int max = GetMaxObjectNum(objtype); while (key = InputInteger(x, y0 + yc, &val, min, max), - key != YK_RETURN && key != YK_ESC) - Beep(); + key != YK_RETURN && key != YK_ESC) + Beep(); return val; } @@ -191,7 +191,7 @@ */ bool Input2VertexNumbers(int x0, int y0, const char *prompt1, int *v1, - int *v2) + int *v2) { int key; int maxlen, first; @@ -204,19 +204,19 @@ int entry2_y0; // FIXME should let InputInteger() tell us const int entry_width = - 2 * HOLLOW_BORDER + 2 * NARROW_HSPACING + 7 * FONTW; + 2 * HOLLOW_BORDER + 2 * NARROW_HSPACING + 7 * FONTW; const int entry_height = 2 * HOLLOW_BORDER + 2 * NARROW_VSPACING + FONTH; sprintf(prompt2, "Enter two numbers between 0 and %d:", NumVertices - 1); if (strlen(prompt1) > strlen(prompt2)) - maxlen = strlen(prompt1); + maxlen = strlen(prompt1); else - maxlen = strlen(prompt2); + maxlen = strlen(prompt2); if (x0 < 0) - x0 = (ScrMaxX - 25 - 8 * maxlen) / 2; + x0 = (ScrMaxX - 25 - 8 * maxlen) / 2; if (y0 < 0) - y0 = (ScrMaxY - 75) / 2; + y0 = (ScrMaxY - 75) / 2; text_x0 = x0 + BOX_BORDER + WIDE_HSPACING; text_y0 = y0 + BOX_BORDER + WIDE_VSPACING; entry1_x0 = text_x0 + 13 * FONTW; @@ -225,9 +225,9 @@ entry2_y0 = text_y0 + 5 * FONTH - HOLLOW_BORDER - NARROW_VSPACING; DrawScreenBox3D(x0, y0, - x0 + 2 * BOX_BORDER + 2 * WIDE_HSPACING - + y_max(entry_width + 13 * FONTW, maxlen * FONTW) - 1, - y0 + 2 * BOX_BORDER + 2 * WIDE_VSPACING + 6 * FONTH - 1); + x0 + 2 * BOX_BORDER + 2 * WIDE_HSPACING + + y_max(entry_width + 13 * FONTW, maxlen * FONTW) - 1, + y0 + 2 * BOX_BORDER + 2 * WIDE_VSPACING + 6 * FONTH - 1); set_colour(WHITE); DrawScreenText(text_x0, text_y0, prompt1); set_colour(WINFG); @@ -239,43 +239,43 @@ key = 0; for (;;) { - DrawScreenBoxHollow(entry1_x0, entry1_y0, - entry1_x0 + entry_width - 1, - entry1_y0 + entry_height - 1, BLACK); - set_colour(first ? WHITE : DARKGREY); - DrawScreenText(entry1_x0 + HOLLOW_BORDER + NARROW_HSPACING, - entry1_y0 + HOLLOW_BORDER + NARROW_VSPACING, "%d", - *v1); + DrawScreenBoxHollow(entry1_x0, entry1_y0, + entry1_x0 + entry_width - 1, + entry1_y0 + entry_height - 1, BLACK); + set_colour(first ? WHITE : DARKGREY); + DrawScreenText(entry1_x0 + HOLLOW_BORDER + NARROW_HSPACING, + entry1_y0 + HOLLOW_BORDER + NARROW_VSPACING, "%d", + *v1); - DrawScreenBoxHollow(entry2_x0, entry2_y0, - entry2_x0 + entry_width - 1, - entry2_y0 + entry_height - 1, BLACK); - set_colour(!first ? WHITE : DARKGREY); - DrawScreenText(entry2_x0 + HOLLOW_BORDER + NARROW_HSPACING, - entry2_y0 + HOLLOW_BORDER + NARROW_VSPACING, "%d", - *v2); + DrawScreenBoxHollow(entry2_x0, entry2_y0, + entry2_x0 + entry_width - 1, + entry2_y0 + entry_height - 1, BLACK); + set_colour(!first ? WHITE : DARKGREY); + DrawScreenText(entry2_x0 + HOLLOW_BORDER + NARROW_HSPACING, + entry2_y0 + HOLLOW_BORDER + NARROW_VSPACING, "%d", + *v2); - if (first) - key = InputInteger(entry1_x0, entry1_y0, v1, 0, NumVertices - 1); - else - key = InputInteger(entry2_x0, entry2_y0, v2, 0, NumVertices - 1); - if (key == YK_LEFT || key == YK_RIGHT || key == YK_TAB - || key == YK_BACKTAB) - first = !first; - else if (key == YK_ESC) - break; - else if (key == YK_RETURN) - { - if (first) - first = 0; - else if (*v1 < 0 || *v1 >= NumVertices - || *v2 < 0 || *v2 >= NumVertices) - Beep(); - else - break; - } - else - Beep(); + if (first) + key = InputInteger(entry1_x0, entry1_y0, v1, 0, NumVertices - 1); + else + key = InputInteger(entry2_x0, entry2_y0, v2, 0, NumVertices - 1); + if (key == YK_LEFT || key == YK_RIGHT || key == YK_TAB + || key == YK_BACKTAB) + first = !first; + else if (key == YK_ESC) + break; + else if (key == YK_RETURN) + { + if (first) + first = 0; + else if (*v1 < 0 || *v1 >= NumVertices + || *v2 < 0 || *v2 >= NumVertices) + Beep(); + else + break; + } + else + Beep(); } return (key == YK_RETURN); } @@ -286,7 +286,7 @@ edit an object or a group of objects */ -void EditObjectsInfo(int x0, int y0, int objtype, SelPtr obj) /* SWAP! */ +void EditObjectsInfo(int x0, int y0, int objtype, SelPtr obj) /* SWAP! */ { char *menustr[3]; int n, val; @@ -294,73 +294,73 @@ int subwin_y0; if (!obj) - return; + return; switch (objtype) { case OBJ_THINGS: - ThingProperties(x0, y0, obj); - break; + ThingProperties(x0, y0, obj); + break; case OBJ_VERTICES: - for (n = 0; n < 3; n++) - menustr[n] = (char *) GetMemory(60); - sprintf(menustr[2], "Edit Vertex #%d", obj->objnum); - sprintf(menustr[0], "Change X position (Current: %d)", - Vertices[obj->objnum].x); - sprintf(menustr[1], "Change Y position (Current: %d)", - Vertices[obj->objnum].y); + for (n = 0; n < 3; n++) + menustr[n] = (char *) GetMemory(60); + sprintf(menustr[2], "Edit Vertex #%d", obj->objnum); + sprintf(menustr[0], "Change X position (Current: %d)", + Vertices[obj->objnum].x); + sprintf(menustr[1], "Change Y position (Current: %d)", + Vertices[obj->objnum].y); #ifdef OLDMEN - val = DisplayMenuArray(0, y0, - menustr[2], 2, NULL, menustr, NULL, NULL, - NULL); + val = DisplayMenuArray(0, y0, + menustr[2], 2, NULL, menustr, NULL, NULL, + NULL); #else - val = vDisplayMenu(0, y0, menustr[2], - menustr[0], YK_, 0, menustr[1], YK_, 0, NULL); + val = vDisplayMenu(0, y0, menustr[2], + menustr[0], YK_, 0, menustr[1], YK_, 0, NULL); #endif - for (n = 0; n < 3; n++) - FreeMemory(menustr[n]); - subwin_y0 = y0 + BOX_BORDER + (2 + val) * FONTH; - switch (val) - { - case 1: - val = InputIntegerValue(x0 + 42, subwin_y0, - y_min(MapMinX, -10000), - y_max(MapMaxX, 10000), - Vertices[obj->objnum].x); - if (val != IIV_CANCEL) - { - n = val - Vertices[obj->objnum].x; - for (cur = obj; cur; cur = cur->next) - Vertices[cur->objnum].x += n; - MadeChanges = 1; - MadeMapChanges = 1; - } - break; + for (n = 0; n < 3; n++) + FreeMemory(menustr[n]); + subwin_y0 = y0 + BOX_BORDER + (2 + val) * FONTH; + switch (val) + { + case 1: + val = InputIntegerValue(x0 + 42, subwin_y0, + y_min(MapMinX, -10000), + y_max(MapMaxX, 10000), + Vertices[obj->objnum].x); + if (val != IIV_CANCEL) + { + n = val - Vertices[obj->objnum].x; + for (cur = obj; cur; cur = cur->next) + Vertices[cur->objnum].x += n; + MadeChanges = 1; + MadeMapChanges = 1; + } + break; - case 2: - val = InputIntegerValue(x0 + 42, subwin_y0, - y_min(MapMinY, -10000), - y_max(MapMaxY, 10000), - Vertices[obj->objnum].y); - if (val != IIV_CANCEL) - { - n = val - Vertices[obj->objnum].y; - for (cur = obj; cur; cur = cur->next) - Vertices[cur->objnum].y += n; - MadeChanges = 1; - MadeMapChanges = 1; - } - break; - } - break; + case 2: + val = InputIntegerValue(x0 + 42, subwin_y0, + y_min(MapMinY, -10000), + y_max(MapMaxY, 10000), + Vertices[obj->objnum].y); + if (val != IIV_CANCEL) + { + n = val - Vertices[obj->objnum].y; + for (cur = obj; cur; cur = cur->next) + Vertices[cur->objnum].y += n; + MadeChanges = 1; + MadeMapChanges = 1; + } + break; + } + break; case OBJ_LINEDEFS: - LinedefProperties(x0, y0, obj); - break; + LinedefProperties(x0, y0, obj); + break; case OBJ_SECTORS: - SectorProperties(x0, y0, obj); - break; + SectorProperties(x0, y0, obj); + break; } } @@ -370,7 +370,7 @@ */ bool Input2Numbers(int x0, int y0, const char *name1, const char *name2, - int v1max, int v2max, int *v1, int *v2) + int v1max, int v2max, int *v1, int *v2) { int key; int maxlen, first; @@ -381,7 +381,7 @@ int entry_height = 2 * HOLLOW_BORDER + 2 * NARROW_VSPACING + FONTH; y_snprintf(prompt, sizeof prompt, "Give the %s and %s for the object:", - name1, name2); + name1, name2); maxlen = strlen(prompt); int title_x0 = BOX_BORDER + FONTW; @@ -390,9 +390,9 @@ int label1_y0 = title_y0 + 2 * FONTH; int label2_x0 = title_x0 + (strlen(name1) + 2) * FONTW; { - int bound = label1_x0 + entry_width + int (FONTW); - if (label2_x0 < bound) - label2_x0 = bound; + int bound = label1_x0 + entry_width + int (FONTW); + if (label2_x0 < bound) + label2_x0 = bound; } // FIXME Assuming the range is not longer than the name int label2_y0 = label1_y0; @@ -415,15 +415,15 @@ int window_x1 = entry2_out_x1 + FONTW + BOX_BORDER; int window_y1 = range1_y0 + 3 * FONTH / 2 + BOX_BORDER; { - int bound = 2 * BOX_BORDER + (maxlen + 2) * int (FONTW); - if (window_x1 < bound) - window_x1 = bound; + int bound = 2 * BOX_BORDER + (maxlen + 2) * int (FONTW); + if (window_x1 < bound) + window_x1 = bound; } if (x0 < 0) - x0 = (ScrMaxX - window_x1) / 2; + x0 = (ScrMaxX - window_x1) / 2; if (y0 < 0) - y0 = (ScrMaxY - window_y1) / 2; + y0 = (ScrMaxY - window_y1) / 2; DrawScreenBox3D(x0, y0, x0 + window_x1, y0 + window_y1); set_colour(WHITE); @@ -437,51 +437,51 @@ key = 0; for (;;) { - ok = true; - DrawScreenBoxHollow(x0 + entry1_out_x0, y0 + entry1_out_y0, - x0 + entry1_out_x1, y0 + entry1_out_y1, BLACK); - if (*v1 < 0 || *v1 > v1max) - { - set_colour(DARKGREY); - ok = false; - } - else - set_colour(LIGHTGREY); - DrawScreenText(x0 + entry1_text_x0, y0 + entry1_text_y0, "%d", *v1); - DrawScreenBoxHollow(x0 + entry2_out_x0, y0 + entry2_out_y0, - x0 + entry2_out_x1, y0 + entry2_out_y1, BLACK); - if (*v2 < 0 || *v2 > v2max) - { - set_colour(DARKGREY); - ok = false; - } - else - set_colour(LIGHTGREY); - DrawScreenText(x0 + entry2_text_x0, y0 + entry2_text_y0, "%d", *v2); - if (first) - key = - InputInteger(x0 + entry1_out_x0, y0 + entry1_out_y0, v1, 0, - v1max); - else - key = - InputInteger(x0 + entry2_out_x0, y0 + entry2_out_y0, v2, 0, - v2max); - if (key == YK_LEFT || key == YK_RIGHT || key == YK_TAB - || key == YK_BACKTAB) - first = !first; - else if (key == YK_ESC) - break; - else if (key == YK_RETURN) - { - if (first) - first = 0; - else if (ok) - break; - else - Beep(); - } - else - Beep(); + ok = true; + DrawScreenBoxHollow(x0 + entry1_out_x0, y0 + entry1_out_y0, + x0 + entry1_out_x1, y0 + entry1_out_y1, BLACK); + if (*v1 < 0 || *v1 > v1max) + { + set_colour(DARKGREY); + ok = false; + } + else + set_colour(LIGHTGREY); + DrawScreenText(x0 + entry1_text_x0, y0 + entry1_text_y0, "%d", *v1); + DrawScreenBoxHollow(x0 + entry2_out_x0, y0 + entry2_out_y0, + x0 + entry2_out_x1, y0 + entry2_out_y1, BLACK); + if (*v2 < 0 || *v2 > v2max) + { + set_colour(DARKGREY); + ok = false; + } + else + set_colour(LIGHTGREY); + DrawScreenText(x0 + entry2_text_x0, y0 + entry2_text_y0, "%d", *v2); + if (first) + key = + InputInteger(x0 + entry1_out_x0, y0 + entry1_out_y0, v1, 0, + v1max); + else + key = + InputInteger(x0 + entry2_out_x0, y0 + entry2_out_y0, v2, 0, + v2max); + if (key == YK_LEFT || key == YK_RIGHT || key == YK_TAB + || key == YK_BACKTAB) + first = !first; + else if (key == YK_ESC) + break; + else if (key == YK_RETURN) + { + if (first) + first = 0; + else if (ok) + break; + else + Beep(); + } + else + Beep(); } return (key == YK_RETURN); } @@ -492,7 +492,7 @@ insert a standard object at given position */ -void InsertStandardObject(int xpos, int ypos, int choice) /* SWAP! */ +void InsertStandardObject(int xpos, int ypos, int choice) /* SWAP! */ { int sector; int n; @@ -507,148 +507,148 @@ switch (choice) { case 1: - a = 256; - b = 128; - if (Input2Numbers(-1, -1, "Width", "Height", 2000, 2000, &a, &b)) - { - if (a < 8) - a = 8; - if (b < 8) - b = 8; - xpos = xpos - a / 2; - ypos = ypos - b / 2; - InsertObject(OBJ_VERTICES, -1, xpos, ypos); - InsertObject(OBJ_VERTICES, -1, xpos + a, ypos); - InsertObject(OBJ_VERTICES, -1, xpos + a, ypos + b); - InsertObject(OBJ_VERTICES, -1, xpos, ypos + b); - if (sector < 0) - InsertObject(OBJ_SECTORS, -1, 0, 0); - for (n = 0; n < 4; n++) - { - InsertObject(OBJ_LINEDEFS, -1, 0, 0); - LineDefs[NumLineDefs - 1].sidedef1 = NumSideDefs; - InsertObject(OBJ_SIDEDEFS, -1, 0, 0); - if (sector >= 0) - SideDefs[NumSideDefs - 1].sector = sector; - } - if (sector >= 0) - { - LineDefs[NumLineDefs - 4].start = NumVertices - 4; - LineDefs[NumLineDefs - 4].end = NumVertices - 3; - LineDefs[NumLineDefs - 3].start = NumVertices - 3; - LineDefs[NumLineDefs - 3].end = NumVertices - 2; - LineDefs[NumLineDefs - 2].start = NumVertices - 2; - LineDefs[NumLineDefs - 2].end = NumVertices - 1; - LineDefs[NumLineDefs - 1].start = NumVertices - 1; - LineDefs[NumLineDefs - 1].end = NumVertices - 4; - } - else - { - LineDefs[NumLineDefs - 4].start = NumVertices - 1; - LineDefs[NumLineDefs - 4].end = NumVertices - 2; - LineDefs[NumLineDefs - 3].start = NumVertices - 2; - LineDefs[NumLineDefs - 3].end = NumVertices - 3; - LineDefs[NumLineDefs - 2].start = NumVertices - 3; - LineDefs[NumLineDefs - 2].end = NumVertices - 4; - LineDefs[NumLineDefs - 1].start = NumVertices - 4; - LineDefs[NumLineDefs - 1].end = NumVertices - 1; - } - } - break; + a = 256; + b = 128; + if (Input2Numbers(-1, -1, "Width", "Height", 2000, 2000, &a, &b)) + { + if (a < 8) + a = 8; + if (b < 8) + b = 8; + xpos = xpos - a / 2; + ypos = ypos - b / 2; + InsertObject(OBJ_VERTICES, -1, xpos, ypos); + InsertObject(OBJ_VERTICES, -1, xpos + a, ypos); + InsertObject(OBJ_VERTICES, -1, xpos + a, ypos + b); + InsertObject(OBJ_VERTICES, -1, xpos, ypos + b); + if (sector < 0) + InsertObject(OBJ_SECTORS, -1, 0, 0); + for (n = 0; n < 4; n++) + { + InsertObject(OBJ_LINEDEFS, -1, 0, 0); + LineDefs[NumLineDefs - 1].sidedef1 = NumSideDefs; + InsertObject(OBJ_SIDEDEFS, -1, 0, 0); + if (sector >= 0) + SideDefs[NumSideDefs - 1].sector = sector; + } + if (sector >= 0) + { + LineDefs[NumLineDefs - 4].start = NumVertices - 4; + LineDefs[NumLineDefs - 4].end = NumVertices - 3; + LineDefs[NumLineDefs - 3].start = NumVertices - 3; + LineDefs[NumLineDefs - 3].end = NumVertices - 2; + LineDefs[NumLineDefs - 2].start = NumVertices - 2; + LineDefs[NumLineDefs - 2].end = NumVertices - 1; + LineDefs[NumLineDefs - 1].start = NumVertices - 1; + LineDefs[NumLineDefs - 1].end = NumVertices - 4; + } + else + { + LineDefs[NumLineDefs - 4].start = NumVertices - 1; + LineDefs[NumLineDefs - 4].end = NumVertices - 2; + LineDefs[NumLineDefs - 3].start = NumVertices - 2; + LineDefs[NumLineDefs - 3].end = NumVertices - 3; + LineDefs[NumLineDefs - 2].start = NumVertices - 3; + LineDefs[NumLineDefs - 2].end = NumVertices - 4; + LineDefs[NumLineDefs - 1].start = NumVertices - 4; + LineDefs[NumLineDefs - 1].end = NumVertices - 1; + } + } + break; case 2: - a = 8; - b = 128; - if (Input2Numbers - (-1, -1, "Number of sides", "Radius", 32, 2000, &a, &b)) - { - if (a < 3) - a = 3; - if (b < 8) - b = 8; - InsertPolygonVertices(xpos, ypos, a, b); - if (sector < 0) - InsertObject(OBJ_SECTORS, -1, 0, 0); - for (n = 0; n < a; n++) - { - InsertObject(OBJ_LINEDEFS, -1, 0, 0); - LineDefs[NumLineDefs - 1].sidedef1 = NumSideDefs; - InsertObject(OBJ_SIDEDEFS, -1, 0, 0); - if (sector >= 0) - SideDefs[NumSideDefs - 1].sector = sector; - } - if (sector >= 0) - { - LineDefs[NumLineDefs - 1].start = NumVertices - 1; - LineDefs[NumLineDefs - 1].end = NumVertices - a; - for (n = 2; n <= a; n++) - { - LineDefs[NumLineDefs - n].start = NumVertices - n; - LineDefs[NumLineDefs - n].end = NumVertices - n + 1; - } - } - else - { - LineDefs[NumLineDefs - 1].start = NumVertices - a; - LineDefs[NumLineDefs - 1].end = NumVertices - 1; - for (n = 2; n <= a; n++) - { - LineDefs[NumLineDefs - n].start = NumVertices - n + 1; - LineDefs[NumLineDefs - n].end = NumVertices - n; - } - } - } - break; + a = 8; + b = 128; + if (Input2Numbers + (-1, -1, "Number of sides", "Radius", 32, 2000, &a, &b)) + { + if (a < 3) + a = 3; + if (b < 8) + b = 8; + InsertPolygonVertices(xpos, ypos, a, b); + if (sector < 0) + InsertObject(OBJ_SECTORS, -1, 0, 0); + for (n = 0; n < a; n++) + { + InsertObject(OBJ_LINEDEFS, -1, 0, 0); + LineDefs[NumLineDefs - 1].sidedef1 = NumSideDefs; + InsertObject(OBJ_SIDEDEFS, -1, 0, 0); + if (sector >= 0) + SideDefs[NumSideDefs - 1].sector = sector; + } + if (sector >= 0) + { + LineDefs[NumLineDefs - 1].start = NumVertices - 1; + LineDefs[NumLineDefs - 1].end = NumVertices - a; + for (n = 2; n <= a; n++) + { + LineDefs[NumLineDefs - n].start = NumVertices - n; + LineDefs[NumLineDefs - n].end = NumVertices - n + 1; + } + } + else + { + LineDefs[NumLineDefs - 1].start = NumVertices - a; + LineDefs[NumLineDefs - 1].end = NumVertices - 1; + for (n = 2; n <= a; n++) + { + LineDefs[NumLineDefs - n].start = NumVertices - n + 1; + LineDefs[NumLineDefs - n].end = NumVertices - n; + } + } + } + break; case 3: - /* - a = 6; - b = 16; - if (Input2Numbers (-1, -1, "Number of steps", "Step height", 32, 48, &a, &b)) - { - if (a < 2) - a = 2; - n = Sectors[sector].ceilh; - h = Sectors[sector].floorh; - if (a * b < n - h) - { - Beep (); - Notify (-1, -1, "The stairs are too high for this Sector", 0); - return; - } - xpos = xpos - 32; - ypos = ypos - 32 * a; - for (n = 0; n < a; n++) - { - InsertObject (OBJ_VERTICES, -1, xpos, ypos); - InsertObject (OBJ_VERTICES, -1, xpos + 64, ypos); - InsertObject (OBJ_VERTICES, -1, xpos + 64, ypos + 64); - InsertObject (OBJ_VERTICES, -1, xpos, ypos + 64); - ypos += 64; - InsertObject (OBJ_SECTORS, sector, 0, 0); - h += b; - Sectors[NumSectors - 1].floorh = h; + /* + a = 6; + b = 16; + if (Input2Numbers (-1, -1, "Number of steps", "Step height", 32, 48, &a, &b)) + { + if (a < 2) + a = 2; + n = Sectors[sector].ceilh; + h = Sectors[sector].floorh; + if (a * b < n - h) + { + Beep (); + Notify (-1, -1, "The stairs are too high for this Sector", 0); + return; + } + xpos = xpos - 32; + ypos = ypos - 32 * a; + for (n = 0; n < a; n++) + { + InsertObject (OBJ_VERTICES, -1, xpos, ypos); + InsertObject (OBJ_VERTICES, -1, xpos + 64, ypos); + InsertObject (OBJ_VERTICES, -1, xpos + 64, ypos + 64); + InsertObject (OBJ_VERTICES, -1, xpos, ypos + 64); + ypos += 64; + InsertObject (OBJ_SECTORS, sector, 0, 0); + h += b; + Sectors[NumSectors - 1].floorh = h; - InsertObject (OBJ_LINEDEFS, -1, 0, 0); - LineDefs[NumLineDefs - 1].sidedef1 = NumSideDefs; - LineDefs[NumLineDefs - 1].sidedef2 = NumSideDefs + 1; - InsertObject (OBJ_SIDEDEFS, -1, 0, 0); - SideDefs[NumSideDefs - 1].sector = sector; - InsertObject (OBJ_SIDEDEFS, -1, 0, 0); + InsertObject (OBJ_LINEDEFS, -1, 0, 0); + LineDefs[NumLineDefs - 1].sidedef1 = NumSideDefs; + LineDefs[NumLineDefs - 1].sidedef2 = NumSideDefs + 1; + InsertObject (OBJ_SIDEDEFS, -1, 0, 0); + SideDefs[NumSideDefs - 1].sector = sector; + InsertObject (OBJ_SIDEDEFS, -1, 0, 0); - LineDefs[NumLineDefs - 4].start = NumVertices - 4; - LineDefs[NumLineDefs - 4].end = NumVertices - 3; - LineDefs[NumLineDefs - 3].start = NumVertices - 3; - LineDefs[NumLineDefs - 3].end = NumVertices - 2; - LineDefs[NumLineDefs - 2].start = NumVertices - 2; - LineDefs[NumLineDefs - 2].end = NumVertices - 1; - LineDefs[NumLineDefs - 1].start = NumVertices - 1; - LineDefs[NumLineDefs - 1].end = NumVertices - 4; - } - } - break; - */ + LineDefs[NumLineDefs - 4].start = NumVertices - 4; + LineDefs[NumLineDefs - 4].end = NumVertices - 3; + LineDefs[NumLineDefs - 3].start = NumVertices - 3; + LineDefs[NumLineDefs - 3].end = NumVertices - 2; + LineDefs[NumLineDefs - 2].start = NumVertices - 2; + LineDefs[NumLineDefs - 2].end = NumVertices - 1; + LineDefs[NumLineDefs - 1].start = NumVertices - 1; + LineDefs[NumLineDefs - 1].end = NumVertices - 4; + } + } + break; + */ case 4: - NotImplemented(); - break; + NotImplemented(); + break; } } @@ -658,18 +658,18 @@ menu of miscellaneous operations */ -void MiscOperations(int objtype, SelPtr * list, int val) /* SWAP! */ +void MiscOperations(int objtype, SelPtr * list, int val) /* SWAP! */ { char msg[80]; int angle, scale; if (val > 1 && !*list) { - Beep(); - sprintf(msg, "You must select at least one %s", - GetObjectTypeName(objtype)); - Notify(-1, -1, msg, 0); - return; + Beep(); + sprintf(msg, "You must select at least one %s", + GetObjectTypeName(objtype)); + Notify(-1, -1, msg, 0); + return; } /* I think this switch statement deserves a prize for "worst @@ -677,356 +677,356 @@ switch (val) { case 1: - // * -> First free tag number - sprintf(msg, "First free tag number: %d", FindFreeTag()); - Notify(-1, -1, msg, 0); - break; + // * -> First free tag number + sprintf(msg, "First free tag number: %d", FindFreeTag()); + Notify(-1, -1, msg, 0); + break; case 2: - // * -> Rotate and scale - if ((objtype == OBJ_THINGS - || objtype == OBJ_VERTICES) && !(*list)->next) - { - Beep(); - sprintf(msg, "You must select more than one %s", - GetObjectTypeName(objtype)); - Notify(-1, -1, msg, 0); - return; - } - angle = 0; - scale = 100; - if (Input2Numbers(-1, -1, "rotation angle (°)", "scale (%)", - 360, 1000, &angle, &scale)) - RotateAndScaleObjects(objtype, *list, (double) angle * 0.0174533, - (double) scale * 0.01); - break; + // * -> Rotate and scale + if ((objtype == OBJ_THINGS + || objtype == OBJ_VERTICES) && !(*list)->next) + { + Beep(); + sprintf(msg, "You must select more than one %s", + GetObjectTypeName(objtype)); + Notify(-1, -1, msg, 0); + return; + } + angle = 0; + scale = 100; + if (Input2Numbers(-1, -1, "rotation angle (°)", "scale (%)", + 360, 1000, &angle, &scale)) + RotateAndScaleObjects(objtype, *list, (double) angle * 0.0174533, + (double) scale * 0.01); + break; case 3: - // Linedef -> Split - if (objtype == OBJ_LINEDEFS) - { - SplitLineDefs(*list); - } - // Sector -> Make door from sector - else if (objtype == OBJ_SECTORS) - { - if ((*list)->next) - { - Beep(); - Notify(-1, -1, "You must select exactly one sector", 0); - } - else - { - MakeDoorFromSector((*list)->objnum); - } - } - // Thing -> Spin 45° clockwise - else if (objtype == OBJ_THINGS) - { - spin_things(*list, -45); - } - // Vertex -> Delete and join linedefs - else if (objtype == OBJ_VERTICES) - { - DeleteVerticesJoinLineDefs(*list); - ForgetSelection(list); - } - break; + // Linedef -> Split + if (objtype == OBJ_LINEDEFS) + { + SplitLineDefs(*list); + } + // Sector -> Make door from sector + else if (objtype == OBJ_SECTORS) + { + if ((*list)->next) + { + Beep(); + Notify(-1, -1, "You must select exactly one sector", 0); + } + else + { + MakeDoorFromSector((*list)->objnum); + } + } + // Thing -> Spin 45° clockwise + else if (objtype == OBJ_THINGS) + { + spin_things(*list, -45); + } + // Vertex -> Delete and join linedefs + else if (objtype == OBJ_VERTICES) + { + DeleteVerticesJoinLineDefs(*list); + ForgetSelection(list); + } + break; case 4: - // Linedef -> Split linedefs and sector - if (objtype == OBJ_LINEDEFS) - { - if (!(*list)->next || (*list)->next->next) - { - Beep(); - Notify(-1, -1, "You must select exactly two linedefs", 0); - } - else - { - SplitLineDefsAndSector((*list)->next->objnum, - (*list)->objnum); - ForgetSelection(list); - } - } - // Sector -> Make lift from sector - else if (objtype == OBJ_SECTORS) - { - if ((*list)->next) - { - Beep(); - Notify(-1, -1, "You must select exactly one Sector", 0); - } - else - { - MakeLiftFromSector((*list)->objnum); - } - } - // Thing -> Spin 45° counter-clockwise - else if (objtype == OBJ_THINGS) - spin_things(*list, 45); - // Vertex -> Merge - else if (objtype == OBJ_VERTICES) - { - MergeVertices(list); - } - break; + // Linedef -> Split linedefs and sector + if (objtype == OBJ_LINEDEFS) + { + if (!(*list)->next || (*list)->next->next) + { + Beep(); + Notify(-1, -1, "You must select exactly two linedefs", 0); + } + else + { + SplitLineDefsAndSector((*list)->next->objnum, + (*list)->objnum); + ForgetSelection(list); + } + } + // Sector -> Make lift from sector + else if (objtype == OBJ_SECTORS) + { + if ((*list)->next) + { + Beep(); + Notify(-1, -1, "You must select exactly one Sector", 0); + } + else + { + MakeLiftFromSector((*list)->objnum); + } + } + // Thing -> Spin 45° counter-clockwise + else if (objtype == OBJ_THINGS) + spin_things(*list, 45); + // Vertex -> Merge + else if (objtype == OBJ_VERTICES) + { + MergeVertices(list); + } + break; case 5: - // Linedef -> Delete linedefs and join sectors - if (objtype == OBJ_LINEDEFS) - { - DeleteLineDefsJoinSectors(list); - } - // Sector -> Distribute sector floor heights - else if (objtype == OBJ_SECTORS) - { - if (!(*list)->next || !(*list)->next->next) - { - Beep(); - Notify(-1, -1, "You must select three or more sectors", 0); - } - else - { - DistributeSectorFloors(*list); - } - } - // Thing -> Mirror horizontally - else if (objtype == OBJ_THINGS) - { - flip_mirror(*list, OBJ_THINGS, 'm'); - } - // Vertex -> Add linedef and split sector - else if (objtype == OBJ_VERTICES) - { - if (!(*list)->next || (*list)->next->next) - { - Beep(); - Notify(-1, -1, "You must select exactly two vertices", 0); - } - else - { - SplitSector((*list)->next->objnum, (*list)->objnum); - ForgetSelection(list); - } - } - break; + // Linedef -> Delete linedefs and join sectors + if (objtype == OBJ_LINEDEFS) + { + DeleteLineDefsJoinSectors(list); + } + // Sector -> Distribute sector floor heights + else if (objtype == OBJ_SECTORS) + { + if (!(*list)->next || !(*list)->next->next) + { + Beep(); + Notify(-1, -1, "You must select three or more sectors", 0); + } + else + { + DistributeSectorFloors(*list); + } + } + // Thing -> Mirror horizontally + else if (objtype == OBJ_THINGS) + { + flip_mirror(*list, OBJ_THINGS, 'm'); + } + // Vertex -> Add linedef and split sector + else if (objtype == OBJ_VERTICES) + { + if (!(*list)->next || (*list)->next->next) + { + Beep(); + Notify(-1, -1, "You must select exactly two vertices", 0); + } + else + { + SplitSector((*list)->next->objnum, (*list)->objnum); + ForgetSelection(list); + } + } + break; case 6: - // Linedef -> Flip - if (objtype == OBJ_LINEDEFS) - { - FlipLineDefs(*list, 1); - } - // Sector -> Distribute ceiling heights - else if (objtype == OBJ_SECTORS) - { - if (!(*list)->next || !(*list)->next->next) - { - Beep(); - Notify(-1, -1, "You must select three or more sectors", 0); - } - else - { - DistributeSectorCeilings(*list); - } - } - // Things -> Mirror vertically - else if (objtype == OBJ_THINGS) - { - flip_mirror(*list, OBJ_THINGS, 'f'); - } - // Vertex -> Mirror horizontally - else if (objtype == OBJ_VERTICES) - { - flip_mirror(*list, OBJ_VERTICES, 'm'); - } - break; + // Linedef -> Flip + if (objtype == OBJ_LINEDEFS) + { + FlipLineDefs(*list, 1); + } + // Sector -> Distribute ceiling heights + else if (objtype == OBJ_SECTORS) + { + if (!(*list)->next || !(*list)->next->next) + { + Beep(); + Notify(-1, -1, "You must select three or more sectors", 0); + } + else + { + DistributeSectorCeilings(*list); + } + } + // Things -> Mirror vertically + else if (objtype == OBJ_THINGS) + { + flip_mirror(*list, OBJ_THINGS, 'f'); + } + // Vertex -> Mirror horizontally + else if (objtype == OBJ_VERTICES) + { + flip_mirror(*list, OBJ_VERTICES, 'm'); + } + break; case 7: - // Linedefs -> Swap sidedefs - if (objtype == OBJ_LINEDEFS) - { - if (Expert - || blindly_swap_sidedefs - || Confirm(-1, -1, - "Warning: the sector references are also swapped", - "You may get strange results if you don't know what you are doing...")) - FlipLineDefs(*list, 0); - } - // Sectors -> Raise or lower - else if (objtype == OBJ_SECTORS) - { - RaiseOrLowerSectors(*list); - } - // Vertices -> Mirror vertically - else if (objtype == OBJ_VERTICES) - { - flip_mirror(*list, OBJ_VERTICES, 'f'); - } - break; + // Linedefs -> Swap sidedefs + if (objtype == OBJ_LINEDEFS) + { + if (Expert + || blindly_swap_sidedefs + || Confirm(-1, -1, + "Warning: the sector references are also swapped", + "You may get strange results if you don't know what you are doing...")) + FlipLineDefs(*list, 0); + } + // Sectors -> Raise or lower + else if (objtype == OBJ_SECTORS) + { + RaiseOrLowerSectors(*list); + } + // Vertices -> Mirror vertically + else if (objtype == OBJ_VERTICES) + { + flip_mirror(*list, OBJ_VERTICES, 'f'); + } + break; case 8: - // Linedef -> Align textures vertically - if (objtype == OBJ_LINEDEFS) - { - SelPtr sdlist, cur; + // Linedef -> Align textures vertically + if (objtype == OBJ_LINEDEFS) + { + SelPtr sdlist, cur; - /* select all sidedefs */ - sdlist = 0; - for (cur = *list; cur; cur = cur->next) - { - if (LineDefs[cur->objnum].sidedef1 >= 0) - SelectObject(&sdlist, LineDefs[cur->objnum].sidedef1); - if (LineDefs[cur->objnum].sidedef2 >= 0) - SelectObject(&sdlist, LineDefs[cur->objnum].sidedef2); - } - /* align the textures along the Y axis (height) */ - AlignTexturesY(&sdlist); - } - // Sector -> Brighten or darken - else if (objtype == OBJ_SECTORS) - { - BrightenOrDarkenSectors(*list); - } - break; + /* select all sidedefs */ + sdlist = 0; + for (cur = *list; cur; cur = cur->next) + { + if (LineDefs[cur->objnum].sidedef1 >= 0) + SelectObject(&sdlist, LineDefs[cur->objnum].sidedef1); + if (LineDefs[cur->objnum].sidedef2 >= 0) + SelectObject(&sdlist, LineDefs[cur->objnum].sidedef2); + } + /* align the textures along the Y axis (height) */ + AlignTexturesY(&sdlist); + } + // Sector -> Brighten or darken + else if (objtype == OBJ_SECTORS) + { + BrightenOrDarkenSectors(*list); + } + break; case 9: - // Linedef -> Align texture horizontally - if (objtype == OBJ_LINEDEFS) - { - SelPtr sdlist, cur; + // Linedef -> Align texture horizontally + if (objtype == OBJ_LINEDEFS) + { + SelPtr sdlist, cur; - /* select all sidedefs */ - sdlist = 0; - for (cur = *list; cur; cur = cur->next) - { - if (LineDefs[cur->objnum].sidedef1 >= 0) - SelectObject(&sdlist, LineDefs[cur->objnum].sidedef1); - if (LineDefs[cur->objnum].sidedef2 >= 0) - SelectObject(&sdlist, LineDefs[cur->objnum].sidedef2); - } - /* align the textures along the X axis (width) */ - AlignTexturesX(&sdlist); - } - // Sector -> Unlink room - else if (objtype == OBJ_SECTORS) - { - NotImplemented(); // FIXME - break; - } - break; + /* select all sidedefs */ + sdlist = 0; + for (cur = *list; cur; cur = cur->next) + { + if (LineDefs[cur->objnum].sidedef1 >= 0) + SelectObject(&sdlist, LineDefs[cur->objnum].sidedef1); + if (LineDefs[cur->objnum].sidedef2 >= 0) + SelectObject(&sdlist, LineDefs[cur->objnum].sidedef2); + } + /* align the textures along the X axis (width) */ + AlignTexturesX(&sdlist); + } + // Sector -> Unlink room + else if (objtype == OBJ_SECTORS) + { + NotImplemented(); // FIXME + break; + } + break; case 10: - // Linedef -> Make linedef single-sided - if (objtype == OBJ_LINEDEFS) - { - SelPtr cur; - for (cur = *list; cur; cur = cur->next) - { - struct LineDef *l = LineDefs + cur->objnum; - l->sidedef2 = -1; /* remove ref. to 2nd SD */ - l->flags &= ~0x04; /* clear "2S" bit */ - l->flags |= 0x01; /* set "Im" bit */ + // Linedef -> Make linedef single-sided + if (objtype == OBJ_LINEDEFS) + { + SelPtr cur; + for (cur = *list; cur; cur = cur->next) + { + struct LineDef *l = LineDefs + cur->objnum; + l->sidedef2 = -1; /* remove ref. to 2nd SD */ + l->flags &= ~0x04; /* clear "2S" bit */ + l->flags |= 0x01; /* set "Im" bit */ - if (is_sidedef(l->sidedef1)) - { - struct SideDef *s = SideDefs + l->sidedef1; - strcpy(s->tex1, "-"); - strcpy(s->tex2, "-"); - strcpy(s->tex3, default_middle_texture); - } - /* Don't delete the 2nd sidedef, it could be used - by another linedef. And if it isn't, the next - cross-references check will delete it anyway. */ - } - } - // Sector -> Mirror horizontally - else if (objtype == OBJ_SECTORS) - { - flip_mirror(*list, OBJ_SECTORS, 'm'); - } - break; + if (is_sidedef(l->sidedef1)) + { + struct SideDef *s = SideDefs + l->sidedef1; + strcpy(s->tex1, "-"); + strcpy(s->tex2, "-"); + strcpy(s->tex3, default_middle_texture); + } + /* Don't delete the 2nd sidedef, it could be used + by another linedef. And if it isn't, the next + cross-references check will delete it anyway. */ + } + } + // Sector -> Mirror horizontally + else if (objtype == OBJ_SECTORS) + { + flip_mirror(*list, OBJ_SECTORS, 'm'); + } + break; case 11: - // Linedef -> Make rectangular nook - if (objtype == OBJ_LINEDEFS) - MakeRectangularNook(*list, 32, 16, 0); - // Sector -> Mirror vertically - else if (objtype == OBJ_SECTORS) - { - flip_mirror(*list, OBJ_SECTORS, 'f'); - } - break; + // Linedef -> Make rectangular nook + if (objtype == OBJ_LINEDEFS) + MakeRectangularNook(*list, 32, 16, 0); + // Sector -> Mirror vertically + else if (objtype == OBJ_SECTORS) + { + flip_mirror(*list, OBJ_SECTORS, 'f'); + } + break; case 12: - // Linedef -> Make rectangular boss - if (objtype == OBJ_LINEDEFS) - MakeRectangularNook(*list, 32, 16, 1); - // Sector -> Swap flats - else if (objtype == OBJ_SECTORS) - swap_flats(*list); - break; + // Linedef -> Make rectangular boss + if (objtype == OBJ_LINEDEFS) + MakeRectangularNook(*list, 32, 16, 1); + // Sector -> Swap flats + else if (objtype == OBJ_SECTORS) + swap_flats(*list); + break; case 13: - // Linedef -> Set length (1st vertex) - if (objtype == OBJ_LINEDEFS) - { - static int length = 24; - length = InputIntegerValue(-1, -1, -10000, 10000, length); - if (length != IIV_CANCEL) - SetLinedefLength(*list, length, 0); - } - break; + // Linedef -> Set length (1st vertex) + if (objtype == OBJ_LINEDEFS) + { + static int length = 24; + length = InputIntegerValue(-1, -1, -10000, 10000, length); + if (length != IIV_CANCEL) + SetLinedefLength(*list, length, 0); + } + break; case 14: - // Linedef -> Set length (2nd vertex) - if (objtype == OBJ_LINEDEFS) - { - static int length = 24; - length = InputIntegerValue(-1, -1, -10000, 10000, length); - if (length != IIV_CANCEL) - SetLinedefLength(*list, length, 1); - } - break; + // Linedef -> Set length (2nd vertex) + if (objtype == OBJ_LINEDEFS) + { + static int length = 24; + length = InputIntegerValue(-1, -1, -10000, 10000, length); + if (length != IIV_CANCEL) + SetLinedefLength(*list, length, 1); + } + break; case 15: - // Linedef -> Unlink 1st sidedef - if (objtype == OBJ_LINEDEFS) - unlink_sidedef(*list, 1, 0); - break; + // Linedef -> Unlink 1st sidedef + if (objtype == OBJ_LINEDEFS) + unlink_sidedef(*list, 1, 0); + break; case 16: - // Linedef -> Unlink 2nd sidedef - if (objtype == OBJ_LINEDEFS) - unlink_sidedef(*list, 0, 1); - break; + // Linedef -> Unlink 2nd sidedef + if (objtype == OBJ_LINEDEFS) + unlink_sidedef(*list, 0, 1); + break; case 17: - // Linedef -> Mirror horizontally - flip_mirror(*list, OBJ_LINEDEFS, 'm'); - break; + // Linedef -> Mirror horizontally + flip_mirror(*list, OBJ_LINEDEFS, 'm'); + break; case 18: - // Linedef -> Mirror vertically - flip_mirror(*list, OBJ_LINEDEFS, 'f'); - break; + // Linedef -> Mirror vertically + flip_mirror(*list, OBJ_LINEDEFS, 'f'); + break; case 19: - // Linedef -> Cut a slice out of a sector - if (objtype == OBJ_LINEDEFS) - { - if (!(*list)->next || (*list)->next->next) - { - Beep(); - Notify(-1, -1, "You must select exactly two linedefs", 0); - } - else - { - sector_slice((*list)->next->objnum, (*list)->objnum); - ForgetSelection(list); - } - } - break; + // Linedef -> Cut a slice out of a sector + if (objtype == OBJ_LINEDEFS) + { + if (!(*list)->next || (*list)->next->next) + { + Beep(); + Notify(-1, -1, "You must select exactly two linedefs", 0); + } + else + { + sector_slice((*list)->next->objnum, (*list)->objnum); + ForgetSelection(list); + } + } + break; } } diff -r 594dea11ccd9 -r a68786b9c74b src/editobj.h --- a/src/editobj.h Sat Sep 24 15:01:56 2011 +0300 +++ b/src/editobj.h Sat Sep 24 15:59:33 2011 +0300 @@ -1,8 +1,8 @@ /* - * editobj.h - * AYM 1998-09-06 + * editobj.h + * AYM 1998-09-06 */ -void DisplayObjectInfo(const edit_t * e, int); /* SWAP! */ +void DisplayObjectInfo(const edit_t * e, int); /* SWAP! */ void input_objid(Objid & objid, const Objid & init, int x0, int y0); diff -r 594dea11ccd9 -r a68786b9c74b src/editsave.cc --- a/src/editsave.cc Sat Sep 24 15:01:56 2011 +0300 +++ b/src/editsave.cc Sat Sep 24 15:59:33 2011 +0300 @@ -1,7 +1,7 @@ /* - * editsave.cc - * Saving an editing session into a pwad - * AYM 1999-04-08 + * editsave.cc + * Saving an editing session into a pwad + * AYM 1999-04-08 */ @@ -44,85 +44,85 @@ /* - * save_save_as - * Save the current level into a pwad. - * - * If neither nor are NULL and the - * level does not come from the iwad and is not - * set, there is no interaction at all. The level is saved - * silently into as . + * save_save_as + * Save the current level into a pwad. + * + * If neither nor are NULL and the + * level does not come from the iwad and is not + * set, there is no interaction at all. The level is saved + * silently into as . * - * Else, the user is first prompted for a level name and a - * file name (in that order). The level name is given a - * default value of "E1M1" in Doom/Heretic mode or "MAP01" - * in Doom II/Hexen/Strife mode. The file name is given a - * default value of "LEVEL.wad" where LEVEL is the level - * name entered previously, lowercased. Upon return from - * the function, and are set - * accordingly. + * Else, the user is first prompted for a level name and a + * file name (in that order). The level name is given a + * default value of "E1M1" in Doom/Heretic mode or "MAP01" + * in Doom II/Hexen/Strife mode. The file name is given a + * default value of "LEVEL.wad" where LEVEL is the level + * name entered previously, lowercased. Upon return from + * the function, and are set + * accordingly. * - * This function is called when the user hits [q], [F2] or - * [F3]. In the latter case, is set to true. + * This function is called when the user hits [q], [F2] or + * [F3]. In the latter case, is set to true. * - * Note: being NULL means that the level name - * is not known, which is the case when using the "c" - * (create) command. When using the "e" (edit) command, - * the level name is always known, since the level data - * comes from an iwad or pwad. The same goes for - * . + * Note: being NULL means that the level name + * is not known, which is the case when using the "c" + * (create) command. When using the "e" (edit) command, + * the level name is always known, since the level data + * comes from an iwad or pwad. The same goes for + * . * - * Upon return from the function, is updated. + * Upon return from the function, is updated. * - * FIXME this should be a method of the Editwin class. + * FIXME this should be a method of the Editwin class. */ #ifdef NEW_SAVE_METHOD bool save_save_as(bool prompt) { - static char l[WAD_NAME + 1]; // "static" to avoid memory shortages - static y_file_name_t f; // "static" to avoid memory shortages + static char l[WAD_NAME + 1]; // "static" to avoid memory shortages + static y_file_name_t f; // "static" to avoid memory shortages if (!CheckStartingPos()) - return; + return; // Fill in the level name if (*Level_name) - al_scps(l, Level_name, sizeof l - 1); + al_scps(l, Level_name, sizeof l - 1); else { - prompt = true; - if (yg_level_name == YGLN_MAP01) - strcpy(l, "map01"); - else - { - strcpy(l, "e1m1"); - if (yg_level_name != YGLN_E1M1 && yg_level_name != YGLN_E1M10) - nf_bug("Bad yg_level_name %d", (int) yg_level_name); - } + prompt = true; + if (yg_level_name == YGLN_MAP01) + strcpy(l, "map01"); + else + { + strcpy(l, "e1m1"); + if (yg_level_name != YGLN_E1M1 && yg_level_name != YGLN_E1M10) + nf_bug("Bad yg_level_name %d", (int) yg_level_name); + } } // Fill in the file name if (*Level_file_name) - al_scps(f, file_name, sizeof f - 1); + al_scps(f, file_name, sizeof f - 1); else { - prompt = true; - al_scpslower(f, l, sizeof f - 1); - al_saps(f, ".wad", sizeof f - 1); + prompt = true; + al_scpslower(f, l, sizeof f - 1); + al_saps(f, ".wad", sizeof f - 1); } // Create the dialog Entry2 e("Save level as...", - "Level %*S\nFile %+*s\n", sizeof l - 1, l, sizeof f - 1, f); + "Level %*S\nFile %+*s\n", sizeof l - 1, l, sizeof f - 1, f); try_again: // If necessary, prompt for new level name and file name if (prompt || !fncmp(level_name, MainWad)) { - int r = e.loop(); - if (!r) // Cancelled by user - return false; // Didn't save + int r = e.loop(); + if (!r) // Cancelled by user + return false; // Didn't save } printf("Saving as \"%s\" into \"%s\"\n", l, f); @@ -134,33 +134,33 @@ // If file already exists, ask for confirmation. if (al_fnature(l) == 1) { - bool ok = - Confirm(-1, -1, - "This file already exists. Saving to it will" - " overwrite _everything_", - "else it might contain, including other levels or lumps !"); - if (!ok) - { - prompt = true; - goto try_again; - } + bool ok = + Confirm(-1, -1, + "This file already exists. Saving to it will" + " overwrite _everything_", + "else it might contain, including other levels or lumps !"); + if (!ok) + { + prompt = true; + goto try_again; + } } // Try to save int r = SaveLevelData( ...); if (r) { - Notify(-1, -1, "Could not save to file", strerror(errno)); - prompt = true; - goto try_again; + Notify(-1, -1, "Could not save to file", strerror(errno)); + prompt = true; + goto try_again; } // Successfully saved - Level = FindMasterDir(levelname); // FIXME useless ? + Level = FindMasterDir(levelname); // FIXME useless ? al_scps(Level_name, l, sizeof Level_name - 1); al_scps(Level_file_name, f, sizeof Level_file_name - 1); al_scps(Level_file_name_saved, f, sizeof Level_file_name_saved - 1); - return true; // Did save + return true; // Did save } #else /* OLD_SAVE_METHOD */ @@ -178,96 +178,96 @@ // If no name, find a default one if (!levelname) { - if (yg_level_name == YGLN_E1M1 || yg_level_name == YGLN_E1M10) - levelname = "E1M1"; - else if (yg_level_name == YGLN_MAP01) - levelname = "MAP01"; - else - { - nf_bug("Bad ygd_level_name %d, using E1M1.", (int) yg_level_name); - levelname = "E1M1"; - } + if (yg_level_name == YGLN_E1M1 || yg_level_name == YGLN_E1M10) + levelname = "E1M1"; + else if (yg_level_name == YGLN_MAP01) + levelname = "MAP01"; + else + { + nf_bug("Bad ygd_level_name %d, using E1M1.", (int) yg_level_name); + levelname = "E1M1"; + } } if (!Level - || !Level->wadfile || !fncmp(Level->wadfile->filename, MainWad)) + || !Level->wadfile || !fncmp(Level->wadfile->filename, MainWad)) { - al_scpslower(outfile, levelname, BUFSZ); - al_saps(outfile, ".wad", BUFSZ); + al_scpslower(outfile, levelname, BUFSZ); + al_saps(outfile, ".wad", BUFSZ); } else - strcpy(outfile, Level->wadfile->filename); + strcpy(outfile, Level->wadfile->filename); do - InputFileName(-1, -1, "Name of the new wad file:", BUFSZ, outfile); + InputFileName(-1, -1, "Name of the new wad file:", BUFSZ, outfile); while (!fncmp(outfile, MainWad)); /* escape */ if (outfile[0] == '\0') { - FreeMemory(outfile); - return 0; + FreeMemory(outfile); + return 0; } /* if the wad file already exists, rename it to "*.bak" */ Wad_file *wf; for (wad_list.rewind(); wad_list.get(wf);) - if (fncmp(outfile, wf->filename) == 0) - { - verbmsg("wf->filename: %s\n", wf->filename); // DEBUG - verbmsg("wf->fp %p\n", wf->fp); // DEBUG - verbmsg("outfile %s\n", outfile); // DEBUG - al_fdrv_t drv; - al_fpath_t path; - al_fbase_t base; + if (fncmp(outfile, wf->filename) == 0) + { + verbmsg("wf->filename: %s\n", wf->filename); // DEBUG + verbmsg("wf->fp %p\n", wf->fp); // DEBUG + verbmsg("outfile %s\n", outfile); // DEBUG + al_fdrv_t drv; + al_fpath_t path; + al_fbase_t base; - al_fana(wf->filename, drv, path, base, 0); - sprintf(wf->filename, "%s%s%s.bak", drv, path, base); - verbmsg("setting wf->filename to %s\n", wf->filename); // DEBUG - /* Need to close, then reopen: problems with SHARE.EXE */ - verbmsg("closing %p\n", wf->fp); // DEBUG - fclose(wf->fp); - verbmsg("renaming %s -> %s\n", outfile, wf->filename); // DEBUG - if (rename(outfile, wf->filename) != 0) - { - verbmsg("removing %s\n", wf->filename); // DEBUG - if (remove(wf->filename) != 0 && errno != ENOENT) - { - char buf1[81]; - char buf2[81]; - y_snprintf(buf1, sizeof buf1, - "Could not delete \"%.64s\"", wf->filename); - y_snprintf(buf2, sizeof buf2, "(%.64s)", strerror(errno)); - Notify(-1, -1, buf1, buf2); - return 0; - } - verbmsg("renaming %s -> %s\n", outfile, wf->filename); // DEBUG - if (rename(outfile, wf->filename)) - { - char buf1[81]; - char buf2[81]; - y_snprintf(buf1, sizeof buf1, - "Could not rename \"%.64s\"", outfile); - y_snprintf(buf2, sizeof buf2, "as \"%.64s\" (%.64s)", - wf->filename, strerror(errno)); - Notify(-1, -1, buf1, buf2); - return 0; - } - } - verbmsg("opening %s\n", wf->filename); // DEBUG - wf->fp = fopen(wf->filename, "rb"); - if (wf->fp == 0) - { - char buf1[81]; - char buf2[81]; - y_snprintf(buf1, sizeof buf1, "Could not reopen \"%.64s\"", - wf->filename); - y_snprintf(buf2, sizeof buf2, "(%.64s)", strerror(errno)); - Notify(-1, -1, buf1, buf2); - return 0; - } - verbmsg("wf->filename: %s\n", wf->filename); // DEBUG - verbmsg("wf->fp %p\n", wf->fp); // DEBUG - verbmsg("outfile %s\n", outfile); // DEBUG - break; - } + al_fana(wf->filename, drv, path, base, 0); + sprintf(wf->filename, "%s%s%s.bak", drv, path, base); + verbmsg("setting wf->filename to %s\n", wf->filename); // DEBUG + /* Need to close, then reopen: problems with SHARE.EXE */ + verbmsg("closing %p\n", wf->fp); // DEBUG + fclose(wf->fp); + verbmsg("renaming %s -> %s\n", outfile, wf->filename); // DEBUG + if (rename(outfile, wf->filename) != 0) + { + verbmsg("removing %s\n", wf->filename); // DEBUG + if (remove(wf->filename) != 0 && errno != ENOENT) + { + char buf1[81]; + char buf2[81]; + y_snprintf(buf1, sizeof buf1, + "Could not delete \"%.64s\"", wf->filename); + y_snprintf(buf2, sizeof buf2, "(%.64s)", strerror(errno)); + Notify(-1, -1, buf1, buf2); + return 0; + } + verbmsg("renaming %s -> %s\n", outfile, wf->filename); // DEBUG + if (rename(outfile, wf->filename)) + { + char buf1[81]; + char buf2[81]; + y_snprintf(buf1, sizeof buf1, + "Could not rename \"%.64s\"", outfile); + y_snprintf(buf2, sizeof buf2, "as \"%.64s\" (%.64s)", + wf->filename, strerror(errno)); + Notify(-1, -1, buf1, buf2); + return 0; + } + } + verbmsg("opening %s\n", wf->filename); // DEBUG + wf->fp = fopen(wf->filename, "rb"); + if (wf->fp == 0) + { + char buf1[81]; + char buf2[81]; + y_snprintf(buf1, sizeof buf1, "Could not reopen \"%.64s\"", + wf->filename); + y_snprintf(buf2, sizeof buf2, "(%.64s)", strerror(errno)); + Notify(-1, -1, buf1, buf2); + return 0; + } + verbmsg("wf->filename: %s\n", wf->filename); // DEBUG + verbmsg("wf->fp %p\n", wf->fp); // DEBUG + verbmsg("outfile %s\n", outfile); // DEBUG + break; + } return outfile; } #endif diff -r 594dea11ccd9 -r a68786b9c74b src/editsave.h --- a/src/editsave.h Sat Sep 24 15:01:56 2011 +0300 +++ b/src/editsave.h Sat Sep 24 15:59:33 2011 +0300 @@ -1,6 +1,6 @@ /* - * editsave.h - * AYM 1999-04-11 + * editsave.h + * AYM 1999-04-11 */ diff -r 594dea11ccd9 -r a68786b9c74b src/editzoom.cc --- a/src/editzoom.cc Sat Sep 24 15:01:56 2011 +0300 +++ b/src/editzoom.cc Sat Sep 24 15:59:33 2011 +0300 @@ -1,7 +1,7 @@ /* - * editzoom.cc - * Zoom functions - * AYM 1998-11-09 + * editzoom.cc + * Zoom functions + * AYM 1998-11-09 */ @@ -43,19 +43,19 @@ { double factor = digit_zoom_base / 100.0; double step = digit_zoom_step != 0 ? (digit_zoom_step + 100.0) / 100 - : pow(2, -.5); + : pow(2, -.5); for (int i = 1; i <= 10; i++, factor *= step) - digit_zoom_factors[i % 10] = factor; + digit_zoom_factors[i % 10] = factor; } int edit_zoom_in(edit_t * e) { if (!e) - return 1; // Prevent compiler warning about unused .p. + return 1; // Prevent compiler warning about unused .p. double step = zoom_step != 0 ? (zoom_step + 100.0) / 100 : sqrt(2); if (Scale * step > 10.0) - return 1; + return 1; OrigX += (int) ((is.x - ScrCenterX) / Scale); OrigY += (int) ((ScrCenterY - is.y) / Scale); Scale *= step; @@ -69,10 +69,10 @@ int edit_zoom_out(edit_t * e) { if (!e) - return 1; // Prevent compiler warning about unused .p. + return 1; // Prevent compiler warning about unused .p. double step = zoom_step != 0 ? (zoom_step + 100.0) / 100 : sqrt(2); if (Scale / step < 0.05) - return 1; + return 1; OrigX += (int) ((is.x - ScrCenterX) / Scale); OrigY += (int) ((ScrCenterY - is.y) / Scale); Scale /= step; @@ -86,11 +86,11 @@ int edit_set_zoom(edit_t * e, double zoom_factor) { if (!e) - return 1; // Prevent compiler warning about unused .p. + return 1; // Prevent compiler warning about unused .p. if (zoom_factor < 0.05) - zoom_factor = 0.05; + zoom_factor = 0.05; if (zoom_factor > 10.0) - zoom_factor = 10.0; + zoom_factor = 10.0; OrigX += (int) ((is.x - ScrCenterX) / Scale); OrigY += (int) ((ScrCenterY - is.y) / Scale); Scale = zoom_factor; diff -r 594dea11ccd9 -r a68786b9c74b src/editzoom.h --- a/src/editzoom.h Sat Sep 24 15:01:56 2011 +0300 +++ b/src/editzoom.h Sat Sep 24 15:59:33 2011 +0300 @@ -1,6 +1,6 @@ /* - * editzoom.h - * AYM 1998-11-09 + * editzoom.h + * AYM 1998-11-09 */ @@ -16,33 +16,33 @@ /* - * edit_zoom_in - zoom_in + * edit_zoom_in - zoom_in * - * If zooming in would result in a zoom factor higher than - * 10.0, do nothing. + * If zooming in would result in a zoom factor higher than + * 10.0, do nothing. * - * Return 0 on success, non-zero on failure. + * Return 0 on success, non-zero on failure. */ int edit_zoom_in(edit_t * e); /* - * edit_zoom_out - zoom_out + * edit_zoom_out - zoom_out * - * If zooming out would result in a zoom factor lesser than - * 0.05, do nothing. + * If zooming out would result in a zoom factor lesser than + * 0.05, do nothing. * - * Return 0 on success, non-zero on failure. + * Return 0 on success, non-zero on failure. */ int edit_zoom_out(edit_t * e); /* - * edit_set_zoom - set zoom factor + * edit_set_zoom - set zoom factor * - * If the new zoom factor is less than 0.05 or more than - * 10.0, do nothing. + * If the new zoom factor is less than 0.05 or more than + * 10.0, do nothing. * - * Return 0 on success, non-zero on failure. + * Return 0 on success, non-zero on failure. */ int edit_set_zoom(edit_t * e, double zoom_factor); diff -r 594dea11ccd9 -r a68786b9c74b src/edwidget.h --- a/src/edwidget.h Sat Sep 24 15:01:56 2011 +0300 +++ b/src/edwidget.h Sat Sep 24 15:59:33 2011 +0300 @@ -1,31 +1,31 @@ /* - * edwidget.h - * The class edwidget_c from which the edisplay widget are derived. - * AYM 1998-09-23 + * edwidget.h + * The class edwidget_c from which the edisplay widget are derived. + * AYM 1998-09-23 */ -#ifndef YH_EDWIDGET /* DO NOT INSERT ANYTHING BEFORE THIS LINE */ +#ifndef YH_EDWIDGET /* DO NOT INSERT ANYTHING BEFORE THIS LINE */ #define YH_EDWIDGET class edwidget_c { public:void const unset(); - void const draw(); // Draw yourself - void const undraw(); // If you're drawn, undraw yourself - int const can_undraw(); // Can you undraw yourself ? - int const need_to_clear(); // You need to undraw yself but can't ? - void const clear(); // Forget you're drawn - int const req_width(); // Tell me the width you'd like to have - int const req_height(); // Tell me the height you'd like 2 have - void const set_x0(int x0); // This is your top left corner + void const draw(); // Draw yourself + void const undraw(); // If you're drawn, undraw yourself + int const can_undraw(); // Can you undraw yourself ? + int const need_to_clear(); // You need to undraw yself but can't ? + void const clear(); // Forget you're drawn + int const req_width(); // Tell me the width you'd like to have + int const req_height(); // Tell me the height you'd like 2 have + void const set_x0(int x0); // This is your top left corner void const set_y0(int y0); - void const set_x1(int x1); // This is your bottom right corner + void const set_x1(int x1); // This is your bottom right corner void const set_y1(int y1); - int const get_x0(); // Tell me where's your top left corner + int const get_x0(); // Tell me where's your top left corner int const get_y0(); - int const get_x1(); // Tell me where's your bottom right c. + int const get_x1(); // Tell me where's your bottom right c. int const get_y1(); }; diff -r 594dea11ccd9 -r a68786b9c74b src/endian.cc --- a/src/endian.cc Sat Sep 24 15:01:56 2011 +0300 +++ b/src/endian.cc Sat Sep 24 15:59:33 2011 +0300 @@ -1,7 +1,7 @@ /* - * endian.cc - * Determine the native endianness - * AYM 1999-03-30 + * endian.cc + * Determine the native endianness + * AYM 1999-03-30 */ @@ -33,33 +33,33 @@ /* - * Returns 0 for little-endian, 1 for big-endian + * Returns 0 for little-endian, 1 for big-endian */ int native_endianness() { verbmsg("CPU endianness: "); union { - char mem[17]; // 5 is enough in theory - u32 n; + char mem[17]; // 5 is enough in theory + u32 n; } u; memset(u.mem, '\0', sizeof(u.mem)); u.n = 0x31323334; if (!strcmp(u.mem, "1234")) { - verbmsg("big-endian\n"); - return 1; + verbmsg("big-endian\n"); + return 1; } else if (!strcmp(u.mem, "4321")) { - verbmsg("little-endian\n"); - return 0; + verbmsg("little-endian\n"); + return 0; } else { - verbmsg("unknown\n"); - warn("weird endianness \"%s\". Report this to the maintainer!\n", - u.mem); - return 0; + verbmsg("unknown\n"); + warn("weird endianness \"%s\". Report this to the maintainer!\n", + u.mem); + return 0; } } diff -r 594dea11ccd9 -r a68786b9c74b src/endian.h --- a/src/endian.h Sat Sep 24 15:01:56 2011 +0300 +++ b/src/endian.h Sat Sep 24 15:59:33 2011 +0300 @@ -1,8 +1,8 @@ /* - * endian.h - * Determine native endianness - * AYM 1999-03-30 + * endian.h + * Determine native endianness + * AYM 1999-03-30 */ -int native_endianness(); // Returns 0 for little-endian, 1 for big-endian +int native_endianness(); // Returns 0 for little-endian, 1 for big-endian diff -r 594dea11ccd9 -r a68786b9c74b src/entry.cc --- a/src/entry.cc Sat Sep 24 15:01:56 2011 +0300 +++ b/src/entry.cc Sat Sep 24 15:59:33 2011 +0300 @@ -1,7 +1,7 @@ /* - * entry.cc - * Entry "widgets" (ahem). - * AYM 1998-11-30 + * entry.cc + * Entry "widgets" (ahem). + * AYM 1998-11-30 */ @@ -37,9 +37,9 @@ /* - * InputInteger - display the integer input box + * InputInteger - display the integer input box * - * FIXME *valp, minv and maxv should be changed to long. + * FIXME *valp, minv and maxv should be changed to long. */ int InputInteger(int x0, int y0, int *valp, int minv, int maxv) { @@ -52,8 +52,8 @@ int entry_text_y0; int entry_text_x1; int entry_text_y1; - const size_t boxlen = 7; // Visible width of entry box - const size_t bufmaxlen = 50; // Slack enough + const size_t boxlen = 7; // Visible width of entry box + const size_t bufmaxlen = 50; // Slack enough char *buf = new char[bufmaxlen + 1]; entry_out_x0 = x0; @@ -65,70 +65,70 @@ entry_text_y1 = entry_text_y0 + FONTH - 1; entry_out_y1 = entry_text_y1 + HOLLOW_BORDER + NARROW_VSPACING; DrawScreenBoxHollow(entry_out_x0, entry_out_y0, entry_out_x1, - entry_out_y1, BLACK); + entry_out_y1, BLACK); long val = *valp; - sprintf(buf, "%d", *valp); // FIXME what if we were in hex ? + sprintf(buf, "%d", *valp); // FIXME what if we were in hex ? for (bool firstkey = true;; firstkey = false) { - bool ok; - { - const char *checkp = buf; - ok = strgetl(checkp, val) == 0 - && checkp == buf + strlen(buf) && val >= minv && val <= maxv; - } - set_colour(BLACK); - DrawScreenBox(entry_text_x0, entry_text_y0, entry_text_x1, - entry_text_y1); - if (ok) - set_colour(WHITE); - else - set_colour(LIGHTRED); - if (strlen(buf) > boxlen) - { - DrawScreenText(entry_text_x0, entry_text_y0, "<%s", - buf + (strlen(buf) - boxlen + 1)); - } - else - DrawScreenString(entry_text_x0, entry_text_y0, buf); + bool ok; + { + const char *checkp = buf; + ok = strgetl(checkp, val) == 0 + && checkp == buf + strlen(buf) && val >= minv && val <= maxv; + } + set_colour(BLACK); + DrawScreenBox(entry_text_x0, entry_text_y0, entry_text_x1, + entry_text_y1); + if (ok) + set_colour(WHITE); + else + set_colour(LIGHTRED); + if (strlen(buf) > boxlen) + { + DrawScreenText(entry_text_x0, entry_text_y0, "<%s", + buf + (strlen(buf) - boxlen + 1)); + } + else + DrawScreenString(entry_text_x0, entry_text_y0, buf); - key = get_key(); - if (key == YK_BACKSPACE && strlen(buf) > 0) - { - buf[strlen(buf) - 1] = '\0'; - } - else if (key == YK_RETURN && ok) - { - *valp = (int) val; - break; // Return current value - } - else if (key == YK_LEFT || key == YK_RIGHT - || key == YK_UP || key == YK_DOWN - || key == YK_TAB || key == YK_BACKTAB) - { - *valp = (int) val; - break; // Return current value, even if not valid - } - else if (key == YK_ESC) - { - *valp = IIV_CANCEL; // Return an out of range value - break; - } - else if (is_ordinary(key) && strlen(buf) < bufmaxlen) - { - if (firstkey) - if (key == ' ') // Kludge : hit space to append to initial value - continue; - else - *buf = '\0'; - al_sapc(buf, key, bufmaxlen); - } - else - { - Beep(); - } + key = get_key(); + if (key == YK_BACKSPACE && strlen(buf) > 0) + { + buf[strlen(buf) - 1] = '\0'; + } + else if (key == YK_RETURN && ok) + { + *valp = (int) val; + break; // Return current value + } + else if (key == YK_LEFT || key == YK_RIGHT + || key == YK_UP || key == YK_DOWN + || key == YK_TAB || key == YK_BACKTAB) + { + *valp = (int) val; + break; // Return current value, even if not valid + } + else if (key == YK_ESC) + { + *valp = IIV_CANCEL; // Return an out of range value + break; + } + else if (is_ordinary(key) && strlen(buf) < bufmaxlen) + { + if (firstkey) + if (key == ' ') // Kludge : hit space to append to initial value + continue; + else + *buf = '\0'; + al_sapc(buf, key, bufmaxlen); + } + else + { + Beep(); + } } - is.key = 0; // Shouldn't have to do that but EditorLoop() is broken + is.key = 0; // Shouldn't have to do that but EditorLoop() is broken delete[]buf; return key; } @@ -143,19 +143,19 @@ char prompt[80]; y_snprintf(prompt, sizeof prompt, - "Enter a number between %d and %d:", minv, maxv); + "Enter a number between %d and %d:", minv, maxv); if (x0 < 0) - x0 = (ScrMaxX - 25 - FONTW * strlen(prompt)) / 2; + x0 = (ScrMaxX - 25 - FONTW * strlen(prompt)) / 2; if (y0 < 0) - y0 = (ScrMaxY - 55) / 2; + y0 = (ScrMaxY - 55) / 2; DrawScreenBox3D(x0, y0, x0 + 25 + FONTW * strlen(prompt), y0 + 55); set_colour(WHITE); DrawScreenText(x0 + 10, y0 + 8, prompt); val = defv; while ((key = - InputInteger(x0 + 10, y0 + 28, &val, minv, maxv)) != YK_RETURN - && key != YK_ESC) - Beep(); + InputInteger(x0 + 10, y0 + 28, &val, minv, maxv)) != YK_RETURN + && key != YK_ESC) + Beep(); return val; } @@ -164,7 +164,7 @@ ask for a filename */ void InputFileName(int x0, int y0, const char *prompt, size_t maxlen, - char *filename) + char *filename) { int key; size_t l; @@ -182,30 +182,30 @@ int entry_text_y1; for (l = strlen(filename) + 1; l <= maxlen; l++) - filename[l] = '\0'; + filename[l] = '\0'; /* compute the width of the input box */ if (maxlen > 20) - boxlen = 20; + boxlen = 20; else - boxlen = maxlen; + boxlen = maxlen; /* compute the width of the dialog box */ if (strlen(prompt) > boxlen) - l = strlen(prompt); + l = strlen(prompt); else - l = boxlen; + l = boxlen; width = 2 * HOLLOW_BORDER + 2 * NARROW_HSPACING + boxlen * FONTW; if ((int) (strlen(prompt) * FONTW) > width) - width = strlen(prompt) * FONTW; + width = strlen(prompt) * FONTW; width += 2 * BOX_BORDER + 2 * WIDE_HSPACING; if (x0 < 0) - x0 = (ScrMaxX - width) / 2; + x0 = (ScrMaxX - width) / 2; if (y0 < 0) - y0 = (ScrMaxY - 2 * BOX_BORDER - - 2 * WIDE_VSPACING - - (int) (2.5 * FONTH) - - 2 * HOLLOW_BORDER - 2 * NARROW_VSPACING) / 2; + y0 = (ScrMaxY - 2 * BOX_BORDER + - 2 * WIDE_VSPACING + - (int) (2.5 * FONTH) + - 2 * HOLLOW_BORDER - 2 * NARROW_VSPACING) / 2; /* draw the dialog box */ entry_out_x0 = x0 + BOX_BORDER + WIDE_HSPACING; entry_text_x0 = entry_out_x0 + HOLLOW_BORDER + NARROW_HSPACING; @@ -219,64 +219,64 @@ DrawScreenBox3D(x0, y0, x0 + width - 1, entry_out_y1 + WIDE_VSPACING); DrawScreenBoxHollow(entry_out_x0, entry_out_y0, entry_out_x1, - entry_out_y1, BLACK); + entry_out_y1, BLACK); set_colour(WINTITLE); DrawScreenString(entry_out_x0, title_y0, prompt); firstkey = true; for (;;) { - l = strlen(filename); - set_colour(BLACK); - DrawScreenBox(entry_text_x0, entry_text_y0, entry_text_x1, - entry_text_y1); - set_colour(WHITE); - if (l > boxlen) - { - DrawScreenText(entry_text_x0, entry_text_y0, "<%s", - filename + (l - boxlen + 1)); - } - else - DrawScreenString(entry_text_x0, entry_text_y0, filename); - key = get_key(); - if (firstkey && is_ordinary(key)) - { - for (l = 0; l <= maxlen; l++) - filename[l] = '\0'; - l = 0; - } - firstkey = false; - if (l < maxlen && is_ordinary(key)) - { - filename[l] = key; - filename[l + 1] = '\0'; - } - else if (l > 0 && key == YK_BACKSPACE) - filename[l - 1] = '\0'; - else if (key == YK_RETURN) - break; /* return "filename" */ - else if (key == YK_ESC) - { - filename[0] = '\0'; /* return an empty string */ - break; - } - else - Beep(); + l = strlen(filename); + set_colour(BLACK); + DrawScreenBox(entry_text_x0, entry_text_y0, entry_text_x1, + entry_text_y1); + set_colour(WHITE); + if (l > boxlen) + { + DrawScreenText(entry_text_x0, entry_text_y0, "<%s", + filename + (l - boxlen + 1)); + } + else + DrawScreenString(entry_text_x0, entry_text_y0, filename); + key = get_key(); + if (firstkey && is_ordinary(key)) + { + for (l = 0; l <= maxlen; l++) + filename[l] = '\0'; + l = 0; + } + firstkey = false; + if (l < maxlen && is_ordinary(key)) + { + filename[l] = key; + filename[l + 1] = '\0'; + } + else if (l > 0 && key == YK_BACKSPACE) + filename[l - 1] = '\0'; + else if (key == YK_RETURN) + break; /* return "filename" */ + else if (key == YK_ESC) + { + filename[0] = '\0'; /* return an empty string */ + break; + } + else + Beep(); } - is.key = 0; // Shouldn't have to do that but EditorLoop() is broken + is.key = 0; // Shouldn't have to do that but EditorLoop() is broken } /* * strgetl - parse a C-style signed long integer * - * Parse anything that would be a legal C signed long - * integer literal (L and U suffixes are not allowed). - * After the function returns, points on the first - * character that could not be parsed. If what was parsed - * constitutes a valid integer, contains its value - * and the return value is a null pointer. Otherwise, - * is undefined and the return value is a static - * string describing the error. + * Parse anything that would be a legal C signed long + * integer literal (L and U suffixes are not allowed). + * After the function returns, points on the first + * character that could not be parsed. If what was parsed + * constitutes a valid integer, contains its value + * and the return value is a null pointer. Otherwise, + * is undefined and the return value is a static + * string describing the error. */ const char *strgetl(const char *&str, long &value) { @@ -286,39 +286,39 @@ // Leading + or - if (*str == '-') { - sign = -1; - str++; + sign = -1; + str++; } else if (*str == '+') - str++; + str++; // 0- or 0x- prefix if (*str == '0' && (str[1] == 'x' || str[1] == 'X')) { - base = 16; - str += 2; + base = 16; + str += 2; } else if (*str == '0') - base = 8; // Don't advance str, so that "0" passes the next test + base = 8; // Don't advance str, so that "0" passes the next test // Check that there is at least one digit if (hextoi(*str) < 0 || hextoi(*str) >= base) { - if (base == 8) - return "expected an octal digit"; - else if (base == 10) - return "expected a decimal digit"; - else - return "expected a hex digit"; + if (base == 8) + return "expected an octal digit"; + else if (base == 10) + return "expected a decimal digit"; + else + return "expected a hex digit"; } // Swallow all non-prefix digits for (value = 0; *str != '\0'; str++) { - int digitval = hextoi(*str); - if (digitval < 0 || digitval >= base) - return 0; - value = base * value + sign * digitval; + int digitval = hextoi(*str); + if (digitval < 0 || digitval >= base) + return 0; + value = base * value + sign * digitval; } return 0; } diff -r 594dea11ccd9 -r a68786b9c74b src/entry.h --- a/src/entry.h Sat Sep 24 15:01:56 2011 +0300 +++ b/src/entry.h Sat Sep 24 15:59:33 2011 +0300 @@ -1,7 +1,7 @@ /* - * entry.h - * Entry "widgets". - * AYM 1998-11-30 + * entry.h + * Entry "widgets". + * AYM 1998-11-30 */ diff -r 594dea11ccd9 -r a68786b9c74b src/entry2.cc --- a/src/entry2.cc Sat Sep 24 15:01:56 2011 +0300 +++ b/src/entry2.cc Sat Sep 24 15:59:33 2011 +0300 @@ -1,7 +1,7 @@ /* - * entry2.cc - * A string entry box class - * AYM 1999-04-12 + * entry2.cc + * A string entry box class + * AYM 1999-04-12 */ @@ -34,7 +34,7 @@ /* - * ctor + * ctor */ Entry2::Entry2(const char *title, const char *fmt, ...) { @@ -48,15 +48,15 @@ entry_flags = new _field_flags_t[nfields]; { - va_list args; - va_start(args, fmt); - fill_in_widgets_info(fmt, args); + va_list args; + va_start(args, fmt); + fill_in_widgets_info(fmt, args); } background_drawn = false; for (size_t f = 0; f < nfields; f++) - entry_drawn[f] = false; - field_no = 0; // This seem redundant with jump_to_field (0) + entry_drawn[f] = false; + field_no = 0; // This seem redundant with jump_to_field (0) // but it's not. jump_to_field() really needs // field_no to be initialized. jump_to_field(0); @@ -74,64 +74,64 @@ /* - * dtor + * dtor */ Entry2::~Entry2() { if (buf) - delete[]buf; + delete[]buf; if (buf_max_len) - delete[]buf_max_len; + delete[]buf_max_len; if (box_len) - delete[]box_len; + delete[]box_len; if (entry_drawn) - delete[]entry_drawn; + delete[]entry_drawn; if (entry_flags) - delete[]entry_flags; + delete[]entry_flags; if (caption) - delete[]caption; + delete[]caption; } /* - * loop - * Block until the user closes the window. - * Return 0 on cancel, non-zero on valid. + * loop + * Block until the user closes the window. + * Return 0 on cancel, non-zero on valid. */ int Entry2::loop() { int r; for (;;) { - get_input_status(); - r = process_event(is); - refresh(); - if (r != ACT_NONE) - break; + get_input_status(); + r = process_event(is); + refresh(); + if (r != ACT_NONE) + break; } - is.key = 0; // FIXME Shouldn't have to do that but EditorLoop() is broken + is.key = 0; // FIXME Shouldn't have to do that but EditorLoop() is broken if (r == ACT_VALID) - return 1; + return 1; else if (r == ACT_CANCEL) - return 0; + return 0; else { - printf("Internal error: Entry2::process_event returned %d\n", - (int) r); - return 0; + printf("Internal error: Entry2::process_event returned %d\n", + (int) r); + return 0; } } /* - * process_event + * process_event */ Entry2_action_t Entry2::process_event(const input_status_t & is) { if (is.key == YE_EXPOSE) { - background_drawn = false; - return ACT_NONE; + background_drawn = false; + return ACT_NONE; } char *s = buf[field_no]; @@ -143,151 +143,151 @@ if (first_key && is_ordinary(key)) { - *s = '\0'; - l = 0; - redraw = true; + *s = '\0'; + l = 0; + redraw = true; } first_key = 0; // Printable character if (is_ordinary(key)) { - if (l >= max_len) - goto reject_key; - if (is_integer_entry(flags)) - { - if (l == 1 && s[0] == '0') - { - if (key == 'x' || key == 'X') - ; - else if (!isdigit(key)) - goto reject_key; - else if (key == '0') - goto reject_key; - else - l = 0; - } - else if (!isdigit(key)) - goto reject_key; - } - if (is_string_entry(flags) && (flags & FF_UPPERCASE)) - key = toupper(key); - s[l] = key; - s[l + 1] = '\0'; - redraw = true; + if (l >= max_len) + goto reject_key; + if (is_integer_entry(flags)) + { + if (l == 1 && s[0] == '0') + { + if (key == 'x' || key == 'X') + ; + else if (!isdigit(key)) + goto reject_key; + else if (key == '0') + goto reject_key; + else + l = 0; + } + else if (!isdigit(key)) + goto reject_key; + } + if (is_string_entry(flags) && (flags & FF_UPPERCASE)) + key = toupper(key); + s[l] = key; + s[l + 1] = '\0'; + redraw = true; } // [BS]: Backspace else if (key == YK_BACKSPACE) { - if (is_integer_entry(flags) && l == 1) - strcpy(s, "0"); - else if (l > 0) - s[l - 1] = '\0'; - else - goto reject_key; - redraw = true; + if (is_integer_entry(flags) && l == 1) + strcpy(s, "0"); + else if (l > 0) + s[l - 1] = '\0'; + else + goto reject_key; + redraw = true; } // ^A, [Home]: Go to SOL (Emacs/readline, Doskey) else if (key == YK_HOME || key == 1) { - ; + ; } // ^B, [Left]: Go to previous character (Emacs, readline) else if (key == YK_LEFT || key == 2) { - ; + ; } // ^D, [Del]: Delete current character (Emacs, readline) else if (key == YK_DEL || key == 4) { - ; + ; } // ^E, [End]: Go to EOL (Emacs/readline, Doskey) else if (key == YK_END || key == 5) { - ; + ; } // ^F, [Right]: Go to next character (Emacs/readline) else if (key == YK_RIGHT || key == 6) { - ; + ; } // ^K, [Ctrl][End]: Del to EOL (Emacs/readline, Doskey) else if (key == YK_END + YK_CTRL || key == 11) { - ; + ; } // ^U, [Ctrl][Home]: Del to SOL (readline, Doskey) else if (key == YK_HOME + YK_CTRL || key == 21) { - if ((flags & FF_SUBTYPE) == FF_INTEGER) - strcpy(s, "0"); - else - *s = '\0'; - redraw = true; + if ((flags & FF_SUBTYPE) == FF_INTEGER) + strcpy(s, "0"); + else + *s = '\0'; + redraw = true; } // ^W: Del last word (Unix, readline) else if (key == 23) { - while (l > 0 && isspace(s[l - 1])) - l--; - while (l > 0 && !isspace(s[l - 1])) - l--; - if (is_integer_entry(flags) && l == 0) - strcpy(s, "0"); - else - s[l] = '\0'; - redraw = true; + while (l > 0 && isspace(s[l - 1])) + l--; + while (l > 0 && !isspace(s[l - 1])) + l--; + if (is_integer_entry(flags) && l == 0) + strcpy(s, "0"); + else + s[l] = '\0'; + redraw = true; } // ^X: Decrement (Vim) else if (key == 24) { - if (!is_integer_entry(flags)) - goto reject_key; - //v--; - //sprintf (s, "%", v); + if (!is_integer_entry(flags)) + goto reject_key; + //v--; + //sprintf (s, "%", v); } // [Tab]: Next field else if (key == YK_TAB) - next_field(); + next_field(); // [Shift][Tab]: Previous field else if (key == YK_BACKTAB) - prev_field(); + prev_field(); // [Return]: Validate else if (key == YK_RETURN) { - size_t f; - for (f = 0; f < nfields; f++) // No FF_NONEMPTY fields must be empty - if ((entry_flags[f] & FF_TYPE) == FF_ENTRY - && (entry_flags[f] & FF_SUBTYPE) == FF_STRING - && (entry_flags[f] & FF_NONEMPTY) && buf[f][0] == '\0') - break; - if (f == nfields) - return ACT_VALID; - else - { - jump_to_field(f); - Beep(); - } + size_t f; + for (f = 0; f < nfields; f++) // No FF_NONEMPTY fields must be empty + if ((entry_flags[f] & FF_TYPE) == FF_ENTRY + && (entry_flags[f] & FF_SUBTYPE) == FF_STRING + && (entry_flags[f] & FF_NONEMPTY) && buf[f][0] == '\0') + break; + if (f == nfields) + return ACT_VALID; + else + { + jump_to_field(f); + Beep(); + } } // [Esc]: Cancel else if (key == YK_ESC) - return ACT_CANCEL; + return ACT_CANCEL; else { reject_key: - Beep(); + Beep(); } if (redraw) - entry_drawn[field_no] = false; + entry_drawn[field_no] = false; return ACT_NONE; } /* - * refresh - * Update the display + * refresh + * Update the display */ void Entry2::refresh() { @@ -295,64 +295,64 @@ changes unless the window is obscured). */ if (!background_drawn) { - if (!geom_up_to_date) - do_geom(); + if (!geom_up_to_date) + do_geom(); - DrawScreenBox3D(win_x0, win_y0, win_x1, win_y1); - push_colour(WINTITLE); - DrawScreenString(title_x0, title_y0, title); - set_colour(WINFG); - for (size_t f = 0; f < nfields; f++) - { - size_t yofs = f * vstep; - DrawScreenString(caption_x0, caption_y0 + yofs, caption[f]); - DrawScreenBoxHollow(entry_box_x0, - entry_box_y0 + yofs, - entry_box_x0 + box_len[f] * FONTW + - 2 * entry_hofs - 1, entry_box_y1 + yofs, - BLACK); - } - pop_colour(); + DrawScreenBox3D(win_x0, win_y0, win_x1, win_y1); + push_colour(WINTITLE); + DrawScreenString(title_x0, title_y0, title); + set_colour(WINFG); + for (size_t f = 0; f < nfields; f++) + { + size_t yofs = f * vstep; + DrawScreenString(caption_x0, caption_y0 + yofs, caption[f]); + DrawScreenBoxHollow(entry_box_x0, + entry_box_y0 + yofs, + entry_box_x0 + box_len[f] * FONTW + + 2 * entry_hofs - 1, entry_box_y1 + yofs, + BLACK); + } + pop_colour(); } /* Draw the foreground (the part that might change as a result of the user actions). */ for (size_t f = 0; f < nfields; f++) { - if (!background_drawn || !entry_drawn[f]) - { - size_t l = strlen(buf[f]); - int yofs = f * vstep; - set_colour(BLACK); - DrawScreenBox(entry_text_x0, - entry_text_y0 + yofs, - entry_text_x0 + box_len[f] * FONTW - 1, - entry_text_y1 + yofs); - set_colour(WINFG); - if (l >= box_len[f]) - { - DrawScreenText(entry_text_x0, entry_text_y0 + yofs, "<%s", - buf[f] + l - (box_len[f] - 2)); - } - else - DrawScreenString(entry_text_x0, entry_text_y0 + yofs, buf[f]); - if (f != field_no) - entry_drawn[f] = true; - } + if (!background_drawn || !entry_drawn[f]) + { + size_t l = strlen(buf[f]); + int yofs = f * vstep; + set_colour(BLACK); + DrawScreenBox(entry_text_x0, + entry_text_y0 + yofs, + entry_text_x0 + box_len[f] * FONTW - 1, + entry_text_y1 + yofs); + set_colour(WINFG); + if (l >= box_len[f]) + { + DrawScreenText(entry_text_x0, entry_text_y0 + yofs, "<%s", + buf[f] + l - (box_len[f] - 2)); + } + else + DrawScreenString(entry_text_x0, entry_text_y0 + yofs, buf[f]); + if (f != field_no) + entry_drawn[f] = true; + } } // Draw the cursor if (!background_drawn || !entry_drawn[field_no]) { - push_colour(WINFG); - int cur_pos = strlen(buf[field_no]); - if (cur_pos >= box_len[field_no]) - cur_pos = box_len[field_no] - 1; - int x = entry_text_x0 + cur_pos * FONTW; - int y = entry_text_y0 + field_no * vstep; - DrawScreenBoxwh(x, y, FONTW, FONTH); - pop_colour(); - entry_drawn[field_no] = true; + push_colour(WINFG); + int cur_pos = strlen(buf[field_no]); + if (cur_pos >= box_len[field_no]) + cur_pos = box_len[field_no] - 1; + int x = entry_text_x0 + cur_pos * FONTW; + int y = entry_text_y0 + field_no * vstep; + DrawScreenBoxwh(x, y, FONTW, FONTH); + pop_colour(); + entry_drawn[field_no] = true; } background_drawn = true; @@ -360,30 +360,30 @@ /* - * PRIVATE METHODS + * PRIVATE METHODS */ /* - * count_widget - * Return the number of widgets found in . + * count_widget + * Return the number of widgets found in . */ int Entry2::count_widgets(const char *fmt) { int nwidgets = 0; for (const char *p = fmt; *p; p++) { - if (p[0] == '%' && p[1] != '%') - nwidgets++; + if (p[0] == '%' && p[1] != '%') + nwidgets++; } return nwidgets; } /* - * fill_in_widgets_info - * Parse and fill in the widgets info arrays. - * Return 0 on success, non-zero on error. + * fill_in_widgets_info + * Parse and fill in the widgets info arrays. + * Return 0 on success, non-zero on error. */ int Entry2::fill_in_widgets_info(const char *fmt, va_list args) { @@ -401,167 +401,167 @@ for (const char *p = fmt;;) { - if (*p == '%') - { - p++; - // Got %% - if (*p == '%') - { - if (!last_literal) - last_literal = p - 1; - p++; - continue; - } - // Got a real %-field - if (f >= nfields) - { - printf - ("Internal error: at offset %d in widget fmt \"%s\": more than" - " %d fields.\nIgnoring excess field(s)\n", - (int) (p - fmt), fmt, (int) f); - break; - } - int flags = 0; - int length = L_OMITTED; - int precision = L_OMITTED; - char type = 0; - // Get the flag - for (;;) - { - if (*p == '+') - { - flags |= F_PLUS; - p++; - } - else if (*p == '-') - { - flags |= F_MINUS; - p++; - } - else if (*p == '0') - { - flags |= F_ZERO; - p++; - } - else - break; - } - // Get the optional length - if (*p == '*') - { - length = L_ASTERISK; - p++; - } - else if (isdigit((unsigned char) *p)) - { - length = 0; - while (isdigit((unsigned char) *p)) - length = 10 * length + dectoi(*p++); - } - // Get the optional precision - if (*p == '.') - { - p++; - if (*p == '*') - { - precision = L_ASTERISK; - p++; - } - else if (!isdigit((unsigned char) *p)) - { - printf - ("Internal error: at offset %d in widget fmt \"%s\": bad" - " precision spec \"%c\"\n", (int) (p - fmt), fmt, - *p); - break; - } - else - { - precision = 0; - while (isdigit((unsigned char) *p)) - precision = 10 * precision + dectoi(*p++); - } - } - // Get the optional modifier (hh, h, l or Z) - _field_flags_t size = FF_INT; - if (*p == 'h') - { - if (p[1] == 'h') - { - size = FF_CHAR; - p += 2; - } - else - { - size = FF_SHORT; - p++; - } - } - else if (*p == 'Z') - { - size = FF_SIZE_T; - p++; - } - else if (*p == 'l') - { - size = FF_LONG; - p++; - } - // Get the type (diousSxX) - if (*p == 'd' || *p == 'i' || *p == 'o' || *p == 'x' || *p == 'X') - type = 'd'; - else if (*p == 'u') - type = 'u'; - else if (*p == 's') - type = 's'; - else if (*p == 'S') - type = 'S'; - else - { - printf - ("Internal error: at offset %d in widget fmt \"%s\": bad" - " format \"%c\"\n", (int) (p - fmt), fmt, *p); - continue; - } - p++; + if (*p == '%') + { + p++; + // Got %% + if (*p == '%') + { + if (!last_literal) + last_literal = p - 1; + p++; + continue; + } + // Got a real %-field + if (f >= nfields) + { + printf + ("Internal error: at offset %d in widget fmt \"%s\": more than" + " %d fields.\nIgnoring excess field(s)\n", + (int) (p - fmt), fmt, (int) f); + break; + } + int flags = 0; + int length = L_OMITTED; + int precision = L_OMITTED; + char type = 0; + // Get the flag + for (;;) + { + if (*p == '+') + { + flags |= F_PLUS; + p++; + } + else if (*p == '-') + { + flags |= F_MINUS; + p++; + } + else if (*p == '0') + { + flags |= F_ZERO; + p++; + } + else + break; + } + // Get the optional length + if (*p == '*') + { + length = L_ASTERISK; + p++; + } + else if (isdigit((unsigned char) *p)) + { + length = 0; + while (isdigit((unsigned char) *p)) + length = 10 * length + dectoi(*p++); + } + // Get the optional precision + if (*p == '.') + { + p++; + if (*p == '*') + { + precision = L_ASTERISK; + p++; + } + else if (!isdigit((unsigned char) *p)) + { + printf + ("Internal error: at offset %d in widget fmt \"%s\": bad" + " precision spec \"%c\"\n", (int) (p - fmt), fmt, + *p); + break; + } + else + { + precision = 0; + while (isdigit((unsigned char) *p)) + precision = 10 * precision + dectoi(*p++); + } + } + // Get the optional modifier (hh, h, l or Z) + _field_flags_t size = FF_INT; + if (*p == 'h') + { + if (p[1] == 'h') + { + size = FF_CHAR; + p += 2; + } + else + { + size = FF_SHORT; + p++; + } + } + else if (*p == 'Z') + { + size = FF_SIZE_T; + p++; + } + else if (*p == 'l') + { + size = FF_LONG; + p++; + } + // Get the type (diousSxX) + if (*p == 'd' || *p == 'i' || *p == 'o' || *p == 'x' || *p == 'X') + type = 'd'; + else if (*p == 'u') + type = 'u'; + else if (*p == 's') + type = 's'; + else if (*p == 'S') + type = 'S'; + else + { + printf + ("Internal error: at offset %d in widget fmt \"%s\": bad" + " format \"%c\"\n", (int) (p - fmt), fmt, *p); + continue; + } + p++; - /* Fill in and and - also and if - they're explicit. */ - box_len[f] = precision; - buf[f] = 0; - buf_max_len[f] = length; - if (type == 'd') - entry_flags[f] = - (_field_flags_t) (FF_ENTRY | FF_INTEGER | FF_SIGNED); - else if (type == 'u') - entry_flags[f] = (_field_flags_t) (FF_ENTRY | FF_INTEGER); - else if (type == 's' || type == 'S') - { - entry_flags[f] = (_field_flags_t) (FF_ENTRY | FF_STRING); - if (type == 'S') - entry_flags[f] = - (_field_flags_t) (entry_flags[f] | FF_UPPERCASE); - if (flags & F_PLUS) - entry_flags[f] = - (_field_flags_t) (entry_flags[f] | FF_NONEMPTY); - } - else - entry_flags[f] = (_field_flags_t) 0; // Ouch ! - caption[f] = last_literal; + /* Fill in and and + also and if + they're explicit. */ + box_len[f] = precision; + buf[f] = 0; + buf_max_len[f] = length; + if (type == 'd') + entry_flags[f] = + (_field_flags_t) (FF_ENTRY | FF_INTEGER | FF_SIGNED); + else if (type == 'u') + entry_flags[f] = (_field_flags_t) (FF_ENTRY | FF_INTEGER); + else if (type == 's' || type == 'S') + { + entry_flags[f] = (_field_flags_t) (FF_ENTRY | FF_STRING); + if (type == 'S') + entry_flags[f] = + (_field_flags_t) (entry_flags[f] | FF_UPPERCASE); + if (flags & F_PLUS) + entry_flags[f] = + (_field_flags_t) (entry_flags[f] | FF_NONEMPTY); + } + else + entry_flags[f] = (_field_flags_t) 0; // Ouch ! + caption[f] = last_literal; - // On to the next field - f++; - last_literal = 0; - } - else - { - if (*p == '\0') - break; - if (!last_literal) - last_literal = p; - p++; - } + // On to the next field + f++; + last_literal = 0; + } + else + { + if (*p == '\0') + break; + if (!last_literal) + last_literal = p; + p++; + } } /* Second phase: retrieve the arguments from @@ -569,95 +569,95 @@ and if needed. */ for (size_t f = 0; f < nfields; f++) { - // "%*": retrieve the length - if (buf_max_len[f] == L_ASTERISK) - buf_max_len[f] = va_arg(args, size_t); + // "%*": retrieve the length + if (buf_max_len[f] == L_ASTERISK) + buf_max_len[f] = va_arg(args, size_t); - // "%.*": retrieve the precision - if (box_len[f] == L_ASTERISK) - box_len[f] = va_arg(args, size_t); + // "%.*": retrieve the precision + if (box_len[f] == L_ASTERISK) + box_len[f] = va_arg(args, size_t); - // Retrieve the pointer on the buffer - if ((entry_flags[f] & FF_TYPE) == FF_ENTRY) - { - if ((entry_flags[f] & FF_SUBTYPE) == FF_STRING) - { - buf[f] = va_arg(args, char *); - if (buf_max_len[f] == L_OMITTED) - buf_max_len[f] = strlen(buf[f]); // Bletch ! - if (box_len[f] == L_OMITTED) - box_len[f] = y_min(buf_max_len[f], 30); - } - else if ((entry_flags[f] & FF_SUBTYPE) == FF_INTEGER) - { - switch (entry_flags[f] & FF_INTSIZE) - { - case FF_CHAR: - buf[f] = (char *) va_arg(args, char *); - break; - case FF_SHORT: - buf[f] = (char *) va_arg(args, short *); - break; - case FF_INT: - buf[f] = (char *) va_arg(args, int *); - break; - case FF_SIZE_T: - buf[f] = (char *) va_arg(args, size_t *); - break; - case FF_LONG: - buf[f] = (char *) va_arg(args, long *); - break; - default: - ; // FIXME - } - } - else; // FIXME - } - else; // To be implemented later + // Retrieve the pointer on the buffer + if ((entry_flags[f] & FF_TYPE) == FF_ENTRY) + { + if ((entry_flags[f] & FF_SUBTYPE) == FF_STRING) + { + buf[f] = va_arg(args, char *); + if (buf_max_len[f] == L_OMITTED) + buf_max_len[f] = strlen(buf[f]); // Bletch ! + if (box_len[f] == L_OMITTED) + box_len[f] = y_min(buf_max_len[f], 30); + } + else if ((entry_flags[f] & FF_SUBTYPE) == FF_INTEGER) + { + switch (entry_flags[f] & FF_INTSIZE) + { + case FF_CHAR: + buf[f] = (char *) va_arg(args, char *); + break; + case FF_SHORT: + buf[f] = (char *) va_arg(args, short *); + break; + case FF_INT: + buf[f] = (char *) va_arg(args, int *); + break; + case FF_SIZE_T: + buf[f] = (char *) va_arg(args, size_t *); + break; + case FF_LONG: + buf[f] = (char *) va_arg(args, long *); + break; + default: + ; // FIXME + } + } + else; // FIXME + } + else; // To be implemented later } return 0; } /* - * do_geom - * Do geometry computations + * do_geom + * Do geometry computations */ void Entry2::do_geom() { // Compute the widths - size_t title_len = strlen(title); // Length of title - size_t entry_len = 0; // Length or longest entry + size_t title_len = strlen(title); // Length of title + size_t entry_len = 0; // Length or longest entry for (size_t f = 0; f < nfields; f++) { - size_t l = box_len[f]; - if (l > entry_len) - entry_len = l; + size_t l = box_len[f]; + if (l > entry_len) + entry_len = l; } - size_t caption_len = 0; // Length of longest caption + size_t caption_len = 0; // Length of longest caption for (size_t f = 0; f < nfields; f++) { - size_t l = strlen(caption[f]); - if (l > caption_len) - caption_len = l; + size_t l = strlen(caption[f]); + if (l > caption_len) + caption_len = l; } size_t entry_width = FONTW * entry_len + 2 * entry_hofs; size_t caption_width = FONTW * caption_len + WIDE_HSPACING; size_t inner_width = - y_max(entry_width + caption_width, FONTW * title_len); + y_max(entry_width + caption_width, FONTW * title_len); size_t outer_width = inner_width + 2 * win_hofs; // Compute the heights vstep = FONTH + 2 * entry_vofs + BOX_VSPACING; size_t inner_height = - nfields * vstep - BOX_VSPACING + title_vspacing + FONTH; + nfields * vstep - BOX_VSPACING + title_vspacing + FONTH; size_t outer_height = inner_height + 2 * win_vofs; // Compute the absolute coordinates if (win_x0 < 0) - win_x0 = (ScrMaxX - outer_width) / 2; + win_x0 = (ScrMaxX - outer_width) / 2; if (win_y0 < 0) - win_y0 = (ScrMaxY - outer_height) / 2; + win_y0 = (ScrMaxY - outer_height) / 2; win_x1 = win_x0 + outer_width - 1; win_y1 = win_y0 + outer_height - 1; title_x0 = win_x0 + win_hofs; @@ -670,24 +670,24 @@ caption_x0 = title_x0; entry_box_x0 = caption_x0 + caption_width; entry_text_x0 = entry_box_x0 + entry_hofs; - entry_text_x1 = entry_text_x0 + entry_len * FONTW - 1; // Unused - entry_box_x1 = entry_text_x1 + entry_hofs; // Unused + entry_text_x1 = entry_text_x0 + entry_len * FONTW - 1; // Unused + entry_box_x1 = entry_text_x1 + entry_hofs; // Unused geom_up_to_date = true; } /* - * jump_to_field - * Jump to a particular field + * jump_to_field + * Jump to a particular field */ void Entry2::jump_to_field(size_t field_no) { if (field_no >= nfields) { - printf("Internal error: Entry2::jump_to_field %d (nf=%d)", - (int) field_no, (int) nfields); - return; + printf("Internal error: Entry2::jump_to_field %d (nf=%d)", + (int) field_no, (int) nfields); + return; } entry_drawn[this->field_no] = false; entry_drawn[field_no] = false; @@ -697,31 +697,31 @@ /* - * prev_field + * prev_field */ void Entry2::prev_field() { if (nfields < 1) - return; + return; size_t f = field_no; if (f < 1) - f = nfields - 1; + f = nfields - 1; else - f--; + f--; jump_to_field(f); } /* - * next_field + * next_field */ void Entry2::next_field() { if (nfields < 1) - return; + return; size_t f = field_no + 1; if (f >= nfields) - f = 0; + f = 0; jump_to_field(f); } diff -r 594dea11ccd9 -r a68786b9c74b src/entry2.h --- a/src/entry2.h Sat Sep 24 15:01:56 2011 +0300 +++ b/src/entry2.h Sat Sep 24 15:59:33 2011 +0300 @@ -1,12 +1,12 @@ /* - * entry2.h - * A string entry box class - * AYM 1999-04-12 + * entry2.h + * A string entry box class + * AYM 1999-04-12 */ -#ifndef YH_ENTRY2 /* To prevent multiple inclusion */ -#define YH_ENTRY2 /* To prevent multiple inclusion */ +#ifndef YH_ENTRY2 /* To prevent multiple inclusion */ +#define YH_ENTRY2 /* To prevent multiple inclusion */ typedef enum @@ -19,26 +19,26 @@ class Entry2 { - typedef enum // Strictly private to the class + typedef enum // Strictly private to the class { - FF_TYPE = 0xf000, // Type mask - FF_ENTRY = 0x0000, // Entry - FF_CHECK = 0x1000, // Check button (unimplemented) - FF_RADIO = 0x2000, // Radio button (unimplemented) - FF_BUTTON = 0x3000, // Button (unimplemented) - FF_SUBTYPE = 0x0f00, // Subtype mask - FF_STRING = 0x0000, // Entry: String entry - FF_INTEGER = 0x0100, // Entry: Integer entry - FF_UPPERCASE = 0x0001, // String entry: upper-case everything - FF_NONEMPTY = 0x0002, // String entry: can't be empty - FF_SIGNED = 0x0001, // Integer entry: it can be signed (unimplemented) - FF_INTSIZE = 0x000e, // Integer entry: size mask - FF_CHAR = 0x0000, // char (signed or unsigned) - FF_SHORT = 0x0002, // short (signed or unsigned) - FF_INT = 0x0004, // int (signed or unsigned) - FF_SIZE_T = 0x0006, // size_t - FF_LONG = 0x0008, // long (signed or unsigned) - FF__ + FF_TYPE = 0xf000, // Type mask + FF_ENTRY = 0x0000, // Entry + FF_CHECK = 0x1000, // Check button (unimplemented) + FF_RADIO = 0x2000, // Radio button (unimplemented) + FF_BUTTON = 0x3000, // Button (unimplemented) + FF_SUBTYPE = 0x0f00, // Subtype mask + FF_STRING = 0x0000, // Entry: String entry + FF_INTEGER = 0x0100, // Entry: Integer entry + FF_UPPERCASE = 0x0001, // String entry: upper-case everything + FF_NONEMPTY = 0x0002, // String entry: can't be empty + FF_SIGNED = 0x0001, // Integer entry: it can be signed (unimplemented) + FF_INTSIZE = 0x000e, // Integer entry: size mask + FF_CHAR = 0x0000, // char (signed or unsigned) + FF_SHORT = 0x0002, // short (signed or unsigned) + FF_INT = 0x0004, // int (signed or unsigned) + FF_SIZE_T = 0x0006, // size_t + FF_LONG = 0x0008, // long (signed or unsigned) + FF__ } _field_flags_t; public:Entry2(const char *title, const char *fmt, ...); @@ -103,14 +103,14 @@ // Convenience functions. bool is_integer_entry(_field_flags_t flags) { - return (flags & FF_TYPE) == FF_ENTRY - && (flags & FF_SUBTYPE) == FF_INTEGER; + return (flags & FF_TYPE) == FF_ENTRY + && (flags & FF_SUBTYPE) == FF_INTEGER; } bool is_string_entry(_field_flags_t flags) { - return (flags & FF_TYPE) == FF_ENTRY - && (flags & FF_SUBTYPE) == FF_STRING; + return (flags & FF_TYPE) == FF_ENTRY + && (flags & FF_SUBTYPE) == FF_STRING; } }; diff -r 594dea11ccd9 -r a68786b9c74b src/events.cc --- a/src/events.cc Sat Sep 24 15:01:56 2011 +0300 +++ b/src/events.cc Sat Sep 24 15:59:33 2011 +0300 @@ -1,7 +1,7 @@ /* - * events.c - * Half baked internal event handling. - * AYM 1998-11-09 + * events.c + * Half baked internal event handling. + * AYM 1998-11-09 */ @@ -74,15 +74,15 @@ void send_event(int event) { if (events_in_queue == Y_EVENT_QUEUE) - fatal_error("Event buffer full"); + fatal_error("Event buffer full"); event_queue[(head + events_in_queue) % Y_EVENT_QUEUE] = event; events_in_queue++; } /* - * has_event - * Is there any event at all ? + * has_event + * Is there any event at all ? */ int has_event() { @@ -91,8 +91,8 @@ /* - * has_event - * Is there an event of that type ? + * has_event + * Is there an event of that type ? */ int has_event(int event) { @@ -101,31 +101,31 @@ /* - * has_key_press_event - * Is there an YK_* event ? - * FIXME should create YE_KEY_PRESS and delete this function. + * has_key_press_event + * Is there an YK_* event ? + * FIXME should create YE_KEY_PRESS and delete this function. */ int has_key_press_event() { return events_in_queue != 0 - && event_queue[head] - && (event_queue[head] & ~(YK_ALT | YK_CTRL | YK_SHIFT)) < YK__LAST; + && event_queue[head] + && (event_queue[head] & ~(YK_ALT | YK_CTRL | YK_SHIFT)) < YK__LAST; } /* - * get_event - * Get the next event + * get_event + * Get the next event */ int get_event() { - if (events_in_queue == 0) // The buffer is empty - return 0; + if (events_in_queue == 0) // The buffer is empty + return 0; int e = event_queue[head]; events_in_queue--; head++; if (head == Y_EVENT_QUEUE) - head = 0; + head = 0; return e; } diff -r 594dea11ccd9 -r a68786b9c74b src/events.h --- a/src/events.h Sat Sep 24 15:01:56 2011 +0300 +++ b/src/events.h Sat Sep 24 15:59:33 2011 +0300 @@ -1,6 +1,6 @@ /* - * events.h - * AYM 1998-11-09 + * events.h + * AYM 1998-11-09 */ diff -r 594dea11ccd9 -r a68786b9c74b src/flats.cc --- a/src/flats.cc Sat Sep 24 15:01:56 2011 +0300 +++ b/src/flats.cc Sat Sep 24 15:59:33 2011 +0300 @@ -1,6 +1,6 @@ /* - * flats.cc - * AYM 1998-??-?? + * flats.cc + * AYM 1998-??-?? */ @@ -47,33 +47,33 @@ */ void ChooseFloorTexture(int x0, int y0, const char *prompt, int listsize, - char **list, char *name) + char **list, char *name) { (void) list; (void) listsize; // Build a list of char *, for InputNameFromListWithFunc()'s sake char **flat_names = (char **) GetMemory(NumFTexture * sizeof *flat_names); for (size_t n = 0; n < NumFTexture; n++) - flat_names[n] = flat_list[n].name; + flat_names[n] = flat_list[n].name; InputNameFromListWithFunc(x0, y0, prompt, (size_t) NumFTexture, - flat_names, 5, name, 64, 64, - DisplayFloorTexture); + flat_names, 5, name, 64, 64, + DisplayFloorTexture); FreeMemory(flat_names); } /* - * flat_list_entry_match - * Function used by bsearch() to locate a particular - * flat in the FTexture. + * flat_list_entry_match + * Function used by bsearch() to locate a particular + * flat in the FTexture. */ static int flat_list_entry_match(const void *key, const void *flat_list_entry) { return y_strnicmp((const char *) key, - ((const flat_list_entry_t *) flat_list_entry)->name, - WAD_FLAT_NAME); + ((const flat_list_entry_t *) flat_list_entry)->name, + WAD_FLAT_NAME); } @@ -84,34 +84,34 @@ void DisplayFloorTexture(hookfunc_comm_t * c) { - c->width = DOOM_FLAT_WIDTH; // Big deal ! + c->width = DOOM_FLAT_WIDTH; // Big deal ! c->height = DOOM_FLAT_HEIGHT; c->flags = HOOK_SIZE_VALID; flat_list_entry_t *flat = (flat_list_entry_t *) - bsearch(c->name, flat_list, NumFTexture, sizeof *flat_list, - flat_list_entry_match); - if (flat == 0) // Not found in list + bsearch(c->name, flat_list, NumFTexture, sizeof *flat_list, + flat_list_entry_match); + if (flat == 0) // Not found in list { - push_colour(WINBG); - DrawScreenBox(c->x0, c->y0, c->x1, c->y1); - set_colour(WINFG_DIM); - DrawScreenLine(c->x0, c->y0, c->x1, c->y1); - DrawScreenLine(c->x0, c->y1, c->x1, c->y0); - pop_colour(); - return; + push_colour(WINBG); + DrawScreenBox(c->x0, c->y0, c->x1, c->y1); + set_colour(WINFG_DIM); + DrawScreenLine(c->x0, c->y0, c->x1, c->y1); + DrawScreenLine(c->x0, c->y1, c->x1, c->y0); + pop_colour(); + return; } c->lump_loc.wad = flat->wadfile; c->lump_loc.ofs = flat->offset; - c->lump_loc.len = DOOM_FLAT_WIDTH * DOOM_FLAT_HEIGHT; // Sorry. + c->lump_loc.len = DOOM_FLAT_WIDTH * DOOM_FLAT_HEIGHT; // Sorry. c->flags |= HOOK_LOC_VALID; const Wad_file *wadfile = flat->wadfile; wadfile->seek(flat->offset); if (wadfile->error()) { - warn("%s: can't seek to %lXh\n", - wadfile->pathname(), (unsigned long) flat->offset); - warn("%.8s: seek error\n", c->name); + warn("%s: can't seek to %lXh\n", + wadfile->pathname(), (unsigned long) flat->offset); + warn("%.8s: seek error\n", c->name); } c->img.resize(c->width, c->height); @@ -120,10 +120,10 @@ wadfile->read_bytes(c->img.wbuf(), nbytes); if (wadfile->error()) { - warn("%s: read error\n", wadfile->where()); - warn("%.8s: short read\n", c->name); + warn("%s: read error\n", wadfile->where()); + warn("%.8s: short read\n", c->name); } - Sticker sticker(c->img, true); // Use opaque because it's faster + Sticker sticker(c->img, true); // Use opaque because it's faster sticker.draw(drw, 't', c->x0, c->y0); c->disp_x0 = c->x0; @@ -136,13 +136,13 @@ /* - * display_flat_depressed - * Display a flat inside a hollow box + * display_flat_depressed + * Display a flat inside a hollow box */ void display_flat_depressed(hookfunc_comm_t * c) { draw_box_border(c->x0, c->y0, c->x1 - c->x0 + 1, c->y1 - c->y0 + 1, - HOLLOW_BORDER, 0); + HOLLOW_BORDER, 0); c->x0 += HOLLOW_BORDER; c->y0 += HOLLOW_BORDER; c->x1 -= HOLLOW_BORDER; diff -r 594dea11ccd9 -r a68786b9c74b src/flats.h --- a/src/flats.h Sat Sep 24 15:01:56 2011 +0300 +++ b/src/flats.h Sat Sep 24 15:59:33 2011 +0300 @@ -1,10 +1,10 @@ /* - * flats.h - * AYM 1998-nn-nn + * flats.h + * AYM 1998-nn-nn */ -#ifndef YH_FLATS /* DO NOT INSERT ANYTHING BEFORE THIS LINE */ +#ifndef YH_FLATS /* DO NOT INSERT ANYTHING BEFORE THIS LINE */ #define YH_FLATS diff -r 594dea11ccd9 -r a68786b9c74b src/game.cc --- a/src/game.cc Sat Sep 24 15:01:56 2011 +0300 +++ b/src/game.cc Sat Sep 24 15:59:33 2011 +0300 @@ -1,7 +1,7 @@ /* - * game.cc - * Load .ygd file (Yadex Game Definitions) - * AYM 1998-01-04 + * game.cc + * Load .ygd file (Yadex Game Definitions) + * AYM 1998-01-04 */ @@ -41,8 +41,8 @@ /* - * InitGameDefs - * Create empty lists for game definitions + * InitGameDefs + * Create empty lists for game definitions */ void InitGameDefs(void) { @@ -55,18 +55,18 @@ /* - * LoadGameDefs - * Looks for file .ygd in various directories and reads it. - * Builds list ThingsDefs. - * A totally boring piece of code. + * LoadGameDefs + * Looks for file .ygd in various directories and reads it. + * Builds list ThingsDefs. + * A totally boring piece of code. */ void LoadGameDefs(const char *game) { - FILE *ygdfile = 0; /* YGD file descriptor */ -#define YGD_BUF 200 /* max. line length + 2 */ - char readbuf[YGD_BUF]; /* buffer the line is read into */ -#define MAX_TOKENS 10 /* tokens per line */ - int lineno; /* current line of file */ + FILE *ygdfile = 0; /* YGD file descriptor */ +#define YGD_BUF 200 /* max. line length + 2 */ + char readbuf[YGD_BUF]; /* buffer the line is read into */ +#define MAX_TOKENS 10 /* tokens per line */ + int lineno; /* current line of file */ char filename[1025]; char basename[256]; @@ -75,284 +75,284 @@ /* Locate the game definition file. */ { - Locate locate(yadex_share_path, basename, false); - const char *pathname = locate.get_next(); - if (pathname == NULL) - fatal_error("Game definition file \"%s\" not found", basename); - if (strlen(pathname) > sizeof filename - 1) - fatal_error("%s: file name too long"); - strcpy(filename, pathname); - printf("Reading game definition file \"%s\".\n", filename); + Locate locate(yadex_share_path, basename, false); + const char *pathname = locate.get_next(); + if (pathname == NULL) + fatal_error("Game definition file \"%s\" not found", basename); + if (strlen(pathname) > sizeof filename - 1) + fatal_error("%s: file name too long"); + strcpy(filename, pathname); + printf("Reading game definition file \"%s\".\n", filename); } ygdfile = fopen(filename, "r"); if (ygdfile == NULL) - fatal_error("%s: %s", filename, strerror(errno)); + fatal_error("%s: %s", filename, strerror(errno)); /* The first line of the ygd file must contain exactly ygd_file_magic. */ if (fgets(readbuf, sizeof readbuf, ygdfile) == NULL - || memcmp(readbuf, ygd_file_magic, sizeof ygd_file_magic - 1) - || readbuf[sizeof ygd_file_magic - 1] != '\n' - || readbuf[sizeof ygd_file_magic] != '\0') + || memcmp(readbuf, ygd_file_magic, sizeof ygd_file_magic - 1) + || readbuf[sizeof ygd_file_magic - 1] != '\n' + || readbuf[sizeof ygd_file_magic] != '\0') { - err("%s is not a valid Yadex game definition file", filename); - fatal_error("Perhaps a leftover from a previous version of Yadex ?"); + err("%s is not a valid Yadex game definition file", filename); + fatal_error("Perhaps a leftover from a previous version of Yadex ?"); } /* Read the game definition file, line by line. */ for (lineno = 2; fgets(readbuf, sizeof readbuf, ygdfile); lineno++) { - int ntoks; - char *token[MAX_TOKENS]; - int quoted; - int in_token; - const char *iptr; - char *optr; - char *buf; - const char *const bad_arg_count = - "%s(%d): directive \"%s\" takes %d parameters"; + int ntoks; + char *token[MAX_TOKENS]; + int quoted; + int in_token; + const char *iptr; + char *optr; + char *buf; + const char *const bad_arg_count = + "%s(%d): directive \"%s\" takes %d parameters"; - /* duplicate the buffer */ - buf = (char *) malloc(strlen(readbuf) + 1); - if (!buf) - fatal_error("not enough memory"); + /* duplicate the buffer */ + buf = (char *) malloc(strlen(readbuf) + 1); + if (!buf) + fatal_error("not enough memory"); - /* break the line into whitespace-separated tokens. - whitespace can be enclosed in double quotes. */ - for (in_token = 0, quoted = 0, iptr = readbuf, optr = buf, ntoks = 0;; - iptr++) - { - if (*iptr == '\n' || *iptr == '\0') - { - if (in_token) - *optr = '\0'; - break; - } + /* break the line into whitespace-separated tokens. + whitespace can be enclosed in double quotes. */ + for (in_token = 0, quoted = 0, iptr = readbuf, optr = buf, ntoks = 0;; + iptr++) + { + if (*iptr == '\n' || *iptr == '\0') + { + if (in_token) + *optr = '\0'; + break; + } - else if (*iptr == '"') - quoted ^= 1; + else if (*iptr == '"') + quoted ^= 1; - // "#" at the beginning of a token - else if (!in_token && !quoted && *iptr == '#') - break; + // "#" at the beginning of a token + else if (!in_token && !quoted && *iptr == '#') + break; - // First character of token - else if (!in_token && (quoted || !isspace(*iptr))) - { - if (ntoks >= (int) (sizeof token / sizeof *token)) - fatal_error("%s(%d): more than %d tokens", - filename, lineno, - sizeof token / sizeof *token); - token[ntoks] = optr; - ntoks++; - in_token = 1; - *optr++ = *iptr; - } + // First character of token + else if (!in_token && (quoted || !isspace(*iptr))) + { + if (ntoks >= (int) (sizeof token / sizeof *token)) + fatal_error("%s(%d): more than %d tokens", + filename, lineno, + sizeof token / sizeof *token); + token[ntoks] = optr; + ntoks++; + in_token = 1; + *optr++ = *iptr; + } - // First space between two tokens - else if (in_token && !quoted && isspace(*iptr)) - { - *optr++ = '\0'; - in_token = 0; - } + // First space between two tokens + else if (in_token && !quoted && isspace(*iptr)) + { + *optr++ = '\0'; + in_token = 0; + } - // Character in the middle of a token - else if (in_token) - *optr++ = *iptr; - } - if (quoted) - fatal_error("%s(%d): unmatched double quote", filename, lineno); + // Character in the middle of a token + else if (in_token) + *optr++ = *iptr; + } + if (quoted) + fatal_error("%s(%d): unmatched double quote", filename, lineno); - /* process line */ - if (ntoks == 0) - { - free(buf); - continue; - } - if (!strcmp(token[0], "ldt")) - { - ldtdef_t buf; + /* process line */ + if (ntoks == 0) + { + free(buf); + continue; + } + if (!strcmp(token[0], "ldt")) + { + ldtdef_t buf; - if (ntoks != 5) - fatal_error(bad_arg_count, filename, lineno, token[0], 4); - buf.number = atoi(token[1]); - buf.ldtgroup = *token[2]; - buf.shortdesc = token[3]; /* FIXME: trunc to 16 char. */ - buf.longdesc = token[4]; /* FIXME: trunc reasonably */ - if (al_lwrite(ldtdef, &buf)) - fatal_error("LGD1 (%s)", al_astrerror(al_aerrno)); - } - else if (!strcmp(token[0], "ldtgroup")) - { - ldtgroup_t buf; + if (ntoks != 5) + fatal_error(bad_arg_count, filename, lineno, token[0], 4); + buf.number = atoi(token[1]); + buf.ldtgroup = *token[2]; + buf.shortdesc = token[3]; /* FIXME: trunc to 16 char. */ + buf.longdesc = token[4]; /* FIXME: trunc reasonably */ + if (al_lwrite(ldtdef, &buf)) + fatal_error("LGD1 (%s)", al_astrerror(al_aerrno)); + } + else if (!strcmp(token[0], "ldtgroup")) + { + ldtgroup_t buf; - if (ntoks != 3) - fatal_error(bad_arg_count, filename, lineno, token[0], 2); - buf.ldtgroup = *token[1]; - buf.desc = token[2]; - if (al_lwrite(ldtgroup, &buf)) - fatal_error("LGD2 (%s)", al_astrerror(al_aerrno)); - } - else if (!strcmp(token[0], "level_format")) - { - if (ntoks != 2) - fatal_error(bad_arg_count, filename, lineno, token[0], 1); - if (!strcmp(token[1], "alpha")) - yg_level_format = YGLF_ALPHA; - else if (!strcmp(token[1], "doom")) - yg_level_format = YGLF_DOOM; - else if (!strcmp(token[1], "hexen")) - yg_level_format = YGLF_HEXEN; - else - fatal_error - ("%s(%d): invalid argument \"%.32s\" (alpha|doom|hexen)", - filename, lineno, token[1]); - free(buf); - } - else if (!strcmp(token[0], "level_name")) - { - if (ntoks != 2) - fatal_error(bad_arg_count, filename, lineno, token[0], 1); - if (!strcmp(token[1], "e1m1")) - yg_level_name = YGLN_E1M1; - else if (!strcmp(token[1], "e1m10")) - yg_level_name = YGLN_E1M10; - else if (!strcmp(token[1], "map01")) - yg_level_name = YGLN_MAP01; - else - fatal_error - ("%s(%d): invalid argument \"%.32s\" (e1m1|e1m10|map01)", - filename, lineno, token[1]); - free(buf); - } - else if (!strcmp(token[0], "picture_format")) - { - if (ntoks != 2) - fatal_error(bad_arg_count, filename, lineno, token[0], 1); - if (!strcmp(token[1], "alpha")) - yg_picture_format = YGPF_ALPHA; - else if (!strcmp(token[1], "pr")) - yg_picture_format = YGPF_PR; - else if (!strcmp(token[1], "normal")) - yg_picture_format = YGPF_NORMAL; - else - fatal_error - ("%s(%d): invalid argument \"%.32s\" (alpha|pr|normal)", - filename, lineno, token[1]); - free(buf); - } - else if (!strcmp(token[0], "sky_flat")) - { - if (ntoks != 2) - fatal_error(bad_arg_count, filename, lineno, token[0], 1); - sky_flat = token[1]; - } - else if (!strcmp(token[0], "st")) - { - stdef_t buf; + if (ntoks != 3) + fatal_error(bad_arg_count, filename, lineno, token[0], 2); + buf.ldtgroup = *token[1]; + buf.desc = token[2]; + if (al_lwrite(ldtgroup, &buf)) + fatal_error("LGD2 (%s)", al_astrerror(al_aerrno)); + } + else if (!strcmp(token[0], "level_format")) + { + if (ntoks != 2) + fatal_error(bad_arg_count, filename, lineno, token[0], 1); + if (!strcmp(token[1], "alpha")) + yg_level_format = YGLF_ALPHA; + else if (!strcmp(token[1], "doom")) + yg_level_format = YGLF_DOOM; + else if (!strcmp(token[1], "hexen")) + yg_level_format = YGLF_HEXEN; + else + fatal_error + ("%s(%d): invalid argument \"%.32s\" (alpha|doom|hexen)", + filename, lineno, token[1]); + free(buf); + } + else if (!strcmp(token[0], "level_name")) + { + if (ntoks != 2) + fatal_error(bad_arg_count, filename, lineno, token[0], 1); + if (!strcmp(token[1], "e1m1")) + yg_level_name = YGLN_E1M1; + else if (!strcmp(token[1], "e1m10")) + yg_level_name = YGLN_E1M10; + else if (!strcmp(token[1], "map01")) + yg_level_name = YGLN_MAP01; + else + fatal_error + ("%s(%d): invalid argument \"%.32s\" (e1m1|e1m10|map01)", + filename, lineno, token[1]); + free(buf); + } + else if (!strcmp(token[0], "picture_format")) + { + if (ntoks != 2) + fatal_error(bad_arg_count, filename, lineno, token[0], 1); + if (!strcmp(token[1], "alpha")) + yg_picture_format = YGPF_ALPHA; + else if (!strcmp(token[1], "pr")) + yg_picture_format = YGPF_PR; + else if (!strcmp(token[1], "normal")) + yg_picture_format = YGPF_NORMAL; + else + fatal_error + ("%s(%d): invalid argument \"%.32s\" (alpha|pr|normal)", + filename, lineno, token[1]); + free(buf); + } + else if (!strcmp(token[0], "sky_flat")) + { + if (ntoks != 2) + fatal_error(bad_arg_count, filename, lineno, token[0], 1); + sky_flat = token[1]; + } + else if (!strcmp(token[0], "st")) + { + stdef_t buf; - if (ntoks != 4) - fatal_error(bad_arg_count, filename, lineno, token[0], 3); - buf.number = atoi(token[1]); - buf.shortdesc = token[2]; /* FIXME: trunc to 14 char. */ - buf.longdesc = token[3]; /* FIXME: trunc reasonably */ - if (al_lwrite(stdef, &buf)) - fatal_error("LGD3 (%s)", al_astrerror(al_aerrno)); - } - else if (!strcmp(token[0], "texture_format")) - { - if (ntoks != 2) - fatal_error(bad_arg_count, filename, lineno, token[0], 1); - if (!strcmp(token[1], "nameless")) - yg_texture_format = YGTF_NAMELESS; - else if (!strcmp(token[1], "normal")) - yg_texture_format = YGTF_NORMAL; - else if (!strcmp(token[1], "strife11")) - yg_texture_format = YGTF_STRIFE11; - else - fatal_error - ("%s(%d): invalid argument \"%.32s\" (normal|nameless|strife11)", - filename, lineno, token[1]); - free(buf); - } - else if (!strcmp(token[0], "texture_lumps")) - { - if (ntoks != 2) - fatal_error(bad_arg_count, filename, lineno, token[0], 1); - if (!strcmp(token[1], "textures")) - yg_texture_lumps = YGTL_TEXTURES; - else if (!strcmp(token[1], "normal")) - yg_texture_lumps = YGTL_NORMAL; - else if (!strcmp(token[1], "none")) - yg_texture_lumps = YGTL_NONE; - else - fatal_error - ("%s(%d): invalid argument \"%.32s\" (normal|textures|none)", - filename, lineno, token[1]); - free(buf); - } - else if (!strcmp(token[0], "thing")) - { - thingdef_t buf; + if (ntoks != 4) + fatal_error(bad_arg_count, filename, lineno, token[0], 3); + buf.number = atoi(token[1]); + buf.shortdesc = token[2]; /* FIXME: trunc to 14 char. */ + buf.longdesc = token[3]; /* FIXME: trunc reasonably */ + if (al_lwrite(stdef, &buf)) + fatal_error("LGD3 (%s)", al_astrerror(al_aerrno)); + } + else if (!strcmp(token[0], "texture_format")) + { + if (ntoks != 2) + fatal_error(bad_arg_count, filename, lineno, token[0], 1); + if (!strcmp(token[1], "nameless")) + yg_texture_format = YGTF_NAMELESS; + else if (!strcmp(token[1], "normal")) + yg_texture_format = YGTF_NORMAL; + else if (!strcmp(token[1], "strife11")) + yg_texture_format = YGTF_STRIFE11; + else + fatal_error + ("%s(%d): invalid argument \"%.32s\" (normal|nameless|strife11)", + filename, lineno, token[1]); + free(buf); + } + else if (!strcmp(token[0], "texture_lumps")) + { + if (ntoks != 2) + fatal_error(bad_arg_count, filename, lineno, token[0], 1); + if (!strcmp(token[1], "textures")) + yg_texture_lumps = YGTL_TEXTURES; + else if (!strcmp(token[1], "normal")) + yg_texture_lumps = YGTL_NORMAL; + else if (!strcmp(token[1], "none")) + yg_texture_lumps = YGTL_NONE; + else + fatal_error + ("%s(%d): invalid argument \"%.32s\" (normal|textures|none)", + filename, lineno, token[1]); + free(buf); + } + else if (!strcmp(token[0], "thing")) + { + thingdef_t buf; - if (ntoks < 6 || ntoks > 7) - fatal_error - ("%s(d%): directive \"%s\" takes between 5 and 6 parameters", - filename, lineno, token[0]); - buf.number = atoi(token[1]); - buf.thinggroup = *token[2]; - buf.flags = *token[3] == 's' ? THINGDEF_SPECTRAL : 0; // FIXME! - buf.radius = atoi(token[4]); - buf.desc = token[5]; - buf.sprite = ntoks >= 7 ? token[6] : 0; - if (al_lwrite(thingdef, &buf)) - fatal_error("LGD4 (%s)", al_astrerror(al_aerrno)); - } - else if (!strcmp(token[0], "thinggroup")) - { - thinggroup_t buf; + if (ntoks < 6 || ntoks > 7) + fatal_error + ("%s(d%): directive \"%s\" takes between 5 and 6 parameters", + filename, lineno, token[0]); + buf.number = atoi(token[1]); + buf.thinggroup = *token[2]; + buf.flags = *token[3] == 's' ? THINGDEF_SPECTRAL : 0; // FIXME! + buf.radius = atoi(token[4]); + buf.desc = token[5]; + buf.sprite = ntoks >= 7 ? token[6] : 0; + if (al_lwrite(thingdef, &buf)) + fatal_error("LGD4 (%s)", al_astrerror(al_aerrno)); + } + else if (!strcmp(token[0], "thinggroup")) + { + thinggroup_t buf; - if (ntoks != 4) - fatal_error(bad_arg_count, filename, lineno, token[0], 3); - buf.thinggroup = *token[1]; - if (getcolour(token[2], &buf.rgb)) - fatal_error("%s(%d): bad colour spec \"%.32s\"", - filename, lineno, token[2]); - buf.acn = add_app_colour(buf.rgb); - buf.desc = token[3]; - if (al_lwrite(thinggroup, &buf)) - fatal_error("LGD5 (%s)", al_astrerror(al_aerrno)); - } - else - { - free(buf); - fatal_error("%s(%d): unknown directive \"%.32s\"", - filename, lineno, token[0]); - } + if (ntoks != 4) + fatal_error(bad_arg_count, filename, lineno, token[0], 3); + buf.thinggroup = *token[1]; + if (getcolour(token[2], &buf.rgb)) + fatal_error("%s(%d): bad colour spec \"%.32s\"", + filename, lineno, token[2]); + buf.acn = add_app_colour(buf.rgb); + buf.desc = token[3]; + if (al_lwrite(thinggroup, &buf)) + fatal_error("LGD5 (%s)", al_astrerror(al_aerrno)); + } + else + { + free(buf); + fatal_error("%s(%d): unknown directive \"%.32s\"", + filename, lineno, token[0]); + } } fclose(ygdfile); /* Verify that all the mandatory directives are present. */ { - bool abort = false; - if (yg_level_format == YGLF__) - { - err("%s: Missing \"level_format\" directive.", filename); - abort = true; - } - if (yg_level_name == YGLN__) - { - err("%s: Missing \"level_name\" directive.", filename); - abort = true; - } + bool abort = false; + if (yg_level_format == YGLF__) + { + err("%s: Missing \"level_format\" directive.", filename); + abort = true; + } + if (yg_level_name == YGLN__) + { + err("%s: Missing \"level_name\" directive.", filename); + abort = true; + } // FIXME perhaps print a warning message if picture_format // is missing ("assuming picture_format=normal"). // FIXME and same thing for texture_format and texture_lumps ? - if (abort) - exit(2); + if (abort) + exit(2); } #if 0 @@ -360,7 +360,7 @@ #endif /* - * Second pass + * Second pass */ /* Speed optimization : build the table of things attributes @@ -370,46 +370,46 @@ /* KLUDGE: Add bogus ldtgroup LDT_FREE. InputLinedefType() knows that it means "let the user enter a number". */ { - ldtgroup_t buf; + ldtgroup_t buf; - buf.ldtgroup = LDT_FREE; /* that is '\0' */ - buf.desc = "Other (enter number)"; - al_lseek(ldtgroup, 0, SEEK_END); - if (al_lwrite(ldtgroup, &buf)) - fatal_error("LGD90 (%s)", al_astrerror(al_aerrno)); + buf.ldtgroup = LDT_FREE; /* that is '\0' */ + buf.desc = "Other (enter number)"; + al_lseek(ldtgroup, 0, SEEK_END); + if (al_lwrite(ldtgroup, &buf)) + fatal_error("LGD90 (%s)", al_astrerror(al_aerrno)); } /* KLUDGE: Add bogus thinggroup THING_FREE. InputThingType() knows that it means "let the user enter a number". */ { - thinggroup_t buf; + thinggroup_t buf; - buf.thinggroup = THING_FREE; /* that is '\0' */ - buf.desc = "Other (enter number)"; - al_lseek(thinggroup, 0, SEEK_END); - if (al_lwrite(thinggroup, &buf)) - fatal_error("LGD91 (%s)", al_astrerror(al_aerrno)); + buf.thinggroup = THING_FREE; /* that is '\0' */ + buf.desc = "Other (enter number)"; + al_lseek(thinggroup, 0, SEEK_END); + if (al_lwrite(thinggroup, &buf)) + fatal_error("LGD91 (%s)", al_astrerror(al_aerrno)); } /* KLUDGE: Add bogus sector type at the end of stdef. SectorProperties() knows that it means "let the user enter a number". */ { - stdef_t buf; + stdef_t buf; - buf.number = 0; /* not significant */ - buf.shortdesc = 0; /* not significant */ - buf.longdesc = "Other (enter number)"; - al_lseek(stdef, 0, SEEK_END); - if (al_lwrite(stdef, &buf)) - fatal_error("LGD92 (%s)", al_astrerror(al_aerrno)); + buf.number = 0; /* not significant */ + buf.shortdesc = 0; /* not significant */ + buf.longdesc = "Other (enter number)"; + al_lseek(stdef, 0, SEEK_END); + if (al_lwrite(stdef, &buf)) + fatal_error("LGD92 (%s)", al_astrerror(al_aerrno)); } } /* - * FreeGameDefs - * Free all memory allocated to game definitions + * FreeGameDefs + * Free all memory allocated to game definitions */ void FreeGameDefs(void) { diff -r 594dea11ccd9 -r a68786b9c74b src/game.h --- a/src/game.h Sat Sep 24 15:01:56 2011 +0300 +++ b/src/game.h Sat Sep 24 15:59:33 2011 +0300 @@ -1,7 +1,7 @@ /* - * game.h - * Header for game.cc - * AYM 19980129 + * game.h + * Header for game.cc + * AYM 19980129 */ @@ -12,7 +12,7 @@ /* - * Data structures for game definition data + * Data structures for game definition data */ // ldt @@ -42,12 +42,12 @@ // thing [] typedef struct { - int number; // Thing number - char thinggroup; // Thing group - char flags; // Flags - int radius; // Radius of thing - const char *desc; // Short description of thing - const char *sprite; // Root of name of sprite for thing + int number; // Thing number + char thinggroup; // Thing group + char flags; // Flags + int radius; // Radius of thing + const char *desc; // Short description of thing + const char *sprite; // Root of name of sprite for thing } thingdef_t; /* (1) This is only here for speed, to avoid having to lookup thinggroup for each thing when drawing things */ @@ -56,16 +56,16 @@ // thinggroup typedef struct { - char thinggroup; // Thing group - rgb_c rgb; // RGB colour - acolour_t acn; // Application colour# - const char *desc; // Description of thing group + char thinggroup; // Thing group + rgb_c rgb; // RGB colour + acolour_t acn; // Application colour# + const char *desc; // Description of thing group } thinggroup_t; /* - * Global variables that contain game definition data - * Those variables are defined in yadex.cc + * Global variables that contain game definition data + * Those variables are defined in yadex.cc */ typedef enum @@ -92,6 +92,6 @@ #define CUR_THINGDEF ((thingdef_t *)al_lptr (thingdef )) #define CUR_THINGGROUP ((thinggroup_t *)al_lptr (thinggroup)) -#define LDT_FREE '\0' /* KLUDGE: bogus ldt group (see game.c) */ -#define ST_FREE '\0' /* KLUDGE: bogus sector type (see game.c) */ -#define THING_FREE '\0' /* KLUDGE: bogus thing group (see game.c) */ +#define LDT_FREE '\0' /* KLUDGE: bogus ldt group (see game.c) */ +#define ST_FREE '\0' /* KLUDGE: bogus sector type (see game.c) */ +#define THING_FREE '\0' /* KLUDGE: bogus thing group (see game.c) */ diff -r 594dea11ccd9 -r a68786b9c74b src/gamedef.h --- a/src/gamedef.h Sat Sep 24 15:01:56 2011 +0300 +++ b/src/gamedef.h Sat Sep 24 15:59:33 2011 +0300 @@ -1,10 +1,10 @@ /* - * gamedef.h - Game_def class - * AYM 2000-08-30 + * gamedef.h - Game_def class + * AYM 2000-08-30 */ -#ifndef YH_GAMEDEF /* DO NOT INSERT ANYTHING BEFORE THIS LINE */ +#ifndef YH_GAMEDEF /* DO NOT INSERT ANYTHING BEFORE THIS LINE */ #define YH_GAMEDEF @@ -40,10 +40,10 @@ typedef struct { - char flags; // Flags - int radius; // Radius of thing - const char *desc; // Short description of thing - const char *sprite; // Root of name of sprite for thing + char flags; // Flags + int radius; // Radius of thing + const char *desc; // Short description of thing + const char *sprite; // Root of name of sprite for thing } thing_type_t; @@ -52,10 +52,10 @@ typedef struct { - char thinggroup; // Thing group - rgb_c rgb; // RGB colour - acolour_t acn; // Application colour# - const char *desc; // Description of thing group + char thinggroup; // Thing group + rgb_c rgb; // RGB colour + acolour_t acn; // Application colour# + const char *desc; // Description of thing group } thing_type_group_t; @@ -73,13 +73,13 @@ /* shorthands to make program more readable */ -#define LDT_FREE '\0' /* KLUDGE: bogus ldt group (see game.c) */ -#define ST_FREE '\0' /* KLUDGE: bogus sector type (see game.c) */ -#define THING_FREE '\0' /* KLUDGE: bogus thing group (see game.c) */ +#define LDT_FREE '\0' /* KLUDGE: bogus ldt group (see game.c) */ +#define ST_FREE '\0' /* KLUDGE: bogus sector type (see game.c) */ +#define THING_FREE '\0' /* KLUDGE: bogus thing group (see game.c) */ /* - * Game_def - contain all the definitions relative to a game + * Game_def - contain all the definitions relative to a game */ class Game_def { @@ -105,8 +105,8 @@ ygtf_t texture_format() const; ygtl_t texture_lumps() const; - private: Game_def(const Game_def &); // Too lazy to implement it - Game_def & operator=(const Game_def &); // Too lazy to implement it + private: Game_def(const Game_def &); // Too lazy to implement it + Game_def & operator=(const Game_def &); // Too lazy to implement it Game_def_priv *priv; }; diff -r 594dea11ccd9 -r a68786b9c74b src/gamesky.h --- a/src/gamesky.h Sat Sep 24 15:01:56 2011 +0300 +++ b/src/gamesky.h Sat Sep 24 15:59:33 2011 +0300 @@ -1,10 +1,10 @@ /* - * gamesky.h - * AYM 2000-04-24 + * gamesky.h + * AYM 2000-04-24 */ -#ifndef YH_GAMESKY /* DO NOT INSERT ANYTHING BEFORE THIS LINE */ +#ifndef YH_GAMESKY /* DO NOT INSERT ANYTHING BEFORE THIS LINE */ #define YH_GAMESKY @@ -15,7 +15,7 @@ /* - * is_sky - is this flat a sky + * is_sky - is this flat a sky */ inline bool is_sky(const char *flat) { diff -r 594dea11ccd9 -r a68786b9c74b src/gcolour1.cc --- a/src/gcolour1.cc Sat Sep 24 15:01:56 2011 +0300 +++ b/src/gcolour1.cc Sat Sep 24 15:59:33 2011 +0300 @@ -1,16 +1,16 @@ /* - * gcolour1.cc - * Allocate and free the game colours. + * gcolour1.cc + * Allocate and free the game colours. * - * By "game colours", I mean the colours used to draw - * the game graphics (flats, textures, sprites), as - * opposed to the "application colours" which don't - * depend on the the game and are used to draw the - * windows, the menus and the map. + * By "game colours", I mean the colours used to draw + * the game graphics (flats, textures, sprites), as + * opposed to the "application colours" which don't + * depend on the the game and are used to draw the + * windows, the menus and the map. * - * The application colours are handled in acolours.cc. + * The application colours are handled in acolours.cc. * - * AYM 1998-11-29 + * AYM 1998-11-29 */ @@ -41,17 +41,17 @@ #include "gcolour1.h" #include "gcolour2.h" #include "gfx.h" -#include "img.h" /* IMG_TRANSP */ +#include "img.h" /* IMG_TRANSP */ #include "rgb.h" #include "wadfile.h" #include "wads.h" /* - * alloc_game_colours - * Allocate the DOOM_COLOURS of PLAYPAL no. . - * Put the DOOM_COLOURS physical colour numbers corresponding - * to the game colours in the array. + * alloc_game_colours + * Allocate the DOOM_COLOURS of PLAYPAL no. . + * Put the DOOM_COLOURS physical colour numbers corresponding + * to the game colours in the array. */ pcolour_t *alloc_game_colours(int playpalnum) { @@ -62,38 +62,38 @@ dir = FindMasterDir(MasterDir, "PLAYPAL"); if (dir == NULL) { - warn("PLAYPAL lump not found.\n"); - return 0; + warn("PLAYPAL lump not found.\n"); + return 0; } int playpal_count = dir->dir.size / (3 * DOOM_COLOURS); if (playpalnum < 0 || playpalnum >= playpal_count) { - warn("playpalnum %d out of range (0-%d). Using #0 instead.\n", - playpalnum, playpal_count - 1); - playpalnum = 0; + warn("playpalnum %d out of range (0-%d). Using #0 instead.\n", + playpalnum, playpal_count - 1); + playpalnum = 0; } dpal = (u8 *) GetMemory(3 * DOOM_COLOURS); dir->wadfile->seek(dir->dir.start); if (dir->wadfile->error()) { - warn("%s: can't seek to %lXh\n", - dir->wadfile->pathname(), (unsigned long) dir->dir.start); - warn("PLAYPAL: seek error\n"); + warn("%s: can't seek to %lXh\n", + dir->wadfile->pathname(), (unsigned long) dir->dir.start); + warn("PLAYPAL: seek error\n"); } for (int n = 0; n <= playpalnum; n++) { - dir->wadfile->read_bytes(dpal, 3 * DOOM_COLOURS); - if (dir->wadfile->error()) - { - warn("%s: read error\n", dir->wadfile->where()); - warn("PLAYPAL: error reading entry #%d\n", n); - } + dir->wadfile->read_bytes(dpal, 3 * DOOM_COLOURS); + if (dir->wadfile->error()) + { + warn("%s: read error\n", dir->wadfile->where()); + warn("PLAYPAL: error reading entry #%d\n", n); + } } #if defined Y_BGI for (int n = 0; n < 3 * DOOM_COLOURS; n++) - dpal[n] /= 4; + dpal[n] /= 4; _AX = 0x1012; _BX = 0; _CX = DOOM_COLOURS; @@ -105,44 +105,44 @@ rgb_c rgb_values[DOOM_COLOURS]; for (size_t n = 0; n < DOOM_COLOURS; n++) { - rgb_values[n].r = (u8) dpal[3 * n]; - rgb_values[n].g = (u8) dpal[3 * n + 1]; - rgb_values[n].b = (u8) dpal[3 * n + 2]; + rgb_values[n].r = (u8) dpal[3 * n]; + rgb_values[n].g = (u8) dpal[3 * n + 1]; + rgb_values[n].b = (u8) dpal[3 * n + 2]; } game_colours = alloc_colours(rgb_values, DOOM_COLOURS); // Find the colour closest to IMG_TRANSP { - colour0 = IMG_TRANSP; - int smallest_delta = INT_MAX; + colour0 = IMG_TRANSP; + int smallest_delta = INT_MAX; - for (size_t n = 1; n < DOOM_COLOURS; n++) - { - int delta = rgb_values[IMG_TRANSP] - rgb_values[n]; - if (delta < smallest_delta) - { - colour0 = n; - smallest_delta = delta; - } - } - verbmsg("colours: colour %d remapped to %d (delta %d)\n", - IMG_TRANSP, colour0, smallest_delta); + for (size_t n = 1; n < DOOM_COLOURS; n++) + { + int delta = rgb_values[IMG_TRANSP] - rgb_values[n]; + if (delta < smallest_delta) + { + colour0 = n; + smallest_delta = delta; + } + } + verbmsg("colours: colour %d remapped to %d (delta %d)\n", + IMG_TRANSP, colour0, smallest_delta); - rgb_c med_blue(0, 0, 128); - sky_colour = 0; - smallest_delta = INT_MAX; + rgb_c med_blue(0, 0, 128); + sky_colour = 0; + smallest_delta = INT_MAX; - for (size_t n = 0; n < DOOM_COLOURS; n++) - { - int delta = med_blue - rgb_values[n]; - if (delta < smallest_delta) - { - sky_colour = n; - smallest_delta = delta; - } - } - verbmsg("Sky Colour remapped to %d (delta %d)\n", sky_colour, - smallest_delta); + for (size_t n = 0; n < DOOM_COLOURS; n++) + { + int delta = med_blue - rgb_values[n]; + if (delta < smallest_delta) + { + sky_colour = n; + smallest_delta = delta; + } + } + verbmsg("Sky Colour remapped to %d (delta %d)\n", sky_colour, + smallest_delta); } #endif @@ -152,8 +152,8 @@ /* - * free_game_colours - * Free the game colours allocated by alloc_game_colours() + * free_game_colours + * Free the game colours allocated by alloc_game_colours() */ void free_game_colours(pcolour_t * game_colours) { @@ -175,30 +175,30 @@ xpv_t b = dpal[3 * n + 2]; if (win_vis_class == DirectColor || win_vis_class == TrueColor) { - xpv_t r_scaled, g_scaled, b_scaled; - if (win_r_ofs + win_r_bits < 8) - r_scaled = r >> (8 - (win_r_ofs + win_r_bits)); - else - r_scaled = r << (win_r_ofs + win_r_bits - 8) & win_r_mask; - if (win_g_ofs + win_g_bits < 8) - g_scaled = g >> (8 - (win_g_ofs + win_g_bits)); - else - g_scaled = g << (win_g_ofs + win_g_bits - 8) & win_g_mask; - if (win_b_ofs + win_b_bits < 8) - b_scaled = b >> (8 - (win_b_ofs + win_b_bits)); - else - b_scaled = b << (win_b_ofs + win_b_bits - 8) & win_b_mask; - game_colour[n] = r_scaled | g_scaled | b_scaled; + xpv_t r_scaled, g_scaled, b_scaled; + if (win_r_ofs + win_r_bits < 8) + r_scaled = r >> (8 - (win_r_ofs + win_r_bits)); + else + r_scaled = r << (win_r_ofs + win_r_bits - 8) & win_r_mask; + if (win_g_ofs + win_g_bits < 8) + g_scaled = g >> (8 - (win_g_ofs + win_g_bits)); + else + g_scaled = g << (win_g_ofs + win_g_bits - 8) & win_g_mask; + if (win_b_ofs + win_b_bits < 8) + b_scaled = b >> (8 - (win_b_ofs + win_b_bits)); + else + b_scaled = b << (win_b_ofs + win_b_bits - 8) & win_b_mask; + game_colour[n] = r_scaled | g_scaled | b_scaled; } else if (win_vis_class == PseudoColor || win_vis_class == StaticColor) - game_colour[n] = n; /* Ugh! */ + game_colour[n] = n; /* Ugh! */ else if (win_vis_class == GrayScale || win_vis_class == StaticGray) { - game_colour[n] = (r + g + b) / 3; - if (win_depth < 8) - game_colour[n] >>= 8 - win_depth; - else - game_colour[n] <<= win_depth - 8; + game_colour[n] = (r + g + b) / 3; + if (win_depth < 8) + game_colour[n] >>= 8 - win_depth; + else + game_colour[n] <<= win_depth - 8; } // printf ("%02X %08lX", n, (unsigned long) game_colour[n]); // if (n % 6 == 5) diff -r 594dea11ccd9 -r a68786b9c74b src/gcolour1.h --- a/src/gcolour1.h Sat Sep 24 15:01:56 2011 +0300 +++ b/src/gcolour1.h Sat Sep 24 15:59:33 2011 +0300 @@ -1,16 +1,16 @@ /* - * gcolour1.h - * Allocate and free the game colours. + * gcolour1.h + * Allocate and free the game colours. * - * By "game colours", I mean the colours used to draw - * the game graphics (flats, textures, sprites), as - * opposed to the "application colours" which don't - * depend on the the game and are used to draw the - * windows, the menus and the map. + * By "game colours", I mean the colours used to draw + * the game graphics (flats, textures, sprites), as + * opposed to the "application colours" which don't + * depend on the the game and are used to draw the + * windows, the menus and the map. * - * The application colours are handled in acolours.cc. + * The application colours are handled in acolours.cc. * - * AYM 1998-11-29 + * AYM 1998-11-29 */ diff -r 594dea11ccd9 -r a68786b9c74b src/gcolour2.cc --- a/src/gcolour2.cc Sat Sep 24 15:01:56 2011 +0300 +++ b/src/gcolour2.cc Sat Sep 24 15:59:33 2011 +0300 @@ -1,7 +1,7 @@ /* - * gcolour2.cc - * The game colour# -> physical colour# conversion table. - * AYM 1998-11-29 + * gcolour2.cc + * The game colour# -> physical colour# conversion table. + * AYM 1998-11-29 */ @@ -33,6 +33,6 @@ #include "gcolour2.h" -pcolour_t *game_colour = 0; // Pixel values for the DOOM_COLOURS game clrs. -int colour0; // Game colour to which g. colour 0 is remapped -int sky_colour; // Game colour for a medium sky blue +pcolour_t *game_colour = 0; // Pixel values for the DOOM_COLOURS game clrs. +int colour0; // Game colour to which g. colour 0 is remapped +int sky_colour; // Game colour for a medium sky blue diff -r 594dea11ccd9 -r a68786b9c74b src/gcolour2.h --- a/src/gcolour2.h Sat Sep 24 15:01:56 2011 +0300 +++ b/src/gcolour2.h Sat Sep 24 15:59:33 2011 +0300 @@ -1,13 +1,13 @@ /* - * gcolour2.h - * The game colour# -> physical colour# conversion table. - * AYM 1998-11-29 + * gcolour2.h + * The game colour# -> physical colour# conversion table. + * AYM 1998-11-29 */ #include "colour.h" -extern pcolour_t *game_colour; // Pixel values for the DOOM_COLOURS game clrs. -extern int colour0; // Game colour to which g. colour 0 is remapped -extern int sky_colour; // Game colour for a medium blue sky +extern pcolour_t *game_colour; // Pixel values for the DOOM_COLOURS game clrs. +extern int colour0; // Game colour to which g. colour 0 is remapped +extern int sky_colour; // Game colour for a medium blue sky diff -r 594dea11ccd9 -r a68786b9c74b src/gcolour3.cc --- a/src/gcolour3.cc Sat Sep 24 15:01:56 2011 +0300 +++ b/src/gcolour3.cc Sat Sep 24 15:59:33 2011 +0300 @@ -1,6 +1,6 @@ /* - * gcolour3.cc - * AYM 2000-04-20 + * gcolour3.cc + * AYM 2000-04-20 */ @@ -38,24 +38,24 @@ void Game_colour_24::refresh(const pcolour_t * game_colour, bool big_endian) { if (pv_table == 0) - pv_table = new pv24_t[DOOM_COLOURS]; + pv_table = new pv24_t[DOOM_COLOURS]; if (big_endian) { - for (size_t n = 0; n < DOOM_COLOURS; n++) - { - pv_table[n][0] = game_colour[n] / 0x10000; - pv_table[n][1] = game_colour[n] / 0x100; - pv_table[n][2] = game_colour[n]; - } + for (size_t n = 0; n < DOOM_COLOURS; n++) + { + pv_table[n][0] = game_colour[n] / 0x10000; + pv_table[n][1] = game_colour[n] / 0x100; + pv_table[n][2] = game_colour[n]; + } } else { - for (size_t n = 0; n < DOOM_COLOURS; n++) - { - pv_table[n][0] = game_colour[n]; - pv_table[n][1] = game_colour[n] / 0x100; - pv_table[n][2] = game_colour[n] / 0x10000; - } + for (size_t n = 0; n < DOOM_COLOURS; n++) + { + pv_table[n][0] = game_colour[n]; + pv_table[n][1] = game_colour[n] / 0x100; + pv_table[n][2] = game_colour[n] / 0x10000; + } } } diff -r 594dea11ccd9 -r a68786b9c74b src/gcolour3.h --- a/src/gcolour3.h Sat Sep 24 15:01:56 2011 +0300 +++ b/src/gcolour3.h Sat Sep 24 15:59:33 2011 +0300 @@ -1,6 +1,6 @@ /* - * gcolour3.h - * AYM 2000-04-20 + * gcolour3.h + * AYM 2000-04-20 */ @@ -27,7 +27,7 @@ */ -#ifndef YH_GCOLOUR3 /* DO NOT INSERT ANYTHING BEFORE THIS LINE */ +#ifndef YH_GCOLOUR3 /* DO NOT INSERT ANYTHING BEFORE THIS LINE */ #define YH_GCOLOUR3 @@ -35,47 +35,47 @@ /* - * Game_colour_24 - convert game colours to pixel values - * - * This class is used to speed up displaying of images on - * visuals where bits_per_pixel is 24. + * Game_colour_24 - convert game colours to pixel values + * + * This class is used to speed up displaying of images on + * visuals where bits_per_pixel is 24. * - * Game_colour_24::lut() returns a pointer to a const table - * that is similar to game_colour[] except that it is - * optimized toward the needs of display_img() : - * each member can be readily copied into the XImage buffer - * (this is not true of game_colour[], at least not if the - * client is big-endian or does not have the same - * endianness as the server). + * Game_colour_24::lut() returns a pointer to a const table + * that is similar to game_colour[] except that it is + * optimized toward the needs of display_img() : + * each member can be readily copied into the XImage buffer + * (this is not true of game_colour[], at least not if the + * client is big-endian or does not have the same + * endianness as the server). * - * There is exactly 1 instance of this class (global). It's - * refreshed in InitGfx() and used in display_img(). - * To avoid wasting memory when it's not needed (when the - * depth is != 24), the array is allocated upon refresh and - * refresh() is only called when the depth is == 24. + * There is exactly 1 instance of this class (global). It's + * refreshed in InitGfx() and used in display_img(). + * To avoid wasting memory when it's not needed (when the + * depth is != 24), the array is allocated upon refresh and + * refresh() is only called when the depth is == 24. */ -typedef u8 pv24_t[3]; // A 24-bit pixel value +typedef u8 pv24_t[3]; // A 24-bit pixel value class Game_colour_24 { public: Game_colour_24() { - pv_table = 0; + pv_table = 0; } ~Game_colour_24() { - if (pv_table) - delete[]pv_table; + if (pv_table) + delete[]pv_table; } // Create/refresh the table void refresh(const pcolour_t * game_colour, const bool big_endian); // Return a pointer on an array of pv24_t[DOOM_COLOURS] const pv24_t *lut() { - return pv_table; + return pv_table; } private: pv24_t * pv_table; diff -r 594dea11ccd9 -r a68786b9c74b src/geom.cc --- a/src/geom.cc Sat Sep 24 15:01:56 2011 +0300 +++ b/src/geom.cc Sat Sep 24 15:59:33 2011 +0300 @@ -1,7 +1,7 @@ /* - * geom.c - * Geometric stuff - * AYM 1998-08-15 + * geom.c + * Geometric stuff + * AYM 1998-08-15 */ diff -r 594dea11ccd9 -r a68786b9c74b src/gfx.cc --- a/src/gfx.cc Sat Sep 24 15:01:56 2011 +0300 +++ b/src/gfx.cc Sat Sep 24 15:59:33 2011 +0300 @@ -1,7 +1,7 @@ /* - * gfx.cc - * Graphics routines. - * BW & RQ sometime in 1993 or 1994. + * gfx.cc + * Graphics routines. + * BW & RQ sometime in 1993 or 1994. */ @@ -39,7 +39,7 @@ #include "gcolour2.h" #include "gcolour3.h" #include "gfx.h" -#include "levels.h" /* Level */ +#include "levels.h" /* Level */ #include "x11.h" #ifdef Y_DOS @@ -48,64 +48,64 @@ /* Parameters set by the command line args and config file */ -const char *font_name = NULL; // X: the name of the font to load -Win_dim initial_window_width("90%"); // X: the name says it all -Win_dim initial_window_height("90%"); // X: the name says it all -int no_pixmap; // X: use no pixmap -- direct window output -int VideoMode = 2; // BGI: default video mode for VESA cards +const char *font_name = NULL; // X: the name of the font to load +Win_dim initial_window_width("90%"); // X: the name says it all +Win_dim initial_window_height("90%"); // X: the name says it all +int no_pixmap; // X: use no pixmap -- direct window output +int VideoMode = 2; // BGI: default video mode for VESA cards /* Global variables */ -int GfxMode = 0; // graphics mode number, or 0 for text - // 1 = 320x200, 2 = 640x480, 3 = 800x600, 4 = 1kx768 - // positive = 16 colors, negative = 256 colors -int OrigX; // Map X-coord of centre of screen/window -int OrigY; // Map Y-coord of centre of screen/window -float Scale; // the scale value -int ScrMaxX; // Maximum display X-coord of screen/window -int ScrMaxY; // Maximum display Y-coord of screen/window -int ScrCenterX; // Display X-coord of centre of screen/window -int ScrCenterY; // Display Y-coord of centre of screen/window +int GfxMode = 0; // graphics mode number, or 0 for text + // 1 = 320x200, 2 = 640x480, 3 = 800x600, 4 = 1kx768 + // positive = 16 colors, negative = 256 colors +int OrigX; // Map X-coord of centre of screen/window +int OrigY; // Map Y-coord of centre of screen/window +float Scale; // the scale value +int ScrMaxX; // Maximum display X-coord of screen/window +int ScrMaxY; // Maximum display Y-coord of screen/window +int ScrCenterX; // Display X-coord of centre of screen/window +int ScrCenterY; // Display Y-coord of centre of screen/window unsigned FONTH; unsigned FONTW; int font_xofs; int font_yofs; -Display *dpy; // The X display -int scn; // The X screen number -Colormap cmap = 0; // The X colormap -GC gc; // Default GC as set by set_colour(), SetDrawingMode() - // and SetLineThickness() -GC pixmap_gc; // The GC used to clear the pixmap -Window win; // The X window -Pixmap pixmap; // The X pixmap (if any) -Drawable drw; // Points to either or -int drw_mods; // Number of modifications to drw since last call to - // update_display(). Number of modifications to drw - // plus 1 since last call to ClearScreen(). -Visual *win_vis; // The visual for win */ -xpv_t win_r_mask; // The RGB masks for win's visual */ +Display *dpy; // The X display +int scn; // The X screen number +Colormap cmap = 0; // The X colormap +GC gc; // Default GC as set by set_colour(), SetDrawingMode() + // and SetLineThickness() +GC pixmap_gc; // The GC used to clear the pixmap +Window win; // The X window +Pixmap pixmap; // The X pixmap (if any) +Drawable drw; // Points to either or +int drw_mods; // Number of modifications to drw since last call to + // update_display(). Number of modifications to drw + // plus 1 since last call to ClearScreen(). +Visual *win_vis; // The visual for win */ +xpv_t win_r_mask; // The RGB masks for win's visual */ xpv_t win_g_mask; xpv_t win_b_mask; -int win_r_bits; // The RGB masks' respective lengths */ +int win_r_bits; // The RGB masks' respective lengths */ int win_g_bits; int win_b_bits; -int win_r_ofs; // The RGB masks' respective offsets relative to b0 */ +int win_r_ofs; // The RGB masks' respective offsets relative to b0 */ int win_g_ofs; int win_b_ofs; -int win_ncolours; // The number of possible colours for win's visual. - // If win_vis_class is TrueColor or DirectColor, - // it's the number of bits in the biggest subfield. -int win_vis_class; // The class of win's visual -VisualID win_vis_id; // The ID of win's visual -int win_depth; // The depth of win in bits -int x_server_big_endian = 0; // Is the X server big endian ? -int ximage_bpp; // Number of bytes per pixels in XImages -int ximage_quantum; // Pad XImages lines to a multiple of that many bytes -static pcolour_t *app_colour = 0; // Pixel values for the app. colours -static int DrawingMode = 0; // 0 = copy, 1 = xor -static int LineThickness = 0; // 0 = thin, 1 = thick -int text_dot = 0; // DrawScreenText() debug flag +int win_ncolours; // The number of possible colours for win's visual. + // If win_vis_class is TrueColor or DirectColor, + // it's the number of bits in the biggest subfield. +int win_vis_class; // The class of win's visual +VisualID win_vis_id; // The ID of win's visual +int win_depth; // The depth of win in bits +int x_server_big_endian = 0; // Is the X server big endian ? +int ximage_bpp; // Number of bytes per pixels in XImages +int ximage_quantum; // Pad XImages lines to a multiple of that many bytes +static pcolour_t *app_colour = 0; // Pixel values for the app. colours +static int DrawingMode = 0; // 0 = copy, 1 = xor +static int LineThickness = 0; // 0 = thin, 1 = thick +int text_dot = 0; // DrawScreenText() debug flag static acolour_t colour_stack[4]; static int colour_stack_pointer = 0; @@ -113,9 +113,9 @@ static bool default_font = true; /* - * InitGfx - initialize the graphics display + * InitGfx - initialize the graphics display * - * Return 0 on success, non-zero on failure + * Return 0 on success, non-zero on failure */ int InitGfx(void) { @@ -129,40 +129,40 @@ dpy = XOpenDisplay(0); if (!dpy) { - err("Can't open display"); - return 1; + err("Can't open display"); + return 1; } scn = DefaultScreen(dpy); { - verbmsg("X: server endianness: "); - int r = ImageByteOrder(dpy); - if (r == LSBFirst) - { - verbmsg("little-endian\n"); - x_server_big_endian = 0; - } - else if (r == MSBFirst) - { - verbmsg("big-endian\n"); - x_server_big_endian = 1; - } - else // Can't happen - { - verbmsg("unknown\n"); - warn("don't understand X server's endianness code %d\n", r); - warn("assuming same endianness as CPU.\n"); - x_server_big_endian = cpu_big_endian; - } + verbmsg("X: server endianness: "); + int r = ImageByteOrder(dpy); + if (r == LSBFirst) + { + verbmsg("little-endian\n"); + x_server_big_endian = 0; + } + else if (r == MSBFirst) + { + verbmsg("big-endian\n"); + x_server_big_endian = 1; + } + else // Can't happen + { + verbmsg("unknown\n"); + warn("don't understand X server's endianness code %d\n", r); + warn("assuming same endianness as CPU.\n"); + x_server_big_endian = cpu_big_endian; + } } int screen_width = DisplayWidth(dpy, scn); int screen_height = DisplayHeight(dpy, scn); // On QNX 6, XFree returns silly values. Use a plausible default instead. if (screen_width == 16383 && screen_height == 16383) { - warn("QNX XFree bug detected (width %d, height %d)\n", - screen_width, screen_height); - screen_width = 1024; - screen_height = 768; + warn("QNX XFree bug detected (width %d, height %d)\n", + screen_width, screen_height); + screen_width = 1024; + screen_height = 768; } @@ -172,91 +172,91 @@ width = initial_window_width.pixels(screen_width); height = initial_window_height.pixels(screen_height); win = XCreateSimpleWindow(dpy, DefaultRootWindow(dpy), - 10, 10, width, height, 0, 0, 0); + 10, 10, width, height, 0, 0, 0); //win = DefaultRootWindow (dpy); { - XWindowAttributes wa; - XVisualInfo model; - XVisualInfo *vis_info; - int nvisuals; + XWindowAttributes wa; + XVisualInfo model; + XVisualInfo *vis_info; + int nvisuals; - XGetWindowAttributes(dpy, win, &wa); - win_vis = wa.visual; - win_depth = wa.depth; - verbmsg("X: window depth: %d b\n", win_depth); + XGetWindowAttributes(dpy, win, &wa); + win_vis = wa.visual; + win_depth = wa.depth; + verbmsg("X: window depth: %d b\n", win_depth); - /* - * Retrieve info regarding win's visual - */ - model.visualid = XVisualIDFromVisual(win_vis); - vis_info = XGetVisualInfo(dpy, VisualIDMask, &model, &nvisuals); - if (!vis_info) - fatal_error("XGetVisualInfo returned NULL for ID %d", - model.visualid); - if (nvisuals != 1) - fatal_error("XGetVisualInfo returned %d visuals", nvisuals); - if (vis_info->depth != win_depth) - fatal_error("Visual depth %d <> win depth %d", vis_info->depth, - win_depth); - win_vis_id = vis_info->visualid; + /* + * Retrieve info regarding win's visual + */ + model.visualid = XVisualIDFromVisual(win_vis); + vis_info = XGetVisualInfo(dpy, VisualIDMask, &model, &nvisuals); + if (!vis_info) + fatal_error("XGetVisualInfo returned NULL for ID %d", + model.visualid); + if (nvisuals != 1) + fatal_error("XGetVisualInfo returned %d visuals", nvisuals); + if (vis_info->depth != win_depth) + fatal_error("Visual depth %d <> win depth %d", vis_info->depth, + win_depth); + win_vis_id = vis_info->visualid; #if defined _cplusplus || defined __cplusplus - win_vis_class = vis_info->c_class; + win_vis_class = vis_info->c_class; #else - win_vis_class = vis_info->class; + win_vis_class = vis_info->class; #endif - win_ncolours = vis_info->colormap_size; - win_r_mask = vis_info->red_mask; - win_g_mask = vis_info->green_mask; - win_b_mask = vis_info->blue_mask; - XFree(vis_info); - verbmsg("X: visual: id %xh, class ", (unsigned) win_vis_id); - if (win_vis_class == PseudoColor) - verbmsg("PseudoColor"); - else if (win_vis_class == TrueColor) - verbmsg("TrueColor"); - else if (win_vis_class == DirectColor) - verbmsg("DirectColor"); - else if (win_vis_class == StaticColor) - verbmsg("StaticColor"); - else if (win_vis_class == GrayScale) - verbmsg("GrayScale"); - else if (win_vis_class == StaticGray) - verbmsg("StaticGray"); - else - verbmsg("unknown (%d)", win_vis_class); - verbmsg(", colours %d, masks %08lX %08lX %08lX\n", - win_ncolours, win_r_mask, win_g_mask, win_b_mask); + win_ncolours = vis_info->colormap_size; + win_r_mask = vis_info->red_mask; + win_g_mask = vis_info->green_mask; + win_b_mask = vis_info->blue_mask; + XFree(vis_info); + verbmsg("X: visual: id %xh, class ", (unsigned) win_vis_id); + if (win_vis_class == PseudoColor) + verbmsg("PseudoColor"); + else if (win_vis_class == TrueColor) + verbmsg("TrueColor"); + else if (win_vis_class == DirectColor) + verbmsg("DirectColor"); + else if (win_vis_class == StaticColor) + verbmsg("StaticColor"); + else if (win_vis_class == GrayScale) + verbmsg("GrayScale"); + else if (win_vis_class == StaticGray) + verbmsg("StaticGray"); + else + verbmsg("unknown (%d)", win_vis_class); + verbmsg(", colours %d, masks %08lX %08lX %08lX\n", + win_ncolours, win_r_mask, win_g_mask, win_b_mask); - // Compute win_[rgb]_bits and win_[rgb]_ofs - /* FIXME can enter infinite loop if MSb of either mask is set - and >> sign extends. */ - if (win_r_mask) - { - xpv_t mask; - for (mask = win_r_mask, win_r_ofs = 0; !(mask & 1); mask >>= 1) - win_r_ofs++; - for (win_r_bits = 0; mask & 1; mask >>= 1) - win_r_bits++; - } - if (win_g_mask) - { - xpv_t mask; - for (mask = win_g_mask, win_g_ofs = 0; !(mask & 1); mask >>= 1) - win_g_ofs++; - for (win_g_bits = 0; mask & 1; mask >>= 1) - win_g_bits++; - } - if (win_b_mask) - { - xpv_t mask; - for (mask = win_b_mask, win_b_ofs = 0; !(mask & 1); mask >>= 1) - win_b_ofs++; - for (win_b_bits = 0; mask & 1; mask >>= 1) - win_b_bits++; - } - verbmsg("X: visual: " "r_ofs %d, r_bits %d, ", win_r_ofs, win_r_bits); - verbmsg("g_ofs %d, g_bits %d, ", win_g_ofs, win_g_bits); - verbmsg("b_ofs %d, b_bits %d\n", win_b_ofs, win_b_bits); + // Compute win_[rgb]_bits and win_[rgb]_ofs + /* FIXME can enter infinite loop if MSb of either mask is set + and >> sign extends. */ + if (win_r_mask) + { + xpv_t mask; + for (mask = win_r_mask, win_r_ofs = 0; !(mask & 1); mask >>= 1) + win_r_ofs++; + for (win_r_bits = 0; mask & 1; mask >>= 1) + win_r_bits++; + } + if (win_g_mask) + { + xpv_t mask; + for (mask = win_g_mask, win_g_ofs = 0; !(mask & 1); mask >>= 1) + win_g_ofs++; + for (win_g_bits = 0; mask & 1; mask >>= 1) + win_g_bits++; + } + if (win_b_mask) + { + xpv_t mask; + for (mask = win_b_mask, win_b_ofs = 0; !(mask & 1); mask >>= 1) + win_b_ofs++; + for (win_b_bits = 0; mask & 1; mask >>= 1) + win_b_bits++; + } + verbmsg("X: visual: " "r_ofs %d, r_bits %d, ", win_r_ofs, win_r_bits); + verbmsg("g_ofs %d, g_bits %d, ", win_g_ofs, win_g_bits); + verbmsg("b_ofs %d, b_bits %d\n", win_b_ofs, win_b_bits); } /* @@ -265,134 +265,134 @@ ximage_bpp = 0; ximage_quantum = 0; { - int nformats = 0; - XPixmapFormatValues *format = XListPixmapFormats(dpy, &nformats); - if (format == 0 || nformats < 1) - { - warn("XListPixmapFormats() trouble (ret=%p, n=%d).\n", format, - nformats); - goto ximage_done; - } - /* Pick the best possible pixmap format. Prefer one that has the - same depth as the drawable, as it is likely to be the fastest - one. Should there be several formats that satisfy that - requirement (I don't think that ever happens), prefer the one - where the line quantum is equal to the number of bits per - pixel, as that is easier to work with. */ - { - const XPixmapFormatValues *best = 0; - for (int n = 0; n < nformats; n++) - { - const XPixmapFormatValues *current = format + n; - verbmsg("X: pixmap format:" - " #%d, depth %2d, bits_per_pixel %2d, scanline_pad %2d\n", - n, current->depth, current->bits_per_pixel, - current->scanline_pad); - if (best == 0) - { - best = current; - continue; - } - int cgoodness = 2 * (current->depth == win_depth) - + 1 * (current->scanline_pad == current->bits_per_pixel); - int bgoodness = 2 * (best->depth == win_depth) - + 1 * (best->scanline_pad == best->bits_per_pixel); - if (cgoodness > bgoodness) - best = current; - } - verbmsg("X: pixmap format: best is #%d\n", int (best - format)); - if (best != 0) - { - int bits_per_pixel = best->bits_per_pixel; - if (bits_per_pixel % 8) // Paranoia - { - round_up(bits_per_pixel, 8); - warn("XImage format has bad bits_per_pixel %d. Rounding up to %d.\n", best->bits_per_pixel, bits_per_pixel); - } - int scanline_pad = best->scanline_pad; - if (best->scanline_pad % 8) // Paranoia - { - round_up(scanline_pad, 8); - warn("XImage format has bad scanline_pad %d. Rounding up to %d.\n", best->scanline_pad, scanline_pad); - } - ximage_bpp = bits_per_pixel / 8; - ximage_quantum = scanline_pad / 8; - } - } - if (ximage_bpp == 0 || ximage_quantum == 0) - { - warn("XListPixmapFormats() returned no suitable formats.\n"); - goto ximage_done; - } + int nformats = 0; + XPixmapFormatValues *format = XListPixmapFormats(dpy, &nformats); + if (format == 0 || nformats < 1) + { + warn("XListPixmapFormats() trouble (ret=%p, n=%d).\n", format, + nformats); + goto ximage_done; + } + /* Pick the best possible pixmap format. Prefer one that has the + same depth as the drawable, as it is likely to be the fastest + one. Should there be several formats that satisfy that + requirement (I don't think that ever happens), prefer the one + where the line quantum is equal to the number of bits per + pixel, as that is easier to work with. */ + { + const XPixmapFormatValues *best = 0; + for (int n = 0; n < nformats; n++) + { + const XPixmapFormatValues *current = format + n; + verbmsg("X: pixmap format:" + " #%d, depth %2d, bits_per_pixel %2d, scanline_pad %2d\n", + n, current->depth, current->bits_per_pixel, + current->scanline_pad); + if (best == 0) + { + best = current; + continue; + } + int cgoodness = 2 * (current->depth == win_depth) + + 1 * (current->scanline_pad == current->bits_per_pixel); + int bgoodness = 2 * (best->depth == win_depth) + + 1 * (best->scanline_pad == best->bits_per_pixel); + if (cgoodness > bgoodness) + best = current; + } + verbmsg("X: pixmap format: best is #%d\n", int (best - format)); + if (best != 0) + { + int bits_per_pixel = best->bits_per_pixel; + if (bits_per_pixel % 8) // Paranoia + { + round_up(bits_per_pixel, 8); + warn("XImage format has bad bits_per_pixel %d. Rounding up to %d.\n", best->bits_per_pixel, bits_per_pixel); + } + int scanline_pad = best->scanline_pad; + if (best->scanline_pad % 8) // Paranoia + { + round_up(scanline_pad, 8); + warn("XImage format has bad scanline_pad %d. Rounding up to %d.\n", best->scanline_pad, scanline_pad); + } + ximage_bpp = bits_per_pixel / 8; + ximage_quantum = scanline_pad / 8; + } + } + if (ximage_bpp == 0 || ximage_quantum == 0) + { + warn("XListPixmapFormats() returned no suitable formats.\n"); + goto ximage_done; + } ximage_done: - if (format != 0) - XFree(format); + if (format != 0) + XFree(format); } /* Could not obtain authoritative/good values. Warn and guess plausible values. */ if (ximage_bpp == 0 || ximage_quantum == 0) { - if (ximage_bpp == 0) - ximage_bpp = (win_depth + 7) / 8; - if (ximage_quantum == 0) - ximage_quantum = 4; - warn("guessing format. Images will probably not be displayed correctly\n"); + if (ximage_bpp == 0) + ximage_bpp = (win_depth + 7) / 8; + if (ximage_quantum == 0) + ximage_quantum = 4; + warn("guessing format. Images will probably not be displayed correctly\n"); } verbmsg("X: pixmap format: %d B per pixel, %d B quantum.\n", - ximage_bpp, ximage_quantum); + ximage_bpp, ximage_quantum); /* * Further configure the window */ - XStoreName(dpy, win, "Yadex"); // Temporary name -- will be overwritten + XStoreName(dpy, win, "Yadex"); // Temporary name -- will be overwritten XSelectInput(dpy, win, - KeyPressMask | KeyReleaseMask - | ButtonPressMask | ButtonReleaseMask - | PointerMotionMask - | EnterWindowMask | LeaveWindowMask - | ExposureMask | StructureNotifyMask); + KeyPressMask | KeyReleaseMask + | ButtonPressMask | ButtonReleaseMask + | PointerMotionMask + | EnterWindowMask | LeaveWindowMask + | ExposureMask | StructureNotifyMask); /* * Possibly load and query the font */ { - XFontStruct *xqf; + XFontStruct *xqf; - // Load the font or use the default font. - default_font = true; - if (font_name != NULL) - { - x_catch_on(); // Catch errors in XLoadFont() - font_xfont = XLoadFont(dpy, font_name); - if (const char *err_msg = x_error()) - { - warn("can't load font \"%s\" (%s).\n", font_name, err_msg); - warn("using default font instead.\n"); - } - else - default_font = false; - x_catch_off(); - } + // Load the font or use the default font. + default_font = true; + if (font_name != NULL) + { + x_catch_on(); // Catch errors in XLoadFont() + font_xfont = XLoadFont(dpy, font_name); + if (const char *err_msg = x_error()) + { + warn("can't load font \"%s\" (%s).\n", font_name, err_msg); + warn("using default font instead.\n"); + } + else + default_font = false; + x_catch_off(); + } - // Query the font we'll use for FONTW, FONTH and FONTYOFS. - xqf = XQueryFont(dpy, - default_font ? XGContextFromGC(DefaultGC(dpy, scn)) : - font_xfont); - if (xqf->direction != FontLeftToRight) - warn("this font is not left-to-right !\n"); - if (xqf->min_byte1 != 0 || xqf->max_byte1 != 0) - warn("this is not a single-byte font !\n"); - if (xqf->min_char_or_byte2 > 32 || xqf->max_char_or_byte2 < 126) - warn("this font does not support the ASCII character set !\n"); - if (xqf->min_bounds.width != xqf->max_bounds.width) - warn("this is not a fixed-width font !\n"); - FONTW = xqf->max_bounds.width; - FONTH = xqf->ascent + xqf->descent; - font_xofs = xqf->min_bounds.lbearing; - font_yofs = xqf->max_bounds.ascent; - XFreeFontInfo(NULL, xqf, 1); - verbmsg("X: font: metrics: %dx%d, xofs %d, yofs %d\n", - FONTW, FONTH, font_xofs, font_yofs); + // Query the font we'll use for FONTW, FONTH and FONTYOFS. + xqf = XQueryFont(dpy, + default_font ? XGContextFromGC(DefaultGC(dpy, scn)) : + font_xfont); + if (xqf->direction != FontLeftToRight) + warn("this font is not left-to-right !\n"); + if (xqf->min_byte1 != 0 || xqf->max_byte1 != 0) + warn("this is not a single-byte font !\n"); + if (xqf->min_char_or_byte2 > 32 || xqf->max_char_or_byte2 < 126) + warn("this font does not support the ASCII character set !\n"); + if (xqf->min_bounds.width != xqf->max_bounds.width) + warn("this is not a fixed-width font !\n"); + FONTW = xqf->max_bounds.width; + FONTH = xqf->ascent + xqf->descent; + font_xofs = xqf->min_bounds.lbearing; + font_yofs = xqf->max_bounds.ascent; + XFreeFontInfo(NULL, xqf, 1); + verbmsg("X: font: metrics: %dx%d, xofs %d, yofs %d\n", + FONTW, FONTH, font_xofs, font_yofs); } /* @@ -401,37 +401,37 @@ */ if (win_vis_class == PseudoColor) { - verbmsg("X: running on PseudoColor visual, using private Colormap\n"); - cmap = XCreateColormap(dpy, win, win_vis, AllocNone); + verbmsg("X: running on PseudoColor visual, using private Colormap\n"); + cmap = XCreateColormap(dpy, win, win_vis, AllocNone); } else - cmap = DefaultColormap(dpy, scn); + cmap = DefaultColormap(dpy, scn); XSetWindowColormap(dpy, win, cmap); game_colour = alloc_game_colours(0); app_colour = commit_app_colours(); if (win_depth == 24) - game_colour_24.refresh(game_colour, x_server_big_endian); + game_colour_24.refresh(game_colour, x_server_big_endian); /* * Create the GC */ { - XGCValues gcv; - unsigned long mask; + XGCValues gcv; + unsigned long mask; - mask = GCForeground | GCFunction | GCLineWidth; - if (!default_font) - { - mask |= GCFont; - gcv.font = font_xfont; - } - gcv.foreground = app_colour[0]; // Default colour - gcv.line_width = 0; - gcv.function = GXcopy; - gc = XCreateGC(dpy, win, mask, &gcv); - if (gc == 0) - fatal_error("XCreateGC() returned NULL"); + mask = GCForeground | GCFunction | GCLineWidth; + if (!default_font) + { + mask |= GCFont; + gcv.font = font_xfont; + } + gcv.foreground = app_colour[0]; // Default colour + gcv.line_width = 0; + gcv.function = GXcopy; + gc = XCreateGC(dpy, win, mask, &gcv); + if (gc == 0) + fatal_error("XCreateGC() returned NULL"); } @@ -443,18 +443,18 @@ // Unless no_pixmap is set, create the pixmap and its own pet GC. if (no_pixmap) - drw = win; + drw = win; else { - XGCValues gcv; + XGCValues gcv; - pixmap = XCreatePixmap(dpy, win, width, height, win_depth); - gcv.foreground = app_colour[0]; - gcv.graphics_exposures = False; // We don't want NoExpose events - pixmap_gc = XCreateGC(dpy, pixmap, GCForeground | GCGraphicsExposures, - &gcv); - drw = win; - drw_mods = 0; // Force display the first time + pixmap = XCreatePixmap(dpy, win, width, height, win_depth); + gcv.foreground = app_colour[0]; + gcv.graphics_exposures = False; // We don't want NoExpose events + pixmap_gc = XCreateGC(dpy, pixmap, GCForeground | GCGraphicsExposures, + &gcv); + drw = win; + drw_mods = 0; // Force display the first time } XSync(dpy, False); GfxMode = -VideoMode; @@ -465,54 +465,54 @@ /* - * TermGfx - terminate the graphics display + * TermGfx - terminate the graphics display */ void TermGfx() { verbmsg("TermGfx: GfxMode=%d\n", GfxMode); if (GfxMode) { - int r; + int r; - if (!no_pixmap) - { - XFreePixmap(dpy, pixmap); - XFreeGC(dpy, pixmap_gc); - } - r = XDestroyWindow(dpy, win); - verbmsg("X: XDestroyWindow returned %d\n", r); - free_game_colours(game_colour); - game_colour = 0; - uncommit_app_colours(app_colour); - app_colour = 0; - if (cmap != DefaultColormap(dpy, scn)) - { - verbmsg("X: freeing Colormap\n"); - XFreeColormap(dpy, cmap); - } - if (!default_font) - { - verbmsg("X: unloading font\n"); - XUnloadFont(dpy, font_xfont); - } - XFreeGC(dpy, gc); - gc = 0; - // FIXME there is surely more to do... - XCloseDisplay(dpy); + if (!no_pixmap) + { + XFreePixmap(dpy, pixmap); + XFreeGC(dpy, pixmap_gc); + } + r = XDestroyWindow(dpy, win); + verbmsg("X: XDestroyWindow returned %d\n", r); + free_game_colours(game_colour); + game_colour = 0; + uncommit_app_colours(app_colour); + app_colour = 0; + if (cmap != DefaultColormap(dpy, scn)) + { + verbmsg("X: freeing Colormap\n"); + XFreeColormap(dpy, cmap); + } + if (!default_font) + { + verbmsg("X: unloading font\n"); + XUnloadFont(dpy, font_xfont); + } + XFreeGC(dpy, gc); + gc = 0; + // FIXME there is surely more to do... + XCloseDisplay(dpy); - GfxMode = 0; + GfxMode = 0; } } /* - * SetWindowSize - set the size of the edit window + * SetWindowSize - set the size of the edit window */ void SetWindowSize(int width, int height) { // Am I called uselessly ? if (width == ScrMaxX + 1 && height == ScrMaxY + 1) - return; + return; ScrMaxX = width - 1; ScrMaxY = height - 1; @@ -522,40 +522,40 @@ // Replace the old pixmap by another of the new size if (!no_pixmap) { - XFreePixmap(dpy, pixmap); - pixmap = XCreatePixmap(dpy, win, width, height, win_depth); - drw = pixmap; + XFreePixmap(dpy, pixmap); + pixmap = XCreatePixmap(dpy, win, width, height, win_depth); + drw = pixmap; } } /* - * ClearScreen - clear the screen + * ClearScreen - clear the screen */ void ClearScreen() { if (no_pixmap) - XClearWindow(dpy, win); + XClearWindow(dpy, win); else { - XFillRectangle(dpy, pixmap, pixmap_gc, 0, 0, ScrMaxX + 1, - ScrMaxY + 1); - drw = pixmap; // Redisplaying from scratch so let's use the pixmap + XFillRectangle(dpy, pixmap, pixmap_gc, 0, 0, ScrMaxX + 1, + ScrMaxY + 1); + drw = pixmap; // Redisplaying from scratch so let's use the pixmap } } /* - * update_display - update the physical display + * update_display - update the physical display * - * Make sure the physical bitmap display (the X window) - * is up to date WRT the logical bitmap display (the X - * pixmap). + * Make sure the physical bitmap display (the X window) + * is up to date WRT the logical bitmap display (the X + * pixmap). * - * If == , it means that only partial - * changes were made and that they were made directly on - * the window, not on the pixmap so no need to copy the - * pixmap onto the window. + * If == , it means that only partial + * changes were made and that they were made directly on + * the window, not on the pixmap so no need to copy the + * pixmap onto the window. */ void update_display() { @@ -565,25 +565,25 @@ //fflush (stdout); if (!no_pixmap && drw == pixmap) { - //putchar ('*'); - XCopyArea(dpy, pixmap, win, pixmap_gc, 0, 0, ScrMaxX + 1, ScrMaxY + 1, - 0, 0); + //putchar ('*'); + XCopyArea(dpy, pixmap, win, pixmap_gc, 0, 0, ScrMaxX + 1, ScrMaxY + 1, + 0, 0); } XFlush(dpy); //printf ("] "); //fflush (stdout); drw_mods = 0; - drw = win; // If they don't like it, they can call ClearScreen() [HHOS] + drw = win; // If they don't like it, they can call ClearScreen() [HHOS] } /* - * force_window_not_pixmap - force graphic ops to use window + * force_window_not_pixmap - force graphic ops to use window * - * Redirect graphic output to window, not pixmap. Used only - * in yadex.cc, before calling the sprite viewer. + * Redirect graphic output to window, not pixmap. Used only + * in yadex.cc, before calling the sprite viewer. * - * FIXME this is not a clean way to do things. + * FIXME this is not a clean way to do things. */ void force_window_not_pixmap() { @@ -592,9 +592,9 @@ /* - * set_pcolour - set the current drawing colour + * set_pcolour - set the current drawing colour * - * must be an physical colour number (a.k.a. pixel value). + * must be an physical colour number (a.k.a. pixel value). */ void set_pcolour(pcolour_t colour) { @@ -607,7 +607,7 @@ /* - * get_colour - get the current drawing colour + * get_colour - get the current drawing colour */ acolour_t get_colour() { @@ -616,33 +616,33 @@ /* - * set_colour - set the current drawing colour + * set_colour - set the current drawing colour * - * must be an application colour number. + * must be an application colour number. */ void set_colour(acolour_t colour) { if (colour != current_acolour) { - current_acolour = colour; - XSetForeground(dpy, gc, app_colour[colour]); + current_acolour = colour; + XSetForeground(dpy, gc, app_colour[colour]); } } /* - * push_colour - push a colour into the colour stack + * push_colour - push a colour into the colour stack * - * Like set_colour() except that it will only last until - * the next call to pop_colour(). + * Like set_colour() except that it will only last until + * the next call to pop_colour(). */ void push_colour(acolour_t colour) { if (colour_stack_pointer >= - (int) (sizeof colour_stack / sizeof *colour_stack)) + (int) (sizeof colour_stack / sizeof *colour_stack)) { - nf_bug("Colour stack overflow"); - return; + nf_bug("Colour stack overflow"); + return; } colour_stack[colour_stack_pointer] = current_acolour; colour_stack_pointer++; @@ -651,16 +651,16 @@ /* - * pop_colour - pop the colour stack + * pop_colour - pop the colour stack * - * Cancel the effect of the last call to push_colour(). + * Cancel the effect of the last call to push_colour(). */ void pop_colour(void) { if (colour_stack_pointer < 1) { - nf_bug("Colour stack underflow"); - return; + nf_bug("Colour stack underflow"); + return; } colour_stack_pointer--; set_colour(colour_stack[colour_stack_pointer]); @@ -668,44 +668,44 @@ /* - * SetLineThickness - set the line style (thin or thick) + * SetLineThickness - set the line style (thin or thick) */ void SetLineThickness(int thick) { if (! !thick != LineThickness) { - LineThickness = ! !thick; - XGCValues gcv; - gcv.line_width = LineThickness ? 3 : (DrawingMode ? 1 : 0); - // ^ It's important to use a line_width of 1 when in xor mode. - // See note (1) in the hacker's guide. - XChangeGC(dpy, gc, GCLineWidth, &gcv); + LineThickness = ! !thick; + XGCValues gcv; + gcv.line_width = LineThickness ? 3 : (DrawingMode ? 1 : 0); + // ^ It's important to use a line_width of 1 when in xor mode. + // See note (1) in the hacker's guide. + XChangeGC(dpy, gc, GCLineWidth, &gcv); } } /* - * SetDrawingMode - set the drawing mode (copy or xor) + * SetDrawingMode - set the drawing mode (copy or xor) */ void SetDrawingMode(int _xor) { if (! !_xor != DrawingMode) { - DrawingMode = ! !_xor; - XGCValues gcv; - gcv.function = DrawingMode ? GXxor : GXcopy; - gcv.line_width = LineThickness ? 3 : (DrawingMode ? 1 : 0); - // ^ It's important to use a line_width of 1 when in xor mode. - // See note (1) in the hacker's guide. - XChangeGC(dpy, gc, GCFunction | GCLineWidth, &gcv); + DrawingMode = ! !_xor; + XGCValues gcv; + gcv.function = DrawingMode ? GXxor : GXcopy; + gcv.line_width = LineThickness ? 3 : (DrawingMode ? 1 : 0); + // ^ It's important to use a line_width of 1 when in xor mode. + // See note (1) in the hacker's guide. + XChangeGC(dpy, gc, GCFunction | GCLineWidth, &gcv); } } /* - * draw_point - draw a point at display coordinates + * draw_point - draw a point at display coordinates * - * The point is drawn at display coordinates (, ). + * The point is drawn at display coordinates (, ). */ void draw_point(int x, int y) { @@ -714,9 +714,9 @@ /* - * draw_map_point - draw a point at map coordinates + * draw_map_point - draw a point at map coordinates * - * The point is drawn at map coordinates (, ) + * The point is drawn at map coordinates (, ) */ void draw_map_point(int mapx, int mapy) { @@ -726,32 +726,32 @@ /* - * DrawMapLine - draw a line on the screen from map coords + * DrawMapLine - draw a line on the screen from map coords */ void DrawMapLine(int mapx1, int mapy1, int mapx2, int mapy2) { XDrawLine(dpy, drw, gc, SCREENX(mapx1), SCREENY(mapy1), - SCREENX(mapx2), SCREENY(mapy2)); + SCREENX(mapx2), SCREENY(mapy2)); drw_mods++; } /* - * DrawMapCircle - draw a circle on the screen from map coords + * DrawMapCircle - draw a circle on the screen from map coords */ void DrawMapCircle(int mapx, int mapy, int mapradius) { XDrawArc(dpy, drw, gc, SCREENX(mapx - mapradius), - SCREENY(mapy + mapradius), - (unsigned int) (2 * mapradius * Scale), - (unsigned int) (2 * mapradius * Scale), 0, 360 * 64); + SCREENY(mapy + mapradius), + (unsigned int) (2 * mapradius * Scale), + (unsigned int) (2 * mapradius * Scale), 0, 360 * 64); drw_mods++; } /* - * DrawMapVector - draw an arrow on the screen from map coords + * DrawMapVector - draw an arrow on the screen from map coords */ void DrawMapVector(int mapx1, int mapy1, int mapx2, int mapy2) { @@ -764,18 +764,18 @@ #if 0 /* AYM 19980216 to avoid getting huge arrowheads when zooming in */ int scrXoff = - (r >= - 1.0) ? (int) ((scrx1 - scrx2) * 8.0 / r * (Scale < - 1 ? Scale : 1)) : 0; + (r >= + 1.0) ? (int) ((scrx1 - scrx2) * 8.0 / r * (Scale < + 1 ? Scale : 1)) : 0; int scrYoff = - (r >= - 1.0) ? (int) ((scry1 - scry2) * 8.0 / r * (Scale < - 1 ? Scale : 1)) : 0; + (r >= + 1.0) ? (int) ((scry1 - scry2) * 8.0 / r * (Scale < + 1 ? Scale : 1)) : 0; #else int scrXoff = - (r >= 1.0) ? (int) ((scrx1 - scrx2) * 8.0 / r * (Scale / 2)) : 0; + (r >= 1.0) ? (int) ((scrx1 - scrx2) * 8.0 / r * (Scale / 2)) : 0; int scrYoff = - (r >= 1.0) ? (int) ((scry1 - scry2) * 8.0 / r * (Scale / 2)) : 0; + (r >= 1.0) ? (int) ((scry1 - scry2) * 8.0 / r * (Scale / 2)) : 0; #endif XDrawLine(dpy, drw, gc, scrx1, scry1, scrx2, scry2); @@ -788,7 +788,7 @@ /* - * DrawMapArrow - draw an arrow on the screen from map coords and angle (0 - 65535) + * DrawMapArrow - draw an arrow on the screen from map coords and angle (0 - 65535) */ void DrawMapArrow(int mapx1, int mapy1, unsigned angle) { @@ -801,18 +801,18 @@ double r = hypot(scrx1 - scrx2, scry1 - scry2); #if 0 int scrXoff = - (r >= - 1.0) ? (int) ((scrx1 - scrx2) * 8.0 / r * (Scale < - 1 ? Scale : 1)) : 0; + (r >= + 1.0) ? (int) ((scrx1 - scrx2) * 8.0 / r * (Scale < + 1 ? Scale : 1)) : 0; int scrYoff = - (r >= - 1.0) ? (int) ((scry1 - scry2) * 8.0 / r * (Scale < - 1 ? Scale : 1)) : 0; + (r >= + 1.0) ? (int) ((scry1 - scry2) * 8.0 / r * (Scale < + 1 ? Scale : 1)) : 0; #else int scrXoff = - (r >= 1.0) ? (int) ((scrx1 - scrx2) * 8.0 / r * (Scale / 2)) : 0; + (r >= 1.0) ? (int) ((scrx1 - scrx2) * 8.0 / r * (Scale / 2)) : 0; int scrYoff = - (r >= 1.0) ? (int) ((scry1 - scry2) * 8.0 / r * (Scale / 2)) : 0; + (r >= 1.0) ? (int) ((scry1 - scry2) * 8.0 / r * (Scale / 2)) : 0; #endif XDrawLine(dpy, drw, gc, scrx1, scry1, scrx2, scry2); @@ -825,7 +825,7 @@ /* - * DrawScreenLine - draw a line on the screen from screen coords + * DrawScreenLine - draw a line on the screen from screen coords */ void DrawScreenLine(int Xstart, int Ystart, int Xend, int Yend) { @@ -835,28 +835,28 @@ /* - * DrawScreenLineLen - draw a line on the screen + * DrawScreenLineLen - draw a line on the screen */ void DrawScreenLineLen(int x, int y, int width, int height) { if (width > 0) - width--; + width--; else if (width < 0) - width++; + width++; if (height > 0) - height--; + height--; else if (height < 0) - height++; + height++; XDrawLine(dpy, drw, gc, x, y, x + width, y + height); drw_mods++; } /* - * DrawScreenRect - draw a rectangle + * DrawScreenRect - draw a rectangle * - * Unlike most functions here, the 3rd and 4th parameters - * specify lengths, not coordinates. + * Unlike most functions here, the 3rd and 4th parameters + * specify lengths, not coordinates. */ void DrawScreenRect(int x, int y, int width, int height) { @@ -866,35 +866,35 @@ /* - * DrawScreenBox - draw a filled in box on the screen from screen coords + * DrawScreenBox - draw a filled in box on the screen from screen coords * - * (scrx1, scry1) is the top left corner - * (scrx2, scry2) is the bottom right corner - * If scrx2 < scrx1 or scry2 < scry1, the function does nothing. + * (scrx1, scry1) is the top left corner + * (scrx2, scry2) is the bottom right corner + * If scrx2 < scrx1 or scry2 < scry1, the function does nothing. */ void DrawScreenBox(int scrx1, int scry1, int scrx2, int scry2) { if (scrx2 < scrx1 || scry2 < scry1) - return; + return; // FIXME missing gc fill_style XFillRectangle(dpy, drw, gc, scrx1, scry1, - scrx2 - scrx1 + 1, scry2 - scry1 + 1); + scrx2 - scrx1 + 1, scry2 - scry1 + 1); drw_mods++; } /* - * DrawScreenBoxwh - draw a filled rectangle of width x height pixels + * DrawScreenBoxwh - draw a filled rectangle of width x height pixels * - * (scrx0, scry0) is the top left corner - * (width, height) is the obvious - * If width < 1 or height < 1, does nothing. + * (scrx0, scry0) is the top left corner + * (width, height) is the obvious + * If width < 1 or height < 1, does nothing. */ void DrawScreenBoxwh(int scrx0, int scry0, int width, int height) { if (width < 1 || height < 1) - return; + return; // FIXME missing gc fill_style XFillRectangle(dpy, drw, gc, scrx0, scry0, width, height); @@ -903,9 +903,9 @@ /* - * DrawScreenBox3D - draw a filled-in 3D box on the screen + * DrawScreenBox3D - draw a filled-in 3D box on the screen * - * The 3D border is rather wide (BOX_BORDER pixels wide). + * The 3D border is rather wide (BOX_BORDER pixels wide). */ void DrawScreenBox3D(int scrx1, int scry1, int scrx2, int scry2) { @@ -926,16 +926,16 @@ /* - * DrawScreenBox3DShallow - draw a filled-in 3D box on the screen + * DrawScreenBox3DShallow - draw a filled-in 3D box on the screen * - * Same thing as DrawScreenBox3D but shallow (the 3D border - * is NARROW_BORDER pixels wide). + * Same thing as DrawScreenBox3D but shallow (the 3D border + * is NARROW_BORDER pixels wide). */ void DrawScreenBox3DShallow(int scrx1, int scry1, int scrx2, int scry2) { push_colour(WINBG); XFillRectangle(dpy, drw, gc, scrx1 + 1, scry1 + 1, scrx2 - scrx1, - scry2 - scry1); + scry2 - scry1); set_colour(WINBG_DARK); XDrawLine(dpy, drw, gc, scrx1, scry2, scrx2, scry2); XDrawLine(dpy, drw, gc, scrx2, scry1, scrx2, scry2); @@ -948,15 +948,15 @@ /* - * draw_box_border - draw the 3D border of a box. + * draw_box_border - draw the 3D border of a box. * - * (x, y) is the outer top left corner. - * (width, height) are the outer dimensions. - * (thickness) is the thickness of the border in pixels. - * (raised) is zero for depressed, non-zero for raised. + * (x, y) is the outer top left corner. + * (width, height) are the outer dimensions. + * (thickness) is the thickness of the border in pixels. + * (raised) is zero for depressed, non-zero for raised. */ void draw_box_border(int x, int y, int width, int height, - int thickness, int raised) + int thickness, int raised) { int n; XPoint points[3]; @@ -975,11 +975,11 @@ points[2].y = 0; for (n = 0; n < thickness; n++) { - XDrawLines(dpy, drw, gc, points, 3, CoordModePrevious); - points[0].x--; - points[0].y++; - points[1].y--; - points[2].x++; + XDrawLines(dpy, drw, gc, points, 3, CoordModePrevious); + points[0].x--; + points[0].y++; + points[1].y--; + points[2].x++; } // Draw the left and top edges @@ -992,11 +992,11 @@ points[2].y = 0; for (n = 0; n < thickness; n++) { - XDrawLines(dpy, drw, gc, points, 3, CoordModePrevious); - points[0].x++; - points[0].y--; - points[1].y++; - points[2].x--; + XDrawLines(dpy, drw, gc, points, 3, CoordModePrevious); + points[0].x++; + points[0].y--; + points[1].y++; + points[2].x--; } pop_colour(); @@ -1004,18 +1004,18 @@ /* - * DrawScreenBoxHollow - draw a hollow 3D box on the screen + * DrawScreenBoxHollow - draw a hollow 3D box on the screen * - * The 3D border is HOLLOW_BORDER pixels wide. + * The 3D border is HOLLOW_BORDER pixels wide. */ void DrawScreenBoxHollow(int scrx1, int scry1, int scrx2, int scry2, - acolour_t colour) + acolour_t colour) { push_colour(colour); XFillRectangle(dpy, drw, gc, - scrx1 + HOLLOW_BORDER, scry1 + HOLLOW_BORDER, - scrx2 + 1 - scrx1 - 2 * HOLLOW_BORDER, - scry2 + 1 - scry1 - 2 * HOLLOW_BORDER); + scrx1 + HOLLOW_BORDER, scry1 + HOLLOW_BORDER, + scrx2 + 1 - scrx1 - 2 * HOLLOW_BORDER, + scry2 + 1 - scry1 - 2 * HOLLOW_BORDER); set_colour(WINBG_LIGHT); XDrawLine(dpy, drw, gc, scrx1, scry2, scrx2, scry2); XDrawLine(dpy, drw, gc, scrx2, scry1, scrx2, scry2); @@ -1028,23 +1028,23 @@ /* - * DrawScreenMeter - draw a meter bar on the screen + * DrawScreenMeter - draw a meter bar on the screen * - * In a hollow box; max. value = 1.0 + * In a hollow box; max. value = 1.0 */ void DrawScreenMeter(int scrx1, int scry1, int scrx2, int scry2, float value) { #if defined Y_BGI if (value < 0.0) - value = 0.0; + value = 0.0; if (value > 1.0) - value = 1.0; + value = 1.0; setfillstyle(1, TranslateToDoomColor(BLACK)); bar(scrx1 + 1 + (int) ((scrx2 - scrx1 - 2) * value), scry1 + 1, scrx2 - 1, - scry2 - 1); + scry2 - 1); setfillstyle(1, TranslateToDoomColor(LIGHTGREEN)); bar(scrx1 + 1, scry1 + 1, scrx1 + 1 + (int) ((scrx2 - scrx1 - 2) * value), - scry2 - 1); + scry2 - 1); #elif defined Y_X11 // FIXME #endif @@ -1064,16 +1064,16 @@ /* - * DrawScreenText - format and display a string + * DrawScreenText - format and display a string * - * Write text to the screen in printf() fashion. - * The top left corner of the first character is at (, ) - * If == -1, the text is printed at the same abscissa - * as the last text printed with this function. - * If == -1, the text is printed one line (FONTH pixels) - * below the last text printed with this function. - * If == NULL, no text is printed. Useful to set the - * coordinates for the next time. + * Write text to the screen in printf() fashion. + * The top left corner of the first character is at (, ) + * If == -1, the text is printed at the same abscissa + * as the last text printed with this function. + * If == -1, the text is printed one line (FONTH pixels) + * below the last text printed with this function. + * If == NULL, no text is printed. Useful to set the + * coordinates for the next time. */ void DrawScreenText(int scrx, int scry, const char *msg, ...) { @@ -1083,17 +1083,17 @@ // == NULL: print nothing, just set the coordinates. if (msg == NULL) { - if (scrx != -1 && scrx != -2) - { - lastx0 = scrx; - lastxcur = scrx; - } - if (scry != -1 && scry != -2) - { - lasty0 = scry; // Note: no "+ FONTH" - lastycur = scry; - } - return; + if (scrx != -1 && scrx != -2) + { + lastx0 = scrx; + lastxcur = scrx; + } + if (scry != -1 && scry != -2) + { + lasty0 = scry; // Note: no "+ FONTH" + lastycur = scry; + } + return; } va_start(args, msg); @@ -1103,27 +1103,27 @@ /* - * DrawScreenString - display a string + * DrawScreenString - display a string * - * Same thing as DrawScreenText() except that the string is - * printed verbatim (no formatting or conversion). + * Same thing as DrawScreenText() except that the string is + * printed verbatim (no formatting or conversion). * - * A "\1" in the string is not displayed but causes - * subsequent characters to be displayed in WINLABEL (or - * WINLABEL_DIM if the current colour before the function - * was called was WINFG_DIM). + * A "\1" in the string is not displayed but causes + * subsequent characters to be displayed in WINLABEL (or + * WINLABEL_DIM if the current colour before the function + * was called was WINFG_DIM). * - * A "\2" in the string is not displayed but causes - * subsequent characters to be displayed in the same colour - * that was active before the function was called. + * A "\2" in the string is not displayed but causes + * subsequent characters to be displayed in the same colour + * that was active before the function was called. * - * The string can contain any number of "\1" and "\2". - * Regardless, upon return from the function, the current - * colour is restored to what it was before the function - * was called. + * The string can contain any number of "\1" and "\2". + * Regardless, upon return from the function, the current + * colour is restored to what it was before the function + * was called. * - * This colour switching business was hacked in a hurry. - * Feel free to improve it. + * This colour switching business was hacked in a hurry. + * Feel free to improve it. */ void DrawScreenString(int scrx, int scry, const char *str) { @@ -1134,75 +1134,75 @@ when the screen was too small, I changed it to a more specific "== -1". A quick and very dirty hack ! */ if (scrx == -1) - x = lastx0; + x = lastx0; else if (scrx == -2) - x = lastxcur; + x = lastxcur; else - x = scrx; + x = scrx; if (scry == -1) - y = lasty0; + y = lasty0; else if (scry == -2) - y = lastycur; + y = lastycur; else - y = scry; + y = scry; size_t len = strlen(str); if (strchr(str, '\1') == 0) { - XDrawString(dpy, drw, gc, x - font_xofs, y + font_yofs, str, len); + XDrawString(dpy, drw, gc, x - font_xofs, y + font_yofs, str, len); } else { - acolour_t save = get_colour(); - int xx = x; - len = 0; - for (const char *p = str; *p != '\0';) - { - int i; - for (i = 0; p[i] != '\0' && p[i] != '\1' && p[i] != '\2'; i++) - ; - len += i; - if (i > 0) - { - XDrawString(dpy, drw, gc, xx - font_xofs, y + font_yofs, p, - i); - xx += i * FONTW; - } - if (p[i] == '\0') - break; - if (p[i] == '\1') - set_colour(save == WINFG_DIM ? WINLABEL_DIM : WINLABEL); - else if (p[i] == '\2') - set_colour(save); - i++; - p += i; - } - set_colour(save); + acolour_t save = get_colour(); + int xx = x; + len = 0; + for (const char *p = str; *p != '\0';) + { + int i; + for (i = 0; p[i] != '\0' && p[i] != '\1' && p[i] != '\2'; i++) + ; + len += i; + if (i > 0) + { + XDrawString(dpy, drw, gc, xx - font_xofs, y + font_yofs, p, + i); + xx += i * FONTW; + } + if (p[i] == '\0') + break; + if (p[i] == '\1') + set_colour(save == WINFG_DIM ? WINLABEL_DIM : WINLABEL); + else if (p[i] == '\2') + set_colour(save); + i++; + p += i; + } + set_colour(save); } if (text_dot) - XDrawPoint(dpy, drw, gc, x, y); + XDrawPoint(dpy, drw, gc, x, y); drw_mods++; lastxcur = x + FONTW * len; lastycur = y; if (scrx != -2) - lastx0 = x; + lastx0 = x; if (scry != -2) - lasty0 = y + FONTH; + lasty0 = y + FONTH; } /* - * DrawScreenChar - display a character + * DrawScreenChar - display a character * - * Same thing as DrawScreenText() except that the string is - * printed verbatim (no formatting or conversion). + * Same thing as DrawScreenText() except that the string is + * printed verbatim (no formatting or conversion). */ void DrawScreenChar(int x, int y, char c) { XDrawString(dpy, drw, gc, x - font_xofs, y + font_yofs, &c, 1); if (text_dot) - XDrawPoint(dpy, drw, gc, x, y); + XDrawPoint(dpy, drw, gc, x, y); drw_mods++; } diff -r 594dea11ccd9 -r a68786b9c74b src/gfx.h --- a/src/gfx.h Sat Sep 24 15:01:56 2011 +0300 +++ b/src/gfx.h Sat Sep 24 15:59:33 2011 +0300 @@ -1,11 +1,11 @@ /* - * gfx.h - * AYM 1998-08-01 + * gfx.h + * AYM 1998-08-01 */ -#ifndef YH_GFX /* Prevent multiple inclusion */ -#define YH_GFX /* Prevent multiple inclusion */ +#ifndef YH_GFX /* Prevent multiple inclusion */ +#define YH_GFX /* Prevent multiple inclusion */ /* Width and height of font cell. Those figures are not meant to @@ -38,41 +38,41 @@ #define WIDE_VSPACING (FONTH / 2) /* Boxes */ -#define BOX_BORDER 2 // Offset between outer and inner edges of a 3D box -#define NARROW_BORDER 1 // Same thing for a shallow 3D box -#define HOLLOW_BORDER 1 // Same thing for a hollow box -#define BOX_VSPACING WIDE_VSPACING // Vertical space between two hollow boxes +#define BOX_BORDER 2 // Offset between outer and inner edges of a 3D box +#define NARROW_BORDER 1 // Same thing for a shallow 3D box +#define HOLLOW_BORDER 1 // Same thing for a hollow box +#define BOX_VSPACING WIDE_VSPACING // Vertical space between two hollow boxes /* Parameters set by command line args and configuration file */ -extern const char *font_name; // X: the name of the font to load - // (if NULL, use the default) -extern Win_dim initial_window_width; // X: the name says it all -extern Win_dim initial_window_height; // X: the name says it all -extern int no_pixmap; // X: use no pixmap -- direct window output -extern int VideoMode; // BGI: default video mode for VESA cards +extern const char *font_name; // X: the name of the font to load + // (if NULL, use the default) +extern Win_dim initial_window_width; // X: the name says it all +extern Win_dim initial_window_height; // X: the name says it all +extern int no_pixmap; // X: use no pixmap -- direct window output +extern int VideoMode; // BGI: default video mode for VESA cards /* Global variables */ extern int GfxMode; -extern int OrigX; // Map X-coord of centre of screen/window -extern int OrigY; // Map Y-coord of centre of screen/window -extern int ScrCenterX; // Display X-coord of center of screen/window -extern int ScrCenterY; // Display Y-coord of center of screen/window -typedef unsigned long xpv_t; // The type of a pixel value in X's opinion +extern int OrigX; // Map X-coord of centre of screen/window +extern int OrigY; // Map Y-coord of centre of screen/window +extern int ScrCenterX; // Display X-coord of center of screen/window +extern int ScrCenterY; // Display Y-coord of center of screen/window +typedef unsigned long xpv_t; // The type of a pixel value in X's opinion #ifdef X_PROTOCOL extern Display *dpy; extern int scn; -extern Colormap cmap; // The X colormap +extern Colormap cmap; // The X colormap extern Window win; extern Drawable drw; extern GC gc; -extern Visual *win_vis; // The visual for win -extern int win_depth; // The depth of win in bits -extern int win_bpp; // The depth of win in bytes -extern int x_server_big_endian; // Is the X server big-endian ? -extern int ximage_bpp; // Number of bytes per pixels in XImages -extern int ximage_quantum; // Pad XImage lines to a mult of that many B. +extern Visual *win_vis; // The visual for win +extern int win_depth; // The depth of win in bits +extern int win_bpp; // The depth of win in bytes +extern int x_server_big_endian; // Is the X server big-endian ? +extern int ximage_bpp; // Number of bytes per pixels in XImages +extern int ximage_quantum; // Pad XImage lines to a mult of that many B. #endif // ifdef X_PROTOCOL -extern int text_dot; // DrawScreenText()/DrawScreenString() debug flag +extern int text_dot; // DrawScreenText()/DrawScreenString() debug flag /* gfx.cc */ int InitGfx(void); @@ -95,7 +95,7 @@ void DrawScreenBox3DShallow(int, int, int, int); void DrawScreenBoxHollow(int x0, int y0, int x1, int y1, acolour_t colour); void draw_box_border(int x, int y, int width, int height, - int thickness, int raised); + int thickness, int raised); void DrawScreenText(int, int, const char *, ...); void DrawScreenString(int, int, const char *); void DrawScreenChar(int x, int y, char c); diff -r 594dea11ccd9 -r a68786b9c74b src/gfx3.cc --- a/src/gfx3.cc Sat Sep 24 15:01:56 2011 +0300 +++ b/src/gfx3.cc Sat Sep 24 15:59:33 2011 +0300 @@ -1,7 +1,7 @@ /* - * gfx3.cc - * Graphics routines - * AYM 1999-06-06 + * gfx3.cc + * Graphics routines + * AYM 1999-06-06 */ @@ -37,29 +37,29 @@ /* - * window_to_rgbbmp - * Grab a rectangle from the window or screen into an - * Rgbbmp, in a portable fashion. + * window_to_rgbbmp + * Grab a rectangle from the window or screen into an + * Rgbbmp, in a portable fashion. */ void window_to_rgbbmp(int x, int y, int width, int height, Rgbbmp & b) { b.resize(width, height); // FIXME for (int y = 0; y < b.height(); y++) - for (int x = 0; x < b.width(); x++) - b.set_r(x, y, 255 * (b.height() - y) / b.height()); + for (int x = 0; x < b.width(); x++) + b.set_r(x, y, 255 * (b.height() - y) / b.height()); for (int y = 0; y < b.height(); y++) - for (int x = 0; x < b.width(); x++) - b.set_g(x, y, 255 * (b.width() - x) / b.width()); + for (int x = 0; x < b.width(); x++) + b.set_g(x, y, 255 * (b.width() - x) / b.width()); for (int y = 0; y < b.height(); y++) - for (int x = 0; x < b.width(); x++) - b.set_b(x, y, 255 * (x + y) / (b.width() + b.height())); + for (int x = 0; x < b.width(); x++) + b.set_b(x, y, 255 * (x + y) / (b.width() + b.height())); } /* - * rgbbmp_to_rawppm - * Return 0 on success, non-zero on failure. + * rgbbmp_to_rawppm + * Return 0 on success, non-zero on failure. */ int rgbbmp_to_rawppm(const Rgbbmp & b, const char *file_name) { @@ -67,28 +67,28 @@ fd = fopen(file_name, "wb"); if (fd == 0) { - fflush(stdout); - fprintf(stderr, "Can't open \"%s\" for writing (%s)\n", - file_name, strerror(errno)); - fflush(stderr); - return 1; + fflush(stdout); + fprintf(stderr, "Can't open \"%s\" for writing (%s)\n", + file_name, strerror(errno)); + fflush(stderr); + return 1; } fprintf(fd, "P6\n" - "# Created by Yadex %s\n" - "%d %d\n" "255\n", yadex_version, b.width(), b.height()); + "# Created by Yadex %s\n" + "%d %d\n" "255\n", yadex_version, b.width(), b.height()); for (int y = 0; y < b.height(); y++) - for (int x = 0; x < b.width(); x++) - { - putc(b.get_r(x, y), fd); - putc(b.get_g(x, y), fd); - putc(b.get_b(x, y), fd); - } + for (int x = 0; x < b.width(); x++) + { + putc(b.get_r(x, y), fd); + putc(b.get_g(x, y), fd); + putc(b.get_b(x, y), fd); + } if (fclose(fd)) { - fflush(stdout); - fprintf(stderr, "Write error in \"%s\"\n", file_name); - fflush(stderr); - return 1; + fflush(stdout); + fprintf(stderr, "Write error in \"%s\"\n", file_name); + fflush(stderr); + return 1; } return 0; } diff -r 594dea11ccd9 -r a68786b9c74b src/gfx3.h --- a/src/gfx3.h Sat Sep 24 15:01:56 2011 +0300 +++ b/src/gfx3.h Sat Sep 24 15:59:33 2011 +0300 @@ -1,6 +1,6 @@ /* - * gfx3.h - * AYM 1999-06-06 + * gfx3.h + * AYM 1999-06-06 */ diff -r 594dea11ccd9 -r a68786b9c74b src/gotoobj.cc --- a/src/gotoobj.cc Sat Sep 24 15:01:56 2011 +0300 +++ b/src/gotoobj.cc Sat Sep 24 15:59:33 2011 +0300 @@ -1,6 +1,6 @@ /* - * gotoobj.cc - * AYM 1998-09-06 + * gotoobj.cc + * AYM 1998-09-06 */ @@ -37,9 +37,9 @@ /* - * CenterMapAroundCoords - * Change the view so that the map coordinates (xpos, ypos) - * appear at the centre of the window + * CenterMapAroundCoords + * Change the view so that the map coordinates (xpos, ypos) + * appear at the centre of the window */ void CenterMapAroundCoords(int xpos, int ypos) { @@ -56,9 +56,9 @@ /* - * focus_on_map_coords - * Change the view so that the map coordinates (xpos, ypos) - * appear under the pointer + * focus_on_map_coords + * Change the view so that the map coordinates (xpos, ypos) + * appear under the pointer */ void focus_on_map_coords(int x, int y) { @@ -68,8 +68,8 @@ /* - * sector_under_pointer - * Convenience function + * sector_under_pointer + * Convenience function */ inline int sector_under_pointer() { @@ -83,7 +83,7 @@ centre the map around the object and zoom in if necessary */ -void GoToObject(const Objid & objid) /* SWAP! */ +void GoToObject(const Objid & objid) /* SWAP! */ { int xpos, ypos; int xpos2, ypos2; @@ -101,12 +101,12 @@ #if 0 /* zoom in until the object can be selected */ while (Scale < 8.0 - && GetCurObject(objid.type, MAPX(is.x), MAPY(is.y)) != objid.num) + && GetCurObject(objid.type, MAPX(is.x), MAPY(is.y)) != objid.num) { - if (Scale < 1.0) - Scale = 1.0 / ((1.0 / Scale) - 1.0); - else - Scale = Scale * 2.0; + if (Scale < 1.0) + Scale = 1.0 / ((1.0 / Scale) - 1.0); + else + Scale = Scale * 2.0; } #endif @@ -123,25 +123,25 @@ fault). */ if (objid.type == OBJ_SECTORS && sector_under_pointer() != objid.num) { - /* restore the Scale */ - Scale = oldscale; - for (int n = 0; n < NumLineDefs; n++) - { - sd1 = LineDefs[n].sidedef1; - sd2 = LineDefs[n].sidedef2; - if (sd1 >= 0 && SideDefs[sd1].sector == objid.num - || sd2 >= 0 && SideDefs[sd2].sector == objid.num) - { - GetObjectCoords(OBJ_LINEDEFS, n, &xpos2, &ypos2); - int d = ComputeDist(abs(xpos - xpos2), abs(ypos - ypos2)) / 7; - if (d <= 1) - d = 2; - xpos = xpos2 + (xpos - xpos2) / d; - ypos = ypos2 + (ypos - ypos2) / d; - focus_on_map_coords(xpos, ypos); - if (sector_under_pointer() == objid.num) - break; - } - } + /* restore the Scale */ + Scale = oldscale; + for (int n = 0; n < NumLineDefs; n++) + { + sd1 = LineDefs[n].sidedef1; + sd2 = LineDefs[n].sidedef2; + if (sd1 >= 0 && SideDefs[sd1].sector == objid.num + || sd2 >= 0 && SideDefs[sd2].sector == objid.num) + { + GetObjectCoords(OBJ_LINEDEFS, n, &xpos2, &ypos2); + int d = ComputeDist(abs(xpos - xpos2), abs(ypos - ypos2)) / 7; + if (d <= 1) + d = 2; + xpos = xpos2 + (xpos - xpos2) / d; + ypos = ypos2 + (ypos - ypos2) / d; + focus_on_map_coords(xpos, ypos); + if (sector_under_pointer() == objid.num) + break; + } + } } } diff -r 594dea11ccd9 -r a68786b9c74b src/gotoobj.h --- a/src/gotoobj.h Sat Sep 24 15:01:56 2011 +0300 +++ b/src/gotoobj.h Sat Sep 24 15:59:33 2011 +0300 @@ -1,6 +1,6 @@ /* - * gotoobj.h - * AYM 1998-09-06 + * gotoobj.h + * AYM 1998-09-06 */ @@ -8,4 +8,4 @@ void CenterMapAroundCoords(int, int); -void GoToObject(const Objid & objid); /* SWAP! */ +void GoToObject(const Objid & objid); /* SWAP! */ diff -r 594dea11ccd9 -r a68786b9c74b src/help1.cc --- a/src/help1.cc Sat Sep 24 15:01:56 2011 +0300 +++ b/src/help1.cc Sat Sep 24 15:59:33 2011 +0300 @@ -1,6 +1,6 @@ /* - * help1.cc - * AYM 1998-10-03 + * help1.cc + * AYM 1998-10-03 */ @@ -33,22 +33,22 @@ /* - * what - * Return a static string containing - * the name and version number of Yadex. + * what + * Return a static string containing + * the name and version number of Yadex. */ const char *what() { static char buf[40]; y_snprintf(buf, sizeof buf, "Yadex %s (%s)", yadex_version, - yadex_source_date); + yadex_source_date); return buf; } /* - * print_usage - * Print the program usage. + * print_usage + * Print the program usage. */ void print_usage(FILE * fd) { @@ -59,66 +59,66 @@ fprintf(fd, " %-33sSame as -?\n", "--help"); fprintf(fd, " %-33sPrint version and exit\n", "--version"); fprintf(fd, "Put a \"+\" instead of a \"-\" before boolean options" - " to reverse their effect.\n"); + " to reverse their effect.\n"); } /* - * print_welcome - * Print the welcome message + * print_welcome + * Print the welcome message */ void print_welcome(FILE * fd) { #ifdef OLD_MESSAGE fprintf(fd, "\n"); fprintf(fd, - "*----------------------------------------------------------------------------*\n"); + "*----------------------------------------------------------------------------*\n"); fprintf(fd, - "| Welcome to DEU! This is a poweful utility and, like all good tools, it |\n"); + "| Welcome to DEU! This is a poweful utility and, like all good tools, it |\n"); fprintf(fd, - "| comes with its user's manual. Please print and read DEU.TXT if you want |\n"); + "| comes with its user's manual. Please print and read DEU.TXT if you want |\n"); fprintf(fd, - "| to discover all the features of this program. If you are new to DEU, the |\n"); + "| to discover all the features of this program. If you are new to DEU, the |\n"); fprintf(fd, - "| tutorial will show you how to build your first level. |\n"); + "| tutorial will show you how to build your first level. |\n"); fprintf(fd, - "| |\n"); + "| |\n"); fprintf(fd, - "| If you are an experienced DEU user and want to know what has changed since |\n"); + "| If you are an experienced DEU user and want to know what has changed since |\n"); fprintf(fd, - "| the last version, you should read the revision history in README.1ST. |\n"); + "| the last version, you should read the revision history in README.1ST. |\n"); fprintf(fd, - "| |\n"); + "| |\n"); fprintf(fd, - "| And if you have lots of suggestions for improvements, bug reports, or even |\n"); + "| And if you have lots of suggestions for improvements, bug reports, or even |\n"); fprintf(fd, - "| complaints about this program, be sure to read README.1ST first. |\n"); + "| complaints about this program, be sure to read README.1ST first. |\n"); fprintf(fd, - "| Hint: you can easily disable this message. Read the docs carefully... |\n"); + "| Hint: you can easily disable this message. Read the docs carefully... |\n"); fprintf(fd, - "*----------------------------------------------------------------------------*\n"); + "*----------------------------------------------------------------------------*\n"); #else fprintf(fd, "\n" - "** Welcome to Yadex. Glad you've made it so far. :-)\n"); + "** Welcome to Yadex. Glad you've made it so far. :-)\n"); #if defined Y_ALPHA fprintf(fd, "**\n" - "** This is an alpha version. Expect it to have bugs. Do\n" - "** yourself a favour and make backup copies of your data !\n" - "**\n"); + "** This is an alpha version. Expect it to have bugs. Do\n" + "** yourself a favour and make backup copies of your data !\n" + "**\n"); #elif defined Y_BETA fprintf(fd, "**\n" - "** This is a beta version. It is believed to be reasonably\n" - "** stable but it's been given only limited testing. So do\n" - "** yourself a favour and make backup copies of your data.\n" - "**\n"); + "** This is a beta version. It is believed to be reasonably\n" + "** stable but it's been given only limited testing. So do\n" + "** yourself a favour and make backup copies of your data.\n" + "**\n"); #else fprintf(fd, "**\n" - "** This version is believed to be stable but you never\n" - "** know so make backup copies of your data anyway.\n" "**\n"); + "** This version is believed to be stable but you never\n" + "** know so make backup copies of your data anyway.\n" "**\n"); #endif fprintf(fd, - "** Yadex is work in progress. Subscribe to yadex-announce\n"); + "** Yadex is work in progress. Subscribe to yadex-announce\n"); fprintf(fd, "** or keep an eye on the web page.\n"); fprintf(fd, "** To edit an existing level, type \"e \".\n"); fprintf(fd, "** To create a new level, type \"c\".\n" "\n"); diff -r 594dea11ccd9 -r a68786b9c74b src/help1.h --- a/src/help1.h Sat Sep 24 15:01:56 2011 +0300 +++ b/src/help1.h Sat Sep 24 15:59:33 2011 +0300 @@ -1,6 +1,6 @@ /* - * help1.h - * AYM 1998-10-03 + * help1.h + * AYM 1998-10-03 */ diff -r 594dea11ccd9 -r a68786b9c74b src/help2.cc --- a/src/help2.cc Sat Sep 24 15:01:56 2011 +0300 +++ b/src/help2.cc Sat Sep 24 15:59:33 2011 +0300 @@ -1,6 +1,6 @@ /* - * help2.cc - * AYM 1998-08-17 + * help2.cc + * AYM 1998-08-17 */ @@ -30,7 +30,7 @@ #include "yadex.h" #include "credits.h" #include "gfx.h" -#include "help1.h" // what() +#include "help1.h" // what() #include "help2.h" @@ -78,7 +78,7 @@ NULL }; -void DisplayHelp() /* SWAP! */ +void DisplayHelp() /* SWAP! */ { int x0; int y0; @@ -89,9 +89,9 @@ for (const char **str = help_text; *str; str++) { - size_t len = strlen(*str); - maxlen = y_max(maxlen, len); - lines++; + size_t len = strlen(*str); + maxlen = y_max(maxlen, len); + lines++; } width = (maxlen + 4) * FONTW + 2 * BOX_BORDER; height = lines * FONTH + 2 * BOX_BORDER; @@ -101,11 +101,11 @@ DrawScreenBox3D(x0, y0, x0 + width - 1, y0 + height - 1); set_colour(LIGHTCYAN); DrawScreenText(x0 + BOX_BORDER + (width - 5 * FONTW) / 2, - y0 + BOX_BORDER + FONTH / 2, "Yadex"); + y0 + BOX_BORDER + FONTH / 2, "Yadex"); set_colour(WINFG); DrawScreenText(x0 + BOX_BORDER + 2 * FONTW, y0 + BOX_BORDER + FONTH, ""); for (const char **str = help_text; *str; str++) - DrawScreenText(-1, -1, *str); + DrawScreenText(-1, -1, *str); set_colour(WINTITLE); DrawScreenText(-1, -1, "Press any key to return to the editor..."); get_key_or_click(); @@ -113,8 +113,8 @@ /* - * about_yadex() - * The name says it all. + * about_yadex() + * The name says it all. */ void about_yadex() { @@ -123,9 +123,9 @@ for (const char *const *s = yadex_copyright; *s != 0; s++) { - if (strlen(*s) > size_t(widthc)) - widthc = strlen(*s); - heightc++; + if (strlen(*s) > size_t(widthc)) + widthc = strlen(*s); + heightc++; } int width = 2 * BOX_BORDER + 2 * WIDE_HSPACING + widthc * FONTW; int height = 2 * BOX_BORDER + 2 * WIDE_VSPACING + heightc * FONTH; @@ -136,11 +136,11 @@ push_colour(WINFG); push_colour(WINFG_HL); DrawScreenText(x0 + BOX_BORDER + WIDE_HSPACING, - y0 + BOX_BORDER + WIDE_VSPACING, what()); + y0 + BOX_BORDER + WIDE_VSPACING, what()); pop_colour(); DrawScreenText(-1, -1, ""); for (const char *const *s = yadex_copyright; *s != 0; s++) - DrawScreenText(-1, -1, *s); + DrawScreenText(-1, -1, *s); DrawScreenText(-1, -1, ""); push_colour(WINFG_HL); DrawScreenText(-1, -1, "Home page :"); @@ -155,14 +155,14 @@ DrawScreenText(-1, -1, "you-know-what-announce@freelists.org"); DrawScreenText(-1, -1, "To subscribe, send mail with the subject"); DrawScreenText(-1, -1, - "\"subscribe \" to ecartis@freelists.org."); + "\"subscribe \" to ecartis@freelists.org."); DrawScreenText(-1, -1, ""); push_colour(WINFG_HL); DrawScreenText(-1, -1, "Maintainer :"); pop_colour(); DrawScreenText(-1, -1, "André Majorel (http://www.teaser.fr/~amajorel/)"); DrawScreenText(-1, -1, - "Send all email to you-know-what@freelists.org, NOT to me."); + "Send all email to you-know-what@freelists.org, NOT to me."); DrawScreenText(-1, -1, ""); DrawScreenText(-1, -1, ""); set_colour(WINTITLE); diff -r 594dea11ccd9 -r a68786b9c74b src/help2.h --- a/src/help2.h Sat Sep 24 15:01:56 2011 +0300 +++ b/src/help2.h Sat Sep 24 15:59:33 2011 +0300 @@ -1,6 +1,6 @@ /* - * help2.h - * AYM + * help2.h + * AYM */ diff -r 594dea11ccd9 -r a68786b9c74b src/highlt.cc --- a/src/highlt.cc Sat Sep 24 15:01:56 2011 +0300 +++ b/src/highlt.cc Sat Sep 24 15:59:33 2011 +0300 @@ -1,6 +1,6 @@ /* - * highlt.cc - * AYM 1998-09-20 + * highlt.cc + * AYM 1998-09-20 */ @@ -44,8 +44,8 @@ { if (!obj_disp() && obj()) { - HighlightObject(obj.type, obj.num, YELLOW); - obj_disp = obj; + HighlightObject(obj.type, obj.num, YELLOW); + obj_disp = obj; } } @@ -54,7 +54,7 @@ { if (obj_disp() && !(obj_disp == obj)) { - HighlightObject(obj_disp.type, obj_disp.num, YELLOW); - obj_disp.nil(); + HighlightObject(obj_disp.type, obj_disp.num, YELLOW); + obj_disp.nil(); } } diff -r 594dea11ccd9 -r a68786b9c74b src/highlt.h --- a/src/highlt.h Sat Sep 24 15:01:56 2011 +0300 +++ b/src/highlt.h Sat Sep 24 15:59:33 2011 +0300 @@ -1,6 +1,6 @@ /* - * highlt.h - * AYM 1998-09-20 + * highlt.h + * AYM 1998-09-20 */ @@ -36,30 +36,30 @@ public: highlight_c(void); void set(Objid & obj) { - this->obj = obj; + this->obj = obj; } /* Methods declared in edwidget */ void unset() { - obj.nil(); + obj.nil(); } void draw(); void undraw(); int can_undraw() { - return 1; - } // I have the ability to undraw myself. + return 1; + } // I have the ability to undraw myself. int need_to_clear() { - return 0; - } // I know how to undraw myself. + return 0; + } // I know how to undraw myself. void clear() { - obj_disp.nil(); + obj_disp.nil(); } private: - Objid obj; // The object we should highlight - Objid obj_disp; // The object that is really highlighted + Objid obj; // The object we should highlight + Objid obj_disp; // The object that is really highlighted }; diff -r 594dea11ccd9 -r a68786b9c74b src/img.cc --- a/src/img.cc Sat Sep 24 15:01:56 2011 +0300 +++ b/src/img.cc Sat Sep 24 15:59:33 2011 +0300 @@ -1,6 +1,6 @@ /* - * img.cc - Game image object (255 colours + transparency) - * AYM 2000-06-13 + * img.cc - Game image object (255 colours + transparency) + * AYM 2000-06-13 */ @@ -40,15 +40,15 @@ public: Img_priv() { - buf = 0; - width = 0; - height = 0; - opaque = false; + buf = 0; + width = 0; + height = 0; + opaque = false; } ~Img_priv() { - if (buf != 0) - delete[]buf; + if (buf != 0) + delete[]buf; } img_pixel_t *buf; img_dim_t width; @@ -58,9 +58,9 @@ /* - * Img::Img - default constructor + * Img::Img - default constructor * - * The new image is a null image. + * The new image is a null image. */ Img::Img() { @@ -69,9 +69,9 @@ /* - * Img::Img - constructor with dimensions + * Img::Img - constructor with dimensions * - * The new image is set to the specified dimensions. + * The new image is set to the specified dimensions. */ Img::Img(img_dim_t width, img_dim_t height, bool opaque) { @@ -82,7 +82,7 @@ /* - * Img::~Img - dtor + * Img::~Img - dtor */ Img::~Img() { @@ -91,7 +91,7 @@ /* - * Img::is_null - return true iff this is a null image + * Img::is_null - return true iff this is a null image */ bool Img::is_null() const { @@ -100,9 +100,9 @@ /* - * Img::width - return the current width + * Img::width - return the current width * - * If the image is null, return 0. + * If the image is null, return 0. */ img_dim_t Img::width() const { @@ -111,9 +111,9 @@ /* - * Img::height - return the current height + * Img::height - return the current height * - * If the image is null, return 0. + * If the image is null, return 0. */ img_dim_t Img::height() const { @@ -122,9 +122,9 @@ /* - * Img::buf - return a const pointer on the buffer + * Img::buf - return a const pointer on the buffer * - * If the image is null, return a null pointer. + * If the image is null, return a null pointer. */ const img_pixel_t *Img::buf() const { @@ -133,9 +133,9 @@ /* - * Img::wbuf - return a writable pointer on the buffer + * Img::wbuf - return a writable pointer on the buffer * - * If the image is null, return a null pointer. + * If the image is null, return a null pointer. */ img_pixel_t *Img::wbuf() { @@ -144,17 +144,17 @@ /* - * Img::clear - clear the image + * Img::clear - clear the image */ void Img::clear() { if (p->buf != 0) - memset(p->buf, IMG_TRANSP, p->width * p->height); + memset(p->buf, IMG_TRANSP, p->width * p->height); } /* - * Img::set_opaque - set or clear the opaque flag + * Img::set_opaque - set or clear the opaque flag */ void Img::set_opaque(bool opaque) { @@ -163,47 +163,47 @@ /* - * Img::resize - resize the image + * Img::resize - resize the image * - * If either dimension is zero, the image becomes a null - * image. + * If either dimension is zero, the image becomes a null + * image. */ void Img::resize(img_dim_t width, img_dim_t height) { if (width == p->width && height == p->height) - return; + return; // Unallocate old buffer if (p->buf != 0) { - delete[]p->buf; - p->buf = 0; + delete[]p->buf; + p->buf = 0; } // Is it a null image ? if (width == 0 || height == 0) { - p->width = 0; - p->height = 0; - return; + p->width = 0; + p->height = 0; + return; } // Allocate new buffer p->width = width; p->height = height; - p->buf = new img_pixel_t[width * height + 10]; // Some slack + p->buf = new img_pixel_t[width * height + 10]; // Some slack clear(); } /* - * Img::save - save an image to file in packed PPM format + * Img::save - save an image to file in packed PPM format * - * Return 0 on success, non-zero on failure + * Return 0 on success, non-zero on failure * - * If an error occurs, errno is set to: - * - ECHILD if PLAYPAL could not be loaded - * - whatever fopen() or fclose() set it to + * If an error occurs, errno is set to: + * - ECHILD if PLAYPAL could not be loaded + * - whatever fopen() or fclose() set it to */ int Img::save(const char *filename) const { @@ -214,67 +214,67 @@ MDirPtr dir = FindMasterDir(MasterDir, "PLAYPAL"); if (dir == 0) { - errno = ECHILD; - return 1; + errno = ECHILD; + return 1; } unsigned char *pal = new unsigned char[768]; dir->wadfile->seek(dir->dir.start); if (dir->wadfile->error()) { - /*warn ("%s: can't seek to %lXh\n", - dir->wadfile->filename, (unsigned long) ftell (dir->wadfile->fp)); - warn ("PLAYPAL: seek error\n"); */ - rc = 1; - errno = ECHILD; - goto byebye; + /*warn ("%s: can't seek to %lXh\n", + dir->wadfile->filename, (unsigned long) ftell (dir->wadfile->fp)); + warn ("PLAYPAL: seek error\n"); */ + rc = 1; + errno = ECHILD; + goto byebye; } dir->wadfile->read_bytes(pal, 768); if (dir->wadfile->error()) { - /*warn ("%s: read error", dir->wadfile->where ()); - warn ("PLAYPAL: read error\n"); */ - rc = 1; - errno = ECHILD; - goto byebye; + /*warn ("%s: read error", dir->wadfile->where ()); + warn ("PLAYPAL: read error\n"); */ + rc = 1; + errno = ECHILD; + goto byebye; } // Create PPM file fp = fopen(filename, "wb"); if (fp == NULL) { - rc = 1; - goto byebye; + rc = 1; + goto byebye; } fputs("P6\n", fp); fprintf(fp, "# %s\n", what()); fprintf(fp, "%d %d 255\n", p->width, p->height); { - const img_pixel_t *pix = p->buf; - const img_pixel_t *pixmax = - pix + (unsigned long) p->width * p->height; - for (; pix < pixmax; pix++) - { - if (*pix == IMG_TRANSP && !p->opaque) - { - putc(0, fp); // DeuTex convention, rgb:0/2f/2f - putc(47, fp); - putc(47, fp); - } - else - { - putc(pal[3 * *pix], fp); - putc(pal[3 * *pix + 1], fp); - putc(pal[3 * *pix + 2], fp); - } - } + const img_pixel_t *pix = p->buf; + const img_pixel_t *pixmax = + pix + (unsigned long) p->width * p->height; + for (; pix < pixmax; pix++) + { + if (*pix == IMG_TRANSP && !p->opaque) + { + putc(0, fp); // DeuTex convention, rgb:0/2f/2f + putc(47, fp); + putc(47, fp); + } + else + { + putc(pal[3 * *pix], fp); + putc(pal[3 * *pix + 1], fp); + putc(pal[3 * *pix + 2], fp); + } + } } if (ferror(fp)) - rc = 1; + rc = 1; byebye: if (fp != 0) - if (fclose(fp)) - rc = 1; + if (fclose(fp)) + rc = 1; delete[]pal; return rc; } diff -r 594dea11ccd9 -r a68786b9c74b src/img.h --- a/src/img.h Sat Sep 24 15:01:56 2011 +0300 +++ b/src/img.h Sat Sep 24 15:59:33 2011 +0300 @@ -1,10 +1,10 @@ /* - * img.h - Game image object (255 colours + transparency) - * AYM 2000-06-13 + * img.h - Game image object (255 colours + transparency) + * AYM 2000-06-13 */ -#ifndef YH_IMG /* DO NOT INSERT ANYTHING BEFORE THIS LINE */ +#ifndef YH_IMG /* DO NOT INSERT ANYTHING BEFORE THIS LINE */ #define YH_IMG @@ -24,18 +24,18 @@ public: Img(); Img(img_dim_t width, img_dim_t height, bool opaque); ~Img(); - bool is_null() const; // Is it a null image ? - img_dim_t width() const; // Return the width - img_dim_t height() const; // Return the height - const img_pixel_t *buf() const; // Return pointer on buffer - img_pixel_t *wbuf(); // Return pointer on buffer + bool is_null() const; // Is it a null image ? + img_dim_t width() const; // Return the width + img_dim_t height() const; // Return the height + const img_pixel_t *buf() const; // Return pointer on buffer + img_pixel_t *wbuf(); // Return pointer on buffer void clear(); void set_opaque(bool opaque); void resize(img_dim_t width, img_dim_t height); int save(const char *filename) const; - private: Img(const Img &); // Too lazy to implement it - Img & operator=(const Img &); // Too lazy to implement it + private: Img(const Img &); // Too lazy to implement it + Img & operator=(const Img &); // Too lazy to implement it Img_priv *p; }; diff -r 594dea11ccd9 -r a68786b9c74b src/imgscale.cc --- a/src/imgscale.cc Sat Sep 24 15:01:56 2011 +0300 +++ b/src/imgscale.cc Sat Sep 24 15:59:33 2011 +0300 @@ -1,6 +1,6 @@ /* - * imgscale.cc - * AYM 2000-06-16 + * imgscale.cc + * AYM 2000-06-16 */ @@ -32,28 +32,28 @@ /* - * scale_img - scale a game image + * scale_img - scale a game image * - * is the source image, is the destination - * image. is the scaling factor (> 1.0 to magnify). - * A scaled copy of is put in . is not - * modified. Any previous data in is lost. + * is the source image, is the destination + * image. is the scaling factor (> 1.0 to magnify). + * A scaled copy of is put in . is not + * modified. Any previous data in is lost. * - * Example: + * Example: * - * Img raw; - * Img scaled; - * LoadPicture (raw, ...); - * scale_img (raw, 2, scaled); - * display_img (scaled, ...); + * Img raw; + * Img scaled; + * LoadPicture (raw, ...); + * scale_img (raw, 2, scaled); + * display_img (scaled, ...); * - * The implementation is mediocre in the case of scale - * factors < 1 because it uses only one source pixel per - * destination pixel. On certain patterns, it's likely to - * cause a visible loss of quality. + * The implementation is mediocre in the case of scale + * factors < 1 because it uses only one source pixel per + * destination pixel. On certain patterns, it's likely to + * cause a visible loss of quality. * - * In the case of scale factors > 1, the algorithm is - * suboptimal. + * In the case of scale factors > 1, the algorithm is + * suboptimal. */ void scale_img(const Img & img, double scale, Img & omg) { @@ -66,49 +66,49 @@ if (scale <= 2.0) { #if 0 - img_pixel_t *orow = obuf; - for (int oy = 0; oy < oheight; oy++) - { - int iy = (int) (oy / scale); - const img_pixel_t *const irow = ibuf + iwidth * iy; - for (int ox = 0; ox < owidth; ox++) - { - int ix = (int) (ox / scale); - *orow++ = irow[ix]; - } - } + img_pixel_t *orow = obuf; + for (int oy = 0; oy < oheight; oy++) + { + int iy = (int) (oy / scale); + const img_pixel_t *const irow = ibuf + iwidth * iy; + for (int ox = 0; ox < owidth; ox++) + { + int ix = (int) (ox / scale); + *orow++ = irow[ix]; + } + } #else // Supposedly faster ? - img_pixel_t *orow = obuf; - int *ix = new int[owidth]; - for (int ox = 0; ox < owidth; ox++) - ix[ox] = (int) (ox / scale); - const int *const ix_end = ix + owidth; - for (int oy = 0; oy < oheight; oy++) - { - int iy = (int) (oy / scale); - const img_pixel_t *const irow = ibuf + iwidth * iy; - for (const int *i = ix; i < ix_end; i++) - *orow++ = irow[*i]; - } - delete[]ix; + img_pixel_t *orow = obuf; + int *ix = new int[owidth]; + for (int ox = 0; ox < owidth; ox++) + ix[ox] = (int) (ox / scale); + const int *const ix_end = ix + owidth; + for (int oy = 0; oy < oheight; oy++) + { + int iy = (int) (oy / scale); + const img_pixel_t *const irow = ibuf + iwidth * iy; + for (const int *i = ix; i < ix_end; i++) + *orow++ = irow[*i]; + } + delete[]ix; #endif } // (Slightly) optimized version for large zoom factors. else { - size_t pixels_at_a_time = (int) (scale + 0.99999999999); - int *ox = new int[iwidth]; - for (int ix = 0; ix < iwidth; ix++) - ox[ix] = (int) (ix * scale); - for (int oy = 0; oy < oheight; oy++) - { - int iy = (int) (oy / scale); - const img_pixel_t *const irow = ibuf + iwidth * iy; - img_pixel_t *const orow = obuf + owidth * oy; - for (int ix = 0; ix < iwidth; ix++) - memset(orow + ox[ix], irow[ix], pixels_at_a_time); - } - fflush(stdout); - delete[]ox; + size_t pixels_at_a_time = (int) (scale + 0.99999999999); + int *ox = new int[iwidth]; + for (int ix = 0; ix < iwidth; ix++) + ox[ix] = (int) (ix * scale); + for (int oy = 0; oy < oheight; oy++) + { + int iy = (int) (oy / scale); + const img_pixel_t *const irow = ibuf + iwidth * iy; + img_pixel_t *const orow = obuf + owidth * oy; + for (int ix = 0; ix < iwidth; ix++) + memset(orow + ox[ix], irow[ix], pixels_at_a_time); + } + fflush(stdout); + delete[]ox; } } diff -r 594dea11ccd9 -r a68786b9c74b src/imgscale.h --- a/src/imgscale.h Sat Sep 24 15:01:56 2011 +0300 +++ b/src/imgscale.h Sat Sep 24 15:59:33 2011 +0300 @@ -1,10 +1,10 @@ /* - * imgscale.h - * AYM 2000-06-16 + * imgscale.h + * AYM 2000-06-16 */ -#ifndef YH_IMGSCALE /* DO NOT INSERT ANYTHING BEFORE THIS LINE */ +#ifndef YH_IMGSCALE /* DO NOT INSERT ANYTHING BEFORE THIS LINE */ #define YH_IMGSCALE diff -r 594dea11ccd9 -r a68786b9c74b src/imgspect.cc --- a/src/imgspect.cc Sat Sep 24 15:01:56 2011 +0300 +++ b/src/imgspect.cc Sat Sep 24 15:59:33 2011 +0300 @@ -1,6 +1,6 @@ /* - * imgspect.cc - * AYM 1999-03-09 + * imgspect.cc + * AYM 1999-03-09 */ @@ -33,7 +33,7 @@ /* - * spectrify_img - make a game image look vaguely like a spectre + * spectrify_img - make a game image look vaguely like a spectre */ void spectrify_img(Img & img) { @@ -42,13 +42,13 @@ // FIXME this is gross if (!strncmp(Game, "doom", 4)) - grey = 104; + grey = 104; else if (!strcmp(Game, "heretic")) - grey = 8; + grey = 8; else { - nf_bug("spectrifying not defined with this game"); - return; + nf_bug("spectrifying not defined with this game"); + return; } img_dim_t width = img.width(); @@ -56,9 +56,9 @@ img_pixel_t *buf = img.wbuf(); for (y = 0; y < height; y++) { - img_pixel_t *row = buf + y * width; - for (x = 0; x < width; x++) - if (row[x] != IMG_TRANSP) - row[x] = grey + (rand() >> 6) % 7; // FIXME more kludgery + img_pixel_t *row = buf + y * width; + for (x = 0; x < width; x++) + if (row[x] != IMG_TRANSP) + row[x] = grey + (rand() >> 6) % 7; // FIXME more kludgery } } diff -r 594dea11ccd9 -r a68786b9c74b src/imgspect.h --- a/src/imgspect.h Sat Sep 24 15:01:56 2011 +0300 +++ b/src/imgspect.h Sat Sep 24 15:59:33 2011 +0300 @@ -1,6 +1,6 @@ /* - * imgspect.h - * AYM 1999-03-09 + * imgspect.h + * AYM 1999-03-09 */ diff -r 594dea11ccd9 -r a68786b9c74b src/infobar.cc --- a/src/infobar.cc Sat Sep 24 15:01:56 2011 +0300 +++ b/src/infobar.cc Sat Sep 24 15:59:33 2011 +0300 @@ -1,7 +1,7 @@ /* - * infobar.cc - * The infobar_c class. - * AYM 1998-10-10 + * infobar.cc + * The infobar_c class. + * AYM 1998-10-10 */ @@ -44,8 +44,8 @@ #include "objid.h" -const char infobar_c::FILE_NAME_UNSET[1] = { ' ' }; // A special pointer value -const char infobar_c::LEVEL_NAME_UNSET[1] = { ' ' }; // A special pointer value +const char infobar_c::FILE_NAME_UNSET[1] = { ' ' }; // A special pointer value +const char infobar_c::LEVEL_NAME_UNSET[1] = { ' ' }; // A special pointer value infobar_c::infobar_c() @@ -82,84 +82,84 @@ x = text_x0; if (!visible) - return; + return; redraw_from_scratch = - visible && !visible_disp - || file_name_disp != file_name - || level_name_disp != level_name - || obj_type_disp != obj_type - || changes_disp != changes - || grid_snap_disp != grid_snap - || grid_step_locked_disp != grid_step_locked - || scale_disp != scale || grid_step_disp != grid_step; + visible && !visible_disp + || file_name_disp != file_name + || level_name_disp != level_name + || obj_type_disp != obj_type + || changes_disp != changes + || grid_snap_disp != grid_snap + || grid_step_locked_disp != grid_step_locked + || scale_disp != scale || grid_step_disp != grid_step; if (redraw_from_scratch) { - DrawScreenBox3D(0, out_y0, ScrMaxX, ScrMaxY); - visible_disp = 1; - flags &= ~pointer_disp_set; + DrawScreenBox3D(0, out_y0, ScrMaxX, ScrMaxY); + visible_disp = 1; + flags &= ~pointer_disp_set; } set_colour(WINFG); // The name of the file being edited. { - int chars; - if (!file_name) - { - const char *const msg = "(New level)"; - if (redraw_from_scratch || file_name_disp != file_name) - DrawScreenText(x, text_y0, msg); - chars = strlen(msg); - } - else - { - al_fbase_t filebase; - al_fext_t fileext; - // FIXME wasteful to do it each time - al_fana(file_name, 0, 0, filebase, fileext); - if (redraw_from_scratch || file_name_disp != file_name) - DrawScreenText(x, text_y0, "%s%s", filebase, fileext); - chars = strlen(filebase) + strlen(fileext); - } - x += (chars + 2) * FONTW; - file_name_disp = file_name; + int chars; + if (!file_name) + { + const char *const msg = "(New level)"; + if (redraw_from_scratch || file_name_disp != file_name) + DrawScreenText(x, text_y0, msg); + chars = strlen(msg); + } + else + { + al_fbase_t filebase; + al_fext_t fileext; + // FIXME wasteful to do it each time + al_fana(file_name, 0, 0, filebase, fileext); + if (redraw_from_scratch || file_name_disp != file_name) + DrawScreenText(x, text_y0, "%s%s", filebase, fileext); + chars = strlen(filebase) + strlen(fileext); + } + x += (chars + 2) * FONTW; + file_name_disp = file_name; } // The name of the level being edited. { - int chars; - if (!level_name) - { - const char *const msg = "(n/s)"; - if (redraw_from_scratch || level_name_disp != level_name) - DrawScreenText(x, text_y0, msg); - chars = strlen(msg); - } - else - { - if (redraw_from_scratch || level_name_disp != level_name) - DrawScreenText(x, text_y0, "%.5s", level_name); - chars = strlen(level_name); - } - x += (chars + 2) * FONTW; - level_name_disp = level_name; + int chars; + if (!level_name) + { + const char *const msg = "(n/s)"; + if (redraw_from_scratch || level_name_disp != level_name) + DrawScreenText(x, text_y0, msg); + chars = strlen(msg); + } + else + { + if (redraw_from_scratch || level_name_disp != level_name) + DrawScreenText(x, text_y0, "%.5s", level_name); + chars = strlen(level_name); + } + x += (chars + 2) * FONTW; + level_name_disp = level_name; } // Type of objects being edited. if (redraw_from_scratch || obj_type_disp != obj_type) { - DrawScreenText(x, text_y0, "%s", GetEditModeName(obj_type)); - obj_type_disp = obj_type; + DrawScreenText(x, text_y0, "%s", GetEditModeName(obj_type)); + obj_type_disp = obj_type; } x += 10 * FONTW; // Any changes made ? if (redraw_from_scratch || changes_disp != changes) { - DrawScreenText(x, text_y0, changes > 1 ? "**" : (changes ? "*" : "")); - changes_disp = changes; + DrawScreenText(x, text_y0, changes > 1 ? "**" : (changes ? "*" : "")); + changes_disp = changes; } x += 4 * FONTW; @@ -167,61 +167,61 @@ if (redraw_from_scratch || scale_disp != scale) { #ifdef OLD - if (Scale < 1.0) - DrawScreenText(x, text_y0, "Scale: 1/%d", - (int) (1.0 / Scale + 0.5)); - else - DrawScreenText(x, text_y0, "Scale: %d/1", (int) Scale); + if (Scale < 1.0) + DrawScreenText(x, text_y0, "Scale: 1/%d", + (int) (1.0 / Scale + 0.5)); + else + DrawScreenText(x, text_y0, "Scale: %d/1", (int) Scale); #else - DrawScreenText(x, text_y0, "Scale: %d%%", (int) (Scale * 100)); + DrawScreenText(x, text_y0, "Scale: %d%%", (int) (Scale * 100)); #endif - scale_disp = scale; + scale_disp = scale; } x += 13 * FONTW; // grid_step if (redraw_from_scratch || grid_step_disp != grid_step) { - DrawScreenText(x, text_y0, "Grid: %d", grid_step); - grid_step_disp = grid_step; + DrawScreenText(x, text_y0, "Grid: %d", grid_step); + grid_step_disp = grid_step; } x += 11 * FONTW; // grid_step_locked if (redraw_from_scratch || grid_step_locked_disp != grid_step_locked) { - DrawScreenText(x, text_y0, "%s", grid_step_locked ? "Lock" : "Auto"); - grid_step_locked_disp = grid_step_locked; + DrawScreenText(x, text_y0, "%s", grid_step_locked ? "Lock" : "Auto"); + grid_step_locked_disp = grid_step_locked; } x += 6 * FONTW; // grid_snap if (redraw_from_scratch || grid_snap_disp != grid_snap) { - DrawScreenText(x, text_y0, "%s", grid_snap ? "Snap" : "Free"); - grid_snap_disp = grid_snap; + DrawScreenText(x, text_y0, "%s", grid_snap ? "Snap" : "Free"); + grid_snap_disp = grid_snap; } x += 6 * FONTW; // The current pointer coordinates. if ((flags & pointer_disp_set) - && !(flags & pointer_set) - || pointer_x_disp != pointer_x || pointer_y_disp != pointer_y) + && !(flags & pointer_set) + || pointer_x_disp != pointer_x || pointer_y_disp != pointer_y) { - set_colour(WINBG); - DrawScreenBox(x, text_y0, x + 14 * FONTW - 1, text_y1); - flags &= ~pointer_disp_set; + set_colour(WINBG); + DrawScreenBox(x, text_y0, x + 14 * FONTW - 1, text_y1); + flags &= ~pointer_disp_set; } if ((flags & pointer_set) - && !(flags & pointer_disp_set) - || pointer_x_disp != pointer_x || pointer_y_disp != pointer_y) + && !(flags & pointer_disp_set) + || pointer_x_disp != pointer_x || pointer_y_disp != pointer_y) { - set_colour(WINFG); - /* FIXME pointer_x/y are not significant the first time. */ - DrawScreenText(x, text_y0, "%5d, %5d", pointer_x, pointer_y); - pointer_x_disp = pointer_x; - pointer_y_disp = pointer_y; - flags |= pointer_disp_set; + set_colour(WINFG); + /* FIXME pointer_x/y are not significant the first time. */ + DrawScreenText(x, text_y0, "%5d, %5d", pointer_x, pointer_y); + pointer_x_disp = pointer_x; + pointer_y_disp = pointer_y; + flags |= pointer_disp_set; } } diff -r 594dea11ccd9 -r a68786b9c74b src/infobar.h --- a/src/infobar.h Sat Sep 24 15:01:56 2011 +0300 +++ b/src/infobar.h Sat Sep 24 15:59:33 2011 +0300 @@ -1,7 +1,7 @@ /* - * infobar.h - * Info bar - * AYM 1998-10-10 + * infobar.h + * Info bar + * AYM 1998-10-10 */ @@ -37,56 +37,56 @@ void set_visible(int visible) { - this->visible = visible; + this->visible = visible; } void set_file_name(const char *file_name) { - this->file_name = file_name; + this->file_name = file_name; } void set_level_name(const char *level_name) { - this->level_name = level_name; + this->level_name = level_name; } void set_obj_type(int obj_type) { - this->obj_type = obj_type; + this->obj_type = obj_type; } void set_changes(int changes) { - this->changes = changes; + this->changes = changes; } void set_grid_snap(int grid_snap) { - this->grid_snap = grid_snap; + this->grid_snap = grid_snap; } void set_grid_step_locked(int grid_step_locked) { - this->grid_step_locked = grid_step_locked; + this->grid_step_locked = grid_step_locked; } void set_scale(float scale) { - this->scale = scale; + this->scale = scale; } void set_grid_step(int grid_step) { - this->grid_step = grid_step; + this->grid_step = grid_step; } void set_pointer(int x, int y) { - flags |= pointer_set; - pointer_x = x; - pointer_y = y; + flags |= pointer_set; + pointer_x = x; + pointer_y = y; } void unset_pointer() { - flags &= ~pointer_set; + flags &= ~pointer_set; } /* Methods declared in edwidget_c */ @@ -94,74 +94,74 @@ void undraw() { - } // I can't undraw myself + } // I can't undraw myself int can_undraw() { - return 0; - } // I don't have the ability to undraw myself + return 0; + } // I don't have the ability to undraw myself int need_to_clear() { - return visible_disp && !visible; - } // I can't undraw myself + return visible_disp && !visible; + } // I can't undraw myself void clear(); int req_width() { - return -1; /* Infinite */ + return -1; /* Infinite */ } int req_height() { - return 2 * BOX_BORDER + 2 * NARROW_VSPACING + FONTH; + return 2 * BOX_BORDER + 2 * NARROW_VSPACING + FONTH; } void set_x0(int x0) { - out_x0 = x0; - text_x0 = x0 + BOX_BORDER + NARROW_HSPACING; + out_x0 = x0; + text_x0 = x0 + BOX_BORDER + NARROW_HSPACING; } void set_y0(int y0) { - out_y0 = y0; - text_y0 = y0 + BOX_BORDER + NARROW_VSPACING; + out_y0 = y0; + text_y0 = y0 + BOX_BORDER + NARROW_VSPACING; } void set_x1(int x1) { - out_x1 = x1; - text_x1 = x1 - BOX_BORDER - NARROW_HSPACING; + out_x1 = x1; + text_x1 = x1 - BOX_BORDER - NARROW_HSPACING; } void set_y1(int y1) { - out_y1 = y1; - text_y1 = y1 - BOX_BORDER - NARROW_VSPACING; + out_y1 = y1; + text_y1 = y1 - BOX_BORDER - NARROW_VSPACING; } int get_x0() { - return out_x0; + return out_x0; } int get_y0() { - return out_y0; + return out_y0; } int get_x1() { - return out_x1; + return out_x1; } int get_y1() { - return out_y1; + return out_y1; } private: - static const char FILE_NAME_UNSET[1]; // A special pointer value - static const char LEVEL_NAME_UNSET[1]; // A special pointer value + static const char FILE_NAME_UNSET[1]; // A special pointer value + static const char LEVEL_NAME_UNSET[1]; // A special pointer value static const int pointer_set = 1; static const int pointer_disp_set = 2; diff -r 594dea11ccd9 -r a68786b9c74b src/input.cc --- a/src/input.cc Sat Sep 24 15:01:56 2011 +0300 +++ b/src/input.cc Sat Sep 24 15:59:33 2011 +0300 @@ -1,7 +1,7 @@ /* - * input.cc - * User input (mouse and keyboard) - * AYM 1998-06-16 + * input.cc + * User input (mouse and keyboard) + * AYM 1998-06-16 */ @@ -30,9 +30,9 @@ #include "yadex.h" #ifdef Y_X11 -#include // nanosleep () +#include // nanosleep () #include -#include // XLookupString +#include // XLookupString #include #include "gfx.h" @@ -47,9 +47,9 @@ /* - * init_input_status - * Initialize . Must be called before using or calling - * get_input_status(). + * init_input_status + * Initialize . Must be called before using or calling + * get_input_status(). */ void init_input_status() { @@ -67,8 +67,8 @@ /* - * Static table for get_input_status to convert keysyms to one - * of the YK_-something codes. + * Static table for get_input_status to convert keysyms to one + * of the YK_-something codes. */ typedef struct { @@ -77,7 +77,7 @@ } key_info_t; static const key_info_t key_info[] = { {XK_BackSpace, YK_BACKSPACE}, -#ifdef XK_ISO_Left_Tab /* OpenServer 5.0 X11R5 doesn't have XK_ISO_Left_Tab */ +#ifdef XK_ISO_Left_Tab /* OpenServer 5.0 X11R5 doesn't have XK_ISO_Left_Tab */ {XK_ISO_Left_Tab, YK_BACKTAB}, #endif {XK_Delete, YK_DEL,}, @@ -98,10 +98,10 @@ {XK_Insert, YK_INS,}, {XK_Left, YK_LEFT,}, {XK_Linefeed, YK_RETURN,}, -#ifdef XK_Page_Down /* HP-UX 10 doesn't have XK_Page_Down */ +#ifdef XK_Page_Down /* HP-UX 10 doesn't have XK_Page_Down */ {XK_Page_Down, YK_PD,}, #endif -#ifdef XK_Page_Up /* HP-UX 10 doesn't have XK_Page_Up */ +#ifdef XK_Page_Up /* HP-UX 10 doesn't have XK_Page_Up */ {XK_Page_Up, YK_PU,}, #endif {XK_Return, YK_RETURN,}, @@ -112,10 +112,10 @@ /* - * get_input_status - * Get the next event and update accordingly. - * If no event is available, waits for idle_sleep_ms ms - * and returns (it's used for the autoscroll feature). + * get_input_status + * Get the next event and update accordingly. + * If no event is available, waits for idle_sleep_ms ms + * and returns (it's used for the autoscroll feature). */ void get_input_status() { @@ -123,318 +123,318 @@ is.key = 0; - if (!dpy) /* Sanity check */ - fatal_error("get_input_status() called before XOpenDisplay()"); + if (!dpy) /* Sanity check */ + fatal_error("get_input_status() called before XOpenDisplay()"); if (XPending(dpy) == 0) { - // No event ? Wait for ms before polling again. + // No event ? Wait for ms before polling again. #if defined Y_NANOSLEEP - struct timespec treq = { 0, 1000000ul * idle_sleep_ms }; - struct timespec trem; - nanosleep(&treq, &trem); + struct timespec treq = { 0, 1000000ul * idle_sleep_ms }; + struct timespec trem; + nanosleep(&treq, &trem); #elif defined Y_USLEEP - usleep(1000ul * idle_sleep_ms); + usleep(1000ul * idle_sleep_ms); #else - ; // Neither nanosleep() no usleep() so be a CPU hog. - // FIXME: if autoscroll is turned off, could as well - // call XNextEvent and sleep for good. + ; // Neither nanosleep() no usleep() so be a CPU hog. + // FIXME: if autoscroll is turned off, could as well + // call XNextEvent and sleep for good. #endif - return; + return; } XNextEvent(dpy, &ev); switch (ev.type) { - /* Exposure */ + /* Exposure */ case Expose: #if 0 - printf("expose: send=%d w=%d x,y=%4d,%4d w,h=%4d,%4d c=%d\n", - (int) ev.xexpose.send_event, - (int) ev.xexpose.window, - (int) ev.xexpose.x, - (int) ev.xexpose.y, - (int) ev.xexpose.width, - (int) ev.xexpose.height, (int) ev.xexpose.count); + printf("expose: send=%d w=%d x,y=%4d,%4d w,h=%4d,%4d c=%d\n", + (int) ev.xexpose.send_event, + (int) ev.xexpose.window, + (int) ev.xexpose.x, + (int) ev.xexpose.y, + (int) ev.xexpose.width, + (int) ev.xexpose.height, (int) ev.xexpose.count); #endif - if (ev.xexpose.window == win && ev.xexpose.count == 0) - is.key = YE_EXPOSE; - break; + if (ev.xexpose.window == win && ev.xexpose.count == 0) + is.key = YE_EXPOSE; + break; - /* Resize */ + /* Resize */ case ConfigureNotify: #if 0 - printf("configure: x,y=%4d,%4d w,h=%4d,%4d\n", - (int) ev.xconfigure.x, - (int) ev.xconfigure.y, - (int) ev.xconfigure.width, (int) ev.xconfigure.height); + printf("configure: x,y=%4d,%4d w,h=%4d,%4d\n", + (int) ev.xconfigure.x, + (int) ev.xconfigure.y, + (int) ev.xconfigure.width, (int) ev.xconfigure.height); #endif - if (is.width < 0 || ev.xconfigure.width != is.width - || ev.xconfigure.height != is.height) - { - is.key = YE_RESIZE; - is.width = ev.xconfigure.width; - is.height = ev.xconfigure.height; - } - break; + if (is.width < 0 || ev.xconfigure.width != is.width + || ev.xconfigure.height != is.height) + { + is.key = YE_RESIZE; + is.width = ev.xconfigure.width; + is.height = ev.xconfigure.height; + } + break; - /* Mouse motion */ + /* Mouse motion */ case EnterNotify: - is.key = YE_ENTER; - is.time = ev.xcrossing.time; - is.in_window = 1; - // Sanity - if (ev.xcrossing.x < 0) - nf_bug("xcrossing.x < 0"); // Paranoia - if (ev.xcrossing.y < 0) - nf_bug("xcrossing.y < 0"); // Paranoia - is.x = ev.xcrossing.x; - is.y = ev.xcrossing.y; - break; + is.key = YE_ENTER; + is.time = ev.xcrossing.time; + is.in_window = 1; + // Sanity + if (ev.xcrossing.x < 0) + nf_bug("xcrossing.x < 0"); // Paranoia + if (ev.xcrossing.y < 0) + nf_bug("xcrossing.y < 0"); // Paranoia + is.x = ev.xcrossing.x; + is.y = ev.xcrossing.y; + break; case LeaveNotify: - is.key = YE_LEAVE; - is.time = ev.xcrossing.time; - is.in_window = 0; /* Should probably "release" buttons */ - return; - break; + is.key = YE_LEAVE; + is.time = ev.xcrossing.time; + is.in_window = 0; /* Should probably "release" buttons */ + return; + break; case MotionNotify: - is.key = YE_MOTION; - is.time = ev.xmotion.time; - if (ev.xmotion.x < 0) - nf_bug("xmotion.x < 0"); // Paranoia - if (ev.xmotion.y < 0) - nf_bug("xmotion.y < 0"); // Paranoia - is.x = ev.xmotion.x; - is.y = ev.xmotion.y; + is.key = YE_MOTION; + is.time = ev.xmotion.time; + if (ev.xmotion.x < 0) + nf_bug("xmotion.x < 0"); // Paranoia + if (ev.xmotion.y < 0) + nf_bug("xmotion.y < 0"); // Paranoia + is.x = ev.xmotion.x; + is.y = ev.xmotion.y; #ifdef DEBUG - { - static bool first_time = true; - static int dxmin = INT_MAX; - static int dxmax = INT_MIN; - static int dymin = INT_MAX; - static int dymax = INT_MIN; - static int prevx = 0; - static int prevy = 0; - bool change = false; - if (!first_time) - { - int dx = prevx - ev.xmotion.x; - int dy = prevy - ev.xmotion.y; + { + static bool first_time = true; + static int dxmin = INT_MAX; + static int dxmax = INT_MIN; + static int dymin = INT_MAX; + static int dymax = INT_MIN; + static int prevx = 0; + static int prevy = 0; + bool change = false; + if (!first_time) + { + int dx = prevx - ev.xmotion.x; + int dy = prevy - ev.xmotion.y; - if (dx < dxmin) - { - dxmin = dx; - change = true; - } - if (dx > dxmax) - { - dxmax = dx; - change = true; - } - if (dy < dymin) - { - dymin = dy; - change = true; - } - if (dy > dymax) - { - dymax = dy; - change = true; - } - } - prevx = ev.xmotion.x; - prevy = ev.xmotion.y; - first_time = false; - if (change) - printf("Mouse: xmin=%d, xmax=%d, ymin=%d, ymax=%d\n", - dxmin, dxmax, dymin, dymax); - } + if (dx < dxmin) + { + dxmin = dx; + change = true; + } + if (dx > dxmax) + { + dxmax = dx; + change = true; + } + if (dy < dymin) + { + dymin = dy; + change = true; + } + if (dy > dymax) + { + dymax = dy; + change = true; + } + } + prevx = ev.xmotion.x; + prevy = ev.xmotion.y; + first_time = false; + if (change) + printf("Mouse: xmin=%d, xmax=%d, ymin=%d, ymax=%d\n", + dxmin, dxmax, dymin, dymax); + } #endif - // DEBUG - break; + // DEBUG + break; - /* Mouse buttons */ + /* Mouse buttons */ case ButtonPress: case ButtonRelease: - { - is.time = ev.xbutton.time; - int press = (ev.type == ButtonPress); - if (ev.xbutton.button == Button1) - { - is.key = press ? YE_BUTL_PRESS : YE_BUTL_RELEASE; - is.butl = press; - } - else if (ev.xbutton.button == Button2) - { - is.key = press ? YE_BUTM_PRESS : YE_BUTM_RELEASE; - is.butm = press; - } - else if (ev.xbutton.button == Button3) - { - is.key = press ? YE_BUTR_PRESS : YE_BUTR_RELEASE; - is.butr = press; - } - else if (ev.xbutton.button == Button4) - { - is.key = press ? YE_WHEEL_UP : 0; - } - else if (ev.xbutton.button == Button5) - { - is.key = press ? YE_WHEEL_DOWN : 0; - } - break; - } + { + is.time = ev.xbutton.time; + int press = (ev.type == ButtonPress); + if (ev.xbutton.button == Button1) + { + is.key = press ? YE_BUTL_PRESS : YE_BUTL_RELEASE; + is.butl = press; + } + else if (ev.xbutton.button == Button2) + { + is.key = press ? YE_BUTM_PRESS : YE_BUTM_RELEASE; + is.butm = press; + } + else if (ev.xbutton.button == Button3) + { + is.key = press ? YE_BUTR_PRESS : YE_BUTR_RELEASE; + is.butr = press; + } + else if (ev.xbutton.button == Button4) + { + is.key = press ? YE_WHEEL_UP : 0; + } + else if (ev.xbutton.button == Button5) + { + is.key = press ? YE_WHEEL_DOWN : 0; + } + break; + } - /* - * Keyboard - * FIXME: need to handle NotifyKeymap event as well. - */ + /* + * Keyboard + * FIXME: need to handle NotifyKeymap event as well. + */ case KeyPress: case KeyRelease: - { - KeySym ks; - int press; - unsigned char c; - int has_string; + { + KeySym ks; + int press; + unsigned char c; + int has_string; - is.time = ev.xkey.time; + is.time = ev.xkey.time; - press = (ev.type == KeyPress); + press = (ev.type == KeyPress); - /* Convert keycode -> keysym + char. The keysym is useful for keys - such as cursor arrows that don't have an ASCII code. */ - has_string = - XLookupString((XKeyEvent *) & ev, (char *) &c, 1, &ks, NULL); + /* Convert keycode -> keysym + char. The keysym is useful for keys + such as cursor arrows that don't have an ASCII code. */ + has_string = + XLookupString((XKeyEvent *) & ev, (char *) &c, 1, &ks, NULL); - /* The event says that Ctrl, Alt and Shift are not in the state we - thought they were. Don't panic ; it's just that we missed the - modifier key press/release event as it happened when we didn't - have focus. Adjust ourselves. */ - if (! !(ev.xkey.state & ShiftMask) != is.shift) - is.shift = ! !(ev.xkey.state & ShiftMask); - if (! !(ev.xkey.state & ControlMask) != is.ctrl) - is.ctrl = ! !(ev.xkey.state & ControlMask); - if (! !(ev.xkey.state & Mod1Mask) != is.alt) - is.alt = ! !(ev.xkey.state & Mod1Mask); + /* The event says that Ctrl, Alt and Shift are not in the state we + thought they were. Don't panic ; it's just that we missed the + modifier key press/release event as it happened when we didn't + have focus. Adjust ourselves. */ + if (! !(ev.xkey.state & ShiftMask) != is.shift) + is.shift = ! !(ev.xkey.state & ShiftMask); + if (! !(ev.xkey.state & ControlMask) != is.ctrl) + is.ctrl = ! !(ev.xkey.state & ControlMask); + if (! !(ev.xkey.state & Mod1Mask) != is.alt) + is.alt = ! !(ev.xkey.state & Mod1Mask); - /* It's a modifier ? Remember its state */ - switch (ks) - { - case XK_Shift_L: - case XK_Shift_R: - is.shift = press; - break; - case XK_Control_L: - case XK_Control_R: - is.ctrl = press; - break; - case XK_Alt_L: - case XK_Alt_R: - case XK_Meta_L: - case XK_Meta_R: - is.alt = press; - break; - } + /* It's a modifier ? Remember its state */ + switch (ks) + { + case XK_Shift_L: + case XK_Shift_R: + is.shift = press; + break; + case XK_Control_L: + case XK_Control_R: + is.ctrl = press; + break; + case XK_Alt_L: + case XK_Alt_R: + case XK_Meta_L: + case XK_Meta_R: + is.alt = press; + break; + } - /* Process ordinary keys */ - if (press) - { - size_t n; - if (has_string) - is.key = c; - for (n = 0; n < sizeof key_info / sizeof *key_info; n++) - if (key_info[n].ks == ks) - { - is.key = key_info[n].key; - break; - } - if (is.key >= YK_ && is.key != YK_BACKTAB && is.shift) - is.key |= YK_SHIFT; - if (is.key >= YK_ && is.ctrl) - is.key |= YK_CTRL; - if (is.key != 0 && is.alt) - is.key |= YK_ALT; - } + /* Process ordinary keys */ + if (press) + { + size_t n; + if (has_string) + is.key = c; + for (n = 0; n < sizeof key_info / sizeof *key_info; n++) + if (key_info[n].ks == ks) + { + is.key = key_info[n].key; + break; + } + if (is.key >= YK_ && is.key != YK_BACKTAB && is.shift) + is.key |= YK_SHIFT; + if (is.key >= YK_ && is.ctrl) + is.key |= YK_CTRL; + if (is.key != 0 && is.alt) + is.key |= YK_ALT; + } #if 0 - if (ev.type == KeyPress) - { - printf("key=%04hXh", is.key); - if (is.key >= 0 && is.key <= UCHAR_MAX && isprint(is.key)) - printf(" (%c)", (char) is.key); - putchar('\n'); - } + if (ev.type == KeyPress) + { + printf("key=%04hXh", is.key); + if (is.key >= 0 && is.key <= UCHAR_MAX && isprint(is.key)) + printf(" (%c)", (char) is.key); + putchar('\n'); + } #endif - break; - } - } /* switch (ev.type) */ + break; + } + } /* switch (ev.type) */ } #endif /* #ifdef Y_X11 */ /* - * has_input_event - * Tells whether there are events in the input queue + * has_input_event + * Tells whether there are events in the input queue */ int has_input_event() { XEvent xev; if (XCheckMaskEvent(dpy, 0xffffffff, &xev) == True) { - XPutBackEvent(dpy, &xev); - return 1; + XPutBackEvent(dpy, &xev); + return 1; } return 0; } /* - * have_key - * Return 0 if there is no key press in the input queue, <>0 else. - * This is a convenience function to replace bioskey(1). + * have_key + * Return 0 if there is no key press in the input queue, <>0 else. + * This is a convenience function to replace bioskey(1). */ int have_key() { - return 1; /* FIXME!! */ + return 1; /* FIXME!! */ } /* - * get_key - * Wait until the user presses a key and returns its code. - * This is a convenience function to replace bioskey(0). + * get_key + * Wait until the user presses a key and returns its code. + * This is a convenience function to replace bioskey(0). */ int get_key() { do - get_input_status(); + get_input_status(); while (!event_is_key(is.key)); return is.key; } /* - * get_key_or_click - * Wait until the user presses a key or clicks the left button. - * In most cases, you should use this and not get_key(). + * get_key_or_click + * Wait until the user presses a key or clicks the left button. + * In most cases, you should use this and not get_key(). */ void get_key_or_click() { do - get_input_status(); + get_input_status(); while (!event_is_key(is.key) && is.key != YE_BUTL_PRESS); - is.key = 0; // FIXME Shouldn't have to do that but EditorLoop() is broken + is.key = 0; // FIXME Shouldn't have to do that but EditorLoop() is broken } /* - * key_to_string - * Return a string corresponding to the key number k. - * Examples : - * - for k equal to 'a', returns "a", - * - for k equal to YK_ALT + 'a', returns "Alt-a". - * The string returned is guaranteed to have a length <= 50. + * key_to_string + * Return a string corresponding to the key number k. + * Examples : + * - for k equal to 'a', returns "a", + * - for k equal to YK_ALT + 'a', returns "Alt-a". + * The string returned is guaranteed to have a length <= 50. */ typedef struct { @@ -478,42 +478,42 @@ size_t n; const size_t nmax = sizeof key_string / sizeof *key_string; for (n = 0; n < nmax; n++) - if (key_string[n].key == k) - break; + if (key_string[n].key == k) + break; *buf = '\0'; if (k & YK_CTRL || (n == nmax && k <= 31)) { - al_saps(buf, "Ctrl-", sizeof buf - 1); - if (k & YK_CTRL) - k ^= YK_CTRL; - if (k <= 31) - k += 96; // Heavy ASCII-ism : 01h (^A) -> 61h ("a") + al_saps(buf, "Ctrl-", sizeof buf - 1); + if (k & YK_CTRL) + k ^= YK_CTRL; + if (k <= 31) + k += 96; // Heavy ASCII-ism : 01h (^A) -> 61h ("a") } if (k & YK_ALT) { - al_saps(buf, "Alt-", sizeof buf - 1); - k ^= YK_ALT; + al_saps(buf, "Alt-", sizeof buf - 1); + k ^= YK_ALT; } if (k & YK_SHIFT) { - al_saps(buf, "Shift-", sizeof buf - 1); - k ^= YK_SHIFT; + al_saps(buf, "Shift-", sizeof buf - 1); + k ^= YK_SHIFT; } if (n == nmax) - if (k <= UCHAR_MAX && isprint(k)) - al_sapc(buf, k, sizeof buf - 1); - else - { - al_sapc(buf, al_adigits[(k >> 12) & 15], sizeof buf - 1); - al_sapc(buf, al_adigits[(k >> 8) & 15], sizeof buf - 1); - al_sapc(buf, al_adigits[(k >> 4) & 15], sizeof buf - 1); - al_sapc(buf, al_adigits[(k >> 0) & 15], sizeof buf - 1); - } + if (k <= UCHAR_MAX && isprint(k)) + al_sapc(buf, k, sizeof buf - 1); + else + { + al_sapc(buf, al_adigits[(k >> 12) & 15], sizeof buf - 1); + al_sapc(buf, al_adigits[(k >> 8) & 15], sizeof buf - 1); + al_sapc(buf, al_adigits[(k >> 4) & 15], sizeof buf - 1); + al_sapc(buf, al_adigits[(k >> 0) & 15], sizeof buf - 1); + } else - al_saps(buf, key_string[n].string, sizeof buf - 1); + al_saps(buf, key_string[n].string, sizeof buf - 1); - buf[sizeof buf - 1] = '\0'; /* Paranoia */ + buf[sizeof buf - 1] = '\0'; /* Paranoia */ return buf; } diff -r 594dea11ccd9 -r a68786b9c74b src/input.h --- a/src/input.h Sat Sep 24 15:01:56 2011 +0300 +++ b/src/input.h Sat Sep 24 15:59:33 2011 +0300 @@ -1,7 +1,7 @@ /* - * input.h - * User input (mouse and keyboard) - * AYM 1998-06-16 + * input.h + * User input (mouse and keyboard) + * AYM 1998-06-16 */ @@ -32,23 +32,23 @@ typedef struct { // Window events - int width; // New window width - int height; // New window height + int width; // New window width + int height; // New window height // Mouse events - char in_window; // <>0 iff mouse pointer is in window - char butl; // <>0 iff left mouse button is depressed - char butm; // <>0 iff middle mouse button is depressed - char butr; // <>0 iff right mouse button is depressed - int x; // Mouse pointer position + char in_window; // <>0 iff mouse pointer is in window + char butl; // <>0 iff left mouse button is depressed + char butm; // <>0 iff middle mouse button is depressed + char butr; // <>0 iff right mouse button is depressed + int x; // Mouse pointer position int y; // Keyboard - char shift; // <>0 iff either [Shift] is pressed - char ctrl; // <>0 iff either [Ctrl] is pressed - char alt; // <>0 iff either [Alt]/[Meta] is pressed - char scroll_lock; // Always 0 for the moment + char shift; // <>0 iff either [Shift] is pressed + char ctrl; // <>0 iff either [Ctrl] is pressed + char alt; // <>0 iff either [Alt]/[Meta] is pressed + char scroll_lock; // Always 0 for the moment // General - inpev_t key; // Code of last event (key, mouse, resize, expose...) - unsigned long time; // Date of event in ms (1) + inpev_t key; // Code of last event (key, mouse, resize, expose...) + unsigned long time; // Date of event in ms (1) } input_status_t; /* Notes: @@ -83,7 +83,7 @@ const inpev_t YK_PD = 274; const inpev_t YK_RIGHT = 275; const inpev_t YK_UP = 276; -const inpev_t YK__LAST = 277; // Marks the end of key events +const inpev_t YK__LAST = 277; // Marks the end of key events // Those are not key numbers but window events const inpev_t YE_RESIZE = 278; @@ -96,8 +96,8 @@ const inpev_t YE_BUTM_RELEASE = 283; const inpev_t YE_BUTR_PRESS = 284; const inpev_t YE_BUTR_RELEASE = 285; -const inpev_t YE_WHEEL_UP = 286; // Negative, normally bound to button 4 -const inpev_t YE_WHEEL_DOWN = 287; // Positive, normally bound to button 5 +const inpev_t YE_WHEEL_UP = 286; // Negative, normally bound to button 4 +const inpev_t YE_WHEEL_DOWN = 287; // Positive, normally bound to button 5 const inpev_t YE_ENTER = 288; const inpev_t YE_LEAVE = 289; const inpev_t YE_MOTION = 290; diff -r 594dea11ccd9 -r a68786b9c74b src/l_align.cc --- a/src/l_align.cc Sat Sep 24 15:01:56 2011 +0300 +++ b/src/l_align.cc Sat Sep 24 15:59:33 2011 +0300 @@ -1,7 +1,7 @@ /* - * l_align.cc - * Linedef/sidedef texture alignment - * AYM 1998-02-03 + * l_align.cc + * Linedef/sidedef texture alignment + * AYM 1998-02-03 */ @@ -43,7 +43,7 @@ get the absolute height from which the textures are drawn */ -int GetTextureRefHeight(int sidedef) /* SWAP! */ +int GetTextureRefHeight(int sidedef) /* SWAP! */ { int l, sector; int otherside = OBJ_NO_NONE; @@ -51,16 +51,16 @@ /* find the sidedef on the other side of the LineDef, if any */ for (l = 0; l < NumLineDefs; l++) { - if (LineDefs[l].sidedef1 == sidedef) - { - otherside = LineDefs[l].sidedef2; - break; - } - if (LineDefs[l].sidedef2 == sidedef) - { - otherside = LineDefs[l].sidedef1; - break; - } + if (LineDefs[l].sidedef1 == sidedef) + { + otherside = LineDefs[l].sidedef2; + break; + } + if (LineDefs[l].sidedef2 == sidedef) + { + otherside = LineDefs[l].sidedef1; + break; + } } /* get the Sector number */ sector = SideDefs[sidedef].sector; @@ -68,19 +68,19 @@ then the reference is taken from the other Sector */ if (otherside >= 0) { - l = SideDefs[otherside].sector; - if (l > 0) - { - if (Sectors[l].ceilh < Sectors[sector].ceilh - && Sectors[l].ceilh > Sectors[sector].floorh) - sector = l; - } + l = SideDefs[otherside].sector; + if (l > 0) + { + if (Sectors[l].ceilh < Sectors[sector].ceilh + && Sectors[l].ceilh > Sectors[sector].floorh) + sector = l; + } } /* return the altitude of the ceiling */ if (sector >= 0) - return Sectors[sector].ceilh; /* textures are drawn from the ceiling down */ + return Sectors[sector].ceilh; /* textures are drawn from the ceiling down */ else - return 0; /* yuck! */ + return 0; /* yuck! */ } @@ -97,12 +97,12 @@ way to select only one side of a two-sided wall. */ -void AlignTexturesY(SelPtr * sdlist) /* SWAP! */ +void AlignTexturesY(SelPtr * sdlist) /* SWAP! */ { int h, refh; if (!*sdlist) - return; + return; /* get the reference height from the first sidedef */ refh = GetTextureRefHeight((*sdlist)->objnum); @@ -112,9 +112,9 @@ /* adjust Y offset in all other SideDefs */ while (*sdlist) { - h = GetTextureRefHeight((*sdlist)->objnum); - SideDefs[(*sdlist)->objnum].yoff = (refh - h) % 128; - UnSelectObject(sdlist, (*sdlist)->objnum); + h = GetTextureRefHeight((*sdlist)->objnum); + SideDefs[(*sdlist)->objnum].yoff = (refh - h) % 128; + UnSelectObject(sdlist, (*sdlist)->objnum); } MadeChanges = 1; } @@ -140,139 +140,139 @@ the following needs to be altered radically. */ -void AlignTexturesX(SelPtr * sdlist) /* SWAP! */ +void AlignTexturesX(SelPtr * sdlist) /* SWAP! */ { /* FIRST texture name used in the highlited objects */ char texname[WAD_TEX_NAME + 1]; - char errormessage[80]; /* area to hold the error messages produced */ - int ldef; /* linedef number */ - int sd1; /* current sidedef in *sdlist */ - int vert1, vert2; /* vertex 1 and 2 for the linedef under scrutiny */ - int xoffset; /* xoffset accumulator */ - int useroffset; /* user input offset for first input */ - i16 texlength; /* the length of texture to format to */ - int length; /* length of linedef under scrutiny */ - i16 dummy; /* holds useless data */ - int type_off; /* do we have an initial offset to use */ - int type_tex; /* do we check for same textures */ - int type_sd; /* do we align sidedef 1 or sidedef 2 */ + char errormessage[80]; /* area to hold the error messages produced */ + int ldef; /* linedef number */ + int sd1; /* current sidedef in *sdlist */ + int vert1, vert2; /* vertex 1 and 2 for the linedef under scrutiny */ + int xoffset; /* xoffset accumulator */ + int useroffset; /* user input offset for first input */ + i16 texlength; /* the length of texture to format to */ + int length; /* length of linedef under scrutiny */ + i16 dummy; /* holds useless data */ + int type_off; /* do we have an initial offset to use */ + int type_tex; /* do we check for same textures */ + int type_sd; /* do we align sidedef 1 or sidedef 2 */ - type_sd = 0; /* which sidedef to align, 1=SideDef1, 2=SideDef2 */ - type_tex = 0; /* do we test for similar textures, 0 = no, 1 = yes */ - type_off = 0; /* do we have an inital offset, 0 = no, 1 = yes */ + type_sd = 0; /* which sidedef to align, 1=SideDef1, 2=SideDef2 */ + type_tex = 0; /* do we test for similar textures, 0 = no, 1 = yes */ + type_off = 0; /* do we have an inital offset, 0 = no, 1 = yes */ vert1 = -1; - vert2 = -1; /* 1st time round the while loop the -1 value is needed */ + vert2 = -1; /* 1st time round the while loop the -1 value is needed */ texlength = 0; xoffset = 0; useroffset = 0; switch (vDisplayMenu(250, 110, "Aligning textures (X offset) :", - " Sidedef 1, Check for identical textures. ", - YK_, 0, - " Sidedef 1, As above, but with inital offset. ", - YK_, 0, - " Sidedef 1, No texture checking. ", - YK_, 0, - " Sidedef 1, As above, but with inital offset. ", - YK_, 0, - " Sidedef 2, Check for identical textures. ", - YK_, 0, - " Sidedef 2, As above, but with inital offset. ", - YK_, 0, - " Sidedef 2, No texture checking. ", - YK_, 0, - " Sidedef 2, As above, but with inital offset. ", - YK_, 0, NULL)) + " Sidedef 1, Check for identical textures. ", + YK_, 0, + " Sidedef 1, As above, but with inital offset. ", + YK_, 0, + " Sidedef 1, No texture checking. ", + YK_, 0, + " Sidedef 1, As above, but with inital offset. ", + YK_, 0, + " Sidedef 2, Check for identical textures. ", + YK_, 0, + " Sidedef 2, As above, but with inital offset. ", + YK_, 0, + " Sidedef 2, No texture checking. ", + YK_, 0, + " Sidedef 2, As above, but with inital offset. ", + YK_, 0, NULL)) { - case 1: /* Sidedef 1 with checking for same textures */ - type_sd = 1; - type_tex = 1; - type_off = 0; - break; + case 1: /* Sidedef 1 with checking for same textures */ + type_sd = 1; + type_tex = 1; + type_off = 0; + break; - case 2: /* Sidedef 1 as above, but with inital offset */ - type_sd = 1; - type_tex = 1; - type_off = 1; - break; + case 2: /* Sidedef 1 as above, but with inital offset */ + type_sd = 1; + type_tex = 1; + type_off = 1; + break; - case 3: /* Sidedef 1 regardless of same textures */ - type_sd = 1; - type_tex = 0; - type_off = 0; - break; + case 3: /* Sidedef 1 regardless of same textures */ + type_sd = 1; + type_tex = 0; + type_off = 0; + break; - case 4: /* Sidedef 1 as above, but with inital offset */ - type_sd = 1; - type_tex = 0; - type_off = 1; - break; + case 4: /* Sidedef 1 as above, but with inital offset */ + type_sd = 1; + type_tex = 0; + type_off = 1; + break; - case 5: /* Sidedef 2 with checking for same textures */ - type_sd = 2; - type_tex = 1; - type_off = 0; - break; + case 5: /* Sidedef 2 with checking for same textures */ + type_sd = 2; + type_tex = 1; + type_off = 0; + break; - case 6: /* Sidedef 2 as above, but with initial offset */ - type_sd = 2; - type_tex = 1; - type_off = 1; - break; + case 6: /* Sidedef 2 as above, but with initial offset */ + type_sd = 2; + type_tex = 1; + type_off = 1; + break; - case 7: /* Sidedef 2 regardless of same textures */ - type_sd = 2; - type_tex = 0; - type_off = 0; - break; + case 7: /* Sidedef 2 regardless of same textures */ + type_sd = 2; + type_tex = 0; + type_off = 0; + break; - case 8: /* Sidedef 2 as above, but with initial offset */ - type_sd = 2; - type_tex = 0; - type_off = 1; - break; + case 8: /* Sidedef 2 as above, but with initial offset */ + type_sd = 2; + type_tex = 0; + type_off = 1; + break; } ldef = 0; if (!*sdlist) { - Notify(-1, -1, "Error in AlignTexturesX: list is empty", 0); - return; + Notify(-1, -1, "Error in AlignTexturesX: list is empty", 0); + return; } sd1 = (*sdlist)->objnum; - if (type_sd == 1) /* throw out all 2nd SideDefs untill a 1st is found */ + if (type_sd == 1) /* throw out all 2nd SideDefs untill a 1st is found */ { - while (*sdlist && LineDefs[ldef].sidedef1 != sd1 - && ldef <= NumLineDefs) - { - ldef++; - if (LineDefs[ldef].sidedef2 == sd1) - { - UnSelectObject(sdlist, (*sdlist)->objnum); - if (!*sdlist) - return; - sd1 = (*sdlist)->objnum; - ldef = 0; - } - } + while (*sdlist && LineDefs[ldef].sidedef1 != sd1 + && ldef <= NumLineDefs) + { + ldef++; + if (LineDefs[ldef].sidedef2 == sd1) + { + UnSelectObject(sdlist, (*sdlist)->objnum); + if (!*sdlist) + return; + sd1 = (*sdlist)->objnum; + ldef = 0; + } + } } - if (type_sd == 2) /* throw out all 1st SideDefs untill a 2nd is found */ + if (type_sd == 2) /* throw out all 1st SideDefs untill a 2nd is found */ { - while (LineDefs[ldef].sidedef2 != sd1 && ldef <= NumLineDefs) - { - ldef++; - if (LineDefs[ldef].sidedef1 == sd1) - { - UnSelectObject(sdlist, (*sdlist)->objnum); - if (!*sdlist) - return; - sd1 = (*sdlist)->objnum; - ldef = 0; - } - } + while (LineDefs[ldef].sidedef2 != sd1 && ldef <= NumLineDefs) + { + ldef++; + if (LineDefs[ldef].sidedef1 == sd1) + { + UnSelectObject(sdlist, (*sdlist)->objnum); + if (!*sdlist) + return; + sd1 = (*sdlist)->objnum; + ldef = 0; + } + } } /* get texture name of the sidedef in the *sdlist) */ @@ -281,141 +281,141 @@ /* test if there is a texture there */ if (texname[0] == '-') { - Beep(); - sprintf(errormessage, "No texture for sidedef #%d.", - (*sdlist)->objnum); - Notify(-1, -1, errormessage, 0); - return; + Beep(); + sprintf(errormessage, "No texture for sidedef #%d.", + (*sdlist)->objnum); + Notify(-1, -1, errormessage, 0); + return; } - GetWallTextureSize(&texlength, &dummy, texname); /* clunky, but it works */ + GetWallTextureSize(&texlength, &dummy, texname); /* clunky, but it works */ /* get initial offset to use (if required) */ - if (type_off == 1) /* source taken from InputObjectNumber */ + if (type_off == 1) /* source taken from InputObjectNumber */ { - int x0; /* left hand (x) window start */ - int y0; /* top (y) window start */ - int key; /* holds value returned by InputInteger */ - char prompt[80]; /* prompt for inital offset input */ + int x0; /* left hand (x) window start */ + int y0; /* top (y) window start */ + int key; /* holds value returned by InputInteger */ + char prompt[80]; /* prompt for inital offset input */ - sprintf(prompt, "Enter initial offset between 0 and %d:", - (int) texlength); + sprintf(prompt, "Enter initial offset between 0 and %d:", + (int) texlength); - x0 = (ScrMaxX - 25 - 8 * strlen(prompt)) / 2; - y0 = (ScrMaxY - 55) / 2; + x0 = (ScrMaxX - 25 - 8 * strlen(prompt)) / 2; + y0 = (ScrMaxY - 55) / 2; - DrawScreenBox3D(x0, y0, x0 + 25 + 8 * strlen(prompt), y0 + 55); - set_colour(WHITE); - DrawScreenText(x0 + 10, y0 + 8, prompt); + DrawScreenBox3D(x0, y0, x0 + 25 + 8 * strlen(prompt), y0 + 55); + set_colour(WHITE); + DrawScreenText(x0 + 10, y0 + 8, prompt); - while ((key = - InputInteger(x0 + 10, y0 + 28, &useroffset, 0, - (int) texlength)) != YK_RETURN && key != YK_ESC) - Beep(); + while ((key = + InputInteger(x0 + 10, y0 + 28, &useroffset, 0, + (int) texlength)) != YK_RETURN && key != YK_ESC) + Beep(); } - while (*sdlist) /* main processing loop */ + while (*sdlist) /* main processing loop */ { - ldef = 0; - sd1 = (*sdlist)->objnum; + ldef = 0; + sd1 = (*sdlist)->objnum; - if (type_sd == 1) /* throw out all 2nd SideDefs untill a 1st is found */ - { - while (LineDefs[ldef].sidedef1 != sd1 && ldef <= NumLineDefs) - { - ldef++; - if (LineDefs[ldef].sidedef2 == sd1) - { - UnSelectObject(sdlist, (*sdlist)->objnum); - sd1 = (*sdlist)->objnum; - ldef = 0; - if (!*sdlist) - return; - } - } - } + if (type_sd == 1) /* throw out all 2nd SideDefs untill a 1st is found */ + { + while (LineDefs[ldef].sidedef1 != sd1 && ldef <= NumLineDefs) + { + ldef++; + if (LineDefs[ldef].sidedef2 == sd1) + { + UnSelectObject(sdlist, (*sdlist)->objnum); + sd1 = (*sdlist)->objnum; + ldef = 0; + if (!*sdlist) + return; + } + } + } - if (type_sd == 2) /* throw out all 1st SideDefs untill a 2nd is found */ - { - while (LineDefs[ldef].sidedef2 != sd1 && ldef <= NumLineDefs) - { - ldef++; - if (LineDefs[ldef].sidedef1 == sd1) - { - UnSelectObject(sdlist, (*sdlist)->objnum); - sd1 = (*sdlist)->objnum; - ldef = 0; - if (!*sdlist) - return; - } - } - } + if (type_sd == 2) /* throw out all 1st SideDefs untill a 2nd is found */ + { + while (LineDefs[ldef].sidedef2 != sd1 && ldef <= NumLineDefs) + { + ldef++; + if (LineDefs[ldef].sidedef1 == sd1) + { + UnSelectObject(sdlist, (*sdlist)->objnum); + sd1 = (*sdlist)->objnum; + ldef = 0; + if (!*sdlist) + return; + } + } + } - /* do we test for same textures for the sidedef in question?? */ - if (type_tex == 1) - { - if (strncmp - (SideDefs[(*sdlist)->objnum].tex3, texname, WAD_TEX_NAME)) - { - Beep(); - sprintf(errormessage, "No texture for sidedef #%d.", - (*sdlist)->objnum); - Notify(-1, -1, errormessage, 0); - return; - } - } + /* do we test for same textures for the sidedef in question?? */ + if (type_tex == 1) + { + if (strncmp + (SideDefs[(*sdlist)->objnum].tex3, texname, WAD_TEX_NAME)) + { + Beep(); + sprintf(errormessage, "No texture for sidedef #%d.", + (*sdlist)->objnum); + Notify(-1, -1, errormessage, 0); + return; + } + } - sd1 = (*sdlist)->objnum; - ldef = 0; + sd1 = (*sdlist)->objnum; + ldef = 0; - /* find out which linedef holds that sidedef */ - if (type_sd == 1) - { - while (LineDefs[ldef].sidedef1 != sd1 && ldef < NumLineDefs) - ldef++; - } - else - { - while (LineDefs[ldef].sidedef2 != sd1 && ldef < NumLineDefs) - ldef++; - } + /* find out which linedef holds that sidedef */ + if (type_sd == 1) + { + while (LineDefs[ldef].sidedef1 != sd1 && ldef < NumLineDefs) + ldef++; + } + else + { + while (LineDefs[ldef].sidedef2 != sd1 && ldef < NumLineDefs) + ldef++; + } - vert1 = LineDefs[ldef].start; - /* test for linedef highlight continuity */ - if (vert1 != vert2 && vert2 != -1) - { - Beep(); - sprintf(errormessage, "Linedef #%d is not contiguous" - " with the previous linedef, please reselect.", - (*sdlist)->objnum); - Notify(-1, -1, errormessage, 0); - return; - } - /* is this the first time round here */ - if (vert1 != vert2) - { - if (type_off == 1) /* do we have an initial offset ? */ - { - SideDefs[sd1].xoff = useroffset; - xoffset = useroffset; - } - else - SideDefs[sd1].xoff = 0; - } - else /* put new xoffset into the sidedef */ - SideDefs[sd1].xoff = xoffset; + vert1 = LineDefs[ldef].start; + /* test for linedef highlight continuity */ + if (vert1 != vert2 && vert2 != -1) + { + Beep(); + sprintf(errormessage, "Linedef #%d is not contiguous" + " with the previous linedef, please reselect.", + (*sdlist)->objnum); + Notify(-1, -1, errormessage, 0); + return; + } + /* is this the first time round here */ + if (vert1 != vert2) + { + if (type_off == 1) /* do we have an initial offset ? */ + { + SideDefs[sd1].xoff = useroffset; + xoffset = useroffset; + } + else + SideDefs[sd1].xoff = 0; + } + else /* put new xoffset into the sidedef */ + SideDefs[sd1].xoff = xoffset; - /* calculate length of linedef */ - vert2 = LineDefs[ldef].end; - length = ComputeDist(Vertices[vert2].x - Vertices[vert1].x, - Vertices[vert2].y - Vertices[vert1].y); + /* calculate length of linedef */ + vert2 = LineDefs[ldef].end; + length = ComputeDist(Vertices[vert2].x - Vertices[vert1].x, + Vertices[vert2].y - Vertices[vert1].y); - xoffset += length; - /* remove multiples of texlength from xoffset */ - xoffset = xoffset % texlength; - /* move to next object in selected list */ - UnSelectObject(sdlist, (*sdlist)->objnum); + xoffset += length; + /* remove multiples of texlength from xoffset */ + xoffset = xoffset % texlength; + /* move to next object in selected list */ + UnSelectObject(sdlist, (*sdlist)->objnum); } MadeChanges = 1; } diff -r 594dea11ccd9 -r a68786b9c74b src/l_centre.cc --- a/src/l_centre.cc Sat Sep 24 15:01:56 2011 +0300 +++ b/src/l_centre.cc Sat Sep 24 15:59:33 2011 +0300 @@ -1,6 +1,6 @@ /* - * l_centre.cc - * AYM 1998-11-22 + * l_centre.cc + * AYM 1998-11-22 */ @@ -35,8 +35,8 @@ /* - * centre_of_linedefs - * Return the coordinates of the centre of a group of linedefs. + * centre_of_linedefs + * Return the coordinates of the centre of a group of linedefs. */ void centre_of_linedefs(SelPtr list, int *x, int *y) { @@ -51,21 +51,21 @@ y_sum = 0; nitems = 0; for (n = 0; n < NumVertices; n++) - if (vertices->get(n)) - { - x_sum += Vertices[n].x; - y_sum += Vertices[n].y; - nitems++; - } + if (vertices->get(n)) + { + x_sum += Vertices[n].x; + y_sum += Vertices[n].y; + nitems++; + } if (nitems == 0) { - *x = 0; - *y = 0; + *x = 0; + *y = 0; } else { - *x = (int) (x_sum / nitems); - *y = (int) (y_sum / nitems); + *x = (int) (x_sum / nitems); + *y = (int) (y_sum / nitems); } delete vertices; } diff -r 594dea11ccd9 -r a68786b9c74b src/l_centre.h --- a/src/l_centre.h Sat Sep 24 15:01:56 2011 +0300 +++ b/src/l_centre.h Sat Sep 24 15:59:33 2011 +0300 @@ -1,6 +1,6 @@ /* - * l_centre.h - * AYM 1998-11-22 + * l_centre.h + * AYM 1998-11-22 */ diff -r 594dea11ccd9 -r a68786b9c74b src/l_flags.cc --- a/src/l_flags.cc Sat Sep 24 15:01:56 2011 +0300 +++ b/src/l_flags.cc Sat Sep 24 15:59:33 2011 +0300 @@ -1,6 +1,6 @@ /* - * l_flags.cc - * AYM 1998-12-21 + * l_flags.cc + * AYM 1998-12-21 */ @@ -34,9 +34,9 @@ /* - * frob_linedefs_flags - * For all the linedefs in , apply the operator - * with the operand on the flags field. + * frob_linedefs_flags + * For all the linedefs in , apply the operator + * with the operand on the flags field. */ void frob_linedefs_flags(SelPtr list, int op, int operand) { @@ -44,23 +44,23 @@ i16 mask; if (op == YO_CLEAR || op == YO_SET || op == YO_TOGGLE) - mask = 1 << operand; + mask = 1 << operand; else - mask = operand; + mask = operand; for (cur = list; cur; cur = cur->next) { - if (op == YO_CLEAR) - LineDefs[cur->objnum].flags &= ~mask; - else if (op == YO_SET) - LineDefs[cur->objnum].flags |= mask; - else if (op == YO_TOGGLE) - LineDefs[cur->objnum].flags ^= mask; - else - { - nf_bug("frob_linedef_flags: op=%02X", op); - return; - } + if (op == YO_CLEAR) + LineDefs[cur->objnum].flags &= ~mask; + else if (op == YO_SET) + LineDefs[cur->objnum].flags |= mask; + else if (op == YO_TOGGLE) + LineDefs[cur->objnum].flags ^= mask; + else + { + nf_bug("frob_linedef_flags: op=%02X", op); + return; + } } MadeChanges = 1; } diff -r 594dea11ccd9 -r a68786b9c74b src/l_flags.h --- a/src/l_flags.h Sat Sep 24 15:01:56 2011 +0300 +++ b/src/l_flags.h Sat Sep 24 15:59:33 2011 +0300 @@ -1,6 +1,6 @@ /* - * l_flags.h - * AYM 1998-12-22 + * l_flags.h + * AYM 1998-12-22 */ diff -r 594dea11ccd9 -r a68786b9c74b src/l_misc.cc --- a/src/l_misc.cc Sat Sep 24 15:01:56 2011 +0300 +++ b/src/l_misc.cc Sat Sep 24 15:59:33 2011 +0300 @@ -1,7 +1,7 @@ /* - * l_misc.c - * Linedef/sidedef misc operations. - * AYM 1998-02-03 + * l_misc.c + * Linedef/sidedef misc operations. + * AYM 1998-02-03 */ @@ -43,24 +43,24 @@ flip one or several LineDefs */ -void FlipLineDefs(SelPtr obj, bool swapvertices) /* SWAP! */ +void FlipLineDefs(SelPtr obj, bool swapvertices) /* SWAP! */ { SelPtr cur; int tmp; for (cur = obj; cur; cur = cur->next) { - if (swapvertices) - { - /* swap starting and ending Vertices */ - tmp = LineDefs[cur->objnum].end; - LineDefs[cur->objnum].end = LineDefs[cur->objnum].start; - LineDefs[cur->objnum].start = tmp; - } - /* swap first and second SideDefs */ - tmp = LineDefs[cur->objnum].sidedef1; - LineDefs[cur->objnum].sidedef1 = LineDefs[cur->objnum].sidedef2; - LineDefs[cur->objnum].sidedef2 = tmp; + if (swapvertices) + { + /* swap starting and ending Vertices */ + tmp = LineDefs[cur->objnum].end; + LineDefs[cur->objnum].end = LineDefs[cur->objnum].start; + LineDefs[cur->objnum].start = tmp; + } + /* swap first and second SideDefs */ + tmp = LineDefs[cur->objnum].sidedef1; + LineDefs[cur->objnum].sidedef1 = LineDefs[cur->objnum].sidedef2; + LineDefs[cur->objnum].sidedef2 = tmp; } MadeChanges = 1; MadeMapChanges = 1; @@ -71,20 +71,20 @@ split one or more LineDefs in two, adding new Vertices in the middle */ -void SplitLineDefs(SelPtr obj) /* SWAP! */ +void SplitLineDefs(SelPtr obj) /* SWAP! */ { SelPtr cur; int vstart, vend; for (cur = obj; cur; cur = cur->next) { - vstart = LineDefs[cur->objnum].start; - vend = LineDefs[cur->objnum].end; - SliceLinedef(cur->objnum, 1); - Vertices[NumVertices - 1].x = - (Vertices[vstart].x + Vertices[vend].x) / 2; - Vertices[NumVertices - 1].y = - (Vertices[vstart].y + Vertices[vend].y) / 2; + vstart = LineDefs[cur->objnum].start; + vend = LineDefs[cur->objnum].end; + SliceLinedef(cur->objnum, 1); + Vertices[NumVertices - 1].x = + (Vertices[vstart].x + Vertices[vend].x) / 2; + Vertices[NumVertices - 1].y = + (Vertices[vstart].y + Vertices[vend].y) / 2; } MadeChanges = 1; MadeMapChanges = 1; @@ -92,121 +92,121 @@ /* - * MakeRectangularNook - Make a nook or boss in a wall - * - * Before : After : - * ^--> - * | | - * +-----------------> +-------> v-------> - * 1st sidedef 1st sidedef + * MakeRectangularNook - Make a nook or boss in a wall + * + * Before : After : + * ^--> + * | | + * +-----------------> +-------> v-------> + * 1st sidedef 1st sidedef * - * The length of the sides of the nook is sidelen. - * This is true when convex is false. If convex is true, the nook - * is actually a bump when viewed from the 1st sidedef. + * The length of the sides of the nook is sidelen. + * This is true when convex is false. If convex is true, the nook + * is actually a bump when viewed from the 1st sidedef. */ -void MakeRectangularNook(SelPtr obj, int width, int depth, int convex) /* SWAP! */ +void MakeRectangularNook(SelPtr obj, int width, int depth, int convex) /* SWAP! */ { SelPtr cur; for (cur = obj; cur; cur = cur->next) { - int vstart, vend; - int x0; - int y0; - int dx0, dx1, dx2; - int dy0, dy1, dy2; - int line_len; - double real_width; - double angle; + int vstart, vend; + int x0; + int y0; + int dx0, dx1, dx2; + int dy0, dy1, dy2; + int line_len; + double real_width; + double angle; - vstart = LineDefs[cur->objnum].start; - vend = LineDefs[cur->objnum].end; - x0 = Vertices[vstart].x; - y0 = Vertices[vstart].y; - dx0 = Vertices[vend].x - x0; - dy0 = Vertices[vend].y - y0; + vstart = LineDefs[cur->objnum].start; + vend = LineDefs[cur->objnum].end; + x0 = Vertices[vstart].x; + y0 = Vertices[vstart].y; + dx0 = Vertices[vend].x - x0; + dy0 = Vertices[vend].y - y0; - /* First split the line 4 times */ - SliceLinedef(cur->objnum, 4); + /* First split the line 4 times */ + SliceLinedef(cur->objnum, 4); - /* Then position the vertices */ - angle = atan2(dy0, dx0); + /* Then position the vertices */ + angle = atan2(dy0, dx0); - /* If line to split is not longer than sidelen, - force sidelen to 1/3 of length */ - line_len = ComputeDist(dx0, dy0); - real_width = line_len > width ? width : line_len / 3; + /* If line to split is not longer than sidelen, + force sidelen to 1/3 of length */ + line_len = ComputeDist(dx0, dy0); + real_width = line_len > width ? width : line_len / 3; - dx2 = (int) (real_width * cos(angle)); - dy2 = (int) (real_width * sin(angle)); + dx2 = (int) (real_width * cos(angle)); + dy2 = (int) (real_width * sin(angle)); - dx1 = (dx0 - dx2) / 2; - dy1 = (dy0 - dy2) / 2; + dx1 = (dx0 - dx2) / 2; + dy1 = (dy0 - dy2) / 2; - { - double normal = convex ? angle - HALFPI : angle + HALFPI; - Vertices[NumVertices - 1 - 3].x = x0 + dx1; - Vertices[NumVertices - 1 - 3].y = y0 + dy1; - Vertices[NumVertices - 1 - 2].x = - x0 + dx1 + (int) (depth * cos(normal)); - Vertices[NumVertices - 1 - 2].y = - y0 + dy1 + (int) (depth * sin(normal)); - Vertices[NumVertices - 1 - 1].x = - x0 + dx1 + dx2 + (int) (depth * cos(normal)); - Vertices[NumVertices - 1 - 1].y = - y0 + dy1 + dy2 + (int) (depth * sin(normal)); - Vertices[NumVertices - 1].x = x0 + dx1 + dx2; - Vertices[NumVertices - 1].y = y0 + dy1 + dy2; - } + { + double normal = convex ? angle - HALFPI : angle + HALFPI; + Vertices[NumVertices - 1 - 3].x = x0 + dx1; + Vertices[NumVertices - 1 - 3].y = y0 + dy1; + Vertices[NumVertices - 1 - 2].x = + x0 + dx1 + (int) (depth * cos(normal)); + Vertices[NumVertices - 1 - 2].y = + y0 + dy1 + (int) (depth * sin(normal)); + Vertices[NumVertices - 1 - 1].x = + x0 + dx1 + dx2 + (int) (depth * cos(normal)); + Vertices[NumVertices - 1 - 1].y = + y0 + dy1 + dy2 + (int) (depth * sin(normal)); + Vertices[NumVertices - 1].x = x0 + dx1 + dx2; + Vertices[NumVertices - 1].y = y0 + dy1 + dy2; + } - MadeChanges = 1; - MadeMapChanges = 1; + MadeChanges = 1; + MadeMapChanges = 1; } } /* - * SliceLinedef - Split a linedef several times + * SliceLinedef - Split a linedef several times * - * Splits linedef no. times. - * Side-effects : creates new vertices, new - * linedefs and 0, or 2* new sidedefs. - * The new vertices are put at (0,0). - * See SplitLineDefs() and MakeRectangularNook() for example of use. + * Splits linedef no. times. + * Side-effects : creates new vertices, new + * linedefs and 0, or 2* new sidedefs. + * The new vertices are put at (0,0). + * See SplitLineDefs() and MakeRectangularNook() for example of use. */ static void SliceLinedef(int linedefno, int times) { int prev_ld_no; for (prev_ld_no = linedefno; times > 0; - times--, prev_ld_no = NumLineDefs - 1) + times--, prev_ld_no = NumLineDefs - 1) { - int sd; + int sd; - InsertObject(OBJ_VERTICES, -1, 0, 0); - InsertObject(OBJ_LINEDEFS, linedefno, 0, 0); - LineDefs[NumLineDefs - 1].start = NumVertices - 1; - LineDefs[NumLineDefs - 1].end = LineDefs[prev_ld_no].end; - LineDefs[prev_ld_no].end = NumVertices - 1; + InsertObject(OBJ_VERTICES, -1, 0, 0); + InsertObject(OBJ_LINEDEFS, linedefno, 0, 0); + LineDefs[NumLineDefs - 1].start = NumVertices - 1; + LineDefs[NumLineDefs - 1].end = LineDefs[prev_ld_no].end; + LineDefs[prev_ld_no].end = NumVertices - 1; - sd = LineDefs[linedefno].sidedef1; - if (sd >= 0) - { - InsertObject(OBJ_SIDEDEFS, sd, 0, 0); - LineDefs[NumLineDefs - 1].sidedef1 = NumSideDefs - 1; - } - sd = LineDefs[linedefno].sidedef2; - if (sd >= 0) - { - InsertObject(OBJ_SIDEDEFS, sd, 0, 0); - LineDefs[NumLineDefs - 1].sidedef2 = NumSideDefs - 1; - } + sd = LineDefs[linedefno].sidedef1; + if (sd >= 0) + { + InsertObject(OBJ_SIDEDEFS, sd, 0, 0); + LineDefs[NumLineDefs - 1].sidedef1 = NumSideDefs - 1; + } + sd = LineDefs[linedefno].sidedef2; + if (sd >= 0) + { + InsertObject(OBJ_SIDEDEFS, sd, 0, 0); + LineDefs[NumLineDefs - 1].sidedef2 = NumSideDefs - 1; + } } } /* - * SetLinedefLength - * Move either vertex to set length of linedef to desired value + * SetLinedefLength + * Move either vertex to set length of linedef to desired value */ void SetLinedefLength(SelPtr obj, int length, int move_2nd_vertex) { @@ -214,25 +214,25 @@ for (cur = obj; cur; cur = cur->next) { - VPtr vertex1 = Vertices + LineDefs[cur->objnum].start; - VPtr vertex2 = Vertices + LineDefs[cur->objnum].end; - double angle = - atan2(vertex2->y - vertex1->y, vertex2->x - vertex1->x); - int dx = (int) (length * cos(angle)); - int dy = (int) (length * sin(angle)); + VPtr vertex1 = Vertices + LineDefs[cur->objnum].start; + VPtr vertex2 = Vertices + LineDefs[cur->objnum].end; + double angle = + atan2(vertex2->y - vertex1->y, vertex2->x - vertex1->x); + int dx = (int) (length * cos(angle)); + int dy = (int) (length * sin(angle)); - if (move_2nd_vertex) - { - vertex2->x = vertex1->x + dx; - vertex2->y = vertex1->y + dy; - } - else - { - vertex1->x = vertex2->x - dx; - vertex1->y = vertex2->y - dy; - } + if (move_2nd_vertex) + { + vertex2->x = vertex1->x + dx; + vertex2->y = vertex1->y + dy; + } + else + { + vertex1->x = vertex2->x - dx; + vertex1->y = vertex2->y - dy; + } - MadeChanges = 1; - MadeMapChanges = 1; + MadeChanges = 1; + MadeMapChanges = 1; } } diff -r 594dea11ccd9 -r a68786b9c74b src/l_prop.cc --- a/src/l_prop.cc Sat Sep 24 15:01:56 2011 +0300 +++ b/src/l_prop.cc Sat Sep 24 15:59:33 2011 +0300 @@ -1,9 +1,9 @@ /* - * l_prop.c - * Linedefs properties - * Some of this was originally in editobj.c. It was moved here to - * improve overlay granularity (therefore memory consumption). - * AYM 1998-02-07 + * l_prop.c + * Linedefs properties + * Some of this was originally in editobj.c. It was moved here to + * improve overlay granularity (therefore memory consumption). + * AYM 1998-02-07 */ @@ -44,7 +44,7 @@ /* - * Menu_data_ldt - Menu_data class for the linedef type + * Menu_data_ldt - Menu_data class for the linedef type */ class Menu_data_ldt:public Menu_data { @@ -58,7 +58,7 @@ /* - * Menu_data_ldt::Menu_data_ldt - ctor + * Menu_data_ldt::Menu_data_ldt - ctor */ Menu_data_ldt::Menu_data_ldt(al_llist_t * list):list(list) { @@ -67,7 +67,7 @@ /* - * Menu_data_ldt::nitems - return the number of items + * Menu_data_ldt::nitems - return the number of items */ size_t Menu_data_ldt::nitems() const { @@ -76,30 +76,30 @@ /* - * Menu_data_ldt::operator[] - return the nth item + * Menu_data_ldt::operator[] - return the nth item */ const char *Menu_data_ldt::operator[] (size_t n) const { - if (al_lseek(list, n, SEEK_SET) != 0) - { - sprintf(buf, "BUG: al_lseek(%p, %lu): %s", - (void *) list, - (unsigned long) n, al_astrerror(al_aerrno)); - return buf; - } - const ldtdef_t **pptr = (const ldtdef_t **) al_lptr(list); - if (pptr == NULL) - sprintf(buf, "BUG: al_lptr(%p): %s", - (void *) list, al_astrerror(al_aerrno)); - else - sprintf(buf, "%3d - %.70s", (*pptr)->number, (*pptr)->longdesc); - return buf; + if (al_lseek(list, n, SEEK_SET) != 0) + { + sprintf(buf, "BUG: al_lseek(%p, %lu): %s", + (void *) list, + (unsigned long) n, al_astrerror(al_aerrno)); + return buf; + } + const ldtdef_t **pptr = (const ldtdef_t **) al_lptr(list); + if (pptr == NULL) + sprintf(buf, "BUG: al_lptr(%p): %s", + (void *) list, al_astrerror(al_aerrno)); + else + sprintf(buf, "%3d - %.70s", (*pptr)->number, (*pptr)->longdesc); + return buf; } /* - * Prototypes of private functions + * Prototypes of private functions */ static char *GetTaggedLineDefFlag(int linedefnum, int flagndx); int InputLinedefType(int x0, int y0, int *number); @@ -117,335 +117,335 @@ int subsubwin_y0; { - bool sd1 = LineDefs[obj->objnum].sidedef1 >= 0; - bool sd2 = LineDefs[obj->objnum].sidedef2 >= 0; - val = vDisplayMenu(x0, y0, "Choose the object to edit:", - "Edit the linedef", YK_, 0, - sd1 ? "Edit the 1st sidedef" : "Add a 1st sidedef", - YK_, 0, - sd2 ? "Edit the 2nd sidedef" : "Add a 2nd sidedef", - YK_, 0, NULL); + bool sd1 = LineDefs[obj->objnum].sidedef1 >= 0; + bool sd2 = LineDefs[obj->objnum].sidedef2 >= 0; + val = vDisplayMenu(x0, y0, "Choose the object to edit:", + "Edit the linedef", YK_, 0, + sd1 ? "Edit the 1st sidedef" : "Add a 1st sidedef", + YK_, 0, + sd2 ? "Edit the 2nd sidedef" : "Add a 2nd sidedef", + YK_, 0, NULL); } subwin_y0 = y0 + BOX_BORDER + (2 + val) * FONTH; switch (val) { case 1: - for (n = 0; n < 8; n++) - menustr[n] = (char *) GetMemory(60); - sprintf(menustr[7], "Edit linedef #%d", obj->objnum); - sprintf(menustr[0], "Change flags (Current: %d)", - LineDefs[obj->objnum].flags); - sprintf(menustr[1], "Change type (Current: %d)", - LineDefs[obj->objnum].type); - sprintf(menustr[2], "Change sector tag (Current: %d)", - LineDefs[obj->objnum].tag); - sprintf(menustr[3], "Change starting vertex (Current: #%d)", - LineDefs[obj->objnum].start); - sprintf(menustr[4], "Change ending vertex (Current: #%d)", - LineDefs[obj->objnum].end); - sprintf(menustr[5], "Change 1st sidedef ref. (Current: #%d)", - LineDefs[obj->objnum].sidedef1); - sprintf(menustr[6], "Change 2nd sidedef ref. (Current: #%d)", - LineDefs[obj->objnum].sidedef2); - val = vDisplayMenu(x0 + 42, subwin_y0, menustr[7], - menustr[0], YK_, 0, - menustr[1], YK_, 0, - menustr[2], YK_, 0, - menustr[3], YK_, 0, - menustr[4], YK_, 0, - menustr[5], YK_, 0, menustr[6], YK_, 0, NULL); - for (n = 0; n < 8; n++) - FreeMemory(menustr[n]); - subsubwin_y0 = subwin_y0 + BOX_BORDER + (2 + val) * FONTH; - switch (val) - { - case 1: - val = vDisplayMenu(x0 + 84, subsubwin_y0, "Toggle the flags:", - GetTaggedLineDefFlag(obj->objnum, 1), YK_, 0, - GetTaggedLineDefFlag(obj->objnum, 2), YK_, 0, - GetTaggedLineDefFlag(obj->objnum, 3), YK_, 0, - GetTaggedLineDefFlag(obj->objnum, 4), YK_, 0, - GetTaggedLineDefFlag(obj->objnum, 5), YK_, 0, - GetTaggedLineDefFlag(obj->objnum, 6), YK_, 0, - GetTaggedLineDefFlag(obj->objnum, 7), YK_, 0, - GetTaggedLineDefFlag(obj->objnum, 8), YK_, 0, - GetTaggedLineDefFlag(obj->objnum, 9), YK_, 0, - GetTaggedLineDefFlag(obj->objnum, 10), YK_, 0, - GetTaggedLineDefFlag(obj->objnum, 11), YK_, 0, - GetTaggedLineDefFlag(obj->objnum, 12), YK_, 0, - GetTaggedLineDefFlag(obj->objnum, 13), YK_, 0, - GetTaggedLineDefFlag(obj->objnum, 14), YK_, 0, - GetTaggedLineDefFlag(obj->objnum, 15), YK_, 0, - GetTaggedLineDefFlag(obj->objnum, 16), YK_, 0, - "(Enter a decimal value)", YK_, 0, NULL); - if (val >= 1 && val <= 16) - { - for (cur = obj; cur; cur = cur->next) - LineDefs[cur->objnum].flags ^= 0x01 << (val - 1); - MadeChanges = 1; - } - else if (val == 17) - { - val = InputIntegerValue(x0 + 126, subsubwin_y0 + 12 * FONTH, - 0, 65535, - LineDefs[obj->objnum].flags); - if (val != IIV_CANCEL) - { - for (cur = obj; cur; cur = cur->next) - LineDefs[cur->objnum].flags = val; - MadeChanges = 1; - } - } - break; + for (n = 0; n < 8; n++) + menustr[n] = (char *) GetMemory(60); + sprintf(menustr[7], "Edit linedef #%d", obj->objnum); + sprintf(menustr[0], "Change flags (Current: %d)", + LineDefs[obj->objnum].flags); + sprintf(menustr[1], "Change type (Current: %d)", + LineDefs[obj->objnum].type); + sprintf(menustr[2], "Change sector tag (Current: %d)", + LineDefs[obj->objnum].tag); + sprintf(menustr[3], "Change starting vertex (Current: #%d)", + LineDefs[obj->objnum].start); + sprintf(menustr[4], "Change ending vertex (Current: #%d)", + LineDefs[obj->objnum].end); + sprintf(menustr[5], "Change 1st sidedef ref. (Current: #%d)", + LineDefs[obj->objnum].sidedef1); + sprintf(menustr[6], "Change 2nd sidedef ref. (Current: #%d)", + LineDefs[obj->objnum].sidedef2); + val = vDisplayMenu(x0 + 42, subwin_y0, menustr[7], + menustr[0], YK_, 0, + menustr[1], YK_, 0, + menustr[2], YK_, 0, + menustr[3], YK_, 0, + menustr[4], YK_, 0, + menustr[5], YK_, 0, menustr[6], YK_, 0, NULL); + for (n = 0; n < 8; n++) + FreeMemory(menustr[n]); + subsubwin_y0 = subwin_y0 + BOX_BORDER + (2 + val) * FONTH; + switch (val) + { + case 1: + val = vDisplayMenu(x0 + 84, subsubwin_y0, "Toggle the flags:", + GetTaggedLineDefFlag(obj->objnum, 1), YK_, 0, + GetTaggedLineDefFlag(obj->objnum, 2), YK_, 0, + GetTaggedLineDefFlag(obj->objnum, 3), YK_, 0, + GetTaggedLineDefFlag(obj->objnum, 4), YK_, 0, + GetTaggedLineDefFlag(obj->objnum, 5), YK_, 0, + GetTaggedLineDefFlag(obj->objnum, 6), YK_, 0, + GetTaggedLineDefFlag(obj->objnum, 7), YK_, 0, + GetTaggedLineDefFlag(obj->objnum, 8), YK_, 0, + GetTaggedLineDefFlag(obj->objnum, 9), YK_, 0, + GetTaggedLineDefFlag(obj->objnum, 10), YK_, 0, + GetTaggedLineDefFlag(obj->objnum, 11), YK_, 0, + GetTaggedLineDefFlag(obj->objnum, 12), YK_, 0, + GetTaggedLineDefFlag(obj->objnum, 13), YK_, 0, + GetTaggedLineDefFlag(obj->objnum, 14), YK_, 0, + GetTaggedLineDefFlag(obj->objnum, 15), YK_, 0, + GetTaggedLineDefFlag(obj->objnum, 16), YK_, 0, + "(Enter a decimal value)", YK_, 0, NULL); + if (val >= 1 && val <= 16) + { + for (cur = obj; cur; cur = cur->next) + LineDefs[cur->objnum].flags ^= 0x01 << (val - 1); + MadeChanges = 1; + } + else if (val == 17) + { + val = InputIntegerValue(x0 + 126, subsubwin_y0 + 12 * FONTH, + 0, 65535, + LineDefs[obj->objnum].flags); + if (val != IIV_CANCEL) + { + for (cur = obj; cur; cur = cur->next) + LineDefs[cur->objnum].flags = val; + MadeChanges = 1; + } + } + break; - case 2: - if (!InputLinedefType(x0, subsubwin_y0, &val)) - { - for (cur = obj; cur; cur = cur->next) - LineDefs[cur->objnum].type = val; - MadeChanges = 1; - } - break; + case 2: + if (!InputLinedefType(x0, subsubwin_y0, &val)) + { + for (cur = obj; cur; cur = cur->next) + LineDefs[cur->objnum].type = val; + MadeChanges = 1; + } + break; - case 3: - val = InputIntegerValue(x0 + 84, subsubwin_y0, - -32768, 32767, LineDefs[obj->objnum].tag); - if (val != IIV_CANCEL) // Not [esc] - { - for (cur = obj; cur; cur = cur->next) - LineDefs[cur->objnum].tag = val; - MadeChanges = 1; - } - break; + case 3: + val = InputIntegerValue(x0 + 84, subsubwin_y0, + -32768, 32767, LineDefs[obj->objnum].tag); + if (val != IIV_CANCEL) // Not [esc] + { + for (cur = obj; cur; cur = cur->next) + LineDefs[cur->objnum].tag = val; + MadeChanges = 1; + } + break; - case 4: - val = InputObjectXRef(x0 + 84, subsubwin_y0, - OBJ_VERTICES, 0, - LineDefs[obj->objnum].start); - if (val >= 0) - { - for (cur = obj; cur; cur = cur->next) - LineDefs[cur->objnum].start = val; - MadeChanges = 1; - MadeMapChanges = 1; - } - break; + case 4: + val = InputObjectXRef(x0 + 84, subsubwin_y0, + OBJ_VERTICES, 0, + LineDefs[obj->objnum].start); + if (val >= 0) + { + for (cur = obj; cur; cur = cur->next) + LineDefs[cur->objnum].start = val; + MadeChanges = 1; + MadeMapChanges = 1; + } + break; - case 5: - val = InputObjectXRef(x0 + 84, subsubwin_y0, - OBJ_VERTICES, 0, LineDefs[obj->objnum].end); - if (val >= 0) - { - for (cur = obj; cur; cur = cur->next) - LineDefs[cur->objnum].end = val; - MadeChanges = 1; - MadeMapChanges = 1; - } - break; + case 5: + val = InputObjectXRef(x0 + 84, subsubwin_y0, + OBJ_VERTICES, 0, LineDefs[obj->objnum].end); + if (val >= 0) + { + for (cur = obj; cur; cur = cur->next) + LineDefs[cur->objnum].end = val; + MadeChanges = 1; + MadeMapChanges = 1; + } + break; - case 6: - val = InputObjectXRef(x0 + 84, subsubwin_y0, - OBJ_SIDEDEFS, 1, - LineDefs[obj->objnum].sidedef1); - if (val >= -1) - { - for (cur = obj; cur; cur = cur->next) - LineDefs[cur->objnum].sidedef1 = val; - MadeChanges = 1; - MadeMapChanges = 1; - } - break; + case 6: + val = InputObjectXRef(x0 + 84, subsubwin_y0, + OBJ_SIDEDEFS, 1, + LineDefs[obj->objnum].sidedef1); + if (val >= -1) + { + for (cur = obj; cur; cur = cur->next) + LineDefs[cur->objnum].sidedef1 = val; + MadeChanges = 1; + MadeMapChanges = 1; + } + break; - case 7: - val = InputObjectXRef(x0 + 84, subsubwin_y0, - OBJ_SIDEDEFS, 1, - LineDefs[obj->objnum].sidedef2); - if (val >= -1) - { - for (cur = obj; cur; cur = cur->next) - LineDefs[cur->objnum].sidedef2 = val; - MadeChanges = 1; - MadeMapChanges = 1; - } - break; - } - break; + case 7: + val = InputObjectXRef(x0 + 84, subsubwin_y0, + OBJ_SIDEDEFS, 1, + LineDefs[obj->objnum].sidedef2); + if (val >= -1) + { + for (cur = obj; cur; cur = cur->next) + LineDefs[cur->objnum].sidedef2 = val; + MadeChanges = 1; + MadeMapChanges = 1; + } + break; + } + break; - // Edit or add the first sidedef + // Edit or add the first sidedef case 2: - if (LineDefs[obj->objnum].sidedef1 >= 0) - { - // Build a new selection list with the first sidedefs - objtype = OBJ_SIDEDEFS; - sdlist = 0; - for (cur = obj; cur; cur = cur->next) - if (LineDefs[cur->objnum].sidedef1 >= 0) - SelectObject(&sdlist, LineDefs[cur->objnum].sidedef1); - } - else - { - // Add a new first sidedef - for (cur = obj; cur; cur = cur->next) - if (LineDefs[cur->objnum].sidedef1 == -1) - { - InsertObject(OBJ_SIDEDEFS, -1, 0, 0); - LineDefs[cur->objnum].sidedef1 = NumSideDefs - 1; - } - break; - } - // FALL THROUGH + if (LineDefs[obj->objnum].sidedef1 >= 0) + { + // Build a new selection list with the first sidedefs + objtype = OBJ_SIDEDEFS; + sdlist = 0; + for (cur = obj; cur; cur = cur->next) + if (LineDefs[cur->objnum].sidedef1 >= 0) + SelectObject(&sdlist, LineDefs[cur->objnum].sidedef1); + } + else + { + // Add a new first sidedef + for (cur = obj; cur; cur = cur->next) + if (LineDefs[cur->objnum].sidedef1 == -1) + { + InsertObject(OBJ_SIDEDEFS, -1, 0, 0); + LineDefs[cur->objnum].sidedef1 = NumSideDefs - 1; + } + break; + } + // FALL THROUGH - // Edit or add the second sidedef + // Edit or add the second sidedef case 3: - if (objtype != OBJ_SIDEDEFS) - { - if (LineDefs[obj->objnum].sidedef2 >= 0) - { - // Build a new selection list with the second (or first) SideDefs - objtype = OBJ_SIDEDEFS; - sdlist = 0; - for (cur = obj; cur; cur = cur->next) - if (LineDefs[cur->objnum].sidedef2 >= 0) - SelectObject(&sdlist, LineDefs[cur->objnum].sidedef2); - else if (LineDefs[cur->objnum].sidedef1 >= 0) - SelectObject(&sdlist, LineDefs[cur->objnum].sidedef1); - } - else - { - // Add a new second (or first) sidedef - for (cur = obj; cur; cur = cur->next) - if (LineDefs[cur->objnum].sidedef1 == -1) - { - InsertObject(OBJ_SIDEDEFS, -1, 0, 0); - LineDefs[cur->objnum].sidedef1 = NumSideDefs - 1; - } - else if (LineDefs[cur->objnum].sidedef2 == -1) - { - n = LineDefs[cur->objnum].sidedef1; - InsertObject(OBJ_SIDEDEFS, -1, 0, 0); - strncpy(SideDefs[NumSideDefs - 1].tex3, "-", - WAD_TEX_NAME); - strncpy(SideDefs[n].tex3, "-", WAD_TEX_NAME); - LineDefs[cur->objnum].sidedef2 = NumSideDefs - 1; - LineDefs[cur->objnum].flags ^= 4; // Set the 2S bit - LineDefs[cur->objnum].flags &= ~1; // Clear the Im bit - } - break; - } - } - for (n = 0; n < 7; n++) - menustr[n] = (char *) GetMemory(60); - sprintf(menustr[6], "Edit sidedef #%d", sdlist->objnum); - texname[WAD_TEX_NAME] = '\0'; - strncpy(texname, SideDefs[sdlist->objnum].tex3, WAD_TEX_NAME); - sprintf(menustr[0], "Change middle texture (Current: %s)", texname); - strncpy(texname, SideDefs[sdlist->objnum].tex1, WAD_TEX_NAME); - sprintf(menustr[1], "Change upper texture (Current: %s)", texname); - strncpy(texname, SideDefs[sdlist->objnum].tex2, WAD_TEX_NAME); - sprintf(menustr[2], "Change lower texture (Current: %s)", texname); - sprintf(menustr[3], "Change texture X offset (Current: %d)", - SideDefs[sdlist->objnum].xoff); - sprintf(menustr[4], "Change texture Y offset (Current: %d)", - SideDefs[sdlist->objnum].yoff); - sprintf(menustr[5], "Change sector ref. (Current: #%d)", - SideDefs[sdlist->objnum].sector); - val = vDisplayMenu(x0 + 42, subwin_y0, menustr[6], - menustr[0], YK_, 0, - menustr[1], YK_, 0, - menustr[2], YK_, 0, - menustr[3], YK_, 0, - menustr[4], YK_, 0, menustr[5], YK_, 0, NULL); - for (n = 0; n < 7; n++) - FreeMemory(menustr[n]); - subsubwin_y0 = subwin_y0 + BOX_BORDER + (2 + val) * FONTH; - switch (val) - { - case 1: - strncpy(texname, SideDefs[sdlist->objnum].tex3, WAD_TEX_NAME); - ChooseWallTexture(x0 + 84, subsubwin_y0, - "Choose a wall texture", NumWTexture, WTexture, - texname); - if (strlen(texname) > 0) - { - for (cur = sdlist; cur; cur = cur->next) - if (cur->objnum >= 0) - strncpy(SideDefs[cur->objnum].tex3, texname, - WAD_TEX_NAME); - MadeChanges = 1; - } - break; + if (objtype != OBJ_SIDEDEFS) + { + if (LineDefs[obj->objnum].sidedef2 >= 0) + { + // Build a new selection list with the second (or first) SideDefs + objtype = OBJ_SIDEDEFS; + sdlist = 0; + for (cur = obj; cur; cur = cur->next) + if (LineDefs[cur->objnum].sidedef2 >= 0) + SelectObject(&sdlist, LineDefs[cur->objnum].sidedef2); + else if (LineDefs[cur->objnum].sidedef1 >= 0) + SelectObject(&sdlist, LineDefs[cur->objnum].sidedef1); + } + else + { + // Add a new second (or first) sidedef + for (cur = obj; cur; cur = cur->next) + if (LineDefs[cur->objnum].sidedef1 == -1) + { + InsertObject(OBJ_SIDEDEFS, -1, 0, 0); + LineDefs[cur->objnum].sidedef1 = NumSideDefs - 1; + } + else if (LineDefs[cur->objnum].sidedef2 == -1) + { + n = LineDefs[cur->objnum].sidedef1; + InsertObject(OBJ_SIDEDEFS, -1, 0, 0); + strncpy(SideDefs[NumSideDefs - 1].tex3, "-", + WAD_TEX_NAME); + strncpy(SideDefs[n].tex3, "-", WAD_TEX_NAME); + LineDefs[cur->objnum].sidedef2 = NumSideDefs - 1; + LineDefs[cur->objnum].flags ^= 4; // Set the 2S bit + LineDefs[cur->objnum].flags &= ~1; // Clear the Im bit + } + break; + } + } + for (n = 0; n < 7; n++) + menustr[n] = (char *) GetMemory(60); + sprintf(menustr[6], "Edit sidedef #%d", sdlist->objnum); + texname[WAD_TEX_NAME] = '\0'; + strncpy(texname, SideDefs[sdlist->objnum].tex3, WAD_TEX_NAME); + sprintf(menustr[0], "Change middle texture (Current: %s)", texname); + strncpy(texname, SideDefs[sdlist->objnum].tex1, WAD_TEX_NAME); + sprintf(menustr[1], "Change upper texture (Current: %s)", texname); + strncpy(texname, SideDefs[sdlist->objnum].tex2, WAD_TEX_NAME); + sprintf(menustr[2], "Change lower texture (Current: %s)", texname); + sprintf(menustr[3], "Change texture X offset (Current: %d)", + SideDefs[sdlist->objnum].xoff); + sprintf(menustr[4], "Change texture Y offset (Current: %d)", + SideDefs[sdlist->objnum].yoff); + sprintf(menustr[5], "Change sector ref. (Current: #%d)", + SideDefs[sdlist->objnum].sector); + val = vDisplayMenu(x0 + 42, subwin_y0, menustr[6], + menustr[0], YK_, 0, + menustr[1], YK_, 0, + menustr[2], YK_, 0, + menustr[3], YK_, 0, + menustr[4], YK_, 0, menustr[5], YK_, 0, NULL); + for (n = 0; n < 7; n++) + FreeMemory(menustr[n]); + subsubwin_y0 = subwin_y0 + BOX_BORDER + (2 + val) * FONTH; + switch (val) + { + case 1: + strncpy(texname, SideDefs[sdlist->objnum].tex3, WAD_TEX_NAME); + ChooseWallTexture(x0 + 84, subsubwin_y0, + "Choose a wall texture", NumWTexture, WTexture, + texname); + if (strlen(texname) > 0) + { + for (cur = sdlist; cur; cur = cur->next) + if (cur->objnum >= 0) + strncpy(SideDefs[cur->objnum].tex3, texname, + WAD_TEX_NAME); + MadeChanges = 1; + } + break; - case 2: - strncpy(texname, SideDefs[sdlist->objnum].tex1, WAD_TEX_NAME); - ChooseWallTexture(x0 + 84, subsubwin_y0, - "Choose a wall texture", NumWTexture, WTexture, - texname); - if (strlen(texname) > 0) - { - for (cur = sdlist; cur; cur = cur->next) - if (cur->objnum >= 0) - strncpy(SideDefs[cur->objnum].tex1, texname, - WAD_TEX_NAME); - MadeChanges = 1; - } - break; + case 2: + strncpy(texname, SideDefs[sdlist->objnum].tex1, WAD_TEX_NAME); + ChooseWallTexture(x0 + 84, subsubwin_y0, + "Choose a wall texture", NumWTexture, WTexture, + texname); + if (strlen(texname) > 0) + { + for (cur = sdlist; cur; cur = cur->next) + if (cur->objnum >= 0) + strncpy(SideDefs[cur->objnum].tex1, texname, + WAD_TEX_NAME); + MadeChanges = 1; + } + break; - case 3: - strncpy(texname, SideDefs[sdlist->objnum].tex2, WAD_TEX_NAME); - ChooseWallTexture(x0 + 84, subsubwin_y0, - "Choose a wall texture", NumWTexture, WTexture, - texname); - if (strlen(texname) > 0) - { - for (cur = sdlist; cur; cur = cur->next) - if (cur->objnum >= 0) - strncpy(SideDefs[cur->objnum].tex2, texname, - WAD_TEX_NAME); - MadeChanges = 1; - } - break; + case 3: + strncpy(texname, SideDefs[sdlist->objnum].tex2, WAD_TEX_NAME); + ChooseWallTexture(x0 + 84, subsubwin_y0, + "Choose a wall texture", NumWTexture, WTexture, + texname); + if (strlen(texname) > 0) + { + for (cur = sdlist; cur; cur = cur->next) + if (cur->objnum >= 0) + strncpy(SideDefs[cur->objnum].tex2, texname, + WAD_TEX_NAME); + MadeChanges = 1; + } + break; - case 4: - val = InputIntegerValue(x0 + 84, subsubwin_y0, - -32768, 32767, - SideDefs[sdlist->objnum].xoff); - if (val != IIV_CANCEL) - { - for (cur = sdlist; cur; cur = cur->next) - if (cur->objnum >= 0) - SideDefs[cur->objnum].xoff = val; - MadeChanges = 1; - } - break; + case 4: + val = InputIntegerValue(x0 + 84, subsubwin_y0, + -32768, 32767, + SideDefs[sdlist->objnum].xoff); + if (val != IIV_CANCEL) + { + for (cur = sdlist; cur; cur = cur->next) + if (cur->objnum >= 0) + SideDefs[cur->objnum].xoff = val; + MadeChanges = 1; + } + break; - case 5: - val = InputIntegerValue(x0 + 84, subsubwin_y0, - -32768, 32767, - SideDefs[sdlist->objnum].yoff); - if (val != IIV_CANCEL) - { - for (cur = sdlist; cur; cur = cur->next) - if (cur->objnum >= 0) - SideDefs[cur->objnum].yoff = val; - MadeChanges = 1; - } - break; + case 5: + val = InputIntegerValue(x0 + 84, subsubwin_y0, + -32768, 32767, + SideDefs[sdlist->objnum].yoff); + if (val != IIV_CANCEL) + { + for (cur = sdlist; cur; cur = cur->next) + if (cur->objnum >= 0) + SideDefs[cur->objnum].yoff = val; + MadeChanges = 1; + } + break; - case 6: - val = InputObjectXRef(x0 + 84, subsubwin_y0, - OBJ_SECTORS, 0, - SideDefs[sdlist->objnum].sector); - if (val >= 0) - { - for (cur = sdlist; cur; cur = cur->next) - if (cur->objnum >= 0) - SideDefs[cur->objnum].sector = val; - MadeChanges = 1; - } - break; - } - ForgetSelection(&sdlist); - break; + case 6: + val = InputObjectXRef(x0 + 84, subsubwin_y0, + OBJ_SECTORS, 0, + SideDefs[sdlist->objnum].sector); + if (val >= 0) + { + for (cur = sdlist; cur; cur = cur->next) + if (cur->objnum >= 0) + SideDefs[cur->objnum].sector = val; + MadeChanges = 1; + } + break; + } + ForgetSelection(&sdlist); + break; } } @@ -458,20 +458,20 @@ static char ldstr[16][50]; if ((LineDefs[linedefnum].flags & (0x01 << (flagndx - 1))) != 0) - strcpy(ldstr[flagndx - 1], "* "); + strcpy(ldstr[flagndx - 1], "* "); else - strcpy(ldstr[flagndx - 1], " "); + strcpy(ldstr[flagndx - 1], " "); strcat(ldstr[flagndx - 1], - GetLineDefFlagsLongName(0x01 << (flagndx - 1))); + GetLineDefFlagsLongName(0x01 << (flagndx - 1))); return ldstr[flagndx - 1]; } /* - * InputLinedefType - * Let the user select a linedef type number and return it. - * Returns 0 if OK, <>0 if cancelled + * InputLinedefType + * Let the user select a linedef type number and return it. + * Returns 0 if OK, <>0 if cancelled */ int InputLinedefType(int x0, int y0, int *number) { @@ -482,54 +482,54 @@ for (;;) { - /* First let user select a ldtgroup */ - if (DisplayMenuList(x0 + 84, y0, "Select group", ldtgroup, - PrintLdtgroup, &ldtgno) < 0) - return 1; - if (al_lseek(ldtgroup, ldtgno, SEEK_SET)) - fatal_error("%s ILT1 (%s)", msg_unexpected, - al_astrerror(al_aerrno)); - ldtg = CUR_LDTGROUP->ldtgroup; + /* First let user select a ldtgroup */ + if (DisplayMenuList(x0 + 84, y0, "Select group", ldtgroup, + PrintLdtgroup, &ldtgno) < 0) + return 1; + if (al_lseek(ldtgroup, ldtgno, SEEK_SET)) + fatal_error("%s ILT1 (%s)", msg_unexpected, + al_astrerror(al_aerrno)); + ldtg = CUR_LDTGROUP->ldtgroup; - /* KLUDGE: Special ldtgroup LDT_FREE means "enter number" - Don't look for this ldtgroup in the .ygd file : - LoadGameDefs() creates it manually. */ - if (ldtg == LDT_FREE) - { - // FIXME should be unsigned - *number = InputIntegerValue(x0 + 126, y0 + (3 + ldtgno) * FONTH, - -32768, 32767, 0); - if (*number != IIV_CANCEL) - break; - goto again; - } + /* KLUDGE: Special ldtgroup LDT_FREE means "enter number" + Don't look for this ldtgroup in the .ygd file : + LoadGameDefs() creates it manually. */ + if (ldtg == LDT_FREE) + { + // FIXME should be unsigned + *number = InputIntegerValue(x0 + 126, y0 + (3 + ldtgno) * FONTH, + -32768, 32767, 0); + if (*number != IIV_CANCEL) + break; + goto again; + } - /* Then build a list of pointers on all ldt that have this - ldtgroup and let user select one */ - list = al_lcreate(sizeof(void *)); - for (al_lrewind(ldtdef); !al_leol(ldtdef); al_lstep(ldtdef)) - if (CUR_LDTDEF->ldtgroup == ldtg) - { - void *ptr = CUR_LDTDEF; - al_lwrite(list, &ptr); - } - { - Menu_data_ldt menudata(list); - r = DisplayMenuList - (x0 + 126, y0 + 2 * FONTH, "Select type", menudata, NULL); - } - if (r < 0) - goto again; - if (al_lseek(list, r, SEEK_SET)) - fatal_error("%s ILT2 (%s)", msg_unexpected, - al_astrerror(al_aerrno)); - *number = (*((ldtdef_t **) al_lptr(list)))->number; - al_ldiscard(list); - break; + /* Then build a list of pointers on all ldt that have this + ldtgroup and let user select one */ + list = al_lcreate(sizeof(void *)); + for (al_lrewind(ldtdef); !al_leol(ldtdef); al_lstep(ldtdef)) + if (CUR_LDTDEF->ldtgroup == ldtg) + { + void *ptr = CUR_LDTDEF; + al_lwrite(list, &ptr); + } + { + Menu_data_ldt menudata(list); + r = DisplayMenuList + (x0 + 126, y0 + 2 * FONTH, "Select type", menudata, NULL); + } + if (r < 0) + goto again; + if (al_lseek(list, r, SEEK_SET)) + fatal_error("%s ILT2 (%s)", msg_unexpected, + al_astrerror(al_aerrno)); + *number = (*((ldtdef_t **) al_lptr(list)))->number; + al_ldiscard(list); + break; again: - ; - /* draw_map (OBJ_THINGS, 0, 0); FIXME! */ + ; + /* draw_map (OBJ_THINGS, 0, 0); FIXME! */ } return 0; @@ -537,13 +537,13 @@ /* - * PrintLdtgroup - * Used by DisplayMenuList when called by InputLinedefType + * PrintLdtgroup + * Used by DisplayMenuList when called by InputLinedefType */ static const char *PrintLdtgroup(void *ptr) { if (!ptr) - return "PrintLdtgroup: (null)"; + return "PrintLdtgroup: (null)"; return ((ldtgroup_t *) ptr)->desc; } @@ -564,20 +564,20 @@ { SelPtr cur; wad_ldflags_t src_flags = - LineDefs[src_linedef].flags & ~LINEDEF_FLAG_KEEP; + LineDefs[src_linedef].flags & ~LINEDEF_FLAG_KEEP; for (cur = linedefs; cur; cur = cur->next) { - if (!is_obj(cur->objnum)) - continue; + if (!is_obj(cur->objnum)) + continue; - // don't transfer certain flags - LineDefs[cur->objnum].flags &= LINEDEF_FLAG_KEEP; - LineDefs[cur->objnum].flags |= src_flags; + // don't transfer certain flags + LineDefs[cur->objnum].flags &= LINEDEF_FLAG_KEEP; + LineDefs[cur->objnum].flags |= src_flags; - LineDefs[cur->objnum].type = LineDefs[src_linedef].type; - LineDefs[cur->objnum].tag = LineDefs[src_linedef].tag; + LineDefs[cur->objnum].type = LineDefs[src_linedef].type; + LineDefs[cur->objnum].tag = LineDefs[src_linedef].tag; - MadeChanges = 1; + MadeChanges = 1; } } diff -r 594dea11ccd9 -r a68786b9c74b src/l_super.h --- a/src/l_super.h Sat Sep 24 15:01:56 2011 +0300 +++ b/src/l_super.h Sat Sep 24 15:59:33 2011 +0300 @@ -1,6 +1,6 @@ /* - * l_super.h - Superimposed_ld class - * AYM 2003-12-02 + * l_super.h - Superimposed_ld class + * AYM 2003-12-02 */ /* @@ -20,7 +20,7 @@ */ -#ifndef YH_L_SUPER /* DO NOT INSERT ANYTHING BEFORE THIS LINE */ +#ifndef YH_L_SUPER /* DO NOT INSERT ANYTHING BEFORE THIS LINE */ #define YH_L_SUPER #include "levels.h" @@ -46,8 +46,8 @@ void rewind(); private: - obj_no_t refldno; // Reference linedef - obj_no_t ldno; // get() will start from there + obj_no_t refldno; // Reference linedef + obj_no_t ldno; // get() will start from there }; @@ -59,16 +59,16 @@ /* - * Superimposed_ld::set - set the reference linedef + * Superimposed_ld::set - set the reference linedef * - * If the argument is not a valid linedef number, does nothing and - * returns a non-zero value. Otherwise, set the linedef number, - * calls rewind() and returns a zero value. + * If the argument is not a valid linedef number, does nothing and + * returns a non-zero value. Otherwise, set the linedef number, + * calls rewind() and returns a zero value. */ inline int Superimposed_ld::set(obj_no_t ldno) { - if (!is_linedef(ldno)) // Paranoia - return 1; + if (!is_linedef(ldno)) // Paranoia + return 1; refldno = ldno; rewind(); @@ -77,34 +77,34 @@ /* - * Superimposed_ld::get - return the next superimposed linedef + * Superimposed_ld::get - return the next superimposed linedef * - * Returns the number of the next superimposed linedef, or -1 if - * there's none. If the reference linedef was not specified, or is - * invalid (possibly as a result of changes in the level), returns - * -1. + * Returns the number of the next superimposed linedef, or -1 if + * there's none. If the reference linedef was not specified, or is + * invalid (possibly as a result of changes in the level), returns + * -1. * - * Linedefs that have invalid start/end vertices are silently - * skipped. + * Linedefs that have invalid start/end vertices are silently + * skipped. */ inline obj_no_t Superimposed_ld::get() { if (refldno == -1) - return -1; + return -1; /* These variables are there to speed things up a bit by avoiding repetitive table lookups. Everything is re-computed each time as LineDefs could very well be realloc'd while we were out. */ if (!is_linedef(refldno)) - return -1; + return -1; const struct LineDef *const pmax = LineDefs + NumLineDefs; const struct LineDef *const pref = LineDefs + refldno; const wad_vn_t refv0 = pref->start; const wad_vn_t refv1 = pref->end; - if (!is_vertex(refv0) || !is_vertex(refv1)) // Paranoia - return -1; + if (!is_vertex(refv0) || !is_vertex(refv1)) // Paranoia + return -1; const wad_coord_t refx0 = Vertices[refv0].x; const wad_coord_t refy0 = Vertices[refv0].y; @@ -112,21 +112,21 @@ const wad_coord_t refy1 = Vertices[refv1].y; for (const struct LineDef * p = LineDefs + ldno; ldno < NumLineDefs; - p++, ldno++) + p++, ldno++) { - if (!is_vertex(p->start) || !is_vertex(p->end)) // Paranoia - continue; - obj_no_t x0 = Vertices[p->start].x; - obj_no_t y0 = Vertices[p->start].y; - obj_no_t x1 = Vertices[p->end].x; - obj_no_t y1 = Vertices[p->end].y; - if (x0 == refx0 && y0 == refy0 && x1 == refx1 && y1 == refy1 - || x0 == refx1 && y0 == refy1 && x1 == refx0 && y1 == refy0) - { - if (ldno == refldno) - continue; - return ldno++; - } + if (!is_vertex(p->start) || !is_vertex(p->end)) // Paranoia + continue; + obj_no_t x0 = Vertices[p->start].x; + obj_no_t y0 = Vertices[p->start].y; + obj_no_t x1 = Vertices[p->end].x; + obj_no_t y1 = Vertices[p->end].y; + if (x0 == refx0 && y0 == refy0 && x1 == refx1 && y1 == refy1 + || x0 == refx1 && y0 == refy1 && x1 == refx0 && y1 == refy0) + { + if (ldno == refldno) + continue; + return ldno++; + } } return -1; @@ -134,10 +134,10 @@ /* - * Superimposed_ld::rewind - rewind the counter + * Superimposed_ld::rewind - rewind the counter * - * After calling this method, the next call to get() will start - * from the first linedef. + * After calling this method, the next call to get() will start + * from the first linedef. */ inline void Superimposed_ld::rewind() { diff -r 594dea11ccd9 -r a68786b9c74b src/l_unlink.cc --- a/src/l_unlink.cc Sat Sep 24 15:01:56 2011 +0300 +++ b/src/l_unlink.cc Sat Sep 24 15:59:33 2011 +0300 @@ -1,6 +1,6 @@ /* - * l_unlink.cc - * AYM 1998-11-07 + * l_unlink.cc + * AYM 1998-11-07 */ @@ -36,17 +36,17 @@ /* - * unlink_sidedef + * unlink_sidedef * - * For all linedefs in the , see whether the sidedefs - * are used by any other linedef _not_in__. If they - * are, duplicate the sidedefs and assign the new duplicate to - * the linedef. - * If is set, take care of the first sidedef. - * If is set, take care of the second sidedef. - * Both can be set, of course. + * For all linedefs in the , see whether the sidedefs + * are used by any other linedef _not_in__. If they + * are, duplicate the sidedefs and assign the new duplicate to + * the linedef. + * If is set, take care of the first sidedef. + * If is set, take care of the second sidedef. + * Both can be set, of course. * - * This function is intended to "unlink" duplicated linedefs. + * This function is intended to "unlink" duplicated linedefs. */ void unlink_sidedef(SelPtr linedefs, int side1, int side2) { @@ -68,20 +68,20 @@ for (n = 0; n < NumLineDefs; n++) { - if (IsSelected(linedefs, n)) - { - if (side1 && is_sidedef(LineDefs[n].sidedef1)) - sd_used_in.set(LineDefs[n].sidedef1); - if (side2 && is_sidedef(LineDefs[n].sidedef2)) - sd_used_in.set(LineDefs[n].sidedef2); - } - else - { - if (is_sidedef(LineDefs[n].sidedef1)) - sd_used_out.set(LineDefs[n].sidedef1); - if (is_sidedef(LineDefs[n].sidedef2)) - sd_used_out.set(LineDefs[n].sidedef2); - } + if (IsSelected(linedefs, n)) + { + if (side1 && is_sidedef(LineDefs[n].sidedef1)) + sd_used_in.set(LineDefs[n].sidedef1); + if (side2 && is_sidedef(LineDefs[n].sidedef2)) + sd_used_in.set(LineDefs[n].sidedef2); + } + else + { + if (is_sidedef(LineDefs[n].sidedef1)) + sd_used_out.set(LineDefs[n].sidedef1); + if (is_sidedef(LineDefs[n].sidedef2)) + sd_used_out.set(LineDefs[n].sidedef2); + } } // For all sidedefs that are used both by a linedef @@ -91,16 +91,16 @@ for (n = 0; n < NumSideDefs; n++) { - if (sd_used_in.get(n) && sd_used_out.get(n)) - { - InsertObject(OBJ_SIDEDEFS, n, 0, 0); - for (cur = linedefs; cur; cur = cur->next) - { - if (side1 && LineDefs[cur->objnum].sidedef1 == n) - LineDefs[cur->objnum].sidedef1 = NumSideDefs - 1; - if (side2 && LineDefs[cur->objnum].sidedef2 == n) - LineDefs[cur->objnum].sidedef2 = NumSideDefs - 1; - } - } + if (sd_used_in.get(n) && sd_used_out.get(n)) + { + InsertObject(OBJ_SIDEDEFS, n, 0, 0); + for (cur = linedefs; cur; cur = cur->next) + { + if (side1 && LineDefs[cur->objnum].sidedef1 == n) + LineDefs[cur->objnum].sidedef1 = NumSideDefs - 1; + if (side2 && LineDefs[cur->objnum].sidedef2 == n) + LineDefs[cur->objnum].sidedef2 = NumSideDefs - 1; + } + } } } diff -r 594dea11ccd9 -r a68786b9c74b src/l_vertices.cc --- a/src/l_vertices.cc Sat Sep 24 15:01:56 2011 +0300 +++ b/src/l_vertices.cc Sat Sep 24 15:59:33 2011 +0300 @@ -1,6 +1,6 @@ /* - * l_vertices.cc - * AYM 1998-11-22 + * l_vertices.cc + * AYM 1998-11-22 */ @@ -34,9 +34,9 @@ /* - * bv_vertices_of_linedefs - * Return a bit vector of all vertices used by the linedefs. - * It's up to the caller to delete the bit vector after use. + * bv_vertices_of_linedefs + * Return a bit vector of all vertices used by the linedefs. + * It's up to the caller to delete the bit vector after use. */ bitvec_c *bv_vertices_of_linedefs(bitvec_c * linedefs) { @@ -45,19 +45,19 @@ vertices = new bitvec_c(NumVertices); for (n = 0; n < NumLineDefs; n++) - if (linedefs->get(n)) - { - vertices->set(LineDefs[n].start); - vertices->set(LineDefs[n].end); - } + if (linedefs->get(n)) + { + vertices->set(LineDefs[n].start); + vertices->set(LineDefs[n].end); + } return vertices; } /* - * bv_vertices_of_linedefs - * Return a bit vector of all vertices used by the linedefs. - * It's up to the caller to delete the bit vector after use. + * bv_vertices_of_linedefs + * Return a bit vector of all vertices used by the linedefs. + * It's up to the caller to delete the bit vector after use. */ bitvec_c *bv_vertices_of_linedefs(SelPtr list) { @@ -67,17 +67,17 @@ vertices = new bitvec_c(NumVertices); for (cur = list; cur; cur = cur->next) { - vertices->set(LineDefs[cur->objnum].start); - vertices->set(LineDefs[cur->objnum].end); + vertices->set(LineDefs[cur->objnum].start); + vertices->set(LineDefs[cur->objnum].end); } return vertices; } /* - * list_vertices_of_linedefs - * Return a list of all vertices used by the linedefs - * It's up to the caller to delete the list after use. + * list_vertices_of_linedefs + * Return a list of all vertices used by the linedefs + * It's up to the caller to delete the list after use. */ SelPtr list_vertices_of_linedefs(SelPtr list) { @@ -88,8 +88,8 @@ vertices_bitvec = bv_vertices_of_linedefs(list); for (n = 0; n < vertices_bitvec->nelements(); n++) { - if (vertices_bitvec->get(n)) - SelectObject(&vertices_list, n); + if (vertices_bitvec->get(n)) + SelectObject(&vertices_list, n); } delete vertices_bitvec; return vertices_list; diff -r 594dea11ccd9 -r a68786b9c74b src/l_vertices.h --- a/src/l_vertices.h Sat Sep 24 15:01:56 2011 +0300 +++ b/src/l_vertices.h Sat Sep 24 15:59:33 2011 +0300 @@ -1,6 +1,6 @@ /* - * l_vertices.h - * AYM 1998-11-22 + * l_vertices.h + * AYM 1998-11-22 */ diff -r 594dea11ccd9 -r a68786b9c74b src/levels.cc --- a/src/levels.cc Sat Sep 24 15:01:56 2011 +0300 +++ b/src/levels.cc Sat Sep 24 15:59:33 2011 +0300 @@ -1,8 +1,8 @@ /* - * levels.cc - * Level loading and saving routines, - * global variables used to hold the level data. - * BW & RQ sometime in 1993 or 1994. + * levels.cc + * Level loading and saving routines, + * global variables used to hold the level data. + * BW & RQ sometime in 1993 or 1994. */ @@ -43,57 +43,57 @@ /* - FIXME - All these variables should be turned - into members of a "Level" class. + FIXME + All these variables should be turned + into members of a "Level" class. */ -MDirPtr Level; /* master dictionary entry for the level */ -int NumThings; /* number of things */ -TPtr Things; /* things data */ -int NumLineDefs; /* number of line defs */ -LDPtr LineDefs; /* line defs data */ -int NumSideDefs; /* number of side defs */ -SDPtr SideDefs; /* side defs data */ -int NumVertices; /* number of vertexes */ -VPtr Vertices; /* vertex data */ -int NumSectors; /* number of sectors */ -SPtr Sectors; /* sectors data */ +MDirPtr Level; /* master dictionary entry for the level */ +int NumThings; /* number of things */ +TPtr Things; /* things data */ +int NumLineDefs; /* number of line defs */ +LDPtr LineDefs; /* line defs data */ +int NumSideDefs; /* number of side defs */ +SDPtr SideDefs; /* side defs data */ +int NumVertices; /* number of vertexes */ +VPtr Vertices; /* vertex data */ +int NumSectors; /* number of sectors */ +SPtr Sectors; /* sectors data */ // FIXME should be somewhere else -int NumWTexture; /* number of wall textures */ -char **WTexture; /* array of wall texture names */ +int NumWTexture; /* number of wall textures */ +char **WTexture; /* array of wall texture names */ // FIXME all the flat list stuff should be put in a separate class -size_t NumFTexture; /* number of floor/ceiling textures */ -flat_list_entry_t *flat_list; // List of all flats in the directory +size_t NumFTexture; /* number of floor/ceiling textures */ +flat_list_entry_t *flat_list; // List of all flats in the directory -int MapMaxX = -32767; /* maximum X value of map */ -int MapMaxY = -32767; /* maximum Y value of map */ -int MapMinX = 32767; /* minimum X value of map */ -int MapMinY = 32767; /* minimum Y value of map */ -bool MadeChanges; /* made changes? */ -bool MadeMapChanges; /* made changes that need rebuilding? */ -unsigned long things_angles; // See levels.h for description. -unsigned long things_types; // See levels.h for description. -char Level_name[WAD_NAME + 1]; /* The name of the level (E.G. - "MAP01" or "E1M1"), followed by a - NUL. If the Level has been created as - the result of a "c" command with no - argument, an empty string. The name - is not necesarily in upper case but - it always a valid lump name, not a - command line shortcut like "17". */ +int MapMaxX = -32767; /* maximum X value of map */ +int MapMaxY = -32767; /* maximum Y value of map */ +int MapMinX = 32767; /* minimum X value of map */ +int MapMinY = 32767; /* minimum Y value of map */ +bool MadeChanges; /* made changes? */ +bool MadeMapChanges; /* made changes that need rebuilding? */ +unsigned long things_angles; // See levels.h for description. +unsigned long things_types; // See levels.h for description. +char Level_name[WAD_NAME + 1]; /* The name of the level (E.G. + "MAP01" or "E1M1"), followed by a + NUL. If the Level has been created as + the result of a "c" command with no + argument, an empty string. The name + is not necesarily in upper case but + it always a valid lump name, not a + command line shortcut like "17". */ -y_file_name_t Level_file_name; /* The name of the file in which - the level would be saved. If the - level has been created as the result - of a "c" command, with or without - argument, an empty string. */ +y_file_name_t Level_file_name; /* The name of the file in which + the level would be saved. If the + level has been created as the result + of a "c" command, with or without + argument, an empty string. */ -y_file_name_t Level_file_name_saved; /* The name of the file in - which the level was last saved. If - the Level has never been saved yet, - an empty string. */ +y_file_name_t Level_file_name_saved; /* The name of the file in + which the level was last saved. If + the Level has never been saved yet, + an empty string. */ void EmptyLevelData(const char *levelname) { @@ -113,8 +113,8 @@ /* - * texno_texname - * A convenience function when loading Doom alpha levels + * texno_texname + * A convenience function when loading Doom alpha levels */ static char *tex_list = 0; static size_t ntex = 0; @@ -122,18 +122,18 @@ inline const char *texno_texname(i16 texno) { if (texno < 0) - return "-"; + return "-"; else if (yg_texture_format == YGTF_NAMELESS) { - sprintf(tex_name, "TEX%04u", (unsigned) texno); - return tex_name; + sprintf(tex_name, "TEX%04u", (unsigned) texno); + return tex_name; } else { - if (texno < (i16) ntex) - return tex_list + WAD_TEX_NAME * texno; - else - return "unknown"; + if (texno < (i16) ntex) + return tex_list + WAD_TEX_NAME * texno; + else + return "unknown"; } } @@ -142,7 +142,7 @@ read in the level data */ -int ReadLevelData(const char *levelname) /* SWAP! */ +int ReadLevelData(const char *levelname) /* SWAP! */ { int rc = 0; MDirPtr dir; @@ -152,243 +152,243 @@ DisplayMessage(-1, -1, "Reading data for level %s...", levelname); Level = FindMasterDir(MasterDir, levelname); if (!Level) - fatal_error("level data not found"); + fatal_error("level data not found"); /* Get the number of vertices */ i32 v_offset = 42; i32 v_length = 42; { - const char *lump_name = "BUG"; - if (yg_level_format == YGLF_ALPHA) // Doom alpha - lump_name = "POINTS"; - else - lump_name = "VERTEXES"; - dir = FindMasterDir(Level, lump_name); - if (dir == 0) - OldNumVertices = 0; - else - { - v_offset = dir->dir.start; - v_length = dir->dir.size; - if (yg_level_format == YGLF_ALPHA) // Doom alpha: skip leading count - { - v_offset += 4; - v_length -= 4; - } - OldNumVertices = (int) (v_length / WAD_VERTEX_BYTES); - if ((i32) (OldNumVertices * WAD_VERTEX_BYTES) != v_length) - warn("the %s lump has a weird size." - " The wad might be corrupt.\n", lump_name); - } + const char *lump_name = "BUG"; + if (yg_level_format == YGLF_ALPHA) // Doom alpha + lump_name = "POINTS"; + else + lump_name = "VERTEXES"; + dir = FindMasterDir(Level, lump_name); + if (dir == 0) + OldNumVertices = 0; + else + { + v_offset = dir->dir.start; + v_length = dir->dir.size; + if (yg_level_format == YGLF_ALPHA) // Doom alpha: skip leading count + { + v_offset += 4; + v_length -= 4; + } + OldNumVertices = (int) (v_length / WAD_VERTEX_BYTES); + if ((i32) (OldNumVertices * WAD_VERTEX_BYTES) != v_length) + warn("the %s lump has a weird size." + " The wad might be corrupt.\n", lump_name); + } } // Read THINGS { - const char *lump_name = "THINGS"; - verbmsg("Reading %s things", levelname); - i32 offset = 42; - i32 length; - dir = FindMasterDir(Level, lump_name); - if (dir == 0) - NumThings = 0; - else - { - offset = dir->dir.start; - length = dir->dir.size; - if (MainWad == Iwad4) // Hexen mode - { - NumThings = (int) (length / WAD_HEXEN_THING_BYTES); - if ((i32) (NumThings * WAD_HEXEN_THING_BYTES) != length) - warn("the %s lump has a weird size." - " The wad might be corrupt.\n", lump_name); - } - else // Doom/Heretic/Strife mode - { - if (yg_level_format == YGLF_ALPHA) // Doom alpha: skip leading count - { - offset += 4; - length -= 4; - } - size_t thing_size = - yg_level_format == YGLF_ALPHA ? 12 : WAD_THING_BYTES; - NumThings = (int) (length / thing_size); - if ((i32) (NumThings * thing_size) != length) - warn("the %s lump has a weird size." - " The wad might be corrupt.\n", lump_name); - } - } - things_angles++; - things_types++; - if (NumThings > 0) - { - Things = (TPtr) GetMemory((unsigned long) NumThings - * sizeof(struct Thing)); - const Wad_file *wf = dir->wadfile; - wf->seek(offset); - if (wf->error()) - { - err("%s: seek error", lump_name); - rc = 1; - goto byebye; - } - if (MainWad == Iwad4) // Hexen mode - for (long n = 0; n < NumThings; n++) - { - u8 dummy2[6]; - wf->read_i16(); // Tid - wf->read_i16(&Things[n].xpos); - wf->read_i16(&Things[n].ypos); - wf->read_i16(); // Height - wf->read_i16(&Things[n].angle); - wf->read_i16(&Things[n].type); - wf->read_i16(&Things[n].when); - wf->read_bytes(dummy2, sizeof dummy2); - if (wf->error()) - { - err("%s: error reading thing #%ld", lump_name, n); - rc = 1; - goto byebye; - } - } - else // Doom/Heretic/Strife mode - for (long n = 0; n < NumThings; n++) - { - wf->read_i16(&Things[n].xpos); - wf->read_i16(&Things[n].ypos); - wf->read_i16(&Things[n].angle); - wf->read_i16(&Things[n].type); - if (yg_level_format == YGLF_ALPHA) - wf->read_i16(); // Alpha. Don't know what it's for. - wf->read_i16(&Things[n].when); - if (wf->error()) - { - err("%s: error reading thing #%ld", lump_name, n); - rc = 1; - goto byebye; - } - } - } + const char *lump_name = "THINGS"; + verbmsg("Reading %s things", levelname); + i32 offset = 42; + i32 length; + dir = FindMasterDir(Level, lump_name); + if (dir == 0) + NumThings = 0; + else + { + offset = dir->dir.start; + length = dir->dir.size; + if (MainWad == Iwad4) // Hexen mode + { + NumThings = (int) (length / WAD_HEXEN_THING_BYTES); + if ((i32) (NumThings * WAD_HEXEN_THING_BYTES) != length) + warn("the %s lump has a weird size." + " The wad might be corrupt.\n", lump_name); + } + else // Doom/Heretic/Strife mode + { + if (yg_level_format == YGLF_ALPHA) // Doom alpha: skip leading count + { + offset += 4; + length -= 4; + } + size_t thing_size = + yg_level_format == YGLF_ALPHA ? 12 : WAD_THING_BYTES; + NumThings = (int) (length / thing_size); + if ((i32) (NumThings * thing_size) != length) + warn("the %s lump has a weird size." + " The wad might be corrupt.\n", lump_name); + } + } + things_angles++; + things_types++; + if (NumThings > 0) + { + Things = (TPtr) GetMemory((unsigned long) NumThings + * sizeof(struct Thing)); + const Wad_file *wf = dir->wadfile; + wf->seek(offset); + if (wf->error()) + { + err("%s: seek error", lump_name); + rc = 1; + goto byebye; + } + if (MainWad == Iwad4) // Hexen mode + for (long n = 0; n < NumThings; n++) + { + u8 dummy2[6]; + wf->read_i16(); // Tid + wf->read_i16(&Things[n].xpos); + wf->read_i16(&Things[n].ypos); + wf->read_i16(); // Height + wf->read_i16(&Things[n].angle); + wf->read_i16(&Things[n].type); + wf->read_i16(&Things[n].when); + wf->read_bytes(dummy2, sizeof dummy2); + if (wf->error()) + { + err("%s: error reading thing #%ld", lump_name, n); + rc = 1; + goto byebye; + } + } + else // Doom/Heretic/Strife mode + for (long n = 0; n < NumThings; n++) + { + wf->read_i16(&Things[n].xpos); + wf->read_i16(&Things[n].ypos); + wf->read_i16(&Things[n].angle); + wf->read_i16(&Things[n].type); + if (yg_level_format == YGLF_ALPHA) + wf->read_i16(); // Alpha. Don't know what it's for. + wf->read_i16(&Things[n].when); + if (wf->error()) + { + err("%s: error reading thing #%ld", lump_name, n); + rc = 1; + goto byebye; + } + } + } } // Read LINEDEFS if (yg_level_format != YGLF_ALPHA) { - const char *lump_name = "LINEDEFS"; - verbmsg(" linedefs"); - dir = FindMasterDir(Level, lump_name); - if (dir == 0) - NumLineDefs = 0; - else - { - if (MainWad == Iwad4) // Hexen mode - { - NumLineDefs = (int) (dir->dir.size / WAD_HEXEN_LINEDEF_BYTES); - if ((i32) (NumLineDefs * WAD_HEXEN_LINEDEF_BYTES) != - dir->dir.size) - warn("the %s lump has a weird size." - " The wad might be corrupt.\n", lump_name); - } - else // Doom/Heretic/Strife mode - { - NumLineDefs = (int) (dir->dir.size / WAD_LINEDEF_BYTES); - if ((i32) (NumLineDefs * WAD_LINEDEF_BYTES) != dir->dir.size) - warn("the %s lump has a weird size." - " The wad might be corrupt.\n", lump_name); - } - } - if (NumLineDefs > 0) - { - LineDefs = (LDPtr) GetMemory((unsigned long) NumLineDefs - * sizeof(struct LineDef)); - const Wad_file *wf = dir->wadfile; - wf->seek(dir->dir.start); - if (wf->error()) - { - err("%s: seek error", lump_name); - rc = 1; - goto byebye; - } - if (MainWad == Iwad4) // Hexen mode - for (long n = 0; n < NumLineDefs; n++) - { - u8 dummy[6]; - wf->read_i16(&LineDefs[n].start); - wf->read_i16(&LineDefs[n].end); - wf->read_i16(&LineDefs[n].flags); - wf->read_bytes(dummy, sizeof dummy); - wf->read_i16(&LineDefs[n].sidedef1); - wf->read_i16(&LineDefs[n].sidedef2); - LineDefs[n].type = dummy[0]; - LineDefs[n].tag = dummy[1]; // arg1 often contains a tag - if (wf->error()) - { - err("%s: error reading linedef #%ld", lump_name, n); - rc = 1; - goto byebye; - } - } - else // Doom/Heretic/Strife mode - for (long n = 0; n < NumLineDefs; n++) - { - wf->read_i16(&LineDefs[n].start); - wf->read_i16(&LineDefs[n].end); - wf->read_i16(&LineDefs[n].flags); - wf->read_i16(&LineDefs[n].type); - wf->read_i16(&LineDefs[n].tag); - wf->read_i16(&LineDefs[n].sidedef1); - wf->read_i16(&LineDefs[n].sidedef2); - if (wf->error()) - { - err("%s: error reading linedef #%ld", lump_name, n); - rc = 1; - goto byebye; - } - } - } + const char *lump_name = "LINEDEFS"; + verbmsg(" linedefs"); + dir = FindMasterDir(Level, lump_name); + if (dir == 0) + NumLineDefs = 0; + else + { + if (MainWad == Iwad4) // Hexen mode + { + NumLineDefs = (int) (dir->dir.size / WAD_HEXEN_LINEDEF_BYTES); + if ((i32) (NumLineDefs * WAD_HEXEN_LINEDEF_BYTES) != + dir->dir.size) + warn("the %s lump has a weird size." + " The wad might be corrupt.\n", lump_name); + } + else // Doom/Heretic/Strife mode + { + NumLineDefs = (int) (dir->dir.size / WAD_LINEDEF_BYTES); + if ((i32) (NumLineDefs * WAD_LINEDEF_BYTES) != dir->dir.size) + warn("the %s lump has a weird size." + " The wad might be corrupt.\n", lump_name); + } + } + if (NumLineDefs > 0) + { + LineDefs = (LDPtr) GetMemory((unsigned long) NumLineDefs + * sizeof(struct LineDef)); + const Wad_file *wf = dir->wadfile; + wf->seek(dir->dir.start); + if (wf->error()) + { + err("%s: seek error", lump_name); + rc = 1; + goto byebye; + } + if (MainWad == Iwad4) // Hexen mode + for (long n = 0; n < NumLineDefs; n++) + { + u8 dummy[6]; + wf->read_i16(&LineDefs[n].start); + wf->read_i16(&LineDefs[n].end); + wf->read_i16(&LineDefs[n].flags); + wf->read_bytes(dummy, sizeof dummy); + wf->read_i16(&LineDefs[n].sidedef1); + wf->read_i16(&LineDefs[n].sidedef2); + LineDefs[n].type = dummy[0]; + LineDefs[n].tag = dummy[1]; // arg1 often contains a tag + if (wf->error()) + { + err("%s: error reading linedef #%ld", lump_name, n); + rc = 1; + goto byebye; + } + } + else // Doom/Heretic/Strife mode + for (long n = 0; n < NumLineDefs; n++) + { + wf->read_i16(&LineDefs[n].start); + wf->read_i16(&LineDefs[n].end); + wf->read_i16(&LineDefs[n].flags); + wf->read_i16(&LineDefs[n].type); + wf->read_i16(&LineDefs[n].tag); + wf->read_i16(&LineDefs[n].sidedef1); + wf->read_i16(&LineDefs[n].sidedef2); + if (wf->error()) + { + err("%s: error reading linedef #%ld", lump_name, n); + rc = 1; + goto byebye; + } + } + } } // Read SIDEDEFS { - const char *lump_name = "SIDEDEFS"; - verbmsg(" sidedefs"); - dir = FindMasterDir(Level, lump_name); - if (dir) - { - NumSideDefs = (int) (dir->dir.size / WAD_SIDEDEF_BYTES); - if ((i32) (NumSideDefs * WAD_SIDEDEF_BYTES) != dir->dir.size) - warn("the SIDEDEFS lump has a weird size." - " The wad might be corrupt.\n"); - } - else - NumSideDefs = 0; - if (NumSideDefs > 0) - { - SideDefs = (SDPtr) GetMemory((unsigned long) NumSideDefs - * sizeof(struct SideDef)); - const Wad_file *wf = dir->wadfile; - wf->seek(dir->dir.start); - if (wf->error()) - { - err("%s: seek error", lump_name); - rc = 1; - goto byebye; - } - for (long n = 0; n < NumSideDefs; n++) - { - wf->read_i16(&SideDefs[n].xoff); - wf->read_i16(&SideDefs[n].yoff); - wf->read_bytes(&SideDefs[n].tex1, WAD_TEX_NAME); - wf->read_bytes(&SideDefs[n].tex2, WAD_TEX_NAME); - wf->read_bytes(&SideDefs[n].tex3, WAD_TEX_NAME); - wf->read_i16(&SideDefs[n].sector); - if (wf->error()) - { - err("%s: error reading sidedef #%ld", lump_name, n); - rc = 1; - goto byebye; - } - } - } + const char *lump_name = "SIDEDEFS"; + verbmsg(" sidedefs"); + dir = FindMasterDir(Level, lump_name); + if (dir) + { + NumSideDefs = (int) (dir->dir.size / WAD_SIDEDEF_BYTES); + if ((i32) (NumSideDefs * WAD_SIDEDEF_BYTES) != dir->dir.size) + warn("the SIDEDEFS lump has a weird size." + " The wad might be corrupt.\n"); + } + else + NumSideDefs = 0; + if (NumSideDefs > 0) + { + SideDefs = (SDPtr) GetMemory((unsigned long) NumSideDefs + * sizeof(struct SideDef)); + const Wad_file *wf = dir->wadfile; + wf->seek(dir->dir.start); + if (wf->error()) + { + err("%s: seek error", lump_name); + rc = 1; + goto byebye; + } + for (long n = 0; n < NumSideDefs; n++) + { + wf->read_i16(&SideDefs[n].xoff); + wf->read_i16(&SideDefs[n].yoff); + wf->read_bytes(&SideDefs[n].tex1, WAD_TEX_NAME); + wf->read_bytes(&SideDefs[n].tex2, WAD_TEX_NAME); + wf->read_bytes(&SideDefs[n].tex3, WAD_TEX_NAME); + wf->read_i16(&SideDefs[n].sector); + if (wf->error()) + { + err("%s: error reading sidedef #%ld", lump_name, n); + rc = 1; + goto byebye; + } + } + } } /* Sanity checkings on linedefs: the 1st and 2nd vertices @@ -396,205 +396,205 @@ set to -1. */ for (long n = 0; n < NumLineDefs; n++) { - if (LineDefs[n].sidedef1 != -1 - && outside(LineDefs[n].sidedef1, 0, NumSideDefs - 1)) - { - err("linedef %ld has bad 1st sidedef number %d, giving up", - n, LineDefs[n].sidedef1); - rc = 1; - goto byebye; - } - if (LineDefs[n].sidedef2 != -1 - && outside(LineDefs[n].sidedef2, 0, NumSideDefs - 1)) - { - err("linedef %ld has bad 2nd sidedef number %d, giving up", - n, LineDefs[n].sidedef2); - rc = 1; - goto byebye; - } - if (outside(LineDefs[n].start, 0, OldNumVertices - 1)) - { - err("linedef %ld has bad 1st vertex number %d, giving up", - n, LineDefs[n].start); - rc = 1; - goto byebye; - } - if (outside(LineDefs[n].end, 0, OldNumVertices - 1)) - { - err("linedef %ld has bad 2nd vertex number %d, giving up", - n, LineDefs[n].end); - rc = 1; - goto byebye; - } + if (LineDefs[n].sidedef1 != -1 + && outside(LineDefs[n].sidedef1, 0, NumSideDefs - 1)) + { + err("linedef %ld has bad 1st sidedef number %d, giving up", + n, LineDefs[n].sidedef1); + rc = 1; + goto byebye; + } + if (LineDefs[n].sidedef2 != -1 + && outside(LineDefs[n].sidedef2, 0, NumSideDefs - 1)) + { + err("linedef %ld has bad 2nd sidedef number %d, giving up", + n, LineDefs[n].sidedef2); + rc = 1; + goto byebye; + } + if (outside(LineDefs[n].start, 0, OldNumVertices - 1)) + { + err("linedef %ld has bad 1st vertex number %d, giving up", + n, LineDefs[n].start); + rc = 1; + goto byebye; + } + if (outside(LineDefs[n].end, 0, OldNumVertices - 1)) + { + err("linedef %ld has bad 2nd vertex number %d, giving up", + n, LineDefs[n].end); + rc = 1; + goto byebye; + } } // Read LINES (Doom alpha only) if (yg_level_format == YGLF_ALPHA) { - const char *lump_name = "LINES"; - verbmsg(" lines"); - dir = FindMasterDir(Level, lump_name); - if (dir) - { - if ((dir->dir.size - 4) % 36) - warn("the %s lump has a weird size. The wad might be corrupt.\n", lump_name); - const size_t nlines = dir->dir.size / 36; - NumLineDefs = nlines; - NumSideDefs = 2 * nlines; // Worst case. We'll adjust later. - LineDefs = (LDPtr) GetMemory((unsigned long) NumLineDefs - * sizeof(struct LineDef)); - SideDefs = (SDPtr) GetMemory((unsigned long) NumSideDefs - * sizeof(struct SideDef)); - // Read TEXTURES - if (yg_texture_format != YGTF_NAMELESS) - { - const char *lump_name = "TEXTURES"; - bool success = false; - ntex = 0; - i32 *offset_table = 0; - MDirPtr d = FindMasterDir(MasterDir, lump_name); - if (!d) - { - warn("%s: lump not found in directory\n", lump_name); - goto textures_done; - } - { - const Wad_file *wf = d->wadfile; - wf->seek(d->dir.start); - if (wf->error()) - { - warn("%s: seek error\n", lump_name); - goto textures_done; - } - i32 num; - wf->read_i32(&num); - if (wf->error()) - { - warn("%s: error reading texture count\n", lump_name); - } - if (num < 0 || num > 32767) - { - warn("%s: bad texture count, giving up\n", lump_name); - goto textures_done; - } - ntex = num; - offset_table = new i32[ntex]; - for (size_t n = 0; n < ntex; n++) - { - wf->read_i32(offset_table + n); - if (wf->error()) - { - warn("%s: error reading offsets table\n"); - goto textures_done; - } - } - tex_list = (char *) GetMemory(ntex * WAD_TEX_NAME); - for (size_t n = 0; n < ntex; n++) - { - const long offset = d->dir.start + offset_table[n]; - wf->seek(offset); - if (wf->error()) - { - warn("%s: seek error\n", lump_name); - goto textures_done; - } - wf->read_bytes(tex_list + WAD_TEX_NAME * n, - WAD_TEX_NAME); - if (wf->error()) - { - warn("%s: error reading texture names\n", - lump_name); - goto textures_done; - } - } - success = true; - } + const char *lump_name = "LINES"; + verbmsg(" lines"); + dir = FindMasterDir(Level, lump_name); + if (dir) + { + if ((dir->dir.size - 4) % 36) + warn("the %s lump has a weird size. The wad might be corrupt.\n", lump_name); + const size_t nlines = dir->dir.size / 36; + NumLineDefs = nlines; + NumSideDefs = 2 * nlines; // Worst case. We'll adjust later. + LineDefs = (LDPtr) GetMemory((unsigned long) NumLineDefs + * sizeof(struct LineDef)); + SideDefs = (SDPtr) GetMemory((unsigned long) NumSideDefs + * sizeof(struct SideDef)); + // Read TEXTURES + if (yg_texture_format != YGTF_NAMELESS) + { + const char *lump_name = "TEXTURES"; + bool success = false; + ntex = 0; + i32 *offset_table = 0; + MDirPtr d = FindMasterDir(MasterDir, lump_name); + if (!d) + { + warn("%s: lump not found in directory\n", lump_name); + goto textures_done; + } + { + const Wad_file *wf = d->wadfile; + wf->seek(d->dir.start); + if (wf->error()) + { + warn("%s: seek error\n", lump_name); + goto textures_done; + } + i32 num; + wf->read_i32(&num); + if (wf->error()) + { + warn("%s: error reading texture count\n", lump_name); + } + if (num < 0 || num > 32767) + { + warn("%s: bad texture count, giving up\n", lump_name); + goto textures_done; + } + ntex = num; + offset_table = new i32[ntex]; + for (size_t n = 0; n < ntex; n++) + { + wf->read_i32(offset_table + n); + if (wf->error()) + { + warn("%s: error reading offsets table\n"); + goto textures_done; + } + } + tex_list = (char *) GetMemory(ntex * WAD_TEX_NAME); + for (size_t n = 0; n < ntex; n++) + { + const long offset = d->dir.start + offset_table[n]; + wf->seek(offset); + if (wf->error()) + { + warn("%s: seek error\n", lump_name); + goto textures_done; + } + wf->read_bytes(tex_list + WAD_TEX_NAME * n, + WAD_TEX_NAME); + if (wf->error()) + { + warn("%s: error reading texture names\n", + lump_name); + goto textures_done; + } + } + success = true; + } - textures_done: - if (offset_table != 0) - delete[]offset_table; - if (!success) - warn("%s: errors found, won't be able to import texture names\n", lump_name); - } + textures_done: + if (offset_table != 0) + delete[]offset_table; + if (!success) + warn("%s: errors found, won't be able to import texture names\n", lump_name); + } - const Wad_file *wf = dir->wadfile; - wf->seek(dir->dir.start + 4); - if (wf->error()) - { - err("%s: seek error", lump_name); - rc = 1; - goto byebye; - } - size_t s = 0; - for (size_t n = 0; n < nlines; n++) - { - LDPtr ld = LineDefs + n; - ld->start = wf->read_i16(); - ld->end = wf->read_i16(); - ld->flags = wf->read_i16(); - wf->read_i16(); // Unused ? - ld->type = wf->read_i16(); - ld->tag = wf->read_i16(); - wf->read_i16(); // Unused ? - i16 sector1 = wf->read_i16(); - i16 xofs1 = wf->read_i16(); - i16 tex1m = wf->read_i16(); - i16 tex1u = wf->read_i16(); - i16 tex1l = wf->read_i16(); - wf->read_i16(); // Unused ? - i16 sector2 = wf->read_i16(); - i16 xofs2 = wf->read_i16(); - i16 tex2m = wf->read_i16(); - i16 tex2u = wf->read_i16(); - i16 tex2l = wf->read_i16(); - if (sector1 >= 0) // Create first sidedef - { - ld->sidedef1 = s; - SDPtr sd = SideDefs + s; - sd->xoff = xofs1; - sd->yoff = 0; - memcpy(sd->tex1, texno_texname(tex1u), sizeof sd->tex1); - memcpy(sd->tex2, texno_texname(tex1l), sizeof sd->tex2); - memcpy(sd->tex3, texno_texname(tex1m), sizeof sd->tex3); - sd->sector = sector1; - s++; - } - else // No first sidedef ! - ld->sidedef1 = -1; - if (ld->flags & 0x04) // Create second sidedef - { - ld->sidedef2 = s; - SDPtr sd = SideDefs + s; - sd->xoff = xofs2; - sd->yoff = 0; - memcpy(sd->tex1, texno_texname(tex2u), sizeof sd->tex1); - memcpy(sd->tex2, texno_texname(tex2l), sizeof sd->tex2); - memcpy(sd->tex3, texno_texname(tex2m), sizeof sd->tex3); - sd->sector = sector2; - s++; - } - else - ld->sidedef2 = -1; - if (wf->error()) - { - err("%s: error reading line #%d", lump_name, int (n)); - rc = 1; - goto byebye; - } - } - // (size_t) to silence GCC warning - if ((size_t) NumSideDefs > s) // Almost always true. - { - NumSideDefs = s; - SideDefs = (SDPtr) ResizeMemory(SideDefs, - (unsigned long) NumSideDefs * - sizeof(struct SideDef)); - } - if (tex_list) - FreeMemory(tex_list); - tex_list = 0; - ntex = 0; - } + const Wad_file *wf = dir->wadfile; + wf->seek(dir->dir.start + 4); + if (wf->error()) + { + err("%s: seek error", lump_name); + rc = 1; + goto byebye; + } + size_t s = 0; + for (size_t n = 0; n < nlines; n++) + { + LDPtr ld = LineDefs + n; + ld->start = wf->read_i16(); + ld->end = wf->read_i16(); + ld->flags = wf->read_i16(); + wf->read_i16(); // Unused ? + ld->type = wf->read_i16(); + ld->tag = wf->read_i16(); + wf->read_i16(); // Unused ? + i16 sector1 = wf->read_i16(); + i16 xofs1 = wf->read_i16(); + i16 tex1m = wf->read_i16(); + i16 tex1u = wf->read_i16(); + i16 tex1l = wf->read_i16(); + wf->read_i16(); // Unused ? + i16 sector2 = wf->read_i16(); + i16 xofs2 = wf->read_i16(); + i16 tex2m = wf->read_i16(); + i16 tex2u = wf->read_i16(); + i16 tex2l = wf->read_i16(); + if (sector1 >= 0) // Create first sidedef + { + ld->sidedef1 = s; + SDPtr sd = SideDefs + s; + sd->xoff = xofs1; + sd->yoff = 0; + memcpy(sd->tex1, texno_texname(tex1u), sizeof sd->tex1); + memcpy(sd->tex2, texno_texname(tex1l), sizeof sd->tex2); + memcpy(sd->tex3, texno_texname(tex1m), sizeof sd->tex3); + sd->sector = sector1; + s++; + } + else // No first sidedef ! + ld->sidedef1 = -1; + if (ld->flags & 0x04) // Create second sidedef + { + ld->sidedef2 = s; + SDPtr sd = SideDefs + s; + sd->xoff = xofs2; + sd->yoff = 0; + memcpy(sd->tex1, texno_texname(tex2u), sizeof sd->tex1); + memcpy(sd->tex2, texno_texname(tex2l), sizeof sd->tex2); + memcpy(sd->tex3, texno_texname(tex2m), sizeof sd->tex3); + sd->sector = sector2; + s++; + } + else + ld->sidedef2 = -1; + if (wf->error()) + { + err("%s: error reading line #%d", lump_name, int (n)); + rc = 1; + goto byebye; + } + } + // (size_t) to silence GCC warning + if ((size_t) NumSideDefs > s) // Almost always true. + { + NumSideDefs = s; + SideDefs = (SDPtr) ResizeMemory(SideDefs, + (unsigned long) NumSideDefs * + sizeof(struct SideDef)); + } + if (tex_list) + FreeMemory(tex_list); + tex_list = 0; + ntex = 0; + } } /* Read the vertices. If the wad has been run through a nodes @@ -612,307 +612,307 @@ end up with many unwanted vertices in the level data. Nothing that a good CheckCrossReferences() couldn't take care of. */ { - verbmsg(" vertices"); - int last_used_vertex = -1; - for (long n = 0; n < NumLineDefs; n++) - { - last_used_vertex = y_max(last_used_vertex, LineDefs[n].start); - last_used_vertex = y_max(last_used_vertex, LineDefs[n].end); - } - NumVertices = last_used_vertex + 1; + verbmsg(" vertices"); + int last_used_vertex = -1; + for (long n = 0; n < NumLineDefs; n++) + { + last_used_vertex = y_max(last_used_vertex, LineDefs[n].start); + last_used_vertex = y_max(last_used_vertex, LineDefs[n].end); + } + NumVertices = last_used_vertex + 1; // This block is only here to warn me if (1) is false. - { - bitvec_c vertex_used(OldNumVertices); - for (long n = 0; n < NumLineDefs; n++) - { - vertex_used.set(LineDefs[n].start); - vertex_used.set(LineDefs[n].end); - } - int unused = 0; - for (long n = 0; n <= last_used_vertex; n++) - { - if (!vertex_used.get(n)) - unused++; - } - if (unused > 0) - { - warn("this level has unused vertices in the middle.\n"); - warn("total %d, tail %d (%d%%), unused %d (", - OldNumVertices, - OldNumVertices - NumVertices, - NumVertices - unused - ? 100 * (OldNumVertices - NumVertices) / (NumVertices - - unused) : 0, - unused); - int first = 1; - for (int n = 0; n <= last_used_vertex; n++) - { - if (!vertex_used.get(n)) - { - if (n == 0 || vertex_used.get(n - 1)) - { - if (first) - first = 0; - else - warn(", "); - warn("%d", n); - } - else if (n == last_used_vertex - || vertex_used.get(n + 1)) - warn("-%d", n); - } - } - warn(")\n"); - } - } + { + bitvec_c vertex_used(OldNumVertices); + for (long n = 0; n < NumLineDefs; n++) + { + vertex_used.set(LineDefs[n].start); + vertex_used.set(LineDefs[n].end); + } + int unused = 0; + for (long n = 0; n <= last_used_vertex; n++) + { + if (!vertex_used.get(n)) + unused++; + } + if (unused > 0) + { + warn("this level has unused vertices in the middle.\n"); + warn("total %d, tail %d (%d%%), unused %d (", + OldNumVertices, + OldNumVertices - NumVertices, + NumVertices - unused + ? 100 * (OldNumVertices - NumVertices) / (NumVertices - + unused) : 0, + unused); + int first = 1; + for (int n = 0; n <= last_used_vertex; n++) + { + if (!vertex_used.get(n)) + { + if (n == 0 || vertex_used.get(n - 1)) + { + if (first) + first = 0; + else + warn(", "); + warn("%d", n); + } + else if (n == last_used_vertex + || vertex_used.get(n + 1)) + warn("-%d", n); + } + } + warn(")\n"); + } + } // Now load all the vertices except the unused ones at the end. - if (NumVertices > 0) - { - const char *lump_name = "BUG"; - Vertices = (VPtr) GetMemory((unsigned long) NumVertices - * sizeof(struct Vertex)); - if (yg_level_format == YGLF_ALPHA) // Doom alpha - lump_name = "POINTS"; - else - lump_name = "VERTEXES"; - dir = FindMasterDir(Level, lump_name); - if (dir == 0) - goto vertexes_done; // FIXME isn't that fatal ? - { - const Wad_file *wf = dir->wadfile; - wf->seek(v_offset); - if (wf->error()) - { - err("%s: seek error", lump_name); - rc = 1; - goto byebye; - } - MapMaxX = -32767; - MapMaxY = -32767; - MapMinX = 32767; - MapMinY = 32767; - for (long n = 0; n < NumVertices; n++) - { - i16 val; - wf->read_i16(&val); - if (val < MapMinX) - MapMinX = val; - if (val > MapMaxX) - MapMaxX = val; - Vertices[n].x = val; - wf->read_i16(&val); - if (val < MapMinY) - MapMinY = val; - if (val > MapMaxY) - MapMaxY = val; - Vertices[n].y = val; - if (wf->error()) - { - err("%s: error reading vertex #%ld", lump_name, n); - rc = 1; - goto byebye; - } - } - } - vertexes_done: - ; - } + if (NumVertices > 0) + { + const char *lump_name = "BUG"; + Vertices = (VPtr) GetMemory((unsigned long) NumVertices + * sizeof(struct Vertex)); + if (yg_level_format == YGLF_ALPHA) // Doom alpha + lump_name = "POINTS"; + else + lump_name = "VERTEXES"; + dir = FindMasterDir(Level, lump_name); + if (dir == 0) + goto vertexes_done; // FIXME isn't that fatal ? + { + const Wad_file *wf = dir->wadfile; + wf->seek(v_offset); + if (wf->error()) + { + err("%s: seek error", lump_name); + rc = 1; + goto byebye; + } + MapMaxX = -32767; + MapMaxY = -32767; + MapMinX = 32767; + MapMinY = 32767; + for (long n = 0; n < NumVertices; n++) + { + i16 val; + wf->read_i16(&val); + if (val < MapMinX) + MapMinX = val; + if (val > MapMaxX) + MapMaxX = val; + Vertices[n].x = val; + wf->read_i16(&val); + if (val < MapMinY) + MapMinY = val; + if (val > MapMaxY) + MapMaxY = val; + Vertices[n].y = val; + if (wf->error()) + { + err("%s: error reading vertex #%ld", lump_name, n); + rc = 1; + goto byebye; + } + } + } + vertexes_done: + ; + } } // Ignore SEGS, SSECTORS and NODES // Read SECTORS { - const char *lump_name = "SECTORS"; - verbmsg(" sectors\n"); - dir = FindMasterDir(Level, lump_name); - if (yg_level_format != YGLF_ALPHA) - { - if (dir) - { - NumSectors = (int) (dir->dir.size / WAD_SECTOR_BYTES); - if ((i32) (NumSectors * WAD_SECTOR_BYTES) != dir->dir.size) - warn("the %s lump has a weird size." - " The wad might be corrupt.\n", lump_name); - } - else - NumSectors = 0; - if (NumSectors > 0) - { - Sectors = (SPtr) GetMemory((unsigned long) NumSectors - * sizeof(struct Sector)); - const Wad_file *wf = dir->wadfile; - wf->seek(dir->dir.start); - if (wf->error()) - { - err("%s: seek error", lump_name); - rc = 1; - goto byebye; - } - for (long n = 0; n < NumSectors; n++) - { - wf->read_i16(&Sectors[n].floorh); - wf->read_i16(&Sectors[n].ceilh); - wf->read_bytes(&Sectors[n].floort, WAD_FLAT_NAME); - wf->read_bytes(&Sectors[n].ceilt, WAD_FLAT_NAME); - wf->read_i16(&Sectors[n].light); - wf->read_i16(&Sectors[n].special); - wf->read_i16(&Sectors[n].tag); - if (wf->error()) - { - err("%s: error reading sector #%ld", lump_name, n); - rc = 1; - goto byebye; - } - } - } - } - else // Doom alpha--a wholly different SECTORS format - { - i32 *offset_table = 0; - i32 nsectors = 0; - i32 nflatnames = 0; - char *flatnames = 0; - if (dir == 0) - { - warn("%s: lump not found in directory\n", lump_name); // FIXME fatal ? - goto sectors_alpha_done; - } - { - const Wad_file *wf = dir->wadfile; - wf->seek(dir->dir.start); - if (wf->error()) - { - err("%s: seek error", lump_name); - rc = 1; - goto byebye; - } - wf->read_i32(&nsectors); - if (wf->error()) - { - err("%s: error reading sector count", lump_name); - rc = 1; - goto byebye; - } - if (nsectors < 0) - { - warn("Negative sector count. Clamping to 0.\n"); - nsectors = 0; - } - NumSectors = nsectors; - Sectors = (SPtr) GetMemory((unsigned long) NumSectors - * sizeof(struct Sector)); - offset_table = new i32[nsectors]; - for (size_t n = 0; n < (size_t) nsectors; n++) - wf->read_i32(offset_table + n); - if (wf->error()) - { - err("%s: error reading offsets table", lump_name); - rc = 1; - goto sectors_alpha_done; - } - // Load FLATNAME - { - const char *lump_name = "FLATNAME"; - bool success = false; - MDirPtr dir2 = FindMasterDir(Level, lump_name); - if (dir2 == 0) - { - warn("%s: lump not found in directory\n", lump_name); - goto flatname_done; // FIXME warn ? - } - { - const Wad_file *wf = dir2->wadfile; - wf->seek(dir2->dir.start); - if (wf->error()) - { - warn("%s: seek error\n", lump_name); - goto flatname_done; - } - wf->read_i32(&nflatnames); - if (wf->error()) - { - warn("%s: error reading flat name count\n", - lump_name); - nflatnames = 0; - goto flatname_done; - } - if (nflatnames < 0 || nflatnames > 32767) - { - warn("%s: bad flat name count, giving up\n", - lump_name); - nflatnames = 0; - goto flatname_done; - } - else - { - flatnames = new char[WAD_FLAT_NAME * nflatnames]; - wf->read_bytes(flatnames, - WAD_FLAT_NAME * nflatnames); - if (wf->error()) - { - warn("%s: error reading flat names\n", - lump_name); - nflatnames = 0; - goto flatname_done; - } - success = true; - } - } - flatname_done: - if (!success) - warn("%s: errors found, you'll have to do without flat names\n", lump_name); - } - for (size_t n = 0; n < (size_t) nsectors; n++) - { - wf->seek(dir->dir.start + offset_table[n]); - if (wf->error()) - { - err("%s: seek error", lump_name); - rc = 1; - goto sectors_alpha_done; - } - i16 index; - wf->read_i16(&Sectors[n].floorh); - wf->read_i16(&Sectors[n].ceilh); - wf->read_i16(&index); - if (nflatnames && flatnames && index >= 0 - && index < nflatnames) - memcpy(Sectors[n].floort, - flatnames + WAD_FLAT_NAME * index, - WAD_FLAT_NAME); - else - strcpy(Sectors[n].floort, "unknown"); - wf->read_i16(&index); - if (nflatnames && flatnames && index >= 0 - && index < nflatnames) - memcpy(Sectors[n].ceilt, - flatnames + WAD_FLAT_NAME * index, - WAD_FLAT_NAME); - else - strcpy(Sectors[n].ceilt, "unknown"); - wf->read_i16(&Sectors[n].light); - wf->read_i16(&Sectors[n].special); - wf->read_i16(&Sectors[n].tag); - // Don't know what the tail is for. Ignore it. - if (wf->error()) - { - err("%s: error reading sector #%ld", lump_name, - long (n)); - rc = 1; - goto sectors_alpha_done; - } - } - } + const char *lump_name = "SECTORS"; + verbmsg(" sectors\n"); + dir = FindMasterDir(Level, lump_name); + if (yg_level_format != YGLF_ALPHA) + { + if (dir) + { + NumSectors = (int) (dir->dir.size / WAD_SECTOR_BYTES); + if ((i32) (NumSectors * WAD_SECTOR_BYTES) != dir->dir.size) + warn("the %s lump has a weird size." + " The wad might be corrupt.\n", lump_name); + } + else + NumSectors = 0; + if (NumSectors > 0) + { + Sectors = (SPtr) GetMemory((unsigned long) NumSectors + * sizeof(struct Sector)); + const Wad_file *wf = dir->wadfile; + wf->seek(dir->dir.start); + if (wf->error()) + { + err("%s: seek error", lump_name); + rc = 1; + goto byebye; + } + for (long n = 0; n < NumSectors; n++) + { + wf->read_i16(&Sectors[n].floorh); + wf->read_i16(&Sectors[n].ceilh); + wf->read_bytes(&Sectors[n].floort, WAD_FLAT_NAME); + wf->read_bytes(&Sectors[n].ceilt, WAD_FLAT_NAME); + wf->read_i16(&Sectors[n].light); + wf->read_i16(&Sectors[n].special); + wf->read_i16(&Sectors[n].tag); + if (wf->error()) + { + err("%s: error reading sector #%ld", lump_name, n); + rc = 1; + goto byebye; + } + } + } + } + else // Doom alpha--a wholly different SECTORS format + { + i32 *offset_table = 0; + i32 nsectors = 0; + i32 nflatnames = 0; + char *flatnames = 0; + if (dir == 0) + { + warn("%s: lump not found in directory\n", lump_name); // FIXME fatal ? + goto sectors_alpha_done; + } + { + const Wad_file *wf = dir->wadfile; + wf->seek(dir->dir.start); + if (wf->error()) + { + err("%s: seek error", lump_name); + rc = 1; + goto byebye; + } + wf->read_i32(&nsectors); + if (wf->error()) + { + err("%s: error reading sector count", lump_name); + rc = 1; + goto byebye; + } + if (nsectors < 0) + { + warn("Negative sector count. Clamping to 0.\n"); + nsectors = 0; + } + NumSectors = nsectors; + Sectors = (SPtr) GetMemory((unsigned long) NumSectors + * sizeof(struct Sector)); + offset_table = new i32[nsectors]; + for (size_t n = 0; n < (size_t) nsectors; n++) + wf->read_i32(offset_table + n); + if (wf->error()) + { + err("%s: error reading offsets table", lump_name); + rc = 1; + goto sectors_alpha_done; + } + // Load FLATNAME + { + const char *lump_name = "FLATNAME"; + bool success = false; + MDirPtr dir2 = FindMasterDir(Level, lump_name); + if (dir2 == 0) + { + warn("%s: lump not found in directory\n", lump_name); + goto flatname_done; // FIXME warn ? + } + { + const Wad_file *wf = dir2->wadfile; + wf->seek(dir2->dir.start); + if (wf->error()) + { + warn("%s: seek error\n", lump_name); + goto flatname_done; + } + wf->read_i32(&nflatnames); + if (wf->error()) + { + warn("%s: error reading flat name count\n", + lump_name); + nflatnames = 0; + goto flatname_done; + } + if (nflatnames < 0 || nflatnames > 32767) + { + warn("%s: bad flat name count, giving up\n", + lump_name); + nflatnames = 0; + goto flatname_done; + } + else + { + flatnames = new char[WAD_FLAT_NAME * nflatnames]; + wf->read_bytes(flatnames, + WAD_FLAT_NAME * nflatnames); + if (wf->error()) + { + warn("%s: error reading flat names\n", + lump_name); + nflatnames = 0; + goto flatname_done; + } + success = true; + } + } + flatname_done: + if (!success) + warn("%s: errors found, you'll have to do without flat names\n", lump_name); + } + for (size_t n = 0; n < (size_t) nsectors; n++) + { + wf->seek(dir->dir.start + offset_table[n]); + if (wf->error()) + { + err("%s: seek error", lump_name); + rc = 1; + goto sectors_alpha_done; + } + i16 index; + wf->read_i16(&Sectors[n].floorh); + wf->read_i16(&Sectors[n].ceilh); + wf->read_i16(&index); + if (nflatnames && flatnames && index >= 0 + && index < nflatnames) + memcpy(Sectors[n].floort, + flatnames + WAD_FLAT_NAME * index, + WAD_FLAT_NAME); + else + strcpy(Sectors[n].floort, "unknown"); + wf->read_i16(&index); + if (nflatnames && flatnames && index >= 0 + && index < nflatnames) + memcpy(Sectors[n].ceilt, + flatnames + WAD_FLAT_NAME * index, + WAD_FLAT_NAME); + else + strcpy(Sectors[n].ceilt, "unknown"); + wf->read_i16(&Sectors[n].light); + wf->read_i16(&Sectors[n].special); + wf->read_i16(&Sectors[n].tag); + // Don't know what the tail is for. Ignore it. + if (wf->error()) + { + err("%s: error reading sector #%ld", lump_name, + long (n)); + rc = 1; + goto sectors_alpha_done; + } + } + } - sectors_alpha_done: - if (offset_table != 0) - delete[]offset_table; - if (flatnames != 0) - delete[]flatnames; - if (rc != 0) - goto byebye; - } + sectors_alpha_done: + if (offset_table != 0) + delete[]offset_table; + if (flatnames != 0) + delete[]flatnames; + if (rc != 0) + goto byebye; + } } /* Sanity checking on sidedefs: the sector must exist. I don't @@ -922,23 +922,23 @@ mm2 (MAP13, MAP28) and requiem (MAP03, MAP08, ...). */ for (long n = 0; n < NumSideDefs; n++) { - if (outside(SideDefs[n].sector, 0, NumSectors - 1)) - warn("sidedef %ld has bad sector number %d\n", - n, SideDefs[n].sector); + if (outside(SideDefs[n].sector, 0, NumSectors - 1)) + warn("sidedef %ld has bad sector number %d\n", + n, SideDefs[n].sector); } // Ignore REJECT and BLOCKMAP // Silly statistics verbmsg - (" %d things, %d vertices, %d linedefs, %d sidedefs, %d sectors\n", - (int) NumThings, (int) NumVertices, (int) NumLineDefs, - (int) NumSideDefs, (int) NumSectors); + (" %d things, %d vertices, %d linedefs, %d sidedefs, %d sectors\n", + (int) NumThings, (int) NumVertices, (int) NumLineDefs, + (int) NumSideDefs, (int) NumSectors); verbmsg(" Map: (%d,%d)-(%d,%d)\n", MapMinX, MapMinY, MapMaxX, MapMaxY); byebye: if (rc != 0) - err("%s: errors found, giving up", levelname); + err("%s: errors found, giving up", levelname); return rc; } @@ -948,12 +948,12 @@ forget the level data */ -void ForgetLevelData() /* SWAP! */ +void ForgetLevelData() /* SWAP! */ { /* forget the things */ NumThings = 0; if (Things != 0) - FreeMemory(Things); + FreeMemory(Things); Things = 0; things_angles++; things_types++; @@ -961,55 +961,55 @@ /* forget the vertices */ NumVertices = 0; if (Vertices != 0) - FreeMemory(Vertices); + FreeMemory(Vertices); Vertices = 0; /* forget the linedefs */ NumLineDefs = 0; if (LineDefs != 0) - FreeMemory(LineDefs); + FreeMemory(LineDefs); LineDefs = 0; /* forget the sidedefs */ NumSideDefs = 0; if (SideDefs != 0) - FreeMemory(SideDefs); + FreeMemory(SideDefs); SideDefs = 0; /* forget the sectors */ NumSectors = 0; if (Sectors != 0) - FreeMemory(Sectors); + FreeMemory(Sectors); Sectors = 0; } /* - * Save the level data to a pwad file - * The name of the level is always obtained from - * , whether or not the level was created from - * scratch. + * Save the level data to a pwad file + * The name of the level is always obtained from + * , whether or not the level was created from + * scratch. * - * The previous contents of the pwad file are lost. Yes, it - * sucks but it's not easy to fix. + * The previous contents of the pwad file are lost. Yes, it + * sucks but it's not easy to fix. * - * The lumps are always written in the same order, the same - * as the one in the Doom iwad. The length field of the - * marker lump is always set to 0. Its offset field is - * always set to the offset of the first lump of the level - * (THINGS). + * The lumps are always written in the same order, the same + * as the one in the Doom iwad. The length field of the + * marker lump is always set to 0. Its offset field is + * always set to the offset of the first lump of the level + * (THINGS). * - * If the level has been created by editing an existing - * level and has not been changed in a way that calls for a - * rebuild of the nodes, the VERTEXES, SEGS, SSECTORS, - * NODES, REJECT and BLOCKMAP lumps are copied from the - * original level. Otherwise, they are created with a - * length of 0 bytes and an offset equal to the offset of - * the previous lump plus its length. + * If the level has been created by editing an existing + * level and has not been changed in a way that calls for a + * rebuild of the nodes, the VERTEXES, SEGS, SSECTORS, + * NODES, REJECT and BLOCKMAP lumps are copied from the + * original level. Otherwise, they are created with a + * length of 0 bytes and an offset equal to the offset of + * the previous lump plus its length. * - * Returns 0 on success and non-zero on failure (see errno). + * Returns 0 on success and non-zero on failure (see errno). */ -int SaveLevelData(const char *outfile, const char *level_name) /* SWAP! */ +int SaveLevelData(const char *outfile, const char *level_name) /* SWAP! */ { FILE *file; MDirPtr dir; @@ -1020,27 +1020,27 @@ if (yg_level_format == YGLF_HEXEN || !strcmp(Game, "hexen")) { - Notify(-1, -1, "I refuse to save. Hexen mode is still", - "too badly broken. You would lose data."); - return 1; + Notify(-1, -1, "I refuse to save. Hexen mode is still", + "too badly broken. You would lose data."); + return 1; } if (!level_name || !levelname2levelno(level_name)) { - nf_bug - ("SaveLevelData: bad level_name \"%s\", using \"E1M1\" instead.", - level_name); - level_name = "E1M1"; + nf_bug + ("SaveLevelData: bad level_name \"%s\", using \"E1M1\" instead.", + level_name); + level_name = "E1M1"; } DisplayMessage(-1, -1, "Saving data to \"%s\"...", outfile); LogMessage(": Saving data to \"%s\"...\n", outfile); if ((file = fopen(outfile, "wb")) == NULL) { - char buf1[81]; - char buf2[81]; - y_snprintf(buf1, sizeof buf1, "Can't open \"%.64s\"", outfile); - y_snprintf(buf2, sizeof buf1, "for writing (%.64s)", strerror(errno)); - Notify(-1, -1, buf1, buf2); - return 1; + char buf1[81]; + char buf2[81]; + y_snprintf(buf1, sizeof buf1, "Can't open \"%.64s\"", outfile); + y_snprintf(buf2, sizeof buf1, "for writing (%.64s)", strerror(errno)); + Notify(-1, -1, buf1, buf2); + return 1; } /* Can we reuse the old nodes ? Not if this is a new level from @@ -1048,120 +1048,120 @@ level comes from an alpha version of Doom, we can't either because that version of Doom didn't have SEGS, NODES, etc. */ bool reuse_nodes = Level - && !MadeMapChanges && yg_level_format != YGLF_ALPHA; + && !MadeMapChanges && yg_level_format != YGLF_ALPHA; // Write the pwad header - WriteBytes(file, "PWAD", 4); // Pwad file - file_write_i32(file, WAD_LL__); // Number of entries = 11 - file_write_i32(file, 0); // Fix this up later + WriteBytes(file, "PWAD", 4); // Pwad file + file_write_i32(file, WAD_LL__); // Number of entries = 11 + file_write_i32(file, 0); // Fix this up later if (Level) - dir = Level->next; + dir = Level->next; else - dir = 0; // Useless except to trap accidental dereferences + dir = 0; // Useless except to trap accidental dereferences // The label (EnMm or MAPnm) l = WAD_LL_LABEL; - lump_offset[l] = ftell(file); // By definition - lump_size[l] = 0; // By definition + lump_offset[l] = ftell(file); // By definition + lump_size[l] = 0; // By definition // Write the THINGS lump l = WAD_LL_THINGS; lump_offset[l] = ftell(file); for (n = 0; n < NumThings; n++) { - file_write_i16(file, Things[n].xpos); - file_write_i16(file, Things[n].ypos); - file_write_i16(file, Things[n].angle); - file_write_i16(file, Things[n].type); - file_write_i16(file, Things[n].when); + file_write_i16(file, Things[n].xpos); + file_write_i16(file, Things[n].ypos); + file_write_i16(file, Things[n].angle); + file_write_i16(file, Things[n].type); + file_write_i16(file, Things[n].when); } lump_size[l] = ftell(file) - lump_offset[l]; if (Level) - dir = dir->next; + dir = dir->next; // Write the LINEDEFS lump l = WAD_LL_LINEDEFS; lump_offset[WAD_LL_LINEDEFS] = ftell(file); for (n = 0; n < NumLineDefs; n++) { - file_write_i16(file, LineDefs[n].start); - file_write_i16(file, LineDefs[n].end); - file_write_i16(file, LineDefs[n].flags); - file_write_i16(file, LineDefs[n].type); - file_write_i16(file, LineDefs[n].tag); - file_write_i16(file, LineDefs[n].sidedef1); - file_write_i16(file, LineDefs[n].sidedef2); + file_write_i16(file, LineDefs[n].start); + file_write_i16(file, LineDefs[n].end); + file_write_i16(file, LineDefs[n].flags); + file_write_i16(file, LineDefs[n].type); + file_write_i16(file, LineDefs[n].tag); + file_write_i16(file, LineDefs[n].sidedef1); + file_write_i16(file, LineDefs[n].sidedef2); } lump_size[l] = ftell(file) - lump_offset[l]; if (Level) - dir = dir->next; + dir = dir->next; // Write the SIDEDEFS lump l = WAD_LL_SIDEDEFS; lump_offset[l] = ftell(file); for (n = 0; n < NumSideDefs; n++) { - file_write_i16(file, SideDefs[n].xoff); - file_write_i16(file, SideDefs[n].yoff); - WriteBytes(file, &(SideDefs[n].tex1), WAD_TEX_NAME); - WriteBytes(file, &(SideDefs[n].tex2), WAD_TEX_NAME); - WriteBytes(file, &(SideDefs[n].tex3), WAD_TEX_NAME); - file_write_i16(file, SideDefs[n].sector); + file_write_i16(file, SideDefs[n].xoff); + file_write_i16(file, SideDefs[n].yoff); + WriteBytes(file, &(SideDefs[n].tex1), WAD_TEX_NAME); + WriteBytes(file, &(SideDefs[n].tex2), WAD_TEX_NAME); + WriteBytes(file, &(SideDefs[n].tex3), WAD_TEX_NAME); + file_write_i16(file, SideDefs[n].sector); } lump_size[l] = ftell(file) - lump_offset[l]; if (Level) - dir = dir->next; + dir = dir->next; // Write the VERTEXES lump l = WAD_LL_VERTEXES; lump_offset[WAD_LL_VERTEXES] = ftell(file); if (reuse_nodes) { - /* Copy the vertices */ - const Wad_file *wf = dir->wadfile; - wf->seek(dir->dir.start); - if (wf->error()) - { - warn("%s: seek error\n", wad_level_lump[l]); - } - copy_bytes(file, wf->fp, dir->dir.size); + /* Copy the vertices */ + const Wad_file *wf = dir->wadfile; + wf->seek(dir->dir.start); + if (wf->error()) + { + warn("%s: seek error\n", wad_level_lump[l]); + } + copy_bytes(file, wf->fp, dir->dir.size); } else { - /* Write the vertices */ - for (n = 0; n < NumVertices; n++) - { - file_write_i16(file, Vertices[n].x); - file_write_i16(file, Vertices[n].y); - } + /* Write the vertices */ + for (n = 0; n < NumVertices; n++) + { + file_write_i16(file, Vertices[n].x); + file_write_i16(file, Vertices[n].y); + } } lump_size[l] = ftell(file) - lump_offset[l]; if (Level) - dir = dir->next; + dir = dir->next; // Write the SEGS, SSECTORS and NODES lumps for (n = 0; n < 3; n++) { - if (n == 0) - l = WAD_LL_SEGS; - else if (n == 1) - l = WAD_LL_SSECTORS; - else if (n == 2) - l = WAD_LL_NODES; - lump_offset[l] = ftell(file); - if (reuse_nodes) - { - const Wad_file *wf = dir->wadfile; - wf->seek(dir->dir.start); - if (wf->error()) - { - warn("%s: seek error\n", wad_level_lump[l]); - } - copy_bytes(file, wf->fp, dir->dir.size); - } - lump_size[l] = ftell(file) - lump_offset[l]; - if (Level) - dir = dir->next; + if (n == 0) + l = WAD_LL_SEGS; + else if (n == 1) + l = WAD_LL_SSECTORS; + else if (n == 2) + l = WAD_LL_NODES; + lump_offset[l] = ftell(file); + if (reuse_nodes) + { + const Wad_file *wf = dir->wadfile; + wf->seek(dir->dir.start); + if (wf->error()) + { + warn("%s: seek error\n", wad_level_lump[l]); + } + copy_bytes(file, wf->fp, dir->dir.size); + } + lump_size[l] = ftell(file) - lump_offset[l]; + if (Level) + dir = dir->next; } // Write the SECTORS lump @@ -1169,92 +1169,92 @@ lump_offset[l] = ftell(file); for (n = 0; n < NumSectors; n++) { - file_write_i16(file, Sectors[n].floorh); - file_write_i16(file, Sectors[n].ceilh); - WriteBytes(file, Sectors[n].floort, WAD_FLAT_NAME); - WriteBytes(file, Sectors[n].ceilt, WAD_FLAT_NAME); - file_write_i16(file, Sectors[n].light); - file_write_i16(file, Sectors[n].special); - file_write_i16(file, Sectors[n].tag); + file_write_i16(file, Sectors[n].floorh); + file_write_i16(file, Sectors[n].ceilh); + WriteBytes(file, Sectors[n].floort, WAD_FLAT_NAME); + WriteBytes(file, Sectors[n].ceilt, WAD_FLAT_NAME); + file_write_i16(file, Sectors[n].light); + file_write_i16(file, Sectors[n].special); + file_write_i16(file, Sectors[n].tag); } lump_size[l] = ftell(file) - lump_offset[l]; if (Level) - dir = dir->next; + dir = dir->next; // Write the REJECT lump l = WAD_LL_REJECT; lump_offset[l] = ftell(file); if (reuse_nodes) { - /* Copy the REJECT data */ - const Wad_file *wf = dir->wadfile; - wf->seek(dir->dir.start); - if (wf->error()) - { - warn("%s: seek error\n", wad_level_lump[l]); - } - copy_bytes(file, wf->fp, dir->dir.size); + /* Copy the REJECT data */ + const Wad_file *wf = dir->wadfile; + wf->seek(dir->dir.start); + if (wf->error()) + { + warn("%s: seek error\n", wad_level_lump[l]); + } + copy_bytes(file, wf->fp, dir->dir.size); } lump_size[l] = ftell(file) - lump_offset[l]; if (Level) - dir = dir->next; + dir = dir->next; // Write the BLOCKMAP lump l = WAD_LL_BLOCKMAP; lump_offset[l] = ftell(file); if (reuse_nodes) { - const Wad_file *wf = dir->wadfile; - wf->seek(dir->dir.start); - if (wf->error()) - { - warn("%s: seek error\n", wad_level_lump[l]); - } - copy_bytes(file, wf->fp, dir->dir.size); + const Wad_file *wf = dir->wadfile; + wf->seek(dir->dir.start); + if (wf->error()) + { + warn("%s: seek error\n", wad_level_lump[l]); + } + copy_bytes(file, wf->fp, dir->dir.size); } lump_size[l] = ftell(file) - lump_offset[l]; if (Level) - dir = dir->next; + dir = dir->next; // Write the actual directory long dir_offset = ftell(file); for (int L = 0; L < (int) WAD_LL__; L++) { - file_write_i32(file, lump_offset[L]); - file_write_i32(file, lump_size[L]); - if (L == (int) WAD_LL_LABEL) - file_write_name(file, level_name); - else - file_write_name(file, wad_level_lump[L].name); + file_write_i32(file, lump_offset[L]); + file_write_i32(file, lump_size[L]); + if (L == (int) WAD_LL_LABEL) + file_write_name(file, level_name); + else + file_write_name(file, wad_level_lump[L].name); } /* Fix up the directory start information */ if (fseek(file, 8, SEEK_SET)) { - char buf1[81]; - char buf2[81]; - y_snprintf(buf1, sizeof buf1, "%.64s: seek error", outfile); - y_snprintf(buf2, sizeof buf2, "(%.64s)", strerror(errno)); - Notify(-1, -1, buf1, buf2); - fclose(file); - return 1; + char buf1[81]; + char buf2[81]; + y_snprintf(buf1, sizeof buf1, "%.64s: seek error", outfile); + y_snprintf(buf2, sizeof buf2, "(%.64s)", strerror(errno)); + Notify(-1, -1, buf1, buf2); + fclose(file); + return 1; } file_write_i32(file, dir_offset); /* Close the file */ if (fclose(file)) { - char buf1[81]; - char buf2[81]; - y_snprintf(buf1, sizeof buf1, "%.64s: write error", outfile); - y_snprintf(buf2, sizeof buf2, "(%.64s)", strerror(errno)); - Notify(-1, -1, buf1, buf2); - return 1; + char buf1[81]; + char buf2[81]; + y_snprintf(buf1, sizeof buf1, "%.64s: write error", outfile); + y_snprintf(buf2, sizeof buf2, "(%.64s)", strerror(errno)); + Notify(-1, -1, buf1, buf2); + return 1; } /* The file is now up to date */ if (!Level || MadeMapChanges) - remind_to_build_nodes = 1; + remind_to_build_nodes = 1; MadeChanges = 0; MadeMapChanges = 0; @@ -1272,14 +1272,14 @@ /* - * flat_list_entry_cmp - * Function used by qsort() to sort the flat_list_entry array - * by ascending flat name. + * flat_list_entry_cmp + * Function used by qsort() to sort the flat_list_entry array + * by ascending flat name. */ static int flat_list_entry_cmp(const void *a, const void *b) { return y_strnicmp(((const flat_list_entry_t *) a)->name, - ((const flat_list_entry_t *) b)->name, WAD_FLAT_NAME); + ((const flat_list_entry_t *) b)->name, WAD_FLAT_NAME); } @@ -1289,7 +1289,7 @@ static int SortTextures(const void *a, const void *b) { return y_strnicmp(*((const char *const *) a), *((const char *const *) b), - WAD_TEX_NAME); + WAD_TEX_NAME); } @@ -1306,216 +1306,216 @@ // Doom alpha 0.4 : "TEXTURES", no names if (yg_texture_lumps == YGTL_TEXTURES - && yg_texture_format == YGTF_NAMELESS) + && yg_texture_format == YGTF_NAMELESS) { - const char *lump_name = "TEXTURES"; - dir = FindMasterDir(MasterDir, lump_name); - if (dir == NULL) - { - warn("%s: lump not found in directory\n", lump_name); - goto textures04_done; - } - { - const Wad_file *wf = dir->wadfile; - wf->seek(dir->dir.start); - if (wf->error()) - { - warn("%s: seek error\n", lump_name); - goto textures04_done; - } - wf->read_i32(&val); - if (wf->error()) - { - warn("%s: error reading texture count\n", lump_name); - goto textures04_done; - } - NumWTexture = (int) val + 1; - WTexture = - (char **) GetMemory((long) NumWTexture * sizeof *WTexture); - WTexture[0] = (char *) GetMemory(WAD_TEX_NAME + 1); - strcpy(WTexture[0], "-"); - if (WAD_TEX_NAME < 7) - nf_bug("WAD_TEX_NAME too small"); // Sanity - for (long n = 0; n < val; n++) - { - WTexture[n + 1] = (char *) GetMemory(WAD_TEX_NAME + 1); - if (n > 9999) - { - warn("more than 10,000 textures. Ignoring excess.\n"); - break; - } - sprintf(WTexture[n + 1], "TEX%04ld", n); - } - } + const char *lump_name = "TEXTURES"; + dir = FindMasterDir(MasterDir, lump_name); + if (dir == NULL) + { + warn("%s: lump not found in directory\n", lump_name); + goto textures04_done; + } + { + const Wad_file *wf = dir->wadfile; + wf->seek(dir->dir.start); + if (wf->error()) + { + warn("%s: seek error\n", lump_name); + goto textures04_done; + } + wf->read_i32(&val); + if (wf->error()) + { + warn("%s: error reading texture count\n", lump_name); + goto textures04_done; + } + NumWTexture = (int) val + 1; + WTexture = + (char **) GetMemory((long) NumWTexture * sizeof *WTexture); + WTexture[0] = (char *) GetMemory(WAD_TEX_NAME + 1); + strcpy(WTexture[0], "-"); + if (WAD_TEX_NAME < 7) + nf_bug("WAD_TEX_NAME too small"); // Sanity + for (long n = 0; n < val; n++) + { + WTexture[n + 1] = (char *) GetMemory(WAD_TEX_NAME + 1); + if (n > 9999) + { + warn("more than 10,000 textures. Ignoring excess.\n"); + break; + } + sprintf(WTexture[n + 1], "TEX%04ld", n); + } + } textures04_done: - ; + ; } // Doom alpha 0.5 : only "TEXTURES" else if (yg_texture_lumps == YGTL_TEXTURES - && (yg_texture_format == YGTF_NORMAL - || yg_texture_format == YGTF_STRIFE11)) + && (yg_texture_format == YGTF_NORMAL + || yg_texture_format == YGTF_STRIFE11)) { - const char *lump_name = "TEXTURES"; - i32 *offsets = 0; - dir = FindMasterDir(MasterDir, lump_name); - if (dir == NULL) // In theory it always exists, though - { - warn("%s: lump not found in directory\n", lump_name); - goto textures05_done; - } - { - const Wad_file *wf = dir->wadfile; - wf->seek(dir->dir.start); - if (wf->error()) - { - warn("%s: seek error\n", lump_name); - goto textures05_done; - } - wf->read_i32(&val); - if (wf->error()) - { - warn("%s: error reading texture count\n", lump_name); - goto textures05_done; - } - NumWTexture = (int) val + 1; - /* read in the offsets for texture1 names */ - offsets = (i32 *) GetMemory((long) NumWTexture * 4); - wf->read_i32(offsets + 1, NumWTexture - 1); - if (wf->error()) - { - warn("%s: error reading offsets table\n", lump_name); - goto textures05_done; - } - /* read in the actual names */ - WTexture = - (char **) GetMemory((long) NumWTexture * sizeof(char *)); - WTexture[0] = (char *) GetMemory(WAD_TEX_NAME + 1); - strcpy(WTexture[0], "-"); - for (n = 1; n < NumWTexture; n++) - { - WTexture[n] = (char *) GetMemory(WAD_TEX_NAME + 1); - long offset = dir->dir.start + offsets[n]; - wf->seek(offset); - if (wf->error()) - { - warn("%s: error seeking to error\n", lump_name); - goto textures05_done; // FIXME cleanup - } - wf->read_bytes(WTexture[n], WAD_TEX_NAME); - if (wf->error()) - { - warn("%s: error reading texture names\n", lump_name); - goto textures05_done; // FIXME cleanup - } - WTexture[n][WAD_TEX_NAME] = '\0'; - } - } + const char *lump_name = "TEXTURES"; + i32 *offsets = 0; + dir = FindMasterDir(MasterDir, lump_name); + if (dir == NULL) // In theory it always exists, though + { + warn("%s: lump not found in directory\n", lump_name); + goto textures05_done; + } + { + const Wad_file *wf = dir->wadfile; + wf->seek(dir->dir.start); + if (wf->error()) + { + warn("%s: seek error\n", lump_name); + goto textures05_done; + } + wf->read_i32(&val); + if (wf->error()) + { + warn("%s: error reading texture count\n", lump_name); + goto textures05_done; + } + NumWTexture = (int) val + 1; + /* read in the offsets for texture1 names */ + offsets = (i32 *) GetMemory((long) NumWTexture * 4); + wf->read_i32(offsets + 1, NumWTexture - 1); + if (wf->error()) + { + warn("%s: error reading offsets table\n", lump_name); + goto textures05_done; + } + /* read in the actual names */ + WTexture = + (char **) GetMemory((long) NumWTexture * sizeof(char *)); + WTexture[0] = (char *) GetMemory(WAD_TEX_NAME + 1); + strcpy(WTexture[0], "-"); + for (n = 1; n < NumWTexture; n++) + { + WTexture[n] = (char *) GetMemory(WAD_TEX_NAME + 1); + long offset = dir->dir.start + offsets[n]; + wf->seek(offset); + if (wf->error()) + { + warn("%s: error seeking to error\n", lump_name); + goto textures05_done; // FIXME cleanup + } + wf->read_bytes(WTexture[n], WAD_TEX_NAME); + if (wf->error()) + { + warn("%s: error reading texture names\n", lump_name); + goto textures05_done; // FIXME cleanup + } + WTexture[n][WAD_TEX_NAME] = '\0'; + } + } textures05_done: - if (offsets != 0) - FreeMemory(offsets); + if (offsets != 0) + FreeMemory(offsets); } // Other iwads : "TEXTURE1" and possibly "TEXTURE2" else if (yg_texture_lumps == YGTL_NORMAL - && (yg_texture_format == YGTF_NORMAL - || yg_texture_format == YGTF_STRIFE11)) + && (yg_texture_format == YGTF_NORMAL + || yg_texture_format == YGTF_STRIFE11)) { - const char *lump_name = "TEXTURE1"; - i32 *offsets = 0; - dir = FindMasterDir(MasterDir, lump_name); - if (dir != NULL) // In theory it always exists, though - { - const Wad_file *wf = dir->wadfile; - wf->seek(dir->dir.start); - if (wf->error()) - { - warn("%s: seek error\n", lump_name); - // FIXME - } - wf->read_i32(&val); - if (wf->error()) - { - // FIXME - } - NumWTexture = (int) val + 1; - /* read in the offsets for texture1 names */ - offsets = (i32 *) GetMemory((long) NumWTexture * 4); - wf->read_i32(offsets + 1, NumWTexture - 1); - { - // FIXME - } - /* read in the actual names */ - WTexture = - (char **) GetMemory((long) NumWTexture * sizeof(char *)); - WTexture[0] = (char *) GetMemory(WAD_TEX_NAME + 1); - strcpy(WTexture[0], "-"); - for (n = 1; n < NumWTexture; n++) - { - WTexture[n] = (char *) GetMemory(WAD_TEX_NAME + 1); - wf->seek(dir->dir.start + offsets[n]); - if (wf->error()) - { - warn("%s: seek error\n", lump_name); - // FIXME - } - wf->read_bytes(WTexture[n], WAD_TEX_NAME); - if (wf->error()) - { - // FIXME - } - WTexture[n][WAD_TEX_NAME] = '\0'; - } - FreeMemory(offsets); - } - { - dir = FindMasterDir(MasterDir, "TEXTURE2"); - if (dir) /* Doom II has no TEXTURE2 */ - { - const Wad_file *wf = dir->wadfile; - wf->seek(dir->dir.start); - if (wf->error()) - { - warn("%s: seek error\n", lump_name); - // FIXME - } - wf->read_i32(&val); - if (wf->error()) - { - // FIXME - } - /* read in the offsets for texture2 names */ - offsets = (i32 *) GetMemory((long) val * 4); - wf->read_i32(offsets, val); - if (wf->error()) - { - // FIXME - } - /* read in the actual names */ - WTexture = (char **) ResizeMemory(WTexture, - (NumWTexture + - val) * sizeof(char *)); - for (n = 0; n < val; n++) - { - WTexture[NumWTexture + n] = - (char *) GetMemory(WAD_TEX_NAME + 1); - wf->seek(dir->dir.start + offsets[n]); - if (wf->error()) - { - warn("%s: seek error\n", lump_name); - // FIXME - } - wf->read_bytes(WTexture[NumWTexture + n], WAD_TEX_NAME); - if (wf->error()) - ; // FIXME - WTexture[NumWTexture + n][WAD_TEX_NAME] = '\0'; - } - NumWTexture += val; - FreeMemory(offsets); - } - } + const char *lump_name = "TEXTURE1"; + i32 *offsets = 0; + dir = FindMasterDir(MasterDir, lump_name); + if (dir != NULL) // In theory it always exists, though + { + const Wad_file *wf = dir->wadfile; + wf->seek(dir->dir.start); + if (wf->error()) + { + warn("%s: seek error\n", lump_name); + // FIXME + } + wf->read_i32(&val); + if (wf->error()) + { + // FIXME + } + NumWTexture = (int) val + 1; + /* read in the offsets for texture1 names */ + offsets = (i32 *) GetMemory((long) NumWTexture * 4); + wf->read_i32(offsets + 1, NumWTexture - 1); + { + // FIXME + } + /* read in the actual names */ + WTexture = + (char **) GetMemory((long) NumWTexture * sizeof(char *)); + WTexture[0] = (char *) GetMemory(WAD_TEX_NAME + 1); + strcpy(WTexture[0], "-"); + for (n = 1; n < NumWTexture; n++) + { + WTexture[n] = (char *) GetMemory(WAD_TEX_NAME + 1); + wf->seek(dir->dir.start + offsets[n]); + if (wf->error()) + { + warn("%s: seek error\n", lump_name); + // FIXME + } + wf->read_bytes(WTexture[n], WAD_TEX_NAME); + if (wf->error()) + { + // FIXME + } + WTexture[n][WAD_TEX_NAME] = '\0'; + } + FreeMemory(offsets); + } + { + dir = FindMasterDir(MasterDir, "TEXTURE2"); + if (dir) /* Doom II has no TEXTURE2 */ + { + const Wad_file *wf = dir->wadfile; + wf->seek(dir->dir.start); + if (wf->error()) + { + warn("%s: seek error\n", lump_name); + // FIXME + } + wf->read_i32(&val); + if (wf->error()) + { + // FIXME + } + /* read in the offsets for texture2 names */ + offsets = (i32 *) GetMemory((long) val * 4); + wf->read_i32(offsets, val); + if (wf->error()) + { + // FIXME + } + /* read in the actual names */ + WTexture = (char **) ResizeMemory(WTexture, + (NumWTexture + + val) * sizeof(char *)); + for (n = 0; n < val; n++) + { + WTexture[NumWTexture + n] = + (char *) GetMemory(WAD_TEX_NAME + 1); + wf->seek(dir->dir.start + offsets[n]); + if (wf->error()) + { + warn("%s: seek error\n", lump_name); + // FIXME + } + wf->read_bytes(WTexture[NumWTexture + n], WAD_TEX_NAME); + if (wf->error()) + ; // FIXME + WTexture[NumWTexture + n][WAD_TEX_NAME] = '\0'; + } + NumWTexture += val; + FreeMemory(offsets); + } + } } else - nf_bug("Invalid texture_format/texture_lumps combination."); + nf_bug("Invalid texture_format/texture_lumps combination."); /* sort the names */ qsort(WTexture, NumWTexture, sizeof(char *), SortTextures); @@ -1533,7 +1533,7 @@ /* forget all names */ for (n = 0; n < NumWTexture; n++) - FreeMemory(WTexture[n]); + FreeMemory(WTexture[n]); /* forget the array */ NumWTexture = 0; @@ -1556,81 +1556,81 @@ for (dir = MasterDir; (dir = FindMasterDir(dir, "F_START", "FF_START"));) { - bool ff_start = !y_strnicmp(dir->dir.name, "FF_START", WAD_NAME); - MDirPtr dir0; - /* count the names */ - dir = dir->next; - dir0 = dir; - for (n = 0; dir && y_strnicmp(dir->dir.name, "F_END", WAD_NAME) - && (!ff_start || y_strnicmp(dir->dir.name, "FF_END", WAD_NAME)); - dir = dir->next) - { - if (dir->dir.start == 0 || dir->dir.size == 0) - { - if (!(toupper(dir->dir.name[0]) == 'F' - && (dir->dir.name[1] == '1' - || dir->dir.name[1] == '2' - || dir->dir.name[1] == '3' - || toupper(dir->dir.name[1]) == 'F') - && dir->dir.name[2] == '_' - && - (!y_strnicmp(dir->dir.name + 3, "START", WAD_NAME - 3) - || !y_strnicmp(dir->dir.name + 3, "END", - WAD_NAME - 3)))) - warn("unexpected label \"%.*s\" among flats.\n", WAD_NAME, - dir->dir.name); - continue; - } - if (dir->dir.size != 4096) - warn("flat \"%.*s\" has weird size %lu." - " Using 4096 instead.\n", - WAD_NAME, dir->dir.name, (unsigned long) dir->dir.size); - n++; - } - /* If FF_START/FF_END followed by F_END (mm2.wad), advance - past F_END. In fact, this does not work because the F_END - that follows has been snatched by OpenPatchWad(), that - thinks it replaces the F_END from the iwad. OpenPatchWad() - needs to be kludged to take this special case into - account. Fortunately, the only consequence is a useless - "this wad uses FF_END" warning. -- AYM 1999-07-10 */ - if (ff_start && dir && !y_strnicmp(dir->dir.name, "FF_END", WAD_NAME)) - if (dir->next - && !y_strnicmp(dir->next->dir.name, "F_END", WAD_NAME)) - dir = dir->next; + bool ff_start = !y_strnicmp(dir->dir.name, "FF_START", WAD_NAME); + MDirPtr dir0; + /* count the names */ + dir = dir->next; + dir0 = dir; + for (n = 0; dir && y_strnicmp(dir->dir.name, "F_END", WAD_NAME) + && (!ff_start || y_strnicmp(dir->dir.name, "FF_END", WAD_NAME)); + dir = dir->next) + { + if (dir->dir.start == 0 || dir->dir.size == 0) + { + if (!(toupper(dir->dir.name[0]) == 'F' + && (dir->dir.name[1] == '1' + || dir->dir.name[1] == '2' + || dir->dir.name[1] == '3' + || toupper(dir->dir.name[1]) == 'F') + && dir->dir.name[2] == '_' + && + (!y_strnicmp(dir->dir.name + 3, "START", WAD_NAME - 3) + || !y_strnicmp(dir->dir.name + 3, "END", + WAD_NAME - 3)))) + warn("unexpected label \"%.*s\" among flats.\n", WAD_NAME, + dir->dir.name); + continue; + } + if (dir->dir.size != 4096) + warn("flat \"%.*s\" has weird size %lu." + " Using 4096 instead.\n", + WAD_NAME, dir->dir.name, (unsigned long) dir->dir.size); + n++; + } + /* If FF_START/FF_END followed by F_END (mm2.wad), advance + past F_END. In fact, this does not work because the F_END + that follows has been snatched by OpenPatchWad(), that + thinks it replaces the F_END from the iwad. OpenPatchWad() + needs to be kludged to take this special case into + account. Fortunately, the only consequence is a useless + "this wad uses FF_END" warning. -- AYM 1999-07-10 */ + if (ff_start && dir && !y_strnicmp(dir->dir.name, "FF_END", WAD_NAME)) + if (dir->next + && !y_strnicmp(dir->next->dir.name, "F_END", WAD_NAME)) + dir = dir->next; - verbmsg(" FF_START/%s %d", dir->dir.name, n); - if (dir && !y_strnicmp(dir->dir.name, "FF_END", WAD_NAME)) - warn("this wad uses FF_END. That won't work with Doom." - " Use F_END instead.\n"); - /* get the actual names from master dir. */ - flat_list = (flat_list_entry_t *) ResizeMemory(flat_list, - (NumFTexture + - n) * - sizeof *flat_list); - for (size_t m = NumFTexture; m < NumFTexture + n; dir0 = dir0->next) - { - // Skip all labels. - if (dir0->dir.start == 0 - || dir0->dir.size == 0 - || (toupper(dir0->dir.name[0]) == 'F' - && (dir0->dir.name[1] == '1' - || dir0->dir.name[1] == '2' - || dir0->dir.name[1] == '3' - || toupper(dir0->dir.name[1]) == 'F') - && dir0->dir.name[2] == '_' - && (!y_strnicmp(dir0->dir.name + 3, "START", WAD_NAME - 3) - || !y_strnicmp(dir0->dir.name + 3, "END", - WAD_NAME - 3)))) - continue; - *flat_list[m].name = '\0'; - strncat(flat_list[m].name, dir0->dir.name, - sizeof flat_list[m].name - 1); - flat_list[m].wadfile = dir0->wadfile; - flat_list[m].offset = dir0->dir.start; - m++; - } - NumFTexture += n; + verbmsg(" FF_START/%s %d", dir->dir.name, n); + if (dir && !y_strnicmp(dir->dir.name, "FF_END", WAD_NAME)) + warn("this wad uses FF_END. That won't work with Doom." + " Use F_END instead.\n"); + /* get the actual names from master dir. */ + flat_list = (flat_list_entry_t *) ResizeMemory(flat_list, + (NumFTexture + + n) * + sizeof *flat_list); + for (size_t m = NumFTexture; m < NumFTexture + n; dir0 = dir0->next) + { + // Skip all labels. + if (dir0->dir.start == 0 + || dir0->dir.size == 0 + || (toupper(dir0->dir.name[0]) == 'F' + && (dir0->dir.name[1] == '1' + || dir0->dir.name[1] == '2' + || dir0->dir.name[1] == '3' + || toupper(dir0->dir.name[1]) == 'F') + && dir0->dir.name[2] == '_' + && (!y_strnicmp(dir0->dir.name + 3, "START", WAD_NAME - 3) + || !y_strnicmp(dir0->dir.name + 3, "END", + WAD_NAME - 3)))) + continue; + *flat_list[m].name = '\0'; + strncat(flat_list[m].name, dir0->dir.name, + sizeof flat_list[m].name - 1); + flat_list[m].wadfile = dir0->wadfile; + flat_list[m].offset = dir0->dir.start; + m++; + } + NumFTexture += n; } verbmsg("\n"); @@ -1642,34 +1642,34 @@ Would be smarter to start by the end. */ for (size_t n = 0; n < NumFTexture; n++) { - size_t m = n; - while (m + 1 < NumFTexture - && !flat_list_entry_cmp(flat_list + n, flat_list + m + 1)) - m++; - // m now contains the index of the last duplicate - int nduplicates = m - n; - if (nduplicates > 0) - { - memmove(flat_list + n, flat_list + m, - (NumFTexture - m) * sizeof *flat_list); - NumFTexture -= nduplicates; - // Note that I'm too lazy to resize flat_list... - } + size_t m = n; + while (m + 1 < NumFTexture + && !flat_list_entry_cmp(flat_list + n, flat_list + m + 1)) + m++; + // m now contains the index of the last duplicate + int nduplicates = m - n; + if (nduplicates > 0) + { + memmove(flat_list + n, flat_list + m, + (NumFTexture - m) * sizeof *flat_list); + NumFTexture -= nduplicates; + // Note that I'm too lazy to resize flat_list... + } } } /* - * is_flat_name_in_list - * FIXME should use bsearch() + * is_flat_name_in_list + * FIXME should use bsearch() */ int is_flat_name_in_list(const char *name) { if (!flat_list) - return 0; + return 0; for (size_t n = 0; n < NumFTexture; n++) - if (!y_strnicmp(name, flat_list[n].name, WAD_FLAT_NAME)) - return 1; + if (!y_strnicmp(name, flat_list[n].name, WAD_FLAT_NAME)) + return 1; return 0; } @@ -1687,7 +1687,7 @@ /* - * update_level_bounds - update Map{Min,Max}{X,Y} + * update_level_bounds - update Map{Min,Max}{X,Y} */ void update_level_bounds() { @@ -1697,15 +1697,15 @@ MapMinY = 32767; for (obj_no_t n = 0; n < NumVertices; n++) { - int x = Vertices[n].x; - if (x < MapMinX) - MapMinX = x; - if (x > MapMaxX) - MapMaxX = x; - int y = Vertices[n].y; - if (y < MapMinY) - MapMinY = y; - if (y > MapMaxY) - MapMaxY = y; + int x = Vertices[n].x; + if (x < MapMinX) + MapMinX = x; + if (x > MapMaxX) + MapMaxX = x; + int y = Vertices[n].y; + if (y < MapMinY) + MapMinY = y; + if (y > MapMaxY) + MapMaxY = y; } } diff -r 594dea11ccd9 -r a68786b9c74b src/levels.h --- a/src/levels.h Sat Sep 24 15:01:56 2011 +0300 +++ b/src/levels.h Sat Sep 24 15:59:33 2011 +0300 @@ -1,13 +1,13 @@ /* - * levels.h - * BW & RQ sometime in 1993 or 1994 - * FIXME all those variables should become members of a - * "Level" class. + * levels.h + * BW & RQ sometime in 1993 or 1994 + * FIXME all those variables should become members of a + * "Level" class. */ -#ifndef YH_LEVELS /* Prevent multiple inclusion */ -#define YH_LEVELS /* Prevent multiple inclusion */ +#ifndef YH_LEVELS /* Prevent multiple inclusion */ +#define YH_LEVELS /* Prevent multiple inclusion */ #include "wstructs.h" @@ -15,75 +15,75 @@ // Defined in levels.cc -extern MDirPtr Level; /* master dictionary entry for the level */ +extern MDirPtr Level; /* master dictionary entry for the level */ -extern int NumThings; /* number of things */ -extern TPtr Things; /* things data */ -extern int NumLineDefs; /* number of linedefs */ -extern LDPtr LineDefs; /* linedefs data */ -extern int NumSideDefs; /* number of sidedefs */ -extern SDPtr SideDefs; /* sidedefs data */ -extern int NumVertices; /* number of vertices */ -extern VPtr Vertices; /* vertices data */ -extern int NumSegs; /* number of segments */ -extern int NumSectors; /* number of sectors */ -extern SPtr Sectors; /* sectors data */ +extern int NumThings; /* number of things */ +extern TPtr Things; /* things data */ +extern int NumLineDefs; /* number of linedefs */ +extern LDPtr LineDefs; /* linedefs data */ +extern int NumSideDefs; /* number of sidedefs */ +extern SDPtr SideDefs; /* sidedefs data */ +extern int NumVertices; /* number of vertices */ +extern VPtr Vertices; /* vertices data */ +extern int NumSegs; /* number of segments */ +extern int NumSectors; /* number of sectors */ +extern SPtr Sectors; /* sectors data */ // FIXME should be somewhere else -extern int NumWTexture; /* number of wall textures */ -extern char **WTexture; /* array of wall texture names */ -extern size_t NumFTexture; /* number of floor/ceiling textures */ +extern int NumWTexture; /* number of wall textures */ +extern char **WTexture; /* array of wall texture names */ +extern size_t NumFTexture; /* number of floor/ceiling textures */ typedef struct { - char name[WAD_NAME + 1]; // Name of flat - const Wad_file *wadfile; // Pointer on wad where flat comes from - i32 offset; // Offset of flat in wad -} flat_list_entry_t; // Length is implicit (always 4096) -extern flat_list_entry_t *flat_list; // List of all flats in the directory + char name[WAD_NAME + 1]; // Name of flat + const Wad_file *wadfile; // Pointer on wad where flat comes from + i32 offset; // Offset of flat in wad +} flat_list_entry_t; // Length is implicit (always 4096) +extern flat_list_entry_t *flat_list; // List of all flats in the directory -extern int MapMaxX; /* maximum X value of map */ -extern int MapMaxY; /* maximum Y value of map */ -extern int MapMinX; /* minimum X value of map */ -extern int MapMinY; /* minimum Y value of map */ -extern bool MadeChanges; /* made changes? */ -extern bool MadeMapChanges; /* made changes that need rebuilding? */ +extern int MapMaxX; /* maximum X value of map */ +extern int MapMaxY; /* maximum Y value of map */ +extern int MapMinX; /* minimum X value of map */ +extern int MapMinY; /* minimum Y value of map */ +extern bool MadeChanges; /* made changes? */ +extern bool MadeMapChanges; /* made changes that need rebuilding? */ -extern unsigned long things_angles; /* Used to know whether a list of - things sorted by type and angle would - need to be rebuilt. Incremented - whenever a thing is created, deleted - or has its type or angle changed. - Presently, no such list exists but - there will be one if - draw_things_sprites() ever draws - sprites according to their angles. */ +extern unsigned long things_angles; /* Used to know whether a list of + things sorted by type and angle would + need to be rebuilt. Incremented + whenever a thing is created, deleted + or has its type or angle changed. + Presently, no such list exists but + there will be one if + draw_things_sprites() ever draws + sprites according to their angles. */ -extern unsigned long things_types; /* Used to know whether the list of - things sorted by type that drawmap.cc - maintains should be rebuilt. - Incremented whenever a thing is - created, deleted or has its type - changed. */ +extern unsigned long things_types; /* Used to know whether the list of + things sorted by type that drawmap.cc + maintains should be rebuilt. + Incremented whenever a thing is + created, deleted or has its type + changed. */ -extern char Level_name[WAD_NAME + 1]; /* The name of the level (E.G. - "MAP01" or "E1M1"), followed by a - NUL. If the Level has been created as - the result of a "c" command with no - argument, an empty string. The name - is not necesarily in upper case but - it always a valid lump name, not a - command line shortcut like "17". */ +extern char Level_name[WAD_NAME + 1]; /* The name of the level (E.G. + "MAP01" or "E1M1"), followed by a + NUL. If the Level has been created as + the result of a "c" command with no + argument, an empty string. The name + is not necesarily in upper case but + it always a valid lump name, not a + command line shortcut like "17". */ -extern y_file_name_t Level_file_name; /* The name of the file in which - the level would be saved. If the - level has been created as the result - of a "c" command, with or without - argument, an empty string. */ +extern y_file_name_t Level_file_name; /* The name of the file in which + the level would be saved. If the + level has been created as the result + of a "c" command, with or without + argument, an empty string. */ -extern y_file_name_t Level_file_name_saved; /* The name of the file in - which the level was last saved. If - the Level has never been saved yet, - an empty string. */ +extern y_file_name_t Level_file_name_saved; /* The name of the file in + which the level was last saved. If + the Level has never been saved yet, + an empty string. */ void EmptyLevelData(const char *levelname); void update_level_bounds(); diff -r 594dea11ccd9 -r a68786b9c74b src/lists.cc --- a/src/lists.cc Sat Sep 24 15:01:56 2011 +0300 +++ b/src/lists.cc Sat Sep 24 15:59:33 2011 +0300 @@ -1,7 +1,7 @@ /* - * lists.cc - * Pick an item from a list. - * AYM 1998-08-22 + * lists.cc + * Pick an item from a list. + * AYM 1998-08-22 */ @@ -38,16 +38,16 @@ void lump_loc_string(char *buf, size_t buf_size, const Lump_loc & lump_loc) { if (buf_size < 1) - return; - int len = buf_size - 1 - (1 + 8 + 1 + 1); // %08lXh + return; + int len = buf_size - 1 - (1 + 8 + 1 + 1); // %08lXh if (len < 1) { - *buf = '\0'; - return; + *buf = '\0'; + return; } y_filename(buf, len + 1, lump_loc.wad->pathname()); sprintf(buf + strlen(buf), "(%08lXh)", - (unsigned long) lump_loc.ofs & 0xffffffff); + (unsigned long) lump_loc.ofs & 0xffffffff); } @@ -65,8 +65,8 @@ width : \ width and height of an optional window where a picture height : / can be displayed (used to display textures, sprites, etc.). hookfunc: function that should be called to display a picture. - (x1, y1, x2, y2 = coordinates of the window in which the - picture must be drawn, name = name of the picture). + (x1, y1, x2, y2 = coordinates of the window in which the + picture must be drawn, name = name of the picture). AYM 1998-02-12 : if hookfunc is <> NULL, a message "Press shift-F1 to save image to file" is displayed and shift-F1 does just that. */ @@ -76,16 +76,16 @@ #endif void InputNameFromListWithFunc(int x0, - int y0, - const char *prompt, - size_t listsize, - const char *const *list, - size_t listdisp, - char *name, - int width, - int height, - void (*hookfunc) (hookfunc_comm_t *), - char flags_to_pass_to_callback) + int y0, + const char *prompt, + size_t listsize, + const char *const *list, + size_t listdisp, + char *name, + int width, + int height, + void (*hookfunc) (hookfunc_comm_t *), + char flags_to_pass_to_callback) { const char *msg1 = "Press Shift-F1 to"; const char *msg2 = "save image to file"; @@ -103,11 +103,11 @@ bool lump_loc_drawn = false; #endif bool ok, firstkey; - int entry_out_x0; /* Edge of name entry widget including border */ + int entry_out_x0; /* Edge of name entry widget including border */ int entry_out_y0; int entry_out_x1; int entry_out_y1; - int entry_text_x0; /* Edge of text area of name entry widget */ + int entry_text_x0; /* Edge of text area of name entry widget */ int entry_text_y0; int entry_text_x1; int entry_text_y1; @@ -115,59 +115,59 @@ // Sanity if (width < 0) { - nf_bug("inflwf1"); - width = 0; + nf_bug("inflwf1"); + width = 0; } if (height < 0) { - nf_bug("inflwf2"); - height = 0; + nf_bug("inflwf2"); + height = 0; } // Compute maxlen, the length of the longest item in the list maxlen = 1; for (n = 0; n < listsize; n++) - if (strlen(list[n]) > maxlen) - maxlen = strlen(list[n]); + if (strlen(list[n]) > maxlen) + maxlen = strlen(list[n]); for (n = strlen(name) + 1; n <= maxlen; n++) - name[n] = '\0'; + name[n] = '\0'; char *namedisp = new char[maxlen + 1]; - memset(namedisp, '\xff', maxlen + 1); // Always != from name + memset(namedisp, '\xff', maxlen + 1); // Always != from name // Compute the minimum width of the dialog box l0 = 12; if (hookfunc != NULL) { - if ((int) (strlen(msg1) + 2) > l0) // (int) to prevent GCC warning - l0 = strlen(msg1) + 2; - if ((int) (strlen(msg2) + 2) > l0) // (int) to prevent GCC warning - l0 = strlen(msg2) + 2; + if ((int) (strlen(msg1) + 2) > l0) // (int) to prevent GCC warning + l0 = strlen(msg1) + 2; + if ((int) (strlen(msg2) + 2) > l0) // (int) to prevent GCC warning + l0 = strlen(msg2) + 2; } xlist = 10 + l0 * FONTW; win_columns = l0 + maxlen; - if ((int) (strlen(prompt)) > win_columns) // (int) to prevent GCC warning - win_columns = strlen(prompt); + if ((int) (strlen(prompt)) > win_columns) // (int) to prevent GCC warning + win_columns = strlen(prompt); win_width = 10 + FONTW * win_columns; x1 = win_width + 8; y1 = 10 + 1; if (width > 0) - win_width += 16 + width; + win_width += 16 + width; // (int) to prevent GCC warning win_height = y_max(height + 20, (int) (listdisp * FONTH + 10 + 28)); if (x0 < 0) - x0 = (ScrMaxX - win_width) / 2; + x0 = (ScrMaxX - win_width) / 2; if (y0 < 0) - y0 = (ScrMaxY - win_height) / 2; + y0 = (ScrMaxY - win_height) / 2; x1 += x0; y1 += y0; if (x1 + width - 1 < ScrMaxX) - x2 = x1 + width - 1; + x2 = x1 + width - 1; else - x2 = ScrMaxX; + x2 = ScrMaxX; if (y1 + height - 1 < ScrMaxY) - y2 = y1 + height - 1; + y2 = y1 + height - 1; else - y2 = ScrMaxY; + y2 = ScrMaxY; entry_out_x0 = x0 + 10; entry_text_x0 = entry_out_x0 + HOLLOW_BORDER + NARROW_HSPACING; @@ -179,27 +179,27 @@ entry_out_y1 = entry_text_y1 + HOLLOW_BORDER + NARROW_VSPACING; listdisp = y_max(listdisp, - (win_height - (entry_out_y0 - y0) - BOX_BORDER - - WIDE_VSPACING) / FONTH); + (win_height - (entry_out_y0 - y0) - BOX_BORDER - + WIDE_VSPACING) / FONTH); // Draw the dialog box DrawScreenBox3D(x0, y0, x0 + win_width, y0 + win_height); DrawScreenBoxHollow(entry_out_x0, entry_out_y0, entry_out_x1, - entry_out_y1, BLACK); + entry_out_y1, BLACK); set_colour(WINTITLE); DrawScreenText(x0 + 10, y0 + 8, prompt); set_colour(WINFG); if (hookfunc != NULL) { - DrawScreenText(x0 + 10, - y0 + win_height - BOX_BORDER - WIDE_VSPACING - - 2 * FONTH, msg1); - DrawScreenText(x0 + 10, - y0 + win_height - BOX_BORDER - WIDE_VSPACING - FONTH, - msg2); + DrawScreenText(x0 + 10, + y0 + win_height - BOX_BORDER - WIDE_VSPACING - + 2 * FONTH, msg1); + DrawScreenText(x0 + 10, + y0 + win_height - BOX_BORDER - WIDE_VSPACING - FONTH, + msg2); } if (width > 0) - DrawScreenBoxHollow(x1 - 1, y1 - 1, x2 + 1, y2 + 1, BLACK); + DrawScreenBoxHollow(x1 - 1, y1 - 1, x2 + 1, y2 + 1, BLACK); firstkey = true; // Another way of saying "nothing to rub out" @@ -213,350 +213,350 @@ // The event loop for (;;) { - hookfunc_comm_t c; + hookfunc_comm_t c; - // Reset maxpatches every time when change texture - if (strcmp(name, namedisp) != 0) - maxpatches = 0; + // Reset maxpatches every time when change texture + if (strcmp(name, namedisp) != 0) + maxpatches = 0; - // Is "name" in the list ? - for (n = 0; n < listsize; n++) - if (y_stricmp(name, list[n]) <= 0) - break; - ok = n < listsize ? !y_stricmp(name, list[n]) : false; - if (n >= listsize) - n = listsize - 1; + // Is "name" in the list ? + for (n = 0; n < listsize; n++) + if (y_stricmp(name, list[n]) <= 0) + break; + ok = n < listsize ? !y_stricmp(name, list[n]) : false; + if (n >= listsize) + n = listsize - 1; - // Display the next items in the list - { - size_t l; // Current line - int y = entry_out_y0; // Y-coord of current line - int xmin = x0 + xlist; - int xmax = xmin + FONTW * maxlen - 1; - for (l = 0; l < listdisp && n + l < listsize; l++) - { - if (false && has_input_event()) // TEST - { - putchar('.'); // TEST - fflush(stdout); // TEST - goto shortcut; // TEST - } - set_colour(WINBG); - DrawScreenBox(xmin, y, xmax, y + FONTH - 1); - set_colour(WINFG); - DrawScreenText(xmin, y, list[n + l]); - y += FONTH; - } - if (l < listdisp) // Less than names to display - { - set_colour(WINBG); - DrawScreenBox(xmin, y, xmax, - entry_out_y0 + listdisp * FONTH - 1); - } - } + // Display the next items in the list + { + size_t l; // Current line + int y = entry_out_y0; // Y-coord of current line + int xmin = x0 + xlist; + int xmax = xmin + FONTW * maxlen - 1; + for (l = 0; l < listdisp && n + l < listsize; l++) + { + if (false && has_input_event()) // TEST + { + putchar('.'); // TEST + fflush(stdout); // TEST + goto shortcut; // TEST + } + set_colour(WINBG); + DrawScreenBox(xmin, y, xmax, y + FONTH - 1); + set_colour(WINFG); + DrawScreenText(xmin, y, list[n + l]); + y += FONTH; + } + if (l < listdisp) // Less than names to display + { + set_colour(WINBG); + DrawScreenBox(xmin, y, xmax, + entry_out_y0 + listdisp * FONTH - 1); + } + } - // Display the entry box and the current text - set_colour(BLACK); - DrawScreenBox(entry_text_x0, entry_text_y0, entry_text_x1, - entry_text_y1); - if (ok) // FIXME this colour scheme should be changed. - set_colour(WHITE); - else - set_colour(WINFG); - DrawScreenText(entry_text_x0, entry_text_y0, name); + // Display the entry box and the current text + set_colour(BLACK); + DrawScreenBox(entry_text_x0, entry_text_y0, entry_text_x1, + entry_text_y1); + if (ok) // FIXME this colour scheme should be changed. + set_colour(WHITE); + else + set_colour(WINFG); + DrawScreenText(entry_text_x0, entry_text_y0, name); - // Call the function to display the picture, if any - if (hookfunc) - { - // Display the picture name - c.x0 = x1; - c.y0 = y1; - c.x1 = x2; - c.y1 = y2; - c.name = name; - c.xofs = 0; - c.yofs = 0; - c.flags = flags_to_pass_to_callback; - const int BAD_VALUE = INT_MAX; - c.disp_x0 = BAD_VALUE; // Catch faulty callbacks - c.disp_y0 = BAD_VALUE; // Catch faulty callbacks - c.disp_x1 = BAD_VALUE; // Catch faulty callbacks - c.disp_y1 = BAD_VALUE; // Catch faulty callbacks - c.maxpatches = maxpatches; - if (ok) - { - hookfunc(&c); - } - else - { - // No picture. Null width & height. Erase everything. - c.disp_x0 = (x2 + x1) / 2; - c.disp_y0 = (y2 + y1) / 2; - c.disp_x1 = c.disp_x0 - 1; - c.disp_y1 = c.disp_y0 - 1; - } - strcpy(namedisp, name); + // Call the function to display the picture, if any + if (hookfunc) + { + // Display the picture name + c.x0 = x1; + c.y0 = y1; + c.x1 = x2; + c.y1 = y2; + c.name = name; + c.xofs = 0; + c.yofs = 0; + c.flags = flags_to_pass_to_callback; + const int BAD_VALUE = INT_MAX; + c.disp_x0 = BAD_VALUE; // Catch faulty callbacks + c.disp_y0 = BAD_VALUE; // Catch faulty callbacks + c.disp_x1 = BAD_VALUE; // Catch faulty callbacks + c.disp_y1 = BAD_VALUE; // Catch faulty callbacks + c.maxpatches = maxpatches; + if (ok) + { + hookfunc(&c); + } + else + { + // No picture. Null width & height. Erase everything. + c.disp_x0 = (x2 + x1) / 2; + c.disp_y0 = (y2 + y1) / 2; + c.disp_x1 = c.disp_x0 - 1; + c.disp_y1 = c.disp_y0 - 1; + } + strcpy(namedisp, name); - // Display the (unclipped) size of the picture - { - const size_t size_chars = 11; - const int size_x0 = x0 + 10; - const int size_y0 = y0 + 50; - if (picture_size_drawn) - { - set_colour(WINBG); - DrawScreenBoxwh(size_x0, size_y0, size_chars * FONTW, - FONTH); - picture_size_drawn = false; - } - if ((c.flags & HOOK_SIZE_VALID) && (c.flags & HOOK_DISP_SIZE)) - { - set_colour(WINFG); - char size_buf[100]; // Slack - y_snprintf(size_buf, sizeof size_buf, "%dx%d", c.width, - c.height); - if (strlen(size_buf) > size_chars) - strcpy(size_buf + size_chars - 1, ">"); - DrawScreenString(size_x0, size_y0, size_buf); - picture_size_drawn = true; - } - } + // Display the (unclipped) size of the picture + { + const size_t size_chars = 11; + const int size_x0 = x0 + 10; + const int size_y0 = y0 + 50; + if (picture_size_drawn) + { + set_colour(WINBG); + DrawScreenBoxwh(size_x0, size_y0, size_chars * FONTW, + FONTH); + picture_size_drawn = false; + } + if ((c.flags & HOOK_SIZE_VALID) && (c.flags & HOOK_DISP_SIZE)) + { + set_colour(WINFG); + char size_buf[100]; // Slack + y_snprintf(size_buf, sizeof size_buf, "%dx%d", c.width, + c.height); + if (strlen(size_buf) > size_chars) + strcpy(size_buf + size_chars - 1, ">"); + DrawScreenString(size_x0, size_y0, size_buf); + picture_size_drawn = true; + } + } #ifdef DEBUG - // Display the file name and file offset of the picture - { - const size_t loc_chars = win_width / FONTW; - const int loc_x0 = x0; - const int loc_y0 = y0 + win_height; - if (lump_loc_drawn) - { - set_colour(WINBG); - DrawScreenBoxwh(loc_x0, loc_y0, loc_chars * FONTW, FONTH); - lump_loc_drawn = false; - } - if (disp_lump_loc && (c.flags & HOOK_LOC_VALID)) - { - set_colour(WINFG); - char buf[150]; // Slack - lump_loc_string(buf, sizeof buf, c.lump_loc); - DrawScreenString(loc_x0, loc_y0, buf); - lump_loc_drawn = true; - } - } + // Display the file name and file offset of the picture + { + const size_t loc_chars = win_width / FONTW; + const int loc_x0 = x0; + const int loc_y0 = y0 + win_height; + if (lump_loc_drawn) + { + set_colour(WINBG); + DrawScreenBoxwh(loc_x0, loc_y0, loc_chars * FONTW, FONTH); + lump_loc_drawn = false; + } + if (disp_lump_loc && (c.flags & HOOK_LOC_VALID)) + { + set_colour(WINFG); + char buf[150]; // Slack + lump_loc_string(buf, sizeof buf, c.lump_loc); + DrawScreenString(loc_x0, loc_y0, buf); + lump_loc_drawn = true; + } + } #endif - /* If the new picture does not completely obscure the - previous one, rub out the old pixels. */ - set_colour(BLACK); - if (c.disp_x0 == BAD_VALUE - || c.disp_y0 == BAD_VALUE - || c.disp_x1 == BAD_VALUE || c.disp_y1 == BAD_VALUE) - nf_bug("Callback %p did not set disp_", hookfunc); - else - { - /* +-WINDOW------------------------+ Erase the dots... - | | - | +-OLD IMAGE---------------+ | (this is for the case where - | | . . : . . . . . . : . . | | the image is centred but the - | |. . .:. . . 3 . . .:. . .| | principle is the same if it's - | | . . : . . . . . . : . . | | E.G. in the top left corner) - | |. . .+-NEW IMAGE---+. . .| | - | | . . | | . . | | - | |. 1 .| |. 2 .| | - | | . . | | . . | | - | |. . .+-------------+. . .| | - | | . . : . . . . . . : . . | | - | |. . .:. . . 4 . . .:. . .| | - | | . . : . . . . . . : . . | | - | +-------------------------+ | - | | - +-------------------------------+ */ - if (c.disp_x0 > disp_x0) - DrawScreenBox(disp_x0, disp_y0, c.disp_x0 - 1, disp_y1); // (1) - if (c.disp_x1 < disp_x1) - DrawScreenBox(c.disp_x1 + 1, disp_y0, disp_x1, disp_y1); // (2) - if (c.disp_y0 > disp_y0) - DrawScreenBox(y_max(c.disp_x0, disp_x0), disp_y0, y_min(c.disp_x1, disp_x1), c.disp_y0 - 1); // (3) - if (c.disp_y1 < disp_y1) - DrawScreenBox(y_max(c.disp_x0, disp_x0), c.disp_y1 + 1, y_min(c.disp_x1, disp_x1), disp_y1); // (4) - } - disp_x0 = c.disp_x0; - disp_y0 = c.disp_y0; - disp_x1 = c.disp_x1; - disp_y1 = c.disp_y1; - } + /* If the new picture does not completely obscure the + previous one, rub out the old pixels. */ + set_colour(BLACK); + if (c.disp_x0 == BAD_VALUE + || c.disp_y0 == BAD_VALUE + || c.disp_x1 == BAD_VALUE || c.disp_y1 == BAD_VALUE) + nf_bug("Callback %p did not set disp_", hookfunc); + else + { + /* +-WINDOW------------------------+ Erase the dots... + | | + | +-OLD IMAGE---------------+ | (this is for the case where + | | . . : . . . . . . : . . | | the image is centred but the + | |. . .:. . . 3 . . .:. . .| | principle is the same if it's + | | . . : . . . . . . : . . | | E.G. in the top left corner) + | |. . .+-NEW IMAGE---+. . .| | + | | . . | | . . | | + | |. 1 .| |. 2 .| | + | | . . | | . . | | + | |. . .+-------------+. . .| | + | | . . : . . . . . . : . . | | + | |. . .:. . . 4 . . .:. . .| | + | | . . : . . . . . . : . . | | + | +-------------------------+ | + | | + +-------------------------------+ */ + if (c.disp_x0 > disp_x0) + DrawScreenBox(disp_x0, disp_y0, c.disp_x0 - 1, disp_y1); // (1) + if (c.disp_x1 < disp_x1) + DrawScreenBox(c.disp_x1 + 1, disp_y0, disp_x1, disp_y1); // (2) + if (c.disp_y0 > disp_y0) + DrawScreenBox(y_max(c.disp_x0, disp_x0), disp_y0, y_min(c.disp_x1, disp_x1), c.disp_y0 - 1); // (3) + if (c.disp_y1 < disp_y1) + DrawScreenBox(y_max(c.disp_x0, disp_x0), c.disp_y1 + 1, y_min(c.disp_x1, disp_x1), disp_y1); // (4) + } + disp_x0 = c.disp_x0; + disp_y0 = c.disp_y0; + disp_x1 = c.disp_x1; + disp_y1 = c.disp_y1; + } - // Process user input + // Process user input shortcut: - key = get_key(); - if (firstkey && is_ordinary(key) && key != ' ') - { - for (size_t i = 0; i <= maxlen; i++) - name[i] = '\0'; - } - firstkey = false; - size_t len = strlen(name); - if (len < maxlen && key >= 'a' && key <= 'z') - { - name[len] = key + 'A' - 'a'; - name[len + 1] = '\0'; - } - else if (len < maxlen && is_ordinary(key) && key != ' ') - { - name[len] = key; - name[len + 1] = '\0'; - } - else if (len > 0 && key == YK_BACKSPACE) // BS - name[len - 1] = '\0'; - else if (key == 21 || key == 23) // ^U, ^W - *name = '\0'; - else if (key == YK_DOWN) // [Down] - { - /* Look for the next item in the list that has a - different name. Why not just use the next item ? - Because sometimes the list has duplicates (for example - when editing a Doom II pwad in Doom mode) and then the - viewer gets "stuck" on the first duplicate. */ - size_t m = n + 1; - while (m < listsize && !y_stricmp(list[n], list[m])) - m++; - if (m < listsize) - strcpy(name, list[m]); - else - Beep(); - } - else if (key == YK_UP) // [Up] - { - // Same trick as for [Down] - int m = n - 1; - while (m >= 0 && !y_stricmp(list[n], list[m])) - m--; - if (m >= 0) - strcpy(name, list[m]); - else - Beep(); - } - else if (key == YK_PD || key == 6 || key == 22) // [Pgdn], ^F, ^V - { - if (n < listsize - listdisp) - strcpy(name, list[y_min(n + listdisp, listsize - 1)]); - else - Beep(); - } - else if ((key == YK_PU || key == 2) && n > 0) // [Pgup], ^B - { - if (n > listdisp) - strcpy(name, list[n - listdisp]); - else - strcpy(name, list[0]); - } - else if (key == 14) // ^N - { - if (n + 1 >= listsize) - { - Beep(); - goto done_with_event; - } - while (n + 1 < listsize) - { - n++; - if (y_strnicmp(list[n - 1], list[n], 4)) - break; - } - strcpy(name, list[n]); - } - else if (key == 16) // ^P - { - if (n < 1) - { - Beep(); - goto done_with_event; - } - // Put in the index of the first entry of the current - // group or, if already at the beginning of the current - // group, the first entry of the previous group. - if (n > 0) - { - if (y_strnicmp(list[n], list[n - 1], 4)) - n--; - while (n > 0 && !y_strnicmp(list[n], list[n - 1], 4)) - n--; - } - strcpy(name, list[n]); - } - else if (key == (YK_CTRL | YK_PD) || key == YK_END) // [Ctrl][Pgdn], [End] - { - if (n + 1 >= listsize) - { - Beep(); - goto done_with_event; - } - strcpy(name, list[listsize - 1]); - } - else if (key == (YK_CTRL | YK_PU) || key == YK_HOME) // [Ctrl][Pgup], [Home] - { - if (n < 1) - { - Beep(); - goto done_with_event; - } - strcpy(name, list[0]); - } - else if (key == YK_TAB) // [Tab] - strcpy(name, list[n]); - else if (key == YK_F1 && c.flags & HOOK_LOC_VALID) // [F1]: print location - { - printf("%.8s: %s(%08lXh)\n", - name, c.lump_loc.wad->pathname(), - (unsigned long) c.lump_loc.ofs); - } - else if (key == YK_F1 + YK_SHIFT // [Shift][F1] : dump image to file - && hookfunc != NULL && (c.flags & HOOK_DRAWN)) - { - const size_t size = strlen(name) + 4 + 1; - char *filename = new char[size]; - al_scpslower(filename, name, size - 1); - al_saps(filename, ".ppm", size - 1); - if (c.img.save(filename) != 0) - { - if (errno == ECHILD) - err("Error loading PLAYPAL"); - else - err("%s: %s", filename, strerror(errno)); - } - else - { - printf("Saved %s as %s\n", name, filename); - } - delete[]filename; - } - else if (key == 1) // ^A: more patches - { - if (maxpatches + 1 < c.npatches) - maxpatches++; - else - maxpatches = 0; - printf("maxpatches %d\n", maxpatches); - } - else if (key == 24) // ^X: less patches - { - if (maxpatches == 0) - maxpatches = c.npatches - 1; - else - maxpatches--; - printf("maxpatches %d\n", maxpatches); - } - else if (ok && key == YK_RETURN) // [Return] - break; /* return "name" */ - else if (key == YK_ESC) // [Esc] - { - name[0] = '\0'; /* return an empty string */ - break; - } - else - Beep(); + key = get_key(); + if (firstkey && is_ordinary(key) && key != ' ') + { + for (size_t i = 0; i <= maxlen; i++) + name[i] = '\0'; + } + firstkey = false; + size_t len = strlen(name); + if (len < maxlen && key >= 'a' && key <= 'z') + { + name[len] = key + 'A' - 'a'; + name[len + 1] = '\0'; + } + else if (len < maxlen && is_ordinary(key) && key != ' ') + { + name[len] = key; + name[len + 1] = '\0'; + } + else if (len > 0 && key == YK_BACKSPACE) // BS + name[len - 1] = '\0'; + else if (key == 21 || key == 23) // ^U, ^W + *name = '\0'; + else if (key == YK_DOWN) // [Down] + { + /* Look for the next item in the list that has a + different name. Why not just use the next item ? + Because sometimes the list has duplicates (for example + when editing a Doom II pwad in Doom mode) and then the + viewer gets "stuck" on the first duplicate. */ + size_t m = n + 1; + while (m < listsize && !y_stricmp(list[n], list[m])) + m++; + if (m < listsize) + strcpy(name, list[m]); + else + Beep(); + } + else if (key == YK_UP) // [Up] + { + // Same trick as for [Down] + int m = n - 1; + while (m >= 0 && !y_stricmp(list[n], list[m])) + m--; + if (m >= 0) + strcpy(name, list[m]); + else + Beep(); + } + else if (key == YK_PD || key == 6 || key == 22) // [Pgdn], ^F, ^V + { + if (n < listsize - listdisp) + strcpy(name, list[y_min(n + listdisp, listsize - 1)]); + else + Beep(); + } + else if ((key == YK_PU || key == 2) && n > 0) // [Pgup], ^B + { + if (n > listdisp) + strcpy(name, list[n - listdisp]); + else + strcpy(name, list[0]); + } + else if (key == 14) // ^N + { + if (n + 1 >= listsize) + { + Beep(); + goto done_with_event; + } + while (n + 1 < listsize) + { + n++; + if (y_strnicmp(list[n - 1], list[n], 4)) + break; + } + strcpy(name, list[n]); + } + else if (key == 16) // ^P + { + if (n < 1) + { + Beep(); + goto done_with_event; + } + // Put in the index of the first entry of the current + // group or, if already at the beginning of the current + // group, the first entry of the previous group. + if (n > 0) + { + if (y_strnicmp(list[n], list[n - 1], 4)) + n--; + while (n > 0 && !y_strnicmp(list[n], list[n - 1], 4)) + n--; + } + strcpy(name, list[n]); + } + else if (key == (YK_CTRL | YK_PD) || key == YK_END) // [Ctrl][Pgdn], [End] + { + if (n + 1 >= listsize) + { + Beep(); + goto done_with_event; + } + strcpy(name, list[listsize - 1]); + } + else if (key == (YK_CTRL | YK_PU) || key == YK_HOME) // [Ctrl][Pgup], [Home] + { + if (n < 1) + { + Beep(); + goto done_with_event; + } + strcpy(name, list[0]); + } + else if (key == YK_TAB) // [Tab] + strcpy(name, list[n]); + else if (key == YK_F1 && c.flags & HOOK_LOC_VALID) // [F1]: print location + { + printf("%.8s: %s(%08lXh)\n", + name, c.lump_loc.wad->pathname(), + (unsigned long) c.lump_loc.ofs); + } + else if (key == YK_F1 + YK_SHIFT // [Shift][F1] : dump image to file + && hookfunc != NULL && (c.flags & HOOK_DRAWN)) + { + const size_t size = strlen(name) + 4 + 1; + char *filename = new char[size]; + al_scpslower(filename, name, size - 1); + al_saps(filename, ".ppm", size - 1); + if (c.img.save(filename) != 0) + { + if (errno == ECHILD) + err("Error loading PLAYPAL"); + else + err("%s: %s", filename, strerror(errno)); + } + else + { + printf("Saved %s as %s\n", name, filename); + } + delete[]filename; + } + else if (key == 1) // ^A: more patches + { + if (maxpatches + 1 < c.npatches) + maxpatches++; + else + maxpatches = 0; + printf("maxpatches %d\n", maxpatches); + } + else if (key == 24) // ^X: less patches + { + if (maxpatches == 0) + maxpatches = c.npatches - 1; + else + maxpatches--; + printf("maxpatches %d\n", maxpatches); + } + else if (ok && key == YK_RETURN) // [Return] + break; /* return "name" */ + else if (key == YK_ESC) // [Esc] + { + name[0] = '\0'; /* return an empty string */ + break; + } + else + Beep(); done_with_event: - ; + ; } delete[]namedisp; } @@ -567,10 +567,10 @@ */ void InputNameFromList(int x0, - int y0, - const char *prompt, - size_t listsize, const char *const *list, char *name) + int y0, + const char *prompt, + size_t listsize, const char *const *list, char *name) { InputNameFromListWithFunc(x0, y0, prompt, listsize, list, 5, name, 0, 0, - NULL); + NULL); } diff -r 594dea11ccd9 -r a68786b9c74b src/lists.h --- a/src/lists.h Sat Sep 24 15:01:56 2011 +0300 +++ b/src/lists.h Sat Sep 24 15:59:33 2011 +0300 @@ -1,6 +1,6 @@ /* - * lists.h - * AYM 2000-04-29 + * lists.h + * AYM 2000-04-29 */ @@ -27,7 +27,7 @@ */ -#ifndef YH_LISTS /* DO NOT INSERT ANYTHING BEFORE THIS LINE */ +#ifndef YH_LISTS /* DO NOT INSERT ANYTHING BEFORE THIS LINE */ #define YH_LISTS #include "img.h" @@ -57,58 +57,58 @@ - "both" means... both :-) img - The Img is part of the structure. The callee should not - make any assumptions regarding the contents and property - of img ; it should call resize() and set_opaque() - systematically. The callee should not clear the Img - before exiting, because the caller may need it for the - save-to-file function. + The Img is part of the structure. The callee should not + make any assumptions regarding the contents and property + of img ; it should call resize() and set_opaque() + systematically. The callee should not clear the Img + before exiting, because the caller may need it for the + save-to-file function. - For that reason, the caller should put the whole image - in img, *not* clipped to the dimensions of the screen - area on which it will be displayed. Unfortunately, that - is currently (2000-10-31) not possible because of - limitations in the Sticker class. + For that reason, the caller should put the whole image + in img, *not* clipped to the dimensions of the screen + area on which it will be displayed. Unfortunately, that + is currently (2000-10-31) not possible because of + limitations in the Sticker class. - The caller may do whatever it pleases with img. + The caller may do whatever it pleases with img. */ typedef struct { - int x0; // [expected] Top left corner of where to draw image + int x0; // [expected] Top left corner of where to draw image int y0; - int x1; // [expected] Bottom right corner + int x1; // [expected] Bottom right corner int y1; - int disp_x0; // [returned] Top left corner and bottom right corner - int disp_y0; // of area that was drawn on by callee. This is so that - int disp_x1; // the caller knows what needs to be cleared... + int disp_x0; // [returned] Top left corner and bottom right corner + int disp_y0; // of area that was drawn on by callee. This is so that + int disp_x1; // the caller knows what needs to be cleared... int disp_y1; - int xofs; // [expected] Top left corner of image in buffer + int xofs; // [expected] Top left corner of image in buffer int yofs; - const char *name; // [expected] Name of image to display - int flags; // [both] Flags - Img img; // [returned] Image buffer (clipped !) - int width; // [returned] Width of image before clipping - int height; // [returned] Height of image before clipping - int npatches; // [returned] Textures only : number of patches - int maxpatches; // [expected] Textures: if !0 only render that many patches - Lump_loc lump_loc; // [returned] Location of lump that was just displayed + const char *name; // [expected] Name of image to display + int flags; // [both] Flags + Img img; // [returned] Image buffer (clipped !) + int width; // [returned] Width of image before clipping + int height; // [returned] Height of image before clipping + int npatches; // [returned] Textures only : number of patches + int maxpatches; // [expected] Textures: if !0 only render that many patches + Lump_loc lump_loc; // [returned] Location of lump that was just displayed } hookfunc_comm_t; -const int HOOK_DRAWN = 1 << 0; // Image is completely drawn -const int HOOK_SIZE_VALID = 1 << 1; // width and height are valid -const int HOOK_DISP_SIZE = 1 << 2; // Caller should display "widthxheight" -const int HOOK_SPECTRAL = 1 << 3; // Render picture with a spectral look -const int HOOK_PATCH = 1 << 4; // Use patch_dir.loc_by_name() -const int HOOK_SPRITE = 1 << 5; // Use wad_res.sprites.loc_by_name() -const int HOOK_LOC_VALID = 1 << 6; // lump_loc is valid -const int HOOK_ROOT = 1 << 7; // .name is the prefix. Use loc_by_root +const int HOOK_DRAWN = 1 << 0; // Image is completely drawn +const int HOOK_SIZE_VALID = 1 << 1; // width and height are valid +const int HOOK_DISP_SIZE = 1 << 2; // Caller should display "widthxheight" +const int HOOK_SPECTRAL = 1 << 3; // Render picture with a spectral look +const int HOOK_PATCH = 1 << 4; // Use patch_dir.loc_by_name() +const int HOOK_SPRITE = 1 << 5; // Use wad_res.sprites.loc_by_name() +const int HOOK_LOC_VALID = 1 << 6; // lump_loc is valid +const int HOOK_ROOT = 1 << 7; // .name is the prefix. Use loc_by_root void InputNameFromListWithFunc(int, int, const char *, size_t, - const char *const *, size_t, char *, int, int, - void (*hookfunc) (hookfunc_comm_t *), - char flags_to_pass_to_callback = 0); + const char *const *, size_t, char *, int, int, + void (*hookfunc) (hookfunc_comm_t *), + char flags_to_pass_to_callback = 0); void InputNameFromList(int, int, const char *, size_t, const char *const *, - char *); + char *); #endif /* DO NOT ADD ANYTHING AFTER THIS LINE */ diff -r 594dea11ccd9 -r a68786b9c74b src/locate.cc --- a/src/locate.cc Sat Sep 24 15:01:56 2011 +0300 +++ b/src/locate.cc Sat Sep 24 15:59:33 2011 +0300 @@ -1,6 +1,6 @@ /* - * locate.cc - Locate class - * AYM 2003-03-24 + * locate.cc - Locate class + * AYM 2003-03-24 */ /* @@ -31,22 +31,22 @@ /* - * Locate::Locate - ctor + * Locate::Locate - ctor * - * - search_path points to a NULL-terminated array of C - * strings (char *) constituting the search path. The - * paths may contains the following macros, which will be - * expanded on the fly : - * %i the installation directory (DOS only) - * %v the version of Yadex - * ~ $HOME + * - search_path points to a NULL-terminated array of C + * strings (char *) constituting the search path. The + * paths may contains the following macros, which will be + * expanded on the fly : + * %i the installation directory (DOS only) + * %v the version of Yadex + * ~ $HOME * - * - name is the basename of the file to locate. It may - * include slashes. If it's absolute, the search path - * won't be used. + * - name is the basename of the file to locate. It may + * include slashes. If it's absolute, the search path + * won't be used. * - * - backwards is the direction in which the search path is - * walked. true is front-to-back, false is back-to-front. + * - backwards is the direction in which the search path is + * walked. true is front-to-back, false is back-to-front. */ Locate::Locate(const char *const *search_path, const char *name, bool backw) { @@ -60,11 +60,11 @@ /* - * Locate::rewind - rewind the cursor + * Locate::rewind - rewind the cursor * - * Calling this method will cause the next call to - * get_next() to return the first match, as if get_next() - * had never been called. + * Calling this method will cause the next call to + * get_next() to return the first match, as if get_next() + * had never been called. */ void Locate::rewind() { @@ -72,39 +72,39 @@ if (backwards) { - // Advance to the end of the list - for (cursor = search_path; *cursor != NULL; cursor++) - ; + // Advance to the end of the list + for (cursor = search_path; *cursor != NULL; cursor++) + ; } else { - cursor = search_path; + cursor = search_path; } } /* - * Locate::get_next - return the next match + * Locate::get_next - return the next match * - * Returns a pointer to the pathname of the next match, or - * a null pointer if there are no more matches left. The - * returned pointer is valid until get_next() is called - * again or the Locate object is destroyed. + * Returns a pointer to the pathname of the next match, or + * a null pointer if there are no more matches left. The + * returned pointer is valid until get_next() is called + * again or the Locate object is destroyed. */ const char *Locate::get_next() { if (absolute) { - if (!rewound) // Result has exactly one element - return NULL; - rewound = false; - if (strlen(name) > sizeof pathname - 1) - { - warn("%s: file name too long\n", name); - return NULL; - } - strcpy(pathname, name); - return pathname; + if (!rewound) // Result has exactly one element + return NULL; + rewound = false; + if (strlen(name) > sizeof pathname - 1) + { + warn("%s: file name too long\n", name); + return NULL; + } + strcpy(pathname, name); + return pathname; } const char *home = getenv("HOME"); @@ -112,70 +112,70 @@ // Walk the list for (;;) { - // Make dirname point to the current path in the search path - const char *dirname; + // Make dirname point to the current path in the search path + const char *dirname; - if (backwards) - { - if (cursor == search_path) - break; - cursor--; - dirname = *cursor; - } - else - { - if (*cursor == NULL) - break; - dirname = *cursor; - cursor++; - } + if (backwards) + { + if (cursor == search_path) + break; + cursor--; + dirname = *cursor; + } + else + { + if (*cursor == NULL) + break; + dirname = *cursor; + cursor++; + } - // Expand the macros in the path into the result buffer - int r = macro_expand(pathname, sizeof pathname - 1, dirname, - "%i", install_dir, - "%v", yadex_version, - "~", home, - (const char *) 0); - if (r != 0) - { - trace("locate", "%s: Could not expand macro #%d", dirname, r); - continue; - } + // Expand the macros in the path into the result buffer + int r = macro_expand(pathname, sizeof pathname - 1, dirname, + "%i", install_dir, + "%v", yadex_version, + "~", home, + (const char *) 0); + if (r != 0) + { + trace("locate", "%s: Could not expand macro #%d", dirname, r); + continue; + } - // Append the basename - if (strlen(pathname) > 0 && pathname[strlen(pathname)] - 1 != '/') - { - if (strlen(pathname) + 2 >= sizeof pathname) - { - warn("%s: file name too long, skipping\n", dirname); - continue; - } - strcat(pathname, "/"); - } - if (strlen(pathname) + strlen(name) + 1 >= sizeof pathname) - { - warn("%s: file name too long, skipping\n", dirname); - continue; - } - strcat(pathname, name); + // Append the basename + if (strlen(pathname) > 0 && pathname[strlen(pathname)] - 1 != '/') + { + if (strlen(pathname) + 2 >= sizeof pathname) + { + warn("%s: file name too long, skipping\n", dirname); + continue; + } + strcat(pathname, "/"); + } + if (strlen(pathname) + strlen(name) + 1 >= sizeof pathname) + { + warn("%s: file name too long, skipping\n", dirname); + continue; + } + strcat(pathname, name); - // Look for a file of that name. - struct stat s; - r = stat(pathname, &s); - if (r == 0 && !S_ISDIR(s.st_mode)) - { - trace("locate", "%s: %s: hit", name, pathname); - return pathname; - } - else if (r == 0 && S_ISDIR(s.st_mode)) - { - errno = EISDIR; - } - else if (r != 0 && errno != ENOENT) - { - warn("%s: %s\n", pathname, strerror(errno)); - } - trace("locate", "%s: %s: miss (%s)", name, pathname, strerror(errno)); + // Look for a file of that name. + struct stat s; + r = stat(pathname, &s); + if (r == 0 && !S_ISDIR(s.st_mode)) + { + trace("locate", "%s: %s: hit", name, pathname); + return pathname; + } + else if (r == 0 && S_ISDIR(s.st_mode)) + { + errno = EISDIR; + } + else if (r != 0 && errno != ENOENT) + { + warn("%s: %s\n", pathname, strerror(errno)); + } + trace("locate", "%s: %s: miss (%s)", name, pathname, strerror(errno)); } return NULL; diff -r 594dea11ccd9 -r a68786b9c74b src/locate.h --- a/src/locate.h Sat Sep 24 15:01:56 2011 +0300 +++ b/src/locate.h Sat Sep 24 15:59:33 2011 +0300 @@ -1,6 +1,6 @@ /* - * locate.h - Locate class - * AYM 2003-03-24 + * locate.h - Locate class + * AYM 2003-03-24 */ /* @@ -20,14 +20,14 @@ */ -#ifndef YH_LOCATE /* DO NOT INSERT ANYTHING BEFORE THIS LINE */ +#ifndef YH_LOCATE /* DO NOT INSERT ANYTHING BEFORE THIS LINE */ #define YH_LOCATE class Locate { public:Locate(const char *const *search_path, const char *name, - bool backwards); + bool backwards); void rewind(); const char *get_next(); diff -r 594dea11ccd9 -r a68786b9c74b src/lumpdir.cc --- a/src/lumpdir.cc Sat Sep 24 15:01:56 2011 +0300 +++ b/src/lumpdir.cc Sat Sep 24 15:59:33 2011 +0300 @@ -1,7 +1,7 @@ /* - * lumpdir.cc - * Lump_dir class - * AYM 1999-11-25 + * lumpdir.cc + * Lump_dir class + * AYM 1999-11-25 */ @@ -38,13 +38,13 @@ /* - * Lump_dir::Lump_dir - ctor + * Lump_dir::Lump_dir - ctor * - * is a pointer to the master directory on which the - * lump directory is based. - * is the first character of the label. - * is a pointer to the Serial_num of the master - * directory. + * is a pointer to the master directory on which the + * lump directory is based. + * is the first character of the label. + * is a pointer to the Serial_num of the master + * directory. */ Lump_dir::Lump_dir(MDirPtr * md, char l, Serial_num * sn) @@ -57,64 +57,64 @@ /* - * Lump_dir::~Lump_dir - dtor + * Lump_dir::~Lump_dir - dtor */ Lump_dir::~Lump_dir() { if (dependency) - delete dependency; + delete dependency; if (!lump_map.empty()) - lump_map.clear(); + lump_map.clear(); } /* - * Lump_dir::loc_by_name - find a lump by name + * Lump_dir::loc_by_name - find a lump by name * - * Return the (wad, offset, length) location of the lump - * named . If not found, set loc.wad to 0. + * Return the (wad, offset, length) location of the lump + * named . If not found, set loc.wad to 0. */ void Lump_dir::loc_by_name(const char *name, Lump_loc & loc) { if (dependency->outdated()) - refresh(); + refresh(); /* Caller asked for same lump twice in a row. Save us a second search. */ if (have_prev && !y_strnicmp(name, name_prev, WAD_NAME)) { - loc = loc_prev; - return; + loc = loc_prev; + return; } Lump_map::const_iterator i = lump_map.find(name); have_prev = true; if (i == lump_map.end()) - loc.wad = loc_prev.wad = 0; + loc.wad = loc_prev.wad = 0; else - loc = loc_prev = i->second; + loc = loc_prev = i->second; } /* - * Lump_dir::list - return an array of lump names + * Lump_dir::list - return an array of lump names * - * Put a list of all lumps in the list, sorted by name and - * with duplicates removed, in . + * Put a list of all lumps in the list, sorted by name and + * with duplicates removed, in . */ void Lump_dir::list(Lump_list & l) { if (dependency->outdated()) - refresh(); + refresh(); l.set(lump_map); } /* - * Lump_dir::refresh - update the lump dir. wrt to the master dir. + * Lump_dir::refresh - update the lump dir. wrt to the master dir. * - * This is called automatically if the master directory has - * changed since the last refresh. + * This is called automatically if the master directory has + * changed since the last refresh. */ void Lump_dir::refresh() { @@ -122,7 +122,7 @@ And usually is ! */ have_prev = false; if (!lump_map.empty()) - lump_map.clear(); + lump_map.clear(); /* Get list of lumps in the master directory. Everything that is between X_START/X_END or XX_START/XX_END and that @@ -132,69 +132,69 @@ Wad_name_c xx_start("%c%c_START", label, label); Wad_name_c xx_end("%c%c_END", label, label); for (MDirPtr dir = *master_dir; - dir && (dir = FindMasterDir(dir, x_start.name, xx_start.name));) + dir && (dir = FindMasterDir(dir, x_start.name, xx_start.name));) { - MDirPtr start_label = dir; - const char *end_label = 0; - if (!x_start.cmp(dir->dir.name)) - end_label = x_end.name; - else if (!xx_start.cmp(dir->dir.name)) - end_label = xx_end.name; - else - fatal_error("Bad start label \"%.*s\"", (int) WAD_NAME, - dir->dir.name); - dir = dir->next; - for (;; dir = dir->next) - { - if (!dir) - { - warn("%.128s: no matching %s for %.*s\n", - start_label->wadfile->pathname(), - end_label, (int) WAD_NAME, start_label->dir.name); - break; - } - // Ended by X_END or, if started by XX_START, XX_END. - if (!x_end.cmp(dir->dir.name) - || end_label == xx_end.name && !xx_end.cmp(dir->dir.name)) - { - if (dir->dir.size != 0) - warn("%.128s: label %.*s has non-zero size %ld\n", - dir->wadfile->pathname(), - (int) WAD_NAME, dir->dir.name, (long) dir->dir.size); - dir = dir->next; - break; - } - // Ignore inner labels (X[123]_START, X[123]_END) - if (dir->dir.start == 0 || dir->dir.size == 0) - { - if (!(toupper(dir->dir.name[0]) == label - && (dir->dir.name[1] == '1' - || dir->dir.name[1] == '2' - || dir->dir.name[1] == '3') - && dir->dir.name[2] == '_' - && - (!y_strnicmp(dir->dir.name + 3, "START", WAD_NAME - 3) - || !y_strnicmp(dir->dir.name + 3, "END", - WAD_NAME - 3)))) - warn("%.128s: unexpected label \"%.*s\" in %s group\n", - dir->wadfile->pathname(), (int) WAD_NAME, - dir->dir.name, start_label->dir.name); - continue; - } - wad_flat_name_t name; - memcpy(name, dir->dir.name, sizeof name); - lump_map[name] - = Lump_loc(dir->wadfile, dir->dir.start, dir->dir.size); - } - if (dir) - dir = dir->next; + MDirPtr start_label = dir; + const char *end_label = 0; + if (!x_start.cmp(dir->dir.name)) + end_label = x_end.name; + else if (!xx_start.cmp(dir->dir.name)) + end_label = xx_end.name; + else + fatal_error("Bad start label \"%.*s\"", (int) WAD_NAME, + dir->dir.name); + dir = dir->next; + for (;; dir = dir->next) + { + if (!dir) + { + warn("%.128s: no matching %s for %.*s\n", + start_label->wadfile->pathname(), + end_label, (int) WAD_NAME, start_label->dir.name); + break; + } + // Ended by X_END or, if started by XX_START, XX_END. + if (!x_end.cmp(dir->dir.name) + || end_label == xx_end.name && !xx_end.cmp(dir->dir.name)) + { + if (dir->dir.size != 0) + warn("%.128s: label %.*s has non-zero size %ld\n", + dir->wadfile->pathname(), + (int) WAD_NAME, dir->dir.name, (long) dir->dir.size); + dir = dir->next; + break; + } + // Ignore inner labels (X[123]_START, X[123]_END) + if (dir->dir.start == 0 || dir->dir.size == 0) + { + if (!(toupper(dir->dir.name[0]) == label + && (dir->dir.name[1] == '1' + || dir->dir.name[1] == '2' + || dir->dir.name[1] == '3') + && dir->dir.name[2] == '_' + && + (!y_strnicmp(dir->dir.name + 3, "START", WAD_NAME - 3) + || !y_strnicmp(dir->dir.name + 3, "END", + WAD_NAME - 3)))) + warn("%.128s: unexpected label \"%.*s\" in %s group\n", + dir->wadfile->pathname(), (int) WAD_NAME, + dir->dir.name, start_label->dir.name); + continue; + } + wad_flat_name_t name; + memcpy(name, dir->dir.name, sizeof name); + lump_map[name] + = Lump_loc(dir->wadfile, dir->dir.start, dir->dir.size); + } + if (dir) + dir = dir->next; } #ifdef DEBUG for (Lump_lumps_map::const_iterator i = lump_map.begin(); - i != lump_map.end(); i++) + i != lump_map.end(); i++) { - printf("%-8.8s %p %08lX %ld\n", - i->first._name, i->second.wad, i->second.ofs, i->second.len); + printf("%-8.8s %p %08lX %ld\n", + i->first._name, i->second.wad, i->second.ofs, i->second.len); } #endif dependency->update(); @@ -226,9 +226,9 @@ Lump_map::const_iterator i = lump_map.begin(); for (size_t n = 0; n < nelements; n++) { - array[n] = new char[WAD_NAME + 1]; - *array[n] = '\0'; - strncat(array[n], i++->first.name, WAD_NAME); + array[n] = new char[WAD_NAME + 1]; + *array[n] = '\0'; + strncat(array[n], i++->first.name, WAD_NAME); } } @@ -237,9 +237,9 @@ { if (array != 0) { - for (size_t n = 0; n < nelements; n++) - delete[]array[n]; - delete[]array; + for (size_t n = 0; n < nelements; n++) + delete[]array[n]; + delete[]array; } } @@ -272,6 +272,6 @@ (const Wad_name & name1, const Wad_name & name2) const { - return name1.less(name2); - //return y_strnicmp ((const char *) &p1, (const char *) &p2, WAD_NAME) < 0; + return name1.less(name2); + //return y_strnicmp ((const char *) &p1, (const char *) &p2, WAD_NAME) < 0; } diff -r 594dea11ccd9 -r a68786b9c74b src/lumpdir.h --- a/src/lumpdir.h Sat Sep 24 15:01:56 2011 +0300 +++ b/src/lumpdir.h Sat Sep 24 15:59:33 2011 +0300 @@ -1,7 +1,7 @@ /* - * lumpdir.h - * Lump_dir class - * AYM 2000-04-08 + * lumpdir.h + * Lump_dir class + * AYM 2000-04-08 */ @@ -28,7 +28,7 @@ */ -#ifndef YH_LUMPDIR /* DO NOT INSERT ANYTHING BEFORE THIS LINE */ +#ifndef YH_LUMPDIR /* DO NOT INSERT ANYTHING BEFORE THIS LINE */ #define YH_LUMPDIR @@ -41,26 +41,26 @@ /* - * Lump_dir - * - * The purpose of this class is to hide the details of how - * lumps are stored in the wads from Yadex. It provides - * two basic services : + * Lump_dir + * + * The purpose of this class is to hide the details of how + * lumps are stored in the wads from Yadex. It provides + * two basic services : * - * - loc_by_name() Return the lump location (WadPtr, - * offset, length) of a lump by name. If - * lump does not exist, returns a NULL - * WadPtr. + * - loc_by_name() Return the lump location (WadPtr, + * offset, length) of a lump by name. If + * lump does not exist, returns a NULL + * WadPtr. * - * - list() Return a Lump_list object that provides - * what InputNameFromListWithFunc() needs - * to browse the patches. I suggest that - * this object be created immediately - * before it's needed and destroyed - * immediately after because it is not - * intended to remain valid across calls to - * refresh(). Ignoring this advice will - * cause some interesting crashes. + * - list() Return a Lump_list object that provides + * what InputNameFromListWithFunc() needs + * to browse the patches. I suggest that + * this object be created immediately + * before it's needed and destroyed + * immediately after because it is not + * intended to remain valid across calls to + * refresh(). Ignoring this advice will + * cause some interesting crashes. */ // The key of the map is the lump name @@ -101,10 +101,10 @@ protected: void refresh(); - Dependency *dependency; // Resource on which we depend + Dependency *dependency; // Resource on which we depend MDirPtr *master_dir; - char label; // First character of label - Lump_map lump_map; // List of lumps, sorted by name + char label; // First character of label + Lump_map lump_map; // List of lumps, sorted by name // (no duplicates), with their // location. bool have_prev; diff -r 594dea11ccd9 -r a68786b9c74b src/macro.cc --- a/src/macro.cc Sat Sep 24 15:01:56 2011 +0300 +++ b/src/macro.cc Sat Sep 24 15:59:33 2011 +0300 @@ -1,7 +1,7 @@ /* - * macro.cc - * Expanding macros - * AYM 1999-11-30 + * macro.cc + * Expanding macros + * AYM 1999-11-30 */ @@ -33,40 +33,40 @@ /* - * macro_expand, vmacro_expand - expand macro references in a string + * macro_expand, vmacro_expand - expand macro references in a string * - * Copies the NUL-terminated string in into the - * buffer , replacing certain strings by other - * strings. must be at least ( + 1) characters - * long. + * Copies the NUL-terminated string in into the + * buffer , replacing certain strings by other + * strings. must be at least ( + 1) characters + * long. * - * The macro definitions are provided by the optional - * arguments that follow . You must pass two (const - * char *) for each macro. The first is the name of the - * macro, NUL-terminated. The second is the value of the - * macro, also NUL-terminated. The last macro value must be - * followed by a null pointer ((const char *) 0). + * The macro definitions are provided by the optional + * arguments that follow . You must pass two (const + * char *) for each macro. The first is the name of the + * macro, NUL-terminated. The second is the value of the + * macro, also NUL-terminated. The last macro value must be + * followed by a null pointer ((const char *) 0). * - * Matching is case-sensitive. The first match is used. - * For example, + * Matching is case-sensitive. The first match is used. + * For example, * - * macro_expand (buf, 99, "a%bcd", "%b", "1", "%bc", "2", (char *) 0); + * macro_expand (buf, 99, "a%bcd", "%b", "1", "%bc", "2", (char *) 0); * - * puts "a1cd" in buf. + * puts "a1cd" in buf. * - * If the value of a macro to expand is a null pointer, the - * macro expands to an empty string. + * If the value of a macro to expand is a null pointer, the + * macro expands to an empty string. * - * If expands to more than characters, only - * the first characters of the expansion are stored - * in . After the function returns, is - * guaranteed to be NUL-terminated. + * If expands to more than characters, only + * the first characters of the expansion are stored + * in . After the function returns, is + * guaranteed to be NUL-terminated. * - * Return 0 if successful, non-zero if one of the macros - * could not be expanded (value was a null pointer). In - * that case, the actual number returned is the number of - * the first macro that could not be expanded, starting - * from 1. + * Return 0 if successful, non-zero if one of the macros + * could not be expanded (value was a null pointer). In + * that case, the actual number returned is the number of + * the first macro that could not be expanded, starting + * from 1. */ int macro_expand(char *buf, size_t size, const char *fmt, ...) { @@ -85,95 +85,95 @@ // This is awful, but who cares ? while (*fmt) { - va_list l; - const char *macro_name = 0; - const char *macro_value = 0; + va_list l; + const char *macro_name = 0; + const char *macro_value = 0; #ifdef __va_copy - __va_copy(l, list); + __va_copy(l, list); #else - l = list; + l = list; #endif - while (macro_name = va_arg(l, const char *)) - { - macro_value = va_arg(l, const char *); - size_t len1 = strlen(fmt); - size_t len2 = strlen(macro_name); - if (len1 >= len2 && !memcmp(fmt, macro_name, len2)) - break; - } - if (macro_name != 0) - { - macro_no++; - if (macro_value == 0) - { - if (rc == 0) - rc = macro_no; - } - else - al_saps(buf, macro_value, size); - fmt += strlen(macro_name); - } - else - { - al_sapc(buf, *fmt, size); - fmt++; - } + while (macro_name = va_arg(l, const char *)) + { + macro_value = va_arg(l, const char *); + size_t len1 = strlen(fmt); + size_t len2 = strlen(macro_name); + if (len1 >= len2 && !memcmp(fmt, macro_name, len2)) + break; + } + if (macro_name != 0) + { + macro_no++; + if (macro_value == 0) + { + if (rc == 0) + rc = macro_no; + } + else + al_saps(buf, macro_value, size); + fmt += strlen(macro_name); + } + else + { + al_sapc(buf, *fmt, size); + fmt++; + } } return rc; } /* - * macro_expand - expand macro references in a string + * macro_expand - expand macro references in a string * - * Copies the NUL-terminated string in into the - * buffer , replacing certain strings by other - * strings. must be at least ( + 1) characters - * long. + * Copies the NUL-terminated string in into the + * buffer , replacing certain strings by other + * strings. must be at least ( + 1) characters + * long. * - * The macro definitions are obtained by scanning the - * iterator range through . The - * only constraints on these iterators are that they must - * be input iterators and iterator->name and - * iterator->value must be defined and point to - * NUL-terminated strings. + * The macro definitions are obtained by scanning the + * iterator range through . The + * only constraints on these iterators are that they must + * be input iterators and iterator->name and + * iterator->value must be defined and point to + * NUL-terminated strings. * - * Matching is case-sensitive. If several names would - * match, the first one is used. For example, + * Matching is case-sensitive. If several names would + * match, the first one is used. For example, * - * struct macdef - * { - * const char *name; - * const char *value; - * macdef (const char *name, const char *value) : - * name (name), value (value); - * }; - * std::list macdefs; - * macdefs.push_back (macdef ("%b", "1")); - * macdefs.push_back (macdef ("%bc", "2")); - * macro_expand (buf, 99, "a%bcd", macdefs.begin (), macdefs.end ()); + * struct macdef + * { + * const char *name; + * const char *value; + * macdef (const char *name, const char *value) : + * name (name), value (value); + * }; + * std::list macdefs; + * macdefs.push_back (macdef ("%b", "1")); + * macdefs.push_back (macdef ("%bc", "2")); + * macro_expand (buf, 99, "a%bcd", macdefs.begin (), macdefs.end ()); * - * puts "a1cd" in buf, not "a2d". + * puts "a1cd" in buf, not "a2d". * - * If the value of a macro to expand is a null pointer, the - * macro expands to an empty string. + * If the value of a macro to expand is a null pointer, the + * macro expands to an empty string. * - * If expands to more than characters, only - * the first characters of the expansion are stored - * in . After the function returns, is - * guaranteed to be NUL-terminated. + * If expands to more than characters, only + * the first characters of the expansion are stored + * in . After the function returns, is + * guaranteed to be NUL-terminated. * - * Return 0 if successful, non-zero if one of the macros - * could not be expanded (value was a null pointer). In - * that case, the actual number returned is the number of - * the first macro that could not be expanded, starting - * from 1. + * Return 0 if successful, non-zero if one of the macros + * could not be expanded (value was a null pointer). In + * that case, the actual number returned is the number of + * the first macro that could not be expanded, starting + * from 1. */ template < typename const_iterator > int macro_expand(char *buf, size_t size, const char *fmt, - const_iterator macdef_begin, const_iterator macdef_end) + const_iterator macdef_begin, const_iterator macdef_end) { int rc = 0; int macro_no = 0; @@ -182,41 +182,41 @@ size_t fmt_len = strlen(fmt); while (*fmt != '\0') { - const char *macro_name = 0; - const char *macro_value = 0; - size_t macro_name_len = 0; - bool match = false; - for (const_iterator i = macdef_begin; i != macdef_end; ++i) - { - macro_name = i->name; - macro_value = i->value; - macro_name_len = strlen(macro_name); - if (macro_name_len <= fmt_len - && memcmp(fmt, macro_name, macro_name_len) == 0) - { - match = true; - break; - } - } - if (match) - { - macro_no++; - if (macro_value == 0) - { - if (rc == 0) - rc = macro_no; - } - else - al_saps(buf, macro_value, size); - fmt += macro_name_len; - fmt_len -= macro_name_len; - } - else - { - al_sapc(buf, *fmt, size); - fmt++; - fmt_len--; - } + const char *macro_name = 0; + const char *macro_value = 0; + size_t macro_name_len = 0; + bool match = false; + for (const_iterator i = macdef_begin; i != macdef_end; ++i) + { + macro_name = i->name; + macro_value = i->value; + macro_name_len = strlen(macro_name); + if (macro_name_len <= fmt_len + && memcmp(fmt, macro_name, macro_name_len) == 0) + { + match = true; + break; + } + } + if (match) + { + macro_no++; + if (macro_value == 0) + { + if (rc == 0) + rc = macro_no; + } + else + al_saps(buf, macro_value, size); + fmt += macro_name_len; + fmt_len -= macro_name_len; + } + else + { + al_sapc(buf, *fmt, size); + fmt++; + fmt_len--; + } } return rc; } @@ -257,7 +257,7 @@ macdefs.push_back(macdef("%bc", "2")); std::for_each(macdefs.begin(), macdefs.end(), dump); macro_expand(buf, sizeof buf - 1, "a%bcd", macdefs.begin(), - macdefs.end()); + macdefs.end()); puts(buf); return 0; } diff -r 594dea11ccd9 -r a68786b9c74b src/macro.h --- a/src/macro.h Sat Sep 24 15:01:56 2011 +0300 +++ b/src/macro.h Sat Sep 24 15:59:33 2011 +0300 @@ -1,7 +1,7 @@ /* - * macro.h - * Expanding macros - * AYM 1999-11-30 + * macro.h + * Expanding macros + * AYM 1999-11-30 */ @@ -37,5 +37,5 @@ int macro_expand(char *buf, size_t size, const char *fmt, ...); int macro_expand(char *buf, size_t size, const char *fmt, - const macdef_t * def); + const macdef_t * def); int vmacro_expand(char *buf, size_t size, const char *fmt, va_list list); diff -r 594dea11ccd9 -r a68786b9c74b src/masterdir.h --- a/src/masterdir.h Sat Sep 24 15:01:56 2011 +0300 +++ b/src/masterdir.h Sat Sep 24 15:59:33 2011 +0300 @@ -1,11 +1,11 @@ /* - * masterdir.h - * Master_dir class - * AYM 2000-04-06 + * masterdir.h + * Master_dir class + * AYM 2000-04-06 */ -#ifndef YH_MASTERDIR /* DO NOT INSERT ANYTHING BEFORE THIS LINE */ +#ifndef YH_MASTERDIR /* DO NOT INSERT ANYTHING BEFORE THIS LINE */ #define YH_MASTERDIR diff -r 594dea11ccd9 -r a68786b9c74b src/memory.cc --- a/src/memory.cc Sat Sep 24 15:01:56 2011 +0300 +++ b/src/memory.cc Sat Sep 24 15:59:33 2011 +0300 @@ -1,7 +1,7 @@ /* - * memory.cc - * Memory allocation routines. - * BW & RQ sometime in 1993 or 1994. + * memory.cc + * Memory allocation routines. + * BW & RQ sometime in 1993 or 1994. */ @@ -44,8 +44,8 @@ about memory fragmentation. */ -#define SIZE_THRESHOLD 1024 -#define SIZE_OF_BLOCK 4095 /* actually, this is (size - 1) */ +#define SIZE_THRESHOLD 1024 +#define SIZE_OF_BLOCK 4095 /* actually, this is (size - 1) */ /* @@ -59,20 +59,20 @@ /* On 16-bit systems (BC 4.0), size_t is only 16-bit long so you can't malloc() more than 64 kB at a time. Catch it. */ if (size != (size_t) size) - fatal_error("GetMemory: %lu B is too much for this poor machine.", - size); + fatal_error("GetMemory: %lu B is too much for this poor machine.", + size); /* limit fragmentation on large blocks */ if (size >= SIZE_THRESHOLD) - size = (size + SIZE_OF_BLOCK) & ~SIZE_OF_BLOCK; + size = (size + SIZE_OF_BLOCK) & ~SIZE_OF_BLOCK; ret = malloc((size_t) size); if (!ret) { - /* retry after having freed some memory, if possible */ - ret = malloc((size_t) size); + /* retry after having freed some memory, if possible */ + ret = malloc((size_t) size); } if (!ret) - fatal_error("out of memory (cannot allocate %u bytes)", size); + fatal_error("out of memory (cannot allocate %u bytes)", size); return ret; } @@ -88,19 +88,19 @@ /* On 16-bit systems (BC 4.0), size_t is only 16-bit long so you can't malloc() more than 64 kB at a time. Catch it. */ if (size != (size_t) size) - fatal_error("ResizeMemory: %lu B is too much for this poor machine.", - size); + fatal_error("ResizeMemory: %lu B is too much for this poor machine.", + size); /* limit fragmentation on large blocks */ if (size >= SIZE_THRESHOLD) - size = (size + SIZE_OF_BLOCK) & ~SIZE_OF_BLOCK; + size = (size + SIZE_OF_BLOCK) & ~SIZE_OF_BLOCK; ret = realloc(old, (size_t) size); if (!ret) { - ret = realloc(old, (size_t) size); + ret = realloc(old, (size_t) size); } if (!ret) - fatal_error("out of memory (cannot reallocate %lu bytes)", size); + fatal_error("out of memory (cannot reallocate %lu bytes)", size); return ret; } diff -r 594dea11ccd9 -r a68786b9c74b src/menu.cc --- a/src/menu.cc Sat Sep 24 15:01:56 2011 +0300 +++ b/src/menu.cc Sat Sep 24 15:59:33 2011 +0300 @@ -1,6 +1,6 @@ /* - * menu.cc - * AYM 1998-12-01 + * menu.cc + * AYM 1998-12-01 */ @@ -49,76 +49,76 @@ const unsigned char MIF_MTICK = 0x0c; const unsigned char MIF_SEPAR = 0x10; -const short VSPACE = 2; // Pixels between items +const short VSPACE = 2; // Pixels between items /* - * Menu_item - a menu item class + * Menu_item - a menu item class */ class Menu_item { public: Menu_item() { - flags = MIF_NTICK | MIF_NACTIVE; - tilde_key = YK_; - shortcut_key = YK_; - str = 0; + flags = MIF_NTICK | MIF_NACTIVE; + tilde_key = YK_; + shortcut_key = YK_; + str = 0; } - unsigned char flags; // Logical-or of MIF_?ACTIVE MIF_?TICK MIF_SEPAR + unsigned char flags; // Logical-or of MIF_?ACTIVE MIF_?TICK MIF_SEPAR inpev_t tilde_key; inpev_t shortcut_key; - short y; // Top of item, relative to ly0. If there is a + short y; // Top of item, relative to ly0. If there is a // separation, it is above y. const char *str; union { - bool s; // Static - bool *v; // Pointer to variable - struct - { - micb_t f; // Pointer to callback function - micbarg_t a; // Argument - } f; + bool s; // Static + bool *v; // Pointer to variable + struct + { + micb_t f; // Pointer to callback function + micbarg_t a; // Argument + } f; } tick; union { - bool s; // Static - bool *v; // Pointer to variable - struct - { - micb_t f; // Pointer to callback function - micbarg_t a; // Argument - } f; + bool s; // Static + bool *v; // Pointer to variable + struct + { + micb_t f; // Pointer to callback function + micbarg_t a; // Argument + } f; } active; }; /* - * Menu_priv - Menu's private data + * Menu_priv - Menu's private data */ class Menu_priv { public:Menu_priv() { - flags = 0; - title = 0; - title_len = 0; - items_ks_len = 0; - items_len = 0; - items.clear(); - user_ox0 = -1; - user_oy0 = -1; - ox0 = -1; - oy0 = -1; - need_geom = true; - visible = false; - visible_disp = false; - line = 0; - line_disp = UINT_MAX; - item_height = FONTH + VSPACE; + flags = 0; + title = 0; + title_len = 0; + items_ks_len = 0; + items_len = 0; + items.clear(); + user_ox0 = -1; + user_oy0 = -1; + ox0 = -1; + oy0 = -1; + need_geom = true; + visible = false; + visible_disp = false; + line = 0; + line_disp = UINT_MAX; + item_height = FONTH + VSPACE; } void vinit(Menu & m, const char *title, va_list argp); @@ -129,7 +129,7 @@ int process_event(const input_status_t * is); // Menu data - unsigned char flags; // MF_MENUDATA + unsigned char flags; // MF_MENUDATA // The strings come from a Menu_data. // MF_POPUP Used as popup (not pull-down) menu // If set, the title is shown and @@ -142,24 +142,24 @@ // MF_NUMS Force the use of standard // shortcuts [0-9a-zA-Z] even if // index/key shortcuts exist. - const char *title; // NULL if no title - size_t title_len; // Length of (or 0 if none) - size_t items_ks_len; // Length of the longest item counting key sc. - size_t items_len; // Length of the longest item not counting k.s. + const char *title; // NULL if no title + size_t title_len; // Length of <title> (or 0 if none) + size_t items_ks_len; // Length of the longest item counting key sc. + size_t items_len; // Length of the longest item not counting k.s. const Menu_data *menudata; std::vector < Menu_item > items; // Geometry as the user would like it to be - int user_ox0; // Top left corner. < 0 means centered. - int user_oy0; // Top left corner. < 0 means centered. + int user_ox0; // Top left corner. < 0 means centered. + int user_oy0; // Top left corner. < 0 means centered. // Geometry as it should be - int ix0, iy0, ix1, iy1; // Corners of inner edge of window - int ox0, oy0, ox1, oy1; // Corners of outer edge of window - int width; // Overall width of window - int height; // Overall height of window - int ty0; // Y-pos of title - int ly0; // Y-pos of first item + int ix0, iy0, ix1, iy1; // Corners of inner edge of window + int ox0, oy0, ox1, oy1; // Corners of outer edge of window + int width; // Overall width of window + int height; // Overall height of window + int ty0; // Y-pos of title + int ly0; // Y-pos of first item // Geometry as it is displayed int ox0_disp; @@ -168,12 +168,12 @@ int height_disp; // Status - bool need_geom; // Need to call geom() again - bool visible; // Should the menu be visible ? - bool visible_disp; // Is it really visible ? - size_t line; // Which line should be highlighted ? - size_t line_disp; // Which line is actually highlighted ? - inpev_t _last_shortcut_key; // Shortcut key for last selected item. + bool need_geom; // Need to call geom() again + bool visible; // Should the menu be visible ? + bool visible_disp; // Is it really visible ? + size_t line; // Which line should be highlighted ? + size_t line_disp; // Which line is actually highlighted ? + inpev_t _last_shortcut_key; // Shortcut key for last selected item. // Misc unsigned short item_height; @@ -184,12 +184,12 @@ Second subscript : 0 = normal, 1 = highlighted */ const colour_pair_t menu_colour[2][2] = { { - {WINBG, WINFG}, // Normal entry - {WINBG_HL, WINFG_HL} // Normal entry, highlighted + {WINBG, WINFG}, // Normal entry + {WINBG_HL, WINFG_HL} // Normal entry, highlighted }, { - {WINBG, WINFG_DIM}, // Greyed out entry - {WINBG_HL, WINFG_DIM_HL} // Greyed out entry, highlighted + {WINBG, WINFG_DIM}, // Greyed out entry + {WINBG_HL, WINFG_DIM_HL} // Greyed out entry, highlighted } }; @@ -202,120 +202,120 @@ /* - * Menu::Menu - ctor from arguments in variable number + * Menu::Menu - ctor from arguments in variable number * - * Another ctor for Menu, suited to the creation of pull - * down menus. + * Another ctor for Menu, suited to the creation of pull + * down menus. * - * Expects the title of the menu followed by repeats of - * either of the following sets of arguments, in any order : + * Expects the title of the menu followed by repeats of + * either of the following sets of arguments, in any order : * - * 1) Menu item + * 1) Menu item * - * A menu item is made of 3 or more arguments : + * A menu item is made of 3 or more arguments : * - * const char * - * A NUL-terminated string that will be - * used to display the item. The first - * occurrence of a tilde ("~") in the - * string indicates that the following - * character will be used as a local - * shortcut for this item. + * const char * + * A NUL-terminated string that will be + * used to display the item. The first + * occurrence of a tilde ("~") in the + * string indicates that the following + * character will be used as a local + * shortcut for this item. * - * That string must remain valid and should - * not change during the lifetime of the - * Menu object. + * That string must remain valid and should + * not change during the lifetime of the + * Menu object. * - * inpev_t The global shortcut key associated to - * this item. That key will be displayed on - * the right of the menu. + * inpev_t The global shortcut key associated to + * this item. That key will be displayed on + * the right of the menu. * - * <option> ... - * Zero or more options. + * <option> ... + * Zero or more options. * - * (unsigned char) 0 - * The end of the item. + * (unsigned char) 0 + * The end of the item. * - * Where <option> is any of the following pairs of - * arguments : + * Where <option> is any of the following pairs of + * arguments : * - * (unsigned char) MIF_STICK - * bool ticked - * Indicates that this item can be ticked. - * If <ticked> is true, the item will be - * initially ticked. To change the state of - * the item, call set_ticked(). + * (unsigned char) MIF_STICK + * bool ticked + * Indicates that this item can be ticked. + * If <ticked> is true, the item will be + * initially ticked. To change the state of + * the item, call set_ticked(). * - * (unsigned char) MIF_VTICK - * bool *ticked - * Indicates that this item can be ticked. - * The argument is a pointer to a boolean - * variable. Whenever this item is - * displayed, the variable is read and the - * item is shown as ticked or unticked - * depending on whether the function - * returned true or false. + * (unsigned char) MIF_VTICK + * bool *ticked + * Indicates that this item can be ticked. + * The argument is a pointer to a boolean + * variable. Whenever this item is + * displayed, the variable is read and the + * item is shown as ticked or unticked + * depending on whether the function + * returned true or false. * - * (unsigned char) MIF_FTICK - * boolcb_t ticked - * void *arg - * Indicates that this item can be ticked. - * The argument is a pointer to a function - * taking only one argument (<arg>) and - * returning bool. Whenever this item is - * displayed, the function is called and - * the item is shown as ticked or unticked - * depending on whether the function - * returned true or false. + * (unsigned char) MIF_FTICK + * boolcb_t ticked + * void *arg + * Indicates that this item can be ticked. + * The argument is a pointer to a function + * taking only one argument (<arg>) and + * returning bool. Whenever this item is + * displayed, the function is called and + * the item is shown as ticked or unticked + * depending on whether the function + * returned true or false. * - * (unsigned char) MIF_SACTIVE - * bool active - * Indicates that this item can be greyed - * out. If <active> is false the item - * will be initially greyed out. To change - * the state of the item, call - * set_active(). + * (unsigned char) MIF_SACTIVE + * bool active + * Indicates that this item can be greyed + * out. If <active> is false the item + * will be initially greyed out. To change + * the state of the item, call + * set_active(). * - * (unsigned char) MIF_VACTIVE - * bool *active - * Indicates that this item can be greyed - * out. The argument is a pointer to a - * boolean variable. Whenever this item is - * displayed, the variable is read and the - * item is shown as greyed out or not - * depending on whether the function - * returned false or true. + * (unsigned char) MIF_VACTIVE + * bool *active + * Indicates that this item can be greyed + * out. The argument is a pointer to a + * boolean variable. Whenever this item is + * displayed, the variable is read and the + * item is shown as greyed out or not + * depending on whether the function + * returned false or true. * - * (unsigned char) MIF_FACTIVE - * boolcb_t active - * Indicates that this item can be greyed - * out. The argument is a pointer to a - * function taking only one argument - * (<arg>) and returning bool. Whenever - * this item is displayed, the function is - * called and the item is shown as greyed - * out or not depending on whether the - * function returned false or true. + * (unsigned char) MIF_FACTIVE + * boolcb_t active + * Indicates that this item can be greyed + * out. The argument is a pointer to a + * function taking only one argument + * (<arg>) and returning bool. Whenever + * this item is displayed, the function is + * called and the item is shown as greyed + * out or not depending on whether the + * function returned false or true. * - * 2) Separation + * 2) Separation * - * A separation is made of exactly 1 argument : + * A separation is made of exactly 1 argument : * - * (const char *) MI_SEPARATION + * (const char *) MI_SEPARATION * - * Pass a NULL pointer after the last group of arguments. + * Pass a NULL pointer after the last group of arguments. * - * For a given item, the options MIF_STICK, MIF_VTICK and - * MIF_FTICK are mutually exclusive. For a given item, the - * options MIF_SACTIVE, MIF_VACTIVE and MIF_FACTIVE are - * mutually exclusive. + * For a given item, the options MIF_STICK, MIF_VTICK and + * MIF_FTICK are mutually exclusive. For a given item, the + * options MIF_SACTIVE, MIF_VACTIVE and MIF_FACTIVE are + * mutually exclusive. * - * A MI_SEPARATION argument at the end of the list (i.e. - * not followed by an item) is ignored. + * A MI_SEPARATION argument at the end of the list (i.e. + * not followed by an item) is ignored. * - * The ticked and greyed out states can change at any time - * but will not be reflected until the menu is redrawn from - * scratch. + * The ticked and greyed out states can change at any time + * but will not be reflected until the menu is redrawn from + * scratch. */ Menu::Menu(const char *title, ...) { @@ -329,11 +329,11 @@ /* - * Menu::Menu - ctor from an argument list + * Menu::Menu - ctor from an argument list * - * This is the same thing as Menu::Menu (const char - * *title, ...) except that it expects a pointer on the - * list of arguments. + * This is the same thing as Menu::Menu (const char + * *title, ...) except that it expects a pointer on the + * list of arguments. */ Menu::Menu(const char *title, va_list argp) { @@ -344,13 +344,13 @@ /* - * Menu::Menu - ctor from a list + * Menu::Menu - ctor from a list * - * Another ctor for Menu, suited to the creation of the - * menu from a list. + * Another ctor for Menu, suited to the creation of the + * menu from a list. */ Menu::Menu(const char *title, - al_llist_t * list, const char *(*getstr) (void *)) + al_llist_t * list, const char *(*getstr) (void *)) { priv = new Menu_priv; set_title(title); @@ -358,14 +358,14 @@ priv->items.resize(nitems); size_t line; for (al_lrewind(list), line = 0; - !al_leol(list) && line < nitems; al_lstep(list), line++) - priv->items[line].str = getstr(al_lptr(list)); + !al_leol(list) && line < nitems; al_lstep(list), line++) + priv->items[line].str = getstr(al_lptr(list)); priv->cook(); } /* - * Menu::Menu - ctor from a Menu_data + * Menu::Menu - ctor from a Menu_data */ Menu::Menu(const char *title, const Menu_data & menudata) { @@ -380,7 +380,7 @@ /* - * Menu::~Menu - dtor + * Menu::~Menu - dtor */ Menu::~Menu() { @@ -389,7 +389,7 @@ /* - * Menu_priv::vinit - initialize the menu from an argument list + * Menu_priv::vinit - initialize the menu from an argument list */ void Menu_priv::vinit(Menu & m, const char *title, va_list argp) { @@ -399,75 +399,75 @@ while (items.size() < 100) { - Menu_item i; + Menu_item i; - const char *str = va_arg(argp, const char *); - while (str == MI_SEPARATION) - { - i.flags |= MIF_SEPAR; - str = va_arg(argp, const char *); - } - if (str == 0) - break; + const char *str = va_arg(argp, const char *); + while (str == MI_SEPARATION) + { + i.flags |= MIF_SEPAR; + str = va_arg(argp, const char *); + } + if (str == 0) + break; - i.str = str; - i.shortcut_key = (inpev_t) va_arg(argp, int); - unsigned char flag; - while ((flag = (unsigned char) va_arg(argp, int)) != 0) - { - if (flag == MIF_SACTIVE) - { - i.flags = (i.flags & ~MIF_MACTIVE) | MIF_SACTIVE; - i.active.s = (bool) va_arg(argp, int); - } - else if (flag == MIF_VACTIVE) - { - i.flags = (i.flags & ~MIF_MACTIVE) | MIF_VACTIVE; - i.active.v = va_arg(argp, bool *); - } - else if (flag == MIF_FACTIVE) - { - i.flags = (i.flags & ~MIF_MACTIVE) | MIF_FACTIVE; - i.active.f.f = va_arg(argp, micb_t); - i.active.f.a = va_arg(argp, micbarg_t); - } - else if (flag == MIF_STICK) - { - tick = true; - i.flags = (i.flags & ~MIF_MTICK) | MIF_STICK; - i.tick.s = (bool) va_arg(argp, int); - } - else if (flag == MIF_VTICK) - { - tick = true; - i.flags = (i.flags & ~MIF_MTICK) | MIF_VTICK; - i.tick.v = va_arg(argp, bool *); - } - else if (flag == MIF_FTICK) - { - tick = true; - i.flags = (i.flags & ~MIF_MTICK) | MIF_FTICK; - i.tick.f.f = va_arg(argp, micb_t); - i.tick.f.a = va_arg(argp, micbarg_t); - } - else if (flag != 0) - { - nf_bug("Menu::ctor: flag %d", (int) flag); - } - } - items.push_back(i); + i.str = str; + i.shortcut_key = (inpev_t) va_arg(argp, int); + unsigned char flag; + while ((flag = (unsigned char) va_arg(argp, int)) != 0) + { + if (flag == MIF_SACTIVE) + { + i.flags = (i.flags & ~MIF_MACTIVE) | MIF_SACTIVE; + i.active.s = (bool) va_arg(argp, int); + } + else if (flag == MIF_VACTIVE) + { + i.flags = (i.flags & ~MIF_MACTIVE) | MIF_VACTIVE; + i.active.v = va_arg(argp, bool *); + } + else if (flag == MIF_FACTIVE) + { + i.flags = (i.flags & ~MIF_MACTIVE) | MIF_FACTIVE; + i.active.f.f = va_arg(argp, micb_t); + i.active.f.a = va_arg(argp, micbarg_t); + } + else if (flag == MIF_STICK) + { + tick = true; + i.flags = (i.flags & ~MIF_MTICK) | MIF_STICK; + i.tick.s = (bool) va_arg(argp, int); + } + else if (flag == MIF_VTICK) + { + tick = true; + i.flags = (i.flags & ~MIF_MTICK) | MIF_VTICK; + i.tick.v = va_arg(argp, bool *); + } + else if (flag == MIF_FTICK) + { + tick = true; + i.flags = (i.flags & ~MIF_MTICK) | MIF_FTICK; + i.tick.f.f = va_arg(argp, micb_t); + i.tick.f.a = va_arg(argp, micbarg_t); + } + else if (flag != 0) + { + nf_bug("Menu::ctor: flag %d", (int) flag); + } + } + items.push_back(i); } if (tick) - flags |= MF_TICK; + flags |= MF_TICK; } /* - * Menu_priv::cook - parse the menu item strings + * Menu_priv::cook - parse the menu item strings * - * Compute items_len, items_ks_len and prepare the cooked - * tilde shortcuts. + * Compute items_len, items_ks_len and prepare the cooked + * tilde shortcuts. */ void Menu_priv::cook() { @@ -477,63 +477,63 @@ for (size_t line = 0; line < items.size(); line++) { - Menu_item & i = items[line]; - if (i.shortcut_key != YK_) - flags |= MF_SHORTCUT; - if ((i.flags & MIF_MTICK) != MIF_NTICK) - flags |= MF_TICK; - if (i.flags & MIF_SEPAR) - y += 2 * (NARROW_VSPACING + NARROW_BORDER); - i.y = y; - y += item_height; - size_t len = 0; - i.tilde_key = YK_; - const char *str = (flags & MF_MENUDATA) ? (*menudata)[line] : i.str; - for (const char *p = str; *p != '\0'; p++) - if (p[0] == '~' && p[1] != '\0' && i.tilde_key == YK_) - { - i.tilde_key = tolower(p[1]); - flags |= MF_TILDE; - } - else - len++; - size_t len_ks = len; - if (i.shortcut_key != YK_) - len_ks += strlen(key_to_string(i.shortcut_key)) + 2; - if (len > items_len) - items_len = len; - if (len_ks > items_ks_len) - items_ks_len = len_ks; + Menu_item & i = items[line]; + if (i.shortcut_key != YK_) + flags |= MF_SHORTCUT; + if ((i.flags & MIF_MTICK) != MIF_NTICK) + flags |= MF_TICK; + if (i.flags & MIF_SEPAR) + y += 2 * (NARROW_VSPACING + NARROW_BORDER); + i.y = y; + y += item_height; + size_t len = 0; + i.tilde_key = YK_; + const char *str = (flags & MF_MENUDATA) ? (*menudata)[line] : i.str; + for (const char *p = str; *p != '\0'; p++) + if (p[0] == '~' && p[1] != '\0' && i.tilde_key == YK_) + { + i.tilde_key = tolower(p[1]); + flags |= MF_TILDE; + } + else + len++; + size_t len_ks = len; + if (i.shortcut_key != YK_) + len_ks += strlen(key_to_string(i.shortcut_key)) + 2; + if (len > items_len) + items_len = len; + if (len_ks > items_ks_len) + items_ks_len = len_ks; } if (flags & MF_TICK) { - items_len += 2; // Tick mark - items_ks_len += 2; + items_len += 2; // Tick mark + items_ks_len += 2; } if (flags & MF_SHORTCUT) { - items_len += 4; // Space between strings and shortcut - items_ks_len += 4; + items_len += 4; // Space between strings and shortcut + items_ks_len += 4; } if (!(flags & MF_TILDE) && !(flags & MF_SHORTCUT)) - flags |= MF_NUMS; + flags |= MF_NUMS; if (flags & MF_NUMS) { - items_len += 4; // [1-9a-zA-Z] prefix - items_ks_len += 4; + items_len += 4; // [1-9a-zA-Z] prefix + items_ks_len += 4; } } /* - * Menu::set_title - set the title + * Menu::set_title - set the title * - * Set the title of the menu (it's ignored unless the menu - * is set in popup mode). + * Set the title of the menu (it's ignored unless the menu + * is set in popup mode). * - * Bug: changing the title does not take effect until the - * next display from scratch. + * Bug: changing the title does not take effect until the + * next display from scratch. */ void Menu::set_title(const char *title) { @@ -543,23 +543,23 @@ /* If the length of the title has changed, force geom() to be called again. */ if (title_len != priv->title_len) - priv->need_geom = true; + priv->need_geom = true; priv->title_len = title_len; } /* - * Menu::set_coords - position or reposition the menu window. + * Menu::set_coords - position or reposition the menu window. * - * (<x0>,<y0>) is the top left corner. - * If <x0> is < 0, the window is horizontally centred. - * If <y0> is < 0, the window is vertically centred. + * (<x0>,<y0>) is the top left corner. + * If <x0> is < 0, the window is horizontally centred. + * If <y0> is < 0, the window is vertically centred. */ void Menu::set_coords(int x0, int y0) { if (x0 != priv->ox0 || y0 != priv->oy0) - priv->need_geom = true; // Force geom() to be called + priv->need_geom = true; // Force geom() to be called priv->user_ox0 = x0; priv->user_oy0 = y0; @@ -567,10 +567,10 @@ /* - * Menu::set_item_no - set the current line + * Menu::set_item_no - set the current line * - * The current line number is set to <item_no>. The first - * line bears number 0. + * The current line number is set to <item_no>. The first + * line bears number 0. */ void Menu::set_item_no(int item_no) { @@ -579,53 +579,53 @@ /* - * Menu::set_popup - set the popup flag + * Menu::set_popup - set the popup flag * - * If <popup> is true, the popup flag is set. If <popup> is - * false, the popup flag is cleared. + * If <popup> is true, the popup flag is set. If <popup> is + * false, the popup flag is cleared. */ void Menu::set_popup(bool popup) { if (popup != ! !(priv->flags & MF_POPUP)) - priv->need_geom = true; // Force geom() to be called + priv->need_geom = true; // Force geom() to be called if (popup) - priv->flags |= MF_POPUP; + priv->flags |= MF_POPUP; else - priv->flags &= ~MF_POPUP; + priv->flags &= ~MF_POPUP; } /* - * Menu::set_force_numbers - set the force_numbers flags + * Menu::set_force_numbers - set the force_numbers flags * - * If <force_numbers> is true, the force_numbers flag is - * set. If <force_numbers> is false, the force_numbers flag - * is cleared. + * If <force_numbers> is true, the force_numbers flag is + * set. If <force_numbers> is false, the force_numbers flag + * is cleared. * - * The effect of the <force_numbers> flag is to disable key - * shortcuts and tilde shortcuts and to add automatic - * numbering of items ([1-9a-zA-Z]). + * The effect of the <force_numbers> flag is to disable key + * shortcuts and tilde shortcuts and to add automatic + * numbering of items ([1-9a-zA-Z]). * - * If none of the items has a tilde or key shortcut, - * <force_numbers> is automatically set. Otherwise, is it - * off by default. + * If none of the items has a tilde or key shortcut, + * <force_numbers> is automatically set. Otherwise, is it + * off by default. */ void Menu::set_force_numbers(bool force_numbers) { if (force_numbers != ! !(priv->flags & MF_NUMS)) - priv->need_geom = true; // Force geom() to be called. + priv->need_geom = true; // Force geom() to be called. if (force_numbers) - priv->flags |= MF_NUMS; + priv->flags |= MF_NUMS; else - priv->flags &= ~MF_NUMS; + priv->flags &= ~MF_NUMS; } /* - * Menu::set_visible - set the visible flag + * Menu::set_visible - set the visible flag * - * If <visible> is true, the visible flag is set. If - * <visible> is false, the visible flag is cleared. + * If <visible> is true, the visible flag is set. If + * <visible> is false, the visible flag is cleared. */ void Menu::set_visible(bool visible) { @@ -634,98 +634,98 @@ /* - * Menu::set_ticked - tick or untick a menu item + * Menu::set_ticked - tick or untick a menu item * - * If <ticked> is true, item number <item_no> is ticked. If - * <ticked> is false, item number <item_no> is unticked. - * If the menu item was not created with the MIF_STICK - * option, emit a warning and return without doing - * anything. + * If <ticked> is true, item number <item_no> is ticked. If + * <ticked> is false, item number <item_no> is unticked. + * If the menu item was not created with the MIF_STICK + * option, emit a warning and return without doing + * anything. */ void Menu::set_ticked(size_t item_no, bool ticked) { if (item_no >= priv->items.size()) { - nf_bug("Menu::set_ticked: item_no %lu", (unsigned long) item_no); - return; + nf_bug("Menu::set_ticked: item_no %lu", (unsigned long) item_no); + return; } Menu_item & i = priv->items[item_no]; if ((i.flags & MIF_MTICK) != MIF_STICK) { - nf_bug("Menu::set_ticked: flags %02X", i.flags); - return; + nf_bug("Menu::set_ticked: flags %02X", i.flags); + return; } i.tick.s = ticked; } /* - * Menu::set_active - grey-out or ungrey-out a menu + * Menu::set_active - grey-out or ungrey-out a menu * - * If <active> is false, item number <item_no> becomes - * greyed out. If <active> is true, item number <item_no> - * ceases to be greyed out. If the item was not created - * with with the MIF_SACTIVE option, emit a warning and - * return without doing anything. + * If <active> is false, item number <item_no> becomes + * greyed out. If <active> is true, item number <item_no> + * ceases to be greyed out. If the item was not created + * with with the MIF_SACTIVE option, emit a warning and + * return without doing anything. */ void Menu::set_active(size_t item_no, bool active) { if (item_no >= priv->items.size()) { - nf_bug("Menu::set_active: item_no %lu", (unsigned long) item_no); - return; + nf_bug("Menu::set_active: item_no %lu", (unsigned long) item_no); + return; } Menu_item & i = priv->items[item_no]; if ((i.flags & MIF_MACTIVE) != MIF_SACTIVE) { - nf_bug("Menu::set_active: flags %02Xh", i.flags); - return; + nf_bug("Menu::set_active: flags %02Xh", i.flags); + return; } i.active.s = active; } /* - * Menu_priv::geom - recalculate the screen coordinates etc. + * Menu_priv::geom - recalculate the screen coordinates etc. */ void Menu_priv::geom() { size_t width_chars = 0; if (title && (flags & MF_POPUP)) - width_chars = y_max(width_chars, title_len); + width_chars = y_max(width_chars, title_len); if (flags & MF_NUMS) - width_chars = y_max(width_chars, items_len + 4); + width_chars = y_max(width_chars, items_len + 4); else - width_chars = y_max(width_chars, items_ks_len); + width_chars = y_max(width_chars, items_ks_len); int title_height = title && (flags & MF_POPUP) ? (int) (1.5 * FONTH) : 0; width = 2 * BOX_BORDER + 2 * WIDE_HSPACING + width_chars * FONTW; height = 2 * BOX_BORDER + 2 * WIDE_VSPACING + title_height - + items.back().y + item_height; + + items.back().y + item_height; if (user_ox0 < 0) - ox0 = (ScrMaxX - width) / 2; + ox0 = (ScrMaxX - width) / 2; else - ox0 = user_ox0; + ox0 = user_ox0; ix0 = ox0 + BOX_BORDER; ix1 = ix0 + 2 * WIDE_HSPACING + width_chars * FONTW - 1; ox1 = ix1 + BOX_BORDER; if (ox1 > ScrMaxX) { - int overlap = ox1 - ScrMaxX; - ox0 -= overlap; - ix0 -= overlap; - ix1 -= overlap; - ox1 -= overlap; + int overlap = ox1 - ScrMaxX; + ox0 -= overlap; + ix0 -= overlap; + ix1 -= overlap; + ox1 -= overlap; } if (user_oy0 < 0) - oy0 = (ScrMaxY - height) / 2; + oy0 = (ScrMaxY - height) / 2; else - oy0 = user_oy0; + oy0 = user_oy0; iy0 = oy0 + BOX_BORDER; - ty0 = iy0 + FONTH / 2; // Title of menu - ly0 = ty0 + title_height; // First item of menu + ty0 = iy0 + FONTH / 2; // Title of menu + ly0 = ty0 + title_height; // First item of menu oy1 = oy0 + height - 1; iy1 = oy1 - BOX_BORDER; @@ -735,17 +735,17 @@ /* - * Menu::process_event - process an input event + * Menu::process_event - process an input event * - * Process event in *<is>. + * Process event in *<is>. * - * Return one of the following : - * - MEN_CANCEL: user pressed [Esc] or clicked outside - * the menu. The caller should delete the menu. - * - MEN_INVALID: we didn't understand the event so we put it - * back in the input buffer. - * - MEN_OTHER: we understood the event and processed it. - * - the number of the item that was validated. + * Return one of the following : + * - MEN_CANCEL: user pressed [Esc] or clicked outside + * the menu. The caller should delete the menu. + * - MEN_INVALID: we didn't understand the event so we put it + * back in the input buffer. + * - MEN_OTHER: we understood the event and processed it. + * - the number of the item that was validated. */ int Menu::process_event(const input_status_t * is) { @@ -759,13 +759,13 @@ char status; if ((int) is->x < ix0 || (int) is->x > ix1 || (int) is->y < ly0) - mouse_line = items.size(); + mouse_line = items.size(); else { - for (mouse_line = 0; mouse_line < items.size(); mouse_line++) - if ((int) is->y >= ly0 + items[mouse_line].y - && (int) is->y < ly0 + items[mouse_line].y + item_height) - break; + for (mouse_line = 0; mouse_line < items.size(); mouse_line++) + if ((int) is->y >= ly0 + items[mouse_line].y + && (int) is->y < ly0 + items[mouse_line].y + item_height) + break; } status = 'i'; @@ -773,15 +773,15 @@ // Clicking left button on an item: validate it. if (is->key == YE_BUTL_PRESS && mouse_line < items.size()) { - line = mouse_line; // Useless ? - status = 'v'; + line = mouse_line; // Useless ? + status = 'v'; } // Moving over the box sets current line. else if (is->key == YE_MOTION && mouse_line < items.size()) { - line = mouse_line; - status = 'o'; + line = mouse_line; + status = 'o'; } /* Releasing the button while standing on an item: has a @@ -796,171 +796,171 @@ likely to exit a submenu (cf. the "thing type" menu) so we ignore the event. */ else if (is->key == YE_BUTL_RELEASE - && mouse_line < items.size() && !(flags & MF_POPUP)) - status = 'v'; + && mouse_line < items.size() && !(flags & MF_POPUP)) + status = 'v'; // [Enter], [Return]: accept selection else if (is->key == YK_RETURN) - status = 'v'; + status = 'v'; // [Esc]: cancel else if (is->key == YK_ESC) - status = 'c'; + status = 'c'; // [Up]: select previous line else if (is->key == YK_UP) { - if (line > 0) - line--; - else - line = items.size() - 1; - status = 'o'; + if (line > 0) + line--; + else + line = items.size() - 1; + status = 'o'; } // [Down]: select next line else if (is->key == YK_DOWN) { - if (line < items.size() - 1) - line++; - else - line = 0; - status = 'o'; + if (line < items.size() - 1) + line++; + else + line = 0; + status = 'o'; } // [Home]: select first line else if (is->key == YK_HOME) { - line = 0; - status = 'o'; + line = 0; + status = 'o'; } // [End]: select last line else if (is->key == YK_END) { - line = items.size() - 1; - status = 'o'; + line = items.size() - 1; + status = 'o'; } // [Pgup]: select line - 5 else if (is->key == YK_PU) { - if (line >= 5) - line -= 5; - else - line = 0; - status = 'o'; + if (line >= 5) + line -= 5; + else + line = 0; + status = 'o'; } // [Pgdn]: select line + 5 else if (is->key == YK_PD) { - if (line + 5 < items.size()) - line += 5; - else - line = items.size() - 1; - status = 'o'; + if (line + 5 < items.size()) + line += 5; + else + line = items.size() - 1; + status = 'o'; } // [1]-[9]: select items 0 through 8 else if ((flags & MF_NUMS) - && is->key < YK_ && within(dectoi(is->key), 1, items.size())) + && is->key < YK_ && within(dectoi(is->key), 1, items.size())) { - line = dectoi(is->key) - 1; - status = 'o'; - send_event(YK_RETURN); + line = dectoi(is->key) - 1; + status = 'o'; + send_event(YK_RETURN); } // [a]-[z]: select items 9 through 34 else if ((flags & MF_NUMS) - && is->key < YK_ - && islower(is->key) && within(b36toi(is->key), 10, items.size())) + && is->key < YK_ + && islower(is->key) && within(b36toi(is->key), 10, items.size())) { - line = b36toi(is->key) - 1; - status = 'o'; - send_event(YK_RETURN); + line = b36toi(is->key) - 1; + status = 'o'; + send_event(YK_RETURN); } // [A]-[Z]: select items 35 through 60 else if ((flags & MF_NUMS) - && is->key < YK_ - && isupper(is->key) - && within(b36toi(is->key) + 26, 36, items.size())) + && is->key < YK_ + && isupper(is->key) + && within(b36toi(is->key) + 26, 36, items.size())) { - line = b36toi(is->key) + 25; - status = 'o'; - send_event(YK_RETURN); + line = b36toi(is->key) + 25; + status = 'o'; + send_event(YK_RETURN); } // A shortcut ? else { - /* First, check the list of tilde shortcuts - (only if is->key is a regular key) */ - if ((flags & MF_TILDE) - && !(flags & MF_NUMS) && is->key == (unsigned char) is->key) - { - for (size_t n = 0; n < items.size(); n++) - if (items[n].tilde_key != YK_ - && items[n].tilde_key == tolower(is->key)) - { - line = n; - status = 'o'; - send_event(YK_RETURN); - break; - } - } - /* If no tilde shortcut matched, check the list of shortcut - keys. It's important to do the tilde shortcuts first so - that you can override a shortcut key (normally global) - with a tilde shortcut (normally local). */ - if (status == 'i' && (flags & MF_SHORTCUT) && !(flags & MF_NUMS)) - { - for (size_t n = 0; n < items.size(); n++) - if (items[n].shortcut_key != YK_ - && items[n].shortcut_key == is->key) - { - line = n; - status = 'o'; - send_event(YK_RETURN); - break; - } - } + /* First, check the list of tilde shortcuts + (only if is->key is a regular key) */ + if ((flags & MF_TILDE) + && !(flags & MF_NUMS) && is->key == (unsigned char) is->key) + { + for (size_t n = 0; n < items.size(); n++) + if (items[n].tilde_key != YK_ + && items[n].tilde_key == tolower(is->key)) + { + line = n; + status = 'o'; + send_event(YK_RETURN); + break; + } + } + /* If no tilde shortcut matched, check the list of shortcut + keys. It's important to do the tilde shortcuts first so + that you can override a shortcut key (normally global) + with a tilde shortcut (normally local). */ + if (status == 'i' && (flags & MF_SHORTCUT) && !(flags & MF_NUMS)) + { + for (size_t n = 0; n < items.size(); n++) + if (items[n].shortcut_key != YK_ + && items[n].shortcut_key == is->key) + { + line = n; + status = 'o'; + send_event(YK_RETURN); + break; + } + } } // See last_shortcut_key() if (status == 'v') - _last_shortcut_key = - (flags & MF_SHORTCUT) ? items[line].shortcut_key : 0; + _last_shortcut_key = + (flags & MF_SHORTCUT) ? items[line].shortcut_key : 0; /* Return - the item# if validated, - MEN_CANCEL if cancelled, - MEN_OTHER or MEN_INVALID if neither. */ if (status == 'v') - return (int) line; + return (int) line; else if (status == 'c') - return MEN_CANCEL; + return MEN_CANCEL; else if (status == 'o') - return MEN_OTHER; + return MEN_OTHER; else if (status == 'i') - return MEN_INVALID; + return MEN_INVALID; else { - // Can't happen - fatal_error("Menu::process_event: bad status %02Xh", status); - return 0; // To please the compiler + // Can't happen + fatal_error("Menu::process_event: bad status %02Xh", status); + return 0; // To please the compiler } } /* - * Menu::last_shortcut_key - shortcut key for last selected item + * Menu::last_shortcut_key - shortcut key for last selected item * - * Return the code of the shortcut key for the last - * selected item. This function shouldn't exist : it's just - * there because it helps editloop.cc. When real key - * bindings are implemented in editloop.cc, - * get_shortcut_key() should disappear. + * Return the code of the shortcut key for the last + * selected item. This function shouldn't exist : it's just + * there because it helps editloop.cc. When real key + * bindings are implemented in editloop.cc, + * get_shortcut_key() should disappear. */ inpev_t Menu::last_shortcut_key() { @@ -969,10 +969,10 @@ /* - * Menu::draw - display the menu + * Menu::draw - display the menu * - * If necessary, redraw everything from scratch. Else, if - * <line> has changed, refresh the highlighted line. + * If necessary, redraw everything from scratch. Else, if + * <line> has changed, refresh the highlighted line. */ void Menu::draw() { @@ -985,52 +985,52 @@ bool from_scratch = false; if (need_geom) - geom(); + geom(); // Do we need to redraw everything from scratch ? if (visible && !visible_disp - || ox0 != ox0_disp - || oy0 != oy0_disp || width != width_disp || height != height_disp) - from_scratch = true; + || ox0 != ox0_disp + || oy0 != oy0_disp || width != width_disp || height != height_disp) + from_scratch = true; // Display the static part of the menu if (from_scratch) { - DrawScreenBox3D(ox0, oy0, ox1, oy1); - set_colour(WINTITLE); - if ((flags & MF_POPUP) && title != 0) - DrawScreenString(ix0 + WIDE_HSPACING, ty0, title); + DrawScreenBox3D(ox0, oy0, ox1, oy1); + set_colour(WINTITLE); + if ((flags & MF_POPUP) && title != 0) + DrawScreenString(ix0 + WIDE_HSPACING, ty0, title); - for (size_t l = 0; l < items.size(); l++) - { - set_colour(WINFG); - draw_one_line(l, false); - } - visible_disp = true; - ox0_disp = ox0; - oy0_disp = oy0; - width_disp = width; - height_disp = height; + for (size_t l = 0; l < items.size(); l++) + { + set_colour(WINFG); + draw_one_line(l, false); + } + visible_disp = true; + ox0_disp = ox0; + oy0_disp = oy0; + width_disp = width; + height_disp = height; } // Display the "highlight" bar if (from_scratch || line != line_disp) { - if (line_disp < items.size()) - draw_one_line(line_disp, false); - if (line < items.size()) - draw_one_line(line, true); - line_disp = line; + if (line_disp < items.size()) + draw_one_line(line_disp, false); + if (line < items.size()) + draw_one_line(line, true); + line_disp = line; } } /* - * Menu::draw_one_line - display just one line of a menu + * Menu::draw_one_line - display just one line of a menu * - * <line> is the number of the option to draw (0 = first - * option). <highlighted> tells whether the option should - * be drawn highlighted. + * <line> is the number of the option to draw (0 = first + * option). <highlighted> tells whether the option should + * be drawn highlighted. */ void Menu_priv::draw_one_line(size_t line, bool highlighted) { @@ -1042,12 +1042,12 @@ // Separation ? if (i.flags & MIF_SEPAR) { - push_colour(WINBG_DARK); - short groove_y = y - NARROW_VSPACING - 2 * NARROW_BORDER; - DrawScreenLine(ix0, groove_y, ix1, groove_y); - set_colour(WINBG_LIGHT); - DrawScreenLine(ix0, groove_y + 1, ix1, groove_y + 1); - pop_colour(); + push_colour(WINBG_DARK); + short groove_y = y - NARROW_VSPACING - 2 * NARROW_BORDER; + DrawScreenLine(ix0, groove_y, ix1, groove_y); + set_colour(WINBG_LIGHT); + DrawScreenLine(ix0, groove_y + 1, ix1, groove_y + 1); + pop_colour(); } // Greyed out ? @@ -1055,24 +1055,24 @@ switch (i.flags & MIF_MACTIVE) { case MIF_NACTIVE: - active = true; - break; + active = true; + break; case MIF_SACTIVE: - active = i.active.s; - break; + active = i.active.s; + break; case MIF_VACTIVE: - active = *i.active.v; - break; + active = *i.active.v; + break; case MIF_FACTIVE: - active = i.active.f.f(i.active.f.a); - break; + active = i.active.f.f(i.active.f.a); + break; default: - nf_bug("Menu::draw_one_line: active %02Xh", i.flags); - break; + nf_bug("Menu::draw_one_line: active %02Xh", i.flags); + break; } set_colour(menu_colour[!active][highlighted].bg); DrawScreenBox(ix0, y, ix1, y + item_height - 1); @@ -1081,124 +1081,124 @@ // Tick mark if any if (flags & MF_TICK) { - bool have_tick = false; - bool ticked = false; - switch (i.flags & MIF_MTICK) - { - case MIF_NTICK: - have_tick = false; - break; + bool have_tick = false; + bool ticked = false; + switch (i.flags & MIF_MTICK) + { + case MIF_NTICK: + have_tick = false; + break; - case MIF_STICK: - have_tick = true; - ticked = i.tick.s; - break; + case MIF_STICK: + have_tick = true; + ticked = i.tick.s; + break; - case MIF_VTICK: - have_tick = true; - ticked = *i.tick.v; - break; + case MIF_VTICK: + have_tick = true; + ticked = *i.tick.v; + break; - case MIF_FTICK: - have_tick = true; - ticked = i.tick.f.f(i.tick.f.a); - break; + case MIF_FTICK: + have_tick = true; + ticked = i.tick.f.f(i.tick.f.a); + break; - default: - nf_bug("Menu::draw_one_line: tick %02Xh", i.flags); - break; - } - if (have_tick) - { - if (ticked) - { - unsigned hside = FONTW * 4 / 5; - unsigned vside = FONTH * 4 / 5; - int x0 = x + (FONTW - hside) / 2; - int y0 = y + (FONTH - vside) / 2; - DrawScreenLine(x0, y0 + vside / 2, x0 + hside / 2, - y0 + vside - 1); - DrawScreenLine(x0 + hside / 2, y0 + vside - 1, x0 + hside - 1, - y0); - } - else - { - unsigned margin = FONTW / 5; - DrawScreenLine(x + margin, y + FONTH / 2, - x + FONTW - 1 - margin, y + FONTH / 2); - } - } - x += 2 * FONTW; + default: + nf_bug("Menu::draw_one_line: tick %02Xh", i.flags); + break; + } + if (have_tick) + { + if (ticked) + { + unsigned hside = FONTW * 4 / 5; + unsigned vside = FONTH * 4 / 5; + int x0 = x + (FONTW - hside) / 2; + int y0 = y + (FONTH - vside) / 2; + DrawScreenLine(x0, y0 + vside / 2, x0 + hside / 2, + y0 + vside - 1); + DrawScreenLine(x0 + hside / 2, y0 + vside - 1, x0 + hside - 1, + y0); + } + else + { + unsigned margin = FONTW / 5; + DrawScreenLine(x + margin, y + FONTH / 2, + x + FONTW - 1 - margin, y + FONTH / 2); + } + } + x += 2 * FONTW; } // Automatic keys if any if (flags & MF_NUMS) { - char c = '\0'; - if (line <= 8) - c = '1' + line; - else if (line >= 9 && line < 9 + 26) - c = 'a' + line - 9; - else if (line >= 9 + 26 && line < 9 + 26 + 26) - c = 'A' + line - (9 + 26); - if (c != '\0') - { - push_colour(highlighted ? WINLABEL_HL : WINLABEL); - DrawScreenString(x, text_y, "[ ]"); - pop_colour(); - DrawScreenChar(x + FONTW, text_y, c); - DrawScreenChar(x + FONTW, text_y + FONTU, '_'); - } - x += 4 * FONTW; + char c = '\0'; + if (line <= 8) + c = '1' + line; + else if (line >= 9 && line < 9 + 26) + c = 'a' + line - 9; + else if (line >= 9 + 26 && line < 9 + 26 + 26) + c = 'A' + line - (9 + 26); + if (c != '\0') + { + push_colour(highlighted ? WINLABEL_HL : WINLABEL); + DrawScreenString(x, text_y, "[ ]"); + pop_colour(); + DrawScreenChar(x + FONTW, text_y, c); + DrawScreenChar(x + FONTW, text_y + FONTU, '_'); + } + x += 4 * FONTW; } // Text int tilde_index = -1; { - const char *str = (flags & MF_MENUDATA) ? (*menudata)[line] : i.str; - char *buf = new char[strlen(str) + 1]; - char *d = buf; - for (const char *s = str; *s != '\0'; s++) - { - if (*s == '~' && tilde_index < 0) - { - tilde_index = s - str; - continue; - } - *d++ = *s; - } - *d = '\0'; - DrawScreenString(x, text_y, buf); - delete[]buf; + const char *str = (flags & MF_MENUDATA) ? (*menudata)[line] : i.str; + char *buf = new char[strlen(str) + 1]; + char *d = buf; + for (const char *s = str; *s != '\0'; s++) + { + if (*s == '~' && tilde_index < 0) + { + tilde_index = s - str; + continue; + } + *d++ = *s; + } + *d = '\0'; + DrawScreenString(x, text_y, buf); + delete[]buf; } // Underscore the tilde shortcut if any if (!(flags & MF_NUMS) && tilde_index >= 0) - DrawScreenString(x + tilde_index * FONTW, text_y + FONTU, "_"); + DrawScreenString(x + tilde_index * FONTW, text_y + FONTU, "_"); // Shortcut key if any if (!(flags & MF_NUMS) && i.shortcut_key != YK_) { - const char *s = key_to_string(i.shortcut_key); - DrawScreenString(ix1 + 1 - FONTW - strlen(s) * FONTW, text_y, s); + const char *s = key_to_string(i.shortcut_key); + DrawScreenString(ix1 + 1 - FONTW - strlen(s) * FONTW, text_y, s); } } /* - * WIDGET METHODS + * WIDGET METHODS */ void Menu::undraw() { - ; // I can't undraw myself + ; // I can't undraw myself } int Menu::can_undraw() { - return 0; // I can't undraw myself + return 0; // I can't undraw myself } @@ -1217,7 +1217,7 @@ int Menu::req_width() { if (priv->need_geom) - priv->geom(); + priv->geom(); return priv->width; } @@ -1225,7 +1225,7 @@ int Menu::req_height() { if (priv->need_geom) - priv->geom(); + priv->geom(); return priv->height; } diff -r 594dea11ccd9 -r a68786b9c74b src/menu.h --- a/src/menu.h Sat Sep 24 15:01:56 2011 +0300 +++ b/src/menu.h Sat Sep 24 15:59:33 2011 +0300 @@ -1,6 +1,6 @@ /* - * menu.h - * AYM 1998-08-15 + * menu.h + * AYM 1998-08-15 */ @@ -27,7 +27,7 @@ */ -#ifndef YH_MENUS /* DO NOT INSERT ANYTHING BEFORE THIS LINE */ +#ifndef YH_MENUS /* DO NOT INSERT ANYTHING BEFORE THIS LINE */ #define YH_MENUS @@ -58,13 +58,13 @@ extern const char *MI_SEPARATION; -typedef void *micbarg_t; // Argument of callback function -typedef bool(*micb_t) (micbarg_t); // Pointer to callback function +typedef void *micbarg_t; // Argument of callback function +typedef bool(*micb_t) (micbarg_t); // Pointer to callback function // Values returned by process_event() -const int MEN_CANCEL = -1; // Exit by [Esc]. Caller should destroy the menu. -const int MEN_OTHER = -2; // Got other event and processed it. -const int MEN_INVALID = -3; // Got invalid event. Caller should process it. +const int MEN_CANCEL = -1; // Exit by [Esc]. Caller should destroy the menu. +const int MEN_OTHER = -2; // Got other event and processed it. +const int MEN_INVALID = -3; // Got invalid event. Caller should process it. class Menu_data; @@ -72,16 +72,16 @@ /* - * Menu - a menu class + * Menu - a menu class */ class Menu:public edwidget_c { public: - // Ctors + // Ctors Menu(const char *title, ...); Menu(const char *title, va_list argp); Menu(const char *title, al_llist_t * list, - const char *(*getstr) (void *)); + const char *(*getstr) (void *)); Menu(const char *title, const Menu_data & menudata); ~Menu(); @@ -112,8 +112,8 @@ int get_x1(); int get_y1(); - private: Menu(const Menu &); // Too lazy to implement it - Menu & operator=(const Menu &); // Too lazy to implement it + private: Menu(const Menu &); // Too lazy to implement it + Menu & operator=(const Menu &); // Too lazy to implement it Menu_priv *priv; }; diff -r 594dea11ccd9 -r a68786b9c74b src/menubar.cc --- a/src/menubar.cc Sat Sep 24 15:01:56 2011 +0300 +++ b/src/menubar.cc Sat Sep 24 15:59:33 2011 +0300 @@ -1,6 +1,6 @@ /* - * menubar.cc - * AYM 1998-08-21 + * menubar.cc + * AYM 1998-08-21 */ @@ -49,7 +49,7 @@ /* - * menubar_c + * menubar_c */ menubar_c::menubar_c() { @@ -68,23 +68,23 @@ #if 0 for (size_t n = 0; n < MAX_ITEMS; n++) { - item_menu[n] = 0; + item_menu[n] = 0; } #endif } /* - * compute_menubar_coords - * Call this one second and each time the screen size - * changes. - * (<scrx0>, <scry0>) are the coordinates - * of the top left corner of the screen/window. - * (<scrx1>, <scry1>) are the coordinates - * of the bottom right corner of the screen/window. + * compute_menubar_coords + * Call this one second and each time the screen size + * changes. + * (<scrx0>, <scry0>) are the coordinates + * of the top left corner of the screen/window. + * (<scrx1>, <scry1>) are the coordinates + * of the bottom right corner of the screen/window. */ void menubar_c::compute_menubar_coords(int scrx0, int scry0, int scrx1, - int scry1) + int scry1) { // Just to prevent the compiler from emitting an // annoying warning about that parameter being unused. @@ -111,19 +111,19 @@ /* - * add_menubar_item - * Add a new item to the menu bar. - * If <right_aligned> is non zero, that item will be - * right aligned on the menu bar. - * Returns the number of the newly created item. + * add_menubar_item + * Add a new item to the menu bar. + * If <right_aligned> is non zero, that item will be + * right aligned on the menu bar. + * Returns the number of the newly created item. */ int menubar_c::add_item(const char *text, int shortcut_index, - int right_aligned, Menu * menu) + int right_aligned, Menu * menu) { if (nitems >= MAX_ITEMS) - fatal_error("Too many items on menu bar"); + fatal_error("Too many items on menu bar"); if (shortcut_index < 0 || shortcut_index >= (int) strlen(text)) - fatal_error("add_menubar_item: shortcut_index out of range"); + fatal_error("add_menubar_item: shortcut_index out of range"); item_text[nitems] = text; item_shortcut_index[nitems] = shortcut_index; item_right_aligned[nitems] = right_aligned; @@ -135,56 +135,56 @@ /* - * set_menu - * Change the menu for an existing menu bar item. + * set_menu + * Change the menu for an existing menu bar item. */ void menubar_c::set_menu(int number, Menu * menu) { if (number >= nitems) - fatal_error("set_menu: bad mbi#"); + fatal_error("set_menu: bad mbi#"); item_menu[number] = menu; // So that need_to_clear() knows something has changed if (number == pulled_down_no) - pulled_down_menu = menu; + pulled_down_menu = menu; } /* - * get_menu - * Return a pointer on the menu for an existing menu bar item. + * get_menu + * Return a pointer on the menu for an existing menu bar item. */ Menu *menubar_c::get_menu(int number) { if (number >= nitems) - fatal_error("set_menu: bad mbi#"); + fatal_error("set_menu: bad mbi#"); return item_menu[number]; } /* - * highlight - * Highlight the menu bar item number <number>. - * Use <number> < 0 to clear the highlighting. + * highlight + * Highlight the menu bar item number <number>. + * Use <number> < 0 to clear the highlighting. */ void menubar_c::highlight(int number) { highlighted_no = number; if (pulled_down_no >= 0) { - pulled_down_no = number; - if (number >= 0) - pulled_down_menu = item_menu[number]; - else - pulled_down_menu = 0; + pulled_down_no = number; + if (number >= 0) + pulled_down_menu = item_menu[number]; + else + pulled_down_menu = 0; } } /* - * highlighted - * Return the number of the menu bar item that is highlighted - * or < 0 if none. + * highlighted + * Return the number of the menu bar item that is highlighted + * or < 0 if none. */ int menubar_c::highlighted() { @@ -193,33 +193,33 @@ /* - * pull_down - * Pull down the menu under the menu bar item number <number>. - * Use <number> < 0 to "unroll". + * pull_down + * Pull down the menu under the menu bar item number <number>. + * Use <number> < 0 to "unroll". */ void menubar_c::pull_down(int number) { if (number >= 0 && number != pulled_down_no) - item_menu[number]->set_item_no(0); + item_menu[number]->set_item_no(0); pulled_down_no = number; if (number >= 0) { - pulled_down_menu = item_menu[number]; - // Pulling down a menu implies highlighting - // the corresponding item on the menu bar. - highlight(number); + pulled_down_menu = item_menu[number]; + // Pulling down a menu implies highlighting + // the corresponding item on the menu bar. + highlight(number); } else - pulled_down_menu = 0; + pulled_down_menu = 0; } /* - * pulled_down - * Return the number of the menu bar item that is pulled down - * or < 0 if none. + * pulled_down + * Return the number of the menu bar item that is pulled down + * or < 0 if none. */ int menubar_c::pulled_down() { @@ -228,7 +228,7 @@ /* - * clear + * clear */ void menubar_c::clear() { @@ -236,7 +236,7 @@ // item_menu[n]->clear (); if (pulled_down_menu_disp) - pulled_down_menu_disp->clear(); + pulled_down_menu_disp->clear(); bar_visible_disp = 0; highlighted_no_disp = -1; pulled_down_no_disp = -1; @@ -245,60 +245,60 @@ /* - * draw - * Draw the menu bar according to its current state. + * draw + * Draw the menu bar according to its current state. */ void menubar_c::draw() { // Draw the menu bar itself if (bar_visible && !bar_visible_disp - || highlighted_no != highlighted_no_disp) + || highlighted_no != highlighted_no_disp) { - if (stale_x0_x1) - compute_x0_x1(); - push_colour(menu_colour[0][0].bg); /* 1 */ - DrawScreenBox3D(0, 0, ScrMaxX, menubar_out_y1); - set_colour(menu_colour[0][0].fg); - for (int n = 0; n < nitems; n++) - { - if (n == highlighted_no) - { - push_colour(menu_colour[0][1].bg); /* 2 */ - DrawScreenBox(item_x0[n], menubar_in_y0, item_x1[n], - menubar_in_y1); - set_colour(menu_colour[0][1].fg); - } - DrawScreenString(item_x0[n] + spacing, menubar_text_y0, - item_text[n]); - DrawScreenString(item_x0[n] + spacing + - item_shortcut_index[n] * FONTW, - menubar_text_y0 + FONTU, "_"); - if (n == highlighted_no) - pop_colour(); /* 2 */ - } - pop_colour(); /* 1 */ - bar_visible_disp = 1; - highlighted_no_disp = highlighted_no; + if (stale_x0_x1) + compute_x0_x1(); + push_colour(menu_colour[0][0].bg); /* 1 */ + DrawScreenBox3D(0, 0, ScrMaxX, menubar_out_y1); + set_colour(menu_colour[0][0].fg); + for (int n = 0; n < nitems; n++) + { + if (n == highlighted_no) + { + push_colour(menu_colour[0][1].bg); /* 2 */ + DrawScreenBox(item_x0[n], menubar_in_y0, item_x1[n], + menubar_in_y1); + set_colour(menu_colour[0][1].fg); + } + DrawScreenString(item_x0[n] + spacing, menubar_text_y0, + item_text[n]); + DrawScreenString(item_x0[n] + spacing + + item_shortcut_index[n] * FONTW, + menubar_text_y0 + FONTU, "_"); + if (n == highlighted_no) + pop_colour(); /* 2 */ + } + pop_colour(); /* 1 */ + bar_visible_disp = 1; + highlighted_no_disp = highlighted_no; } // If there is a menu that used to be visible // but isn't anymore, let it be aware of it. if (pulled_down_menu_disp && pulled_down_menu != pulled_down_menu_disp) { - pulled_down_menu_disp->clear(); - pulled_down_menu_disp->set_visible(0); + pulled_down_menu_disp->clear(); + pulled_down_menu_disp->set_visible(0); } // Draw the pulled down menu (if any) if (pulled_down_menu) { - int x, y; - menubar_item_coords(pulled_down_no, &x, &y); - pulled_down_menu->set_popup(0); - pulled_down_menu->set_force_numbers(0); - pulled_down_menu->set_coords(x, y); - pulled_down_menu->set_visible(1); - pulled_down_menu->draw(); + int x, y; + menubar_item_coords(pulled_down_no, &x, &y); + pulled_down_menu->set_popup(0); + pulled_down_menu->set_force_numbers(0); + pulled_down_menu->set_coords(x, y); + pulled_down_menu->set_visible(1); + pulled_down_menu->draw(); } pulled_down_no_disp = pulled_down_no; @@ -307,52 +307,52 @@ /* - * is_on_menubar_item - * Returns the number of the menu bar item which should - * be pulled down if the user clicked at screen coords (x,y). - * Returns -1 if none. + * is_on_menubar_item + * Returns the number of the menu bar item which should + * be pulled down if the user clicked at screen coords (x,y). + * Returns -1 if none. */ int menubar_c::is_on_menubar_item(int x, int y) { if (stale_coords) - fatal_error("Called iomi before cc"); + fatal_error("Called iomi before cc"); if (x < menubar_in_x0 || x > menubar_in_x1 - || y < menubar_in_y0 || y > menubar_in_y1) - return -1; + || y < menubar_in_y0 || y > menubar_in_y1) + return -1; if (stale_x0_x1) - compute_x0_x1(); + compute_x0_x1(); for (int n = 0; n < nitems; n++) - if (x >= item_x0[n] && x <= item_x1[n]) - return n; + if (x >= item_x0[n] && x <= item_x1[n]) + return n; return -1; } /* - * is_under_menubar_item - * Returns whether the screen abscissa <scrx> is "under" - * (or "over") one of the menu bar items. - * This weird function is used in only one place ; the - * autoscroll code. If the mouse pointer is at the same - * abscissa as a menubar item, it probably means that the - * user is reaching for the menus so don't scroll. + * is_under_menubar_item + * Returns whether the screen abscissa <scrx> is "under" + * (or "over") one of the menu bar items. + * This weird function is used in only one place ; the + * autoscroll code. If the mouse pointer is at the same + * abscissa as a menubar item, it probably means that the + * user is reaching for the menus so don't scroll. */ int menubar_c::is_under_menubar_item(int scrx) { if (stale_coords) - fatal_error("Called iumi before cc"); + fatal_error("Called iumi before cc"); if (stale_x0_x1) - compute_x0_x1(); + compute_x0_x1(); for (int n = 0; n < nitems; n++) - if (scrx >= item_x0[n] && scrx <= item_x1[n]) - return n; + if (scrx >= item_x0[n] && scrx <= item_x1[n]) + return n; return -1; } /* - * compute_x0_x1 - * Fill in item_x0 and item_x1. + * compute_x0_x1 + * Fill in item_x0 and item_x1. */ void menubar_c::compute_x0_x1() { @@ -361,50 +361,50 @@ int n; if (stale_coords) - fatal_error("Called compute_x0_x1 before compute_coords"); + fatal_error("Called compute_x0_x1 before compute_coords"); x_left = menubar_text_x0; x_right = menubar_text_x1; for (n = 0; n < nitems; n++) { - int item_width = 2 * spacing + strlen(item_text[n]) * FONTW; + int item_width = 2 * spacing + strlen(item_text[n]) * FONTW; - /* This item is right-aligned ? - Place it to the left of the last right-aligned item. */ - if (item_right_aligned[n]) - { - item_x1[n] = x_right; - x_right -= item_width; - item_x0[n] = x_right + 1; - } + /* This item is right-aligned ? + Place it to the left of the last right-aligned item. */ + if (item_right_aligned[n]) + { + item_x1[n] = x_right; + x_right -= item_width; + item_x0[n] = x_right + 1; + } - /* It's left-aligned. - Place it to the right of the last left-aligned item. */ - else - { - item_x0[n] = x_left; - x_left += item_width; - item_x1[n] = x_left - 1; - } + /* It's left-aligned. + Place it to the right of the last left-aligned item. */ + else + { + item_x0[n] = x_left; + x_left += item_width; + item_x1[n] = x_left - 1; + } } stale_x0_x1 = 0; } /* - * menubar_item_coords - * Returns coordinates of top left corner of a pulled down - * menu. - * This function will be removed when menus are pulled down - * by menubar.cc itself. + * menubar_item_coords + * Returns coordinates of top left corner of a pulled down + * menu. + * This function will be removed when menus are pulled down + * by menubar.cc itself. */ void menubar_c::menubar_item_coords(int item_no, int *x, int *y) { if (item_no < 0 || item_no >= nitems) - fatal_error("menubar_item_coords passed bad item no. %d", item_no); + fatal_error("menubar_item_coords passed bad item no. %d", item_no); if (stale_coords) - fatal_error("Called menubar_item_coords before compute_coords"); + fatal_error("Called menubar_item_coords before compute_coords"); if (stale_x0_x1) - compute_x0_x1(); + compute_x0_x1(); *x = item_x0[item_no]; *y = menubar_out_y1 + 1; } diff -r 594dea11ccd9 -r a68786b9c74b src/menubar.h --- a/src/menubar.h Sat Sep 24 15:01:56 2011 +0300 +++ b/src/menubar.h Sat Sep 24 15:59:33 2011 +0300 @@ -1,7 +1,7 @@ /* - * menubar.h - * Header for menubar.c - * AYM 1998-08-21 + * menubar.h + * Header for menubar.c + * AYM 1998-08-21 */ @@ -53,7 +53,7 @@ public: menubar_c(); int add_item(const char *text, int shortcut_index, int right_aligned, - Menu * menu); + Menu * menu); void set_menu(int number, Menu * menu); Menu *get_menu(int number); void compute_menubar_coords(int scrx0, int scrx1, int scry0, int scry1); @@ -71,17 +71,17 @@ void draw(); void undraw() { - } // I can't undraw myself + } // I can't undraw myself int can_undraw() { - return 0; - } // I can't undraw myself + return 0; + } // I can't undraw myself int need_to_clear() { - return bar_visible_disp && !bar_visible - || pulled_down_no_disp && !pulled_down_no - || pulled_down_menu_disp != pulled_down_menu; + return bar_visible_disp && !bar_visible + || pulled_down_no_disp && !pulled_down_no + || pulled_down_menu_disp != pulled_down_menu; } void clear(); @@ -89,38 +89,38 @@ private: void compute_x0_x1(); - int spacing; // Horizontal spacing around item name + int spacing; // Horizontal spacing around item name - int stale_coords; // Should menubar_* be recalculated ? - int menubar_out_x0; // Edge of the menu bar, includ. border + int stale_coords; // Should menubar_* be recalculated ? + int menubar_out_x0; // Edge of the menu bar, includ. border int menubar_out_x1; int menubar_out_y0; int menubar_out_y1; - int menubar_in_x0; // Edge of the menu bar, exclud. border + int menubar_in_x0; // Edge of the menu bar, exclud. border int menubar_in_x1; int menubar_in_y0; int menubar_in_y1; - int menubar_text_x0; // Edge of the text area of the menu bar + int menubar_text_x0; // Edge of the text area of the menu bar int menubar_text_x1; int menubar_text_y0; int menubar_text_y1; - int nitems; // Number of items - const char *item_text[MAX_ITEMS]; // Definition of items + int nitems; // Number of items + const char *item_text[MAX_ITEMS]; // Definition of items int item_shortcut_index[MAX_ITEMS]; int item_right_aligned[MAX_ITEMS]; Menu *item_menu[MAX_ITEMS]; - int stale_x0_x1; // Should item_x? be recalculated ? - int item_x0[MAX_ITEMS]; // Left edge of items, includ. spacing - int item_x1[MAX_ITEMS]; // Right edge of items, includ. spacing + int stale_x0_x1; // Should item_x? be recalculated ? + int item_x0[MAX_ITEMS]; // Left edge of items, includ. spacing + int item_x1[MAX_ITEMS]; // Right edge of items, includ. spacing - int bar_visible; // Should the bar be visible ? - int bar_visible_disp; // Is the bar actually visible ? - int highlighted_no; // # of the item that should be h.l. - int highlighted_no_disp; // # of the item that is actually h.l. - int pulled_down_no; // # of menu that should be p.d. - int pulled_down_no_disp; // # of menu that is actually p.d. - Menu *pulled_down_menu; // Menu that should be p.d. - Menu *pulled_down_menu_disp; // Menu that is actually p.d. + int bar_visible; // Should the bar be visible ? + int bar_visible_disp; // Is the bar actually visible ? + int highlighted_no; // # of the item that should be h.l. + int highlighted_no_disp; // # of the item that is actually h.l. + int pulled_down_no; // # of menu that should be p.d. + int pulled_down_no_disp; // # of menu that is actually p.d. + Menu *pulled_down_menu; // Menu that should be p.d. + Menu *pulled_down_menu_disp; // Menu that is actually p.d. }; diff -r 594dea11ccd9 -r a68786b9c74b src/menudata.h --- a/src/menudata.h Sat Sep 24 15:01:56 2011 +0300 +++ b/src/menudata.h Sat Sep 24 15:59:33 2011 +0300 @@ -1,6 +1,6 @@ /* - * menudata.h - Menu_data abstract base class - * AYM 2002-05-09 + * menudata.h - Menu_data abstract base class + * AYM 2002-05-09 */ @@ -27,7 +27,7 @@ */ -#ifndef YH_MENUDATA /* DO NOT INSERT ANYTHING BEFORE THIS LINE */ +#ifndef YH_MENUDATA /* DO NOT INSERT ANYTHING BEFORE THIS LINE */ #define YH_MENUDATA diff -r 594dea11ccd9 -r a68786b9c74b src/mkpalette.cc --- a/src/mkpalette.cc Sat Sep 24 15:01:56 2011 +0300 +++ b/src/mkpalette.cc Sat Sep 24 15:59:33 2011 +0300 @@ -1,7 +1,7 @@ /* - * mkpalette.cc - * Generate palette files from lump PLAYPAL. - * AYM 1998-12-29 + * mkpalette.cc + * Generate palette files from lump PLAYPAL. + * AYM 1998-12-29 */ @@ -37,10 +37,10 @@ /* - * make_gimp_palette - * Generate a Gimp palette file for the <playpalnum>th - * palette in the PLAYPAL entry. - * Return 0 on success, non-zero on failure. + * make_gimp_palette + * Generate a Gimp palette file for the <playpalnum>th + * palette in the PLAYPAL entry. + * Return 0 on success, non-zero on failure. */ int make_gimp_palette(int playpalnum, const char *filename) { @@ -53,64 +53,64 @@ dir = FindMasterDir(MasterDir, lump_name); if (dir == 0) { - warn("%s: lump not found\n", lump_name); - return 1; + warn("%s: lump not found\n", lump_name); + return 1; } int playpal_count = dir->dir.size / (3 * DOOM_COLOURS); if (playpalnum < 0 || playpalnum >= playpal_count) { - warn("playpalnum %d out of range (0-%d), using #0 instead\n", - playpalnum, playpal_count - 1); - playpalnum = 0; + warn("playpalnum %d out of range (0-%d), using #0 instead\n", + playpalnum, playpal_count - 1); + playpalnum = 0; } output_fp = fopen(filename, "w"); if (output_fp == 0) { - warn("%s: %s\n", filename, strerror(errno)); - return 1; + warn("%s: %s\n", filename, strerror(errno)); + return 1; } fprintf(output_fp, - "GIMP Palette\n" "# Generated by Yadex %s\n", yadex_version); + "GIMP Palette\n" "# Generated by Yadex %s\n", yadex_version); dpal = (u8 *) GetMemory(3 * DOOM_COLOURS); const Wad_file *wf = dir->wadfile; wf->seek(dir->dir.start + (long) playpalnum * 3 * DOOM_COLOURS); if (wf->error()) { - err("%s: seek error", lump_name); - rc = 1; - goto byebye; + err("%s: seek error", lump_name); + rc = 1; + goto byebye; } wf->read_bytes(dpal, 3 * DOOM_COLOURS); if (wf->error()) { - err("%s: read error", lump_name); - rc = 1; - goto byebye; + err("%s: read error", lump_name); + rc = 1; + goto byebye; } for (size_t n = 0; n < DOOM_COLOURS; n++) - fprintf(output_fp, - "%3d %3d %3d Index = %d (%02Xh) RGB = %d, %d, %d\n", - dpal[3 * n], dpal[3 * n + 1], dpal[3 * n + 2], n, n, - dpal[3 * n], dpal[3 * n + 1], dpal[3 * n + 2]); + fprintf(output_fp, + "%3d %3d %3d Index = %d (%02Xh) RGB = %d, %d, %d\n", + dpal[3 * n], dpal[3 * n + 1], dpal[3 * n + 2], n, n, + dpal[3 * n], dpal[3 * n + 1], dpal[3 * n + 2]); byebye: if (dpal != 0) - FreeMemory(dpal); + FreeMemory(dpal); if (output_fp != 0) - if (fclose(output_fp)) - return 1; + if (fclose(output_fp)) + return 1; return rc; } /* - * make_palette_ppm - * Generate a 256 x 128 raw PPM image showing all the - * colours in the palette. - * Return 0 on success, non-zero on failure. + * make_palette_ppm + * Generate a 256 x 128 raw PPM image showing all the + * colours in the palette. + * Return 0 on success, non-zero on failure. */ int make_palette_ppm(int playpalnum, const char *filename) { @@ -123,23 +123,23 @@ dir = FindMasterDir(MasterDir, lump_name); if (dir == 0) { - warn("%s: lump not found\n", lump_name); - return 1; + warn("%s: lump not found\n", lump_name); + return 1; } int playpal_count = dir->dir.size / (3 * DOOM_COLOURS); if (playpalnum < 0 || playpalnum >= playpal_count) { - warn("playpalnum %d out of range (0-%d), using #0 instead\n", - playpalnum, playpal_count - 1); - playpalnum = 0; + warn("playpalnum %d out of range (0-%d), using #0 instead\n", + playpalnum, playpal_count - 1); + playpalnum = 0; } output_fp = fopen(filename, "wb"); if (output_fp == 0) { - warn("%s: %s\n", filename, strerror(errno)); - return 1; + warn("%s: %s\n", filename, strerror(errno)); + return 1; } const int width = 128; @@ -152,7 +152,7 @@ fnewline(output_fp); fprintf(output_fp, "%d %d", width, height); fnewline(output_fp); - fputs("255\n", output_fp); // Always \n (must be a single character) + fputs("255\n", output_fp); // Always \n (must be a single character) int rect_w = width / columns; int rect_h = height / (DOOM_COLOURS / columns); @@ -162,49 +162,49 @@ wf->seek(dir->dir.start + (long) playpalnum * 3 * DOOM_COLOURS); if (wf->error()) { - err("%s: seek error", lump_name); - rc = 1; - goto byebye; + err("%s: seek error", lump_name); + rc = 1; + goto byebye; } wf->read_bytes(dpal, 3 * DOOM_COLOURS); if (wf->error()) { - err("%s: read error", lump_name); - rc = 1; - goto byebye; + err("%s: read error", lump_name); + rc = 1; + goto byebye; } for (size_t n = 0; n < DOOM_COLOURS; n += columns) - for (int subrow = 0; subrow < rect_h; subrow++) - for (int c = 0; c < columns; c++) - for (int subcol = 0; subcol < rect_w; subcol++) - { - if (subrow == 0 && subcol == 0) - { - putc(0, output_fp); - putc(0, output_fp); - putc(0, output_fp); - } - else - { - putc(dpal[3 * (n + c)], output_fp); - putc(dpal[3 * (n + c) + 1], output_fp); - putc(dpal[3 * (n + c) + 2], output_fp); - } - } + for (int subrow = 0; subrow < rect_h; subrow++) + for (int c = 0; c < columns; c++) + for (int subcol = 0; subcol < rect_w; subcol++) + { + if (subrow == 0 && subcol == 0) + { + putc(0, output_fp); + putc(0, output_fp); + putc(0, output_fp); + } + else + { + putc(dpal[3 * (n + c)], output_fp); + putc(dpal[3 * (n + c) + 1], output_fp); + putc(dpal[3 * (n + c) + 2], output_fp); + } + } byebye: if (dpal != 0) - FreeMemory(dpal); + FreeMemory(dpal); if (output_fp != 0) - if (fclose(output_fp)) - return 1; + if (fclose(output_fp)) + return 1; return rc; } /* - * make_palette_ppm_2 - * Make a wide PPM containing all the colours in the palette + * make_palette_ppm_2 + * Make a wide PPM containing all the colours in the palette */ int make_palette_ppm_2(int playpalnum, const char *filename) @@ -218,23 +218,23 @@ dir = FindMasterDir(MasterDir, lump_name); if (dir == 0) { - warn("%s: lump not found", lump_name); - return 1; + warn("%s: lump not found", lump_name); + return 1; } int playpal_count = dir->dir.size / (3 * DOOM_COLOURS); if (playpalnum < 0 || playpalnum >= playpal_count) { - warn("playpalnum %d out of range (0-%d), using #0 instead", - playpalnum, playpal_count - 1); - playpalnum = 0; + warn("playpalnum %d out of range (0-%d), using #0 instead", + playpalnum, playpal_count - 1); + playpalnum = 0; } output_fp = fopen(filename, "wb"); if (output_fp == 0) { - warn("%s: %s\n", filename, strerror(errno)); - return 1; + warn("%s: %s\n", filename, strerror(errno)); + return 1; } const int width = DOOM_COLOURS; @@ -246,37 +246,37 @@ fnewline(output_fp); fprintf(output_fp, "%d %d", width, height); fnewline(output_fp); - fputs("255\n", output_fp); // Always \n (must be a single character) + fputs("255\n", output_fp); // Always \n (must be a single character) dpal = (u8 *) GetMemory(3 * DOOM_COLOURS); const Wad_file *wf = dir->wadfile; wf->seek(dir->dir.start + (long) playpalnum * 3 * DOOM_COLOURS); if (wf->error()) { - err("%s: seek error", lump_name); - rc = 1; - goto byebye; + err("%s: seek error", lump_name); + rc = 1; + goto byebye; } wf->read_bytes(dpal, 3 * DOOM_COLOURS); if (wf->error()) { - err("%s: read error", lump_name); - rc = 1; - goto byebye; + err("%s: read error", lump_name); + rc = 1; + goto byebye; } for (int l = 0; l < height; l++) - for (int c = 0; c < width; c++) - { - putc(dpal[3 * ((c + l) % DOOM_COLOURS)], output_fp); - putc(dpal[3 * ((c + l) % DOOM_COLOURS) + 1], output_fp); - putc(dpal[3 * ((c + l) % DOOM_COLOURS) + 2], output_fp); - } + for (int c = 0; c < width; c++) + { + putc(dpal[3 * ((c + l) % DOOM_COLOURS)], output_fp); + putc(dpal[3 * ((c + l) % DOOM_COLOURS) + 1], output_fp); + putc(dpal[3 * ((c + l) % DOOM_COLOURS) + 2], output_fp); + } byebye: if (dpal != 0) - FreeMemory(dpal); + FreeMemory(dpal); if (output_fp != 0) - if (fclose(output_fp)) - return 1; + if (fclose(output_fp)) + return 1; return rc; } diff -r 594dea11ccd9 -r a68786b9c74b src/mkpalette.h --- a/src/mkpalette.h Sat Sep 24 15:01:56 2011 +0300 +++ b/src/mkpalette.h Sat Sep 24 15:59:33 2011 +0300 @@ -1,7 +1,7 @@ /* - * mkpalette.h - * Make palette files from lump PLAYPAL - * AYM 1998-12-29 + * mkpalette.h + * Make palette files from lump PLAYPAL + * AYM 1998-12-29 */ diff -r 594dea11ccd9 -r a68786b9c74b src/modpopup.h --- a/src/modpopup.h Sat Sep 24 15:01:56 2011 +0300 +++ b/src/modpopup.h Sat Sep 24 15:59:33 2011 +0300 @@ -1,8 +1,8 @@ /* - * modpopup.h - * The modpopup_c class: a modal popup menu widget. - * Basically a wrapper for the Menu class. - * AYM 1998-12-16 + * modpopup.h + * The modpopup_c class: a modal popup menu widget. + * Basically a wrapper for the Menu class. + * AYM 1998-12-16 */ @@ -36,37 +36,37 @@ class modpopup_c:public edwidget_c { public: - /* - * EditorLoop() side methods - */ + /* + * EditorLoop() side methods + */ modpopup_c() { - menu = 0; - menu_disp = 0; + menu = 0; + menu_disp = 0; } void set(Menu * menu, int force_numbers) { - if (menu_disp) - menu_disp->set_visible(0); - this->menu = menu; - menu->set_popup(1); - menu->set_force_numbers(force_numbers); - menu->set_coords(-1, -1); - menu->set_item_no(0); - menu->set_visible(1); + if (menu_disp) + menu_disp->set_visible(0); + this->menu = menu; + menu->set_popup(1); + menu->set_force_numbers(force_numbers); + menu->set_coords(-1, -1); + menu->set_item_no(0); + menu->set_visible(1); } void unset() { - if (menu_disp) - menu_disp->set_visible(0); - menu = 0; + if (menu_disp) + menu_disp->set_visible(0); + menu = 0; } Menu *get() { - return menu; + return menu; } /* @@ -74,42 +74,42 @@ */ void draw() { - if (menu) - { - menu->draw(); - menu_disp = menu; - } + if (menu) + { + menu->draw(); + menu_disp = menu; + } } void undraw() { - if (menu_disp) - { - menu_disp->undraw(); - //menu_disp = 0; - } + if (menu_disp) + { + menu_disp->undraw(); + //menu_disp = 0; + } } int can_undraw() { - if (menu_disp) - return menu_disp->can_undraw(); - else - return 1; + if (menu_disp) + return menu_disp->can_undraw(); + else + return 1; } int need_to_clear() { - if (menu_disp) - return menu_disp->need_to_clear(); - else - return 0; + if (menu_disp) + return menu_disp->need_to_clear(); + else + return 0; } void clear() { - if (menu_disp) - menu_disp->clear(); + if (menu_disp) + menu_disp->clear(); } private: diff -r 594dea11ccd9 -r a68786b9c74b src/names.cc --- a/src/names.cc Sat Sep 24 15:01:56 2011 +0300 +++ b/src/names.cc Sat Sep 24 15:59:33 2011 +0300 @@ -1,6 +1,6 @@ /* - * names.cc - * BW & RQ sometime in 1993 or 1994. + * names.cc + * BW & RQ sometime in 1993 or 1994. */ @@ -40,25 +40,25 @@ switch (objtype) { case OBJ_THINGS: - return "thing"; + return "thing"; case OBJ_LINEDEFS: - return "linedef"; + return "linedef"; case OBJ_SIDEDEFS: - return "sidedef"; + return "sidedef"; case OBJ_VERTICES: - return "vertex"; + return "vertex"; case OBJ_SEGS: - return "segment"; + return "segment"; case OBJ_SSECTORS: - return "ssector"; + return "ssector"; case OBJ_NODES: - return "node"; + return "node"; case OBJ_SECTORS: - return "sector"; + return "sector"; case OBJ_REJECT: - return "reject"; + return "reject"; case OBJ_BLOCKMAP: - return "blockmap"; + return "blockmap"; } return "< Bug! >"; } @@ -73,20 +73,20 @@ switch (objtype) { case OBJ_THINGS: - return "Things"; + return "Things"; case OBJ_LINEDEFS: case OBJ_SIDEDEFS: - return "LD & SD"; + return "LD & SD"; case OBJ_VERTICES: - return "Vertices"; + return "Vertices"; case OBJ_SEGS: - return "Segments"; + return "Segments"; case OBJ_SSECTORS: - return "Seg-Sectors"; + return "Seg-Sectors"; case OBJ_NODES: - return "Nodes"; + return "Nodes"; case OBJ_SECTORS: - return "Sectors"; + return "Sectors"; } return "< Bug! >"; } @@ -100,10 +100,10 @@ const char *GetLineDefTypeName(int type) { if (CUR_LDTDEF != NULL && CUR_LDTDEF->number == type) - return CUR_LDTDEF->shortdesc; + return CUR_LDTDEF->shortdesc; for (al_lrewind(ldtdef); !al_leol(ldtdef); al_lstep(ldtdef)) - if (CUR_LDTDEF->number == type) - return CUR_LDTDEF->shortdesc; + if (CUR_LDTDEF->number == type) + return CUR_LDTDEF->shortdesc; return "?? UNKNOWN"; } @@ -123,12 +123,12 @@ char *p = buf; for (n = 0; n < 16; n++) { - if (n != 0 && n % 4 == 0) - *p++ = ' '; - if (flags & (0x8000u >> n)) - *p++ = flag_chars[n]; - else - *p++ = '-'; + if (n != 0 && n % 4 == 0) + *p++ = ' '; + if (flags & (0x8000u >> n)) + *p++ = flag_chars[n]; + else + *p++ = '-'; } *p = '\0'; return buf; @@ -136,45 +136,45 @@ #if 0 static char temp[20]; if (flags & 0x0100) - strcpy(temp, "A"); /* Already on the map (Ma) */ + strcpy(temp, "A"); /* Already on the map (Ma) */ else - strcpy(temp, "-"); + strcpy(temp, "-"); if (flags & 0x80) - strcat(temp, "V"); /* Invisible on the map (In) */ + strcat(temp, "V"); /* Invisible on the map (In) */ else - strcat(temp, "-"); + strcat(temp, "-"); if (flags & 0x40) - strcat(temp, "B"); /* Blocks sound (So) */ + strcat(temp, "B"); /* Blocks sound (So) */ else - strcat(temp, "-"); + strcat(temp, "-"); if (flags & 0x20) - strcat(temp, "S"); /* Secret (normal on the map) (Se) */ + strcat(temp, "S"); /* Secret (normal on the map) (Se) */ else - strcat(temp, "-"); + strcat(temp, "-"); if (flags & 0x10) - strcat(temp, "L"); /* Lower texture offset changed (Lo) */ + strcat(temp, "L"); /* Lower texture offset changed (Lo) */ else - strcat(temp, "-"); + strcat(temp, "-"); if (flags & 0x08) - strcat(temp, "U"); /* Upper texture offset changed (Up) */ + strcat(temp, "U"); /* Upper texture offset changed (Up) */ else - strcat(temp, "-"); + strcat(temp, "-"); if (flags & 0x04) - strcat(temp, "2"); /* Two-sided (2S) */ + strcat(temp, "2"); /* Two-sided (2S) */ else - strcat(temp, "-"); + strcat(temp, "-"); if (flags & 0x02) - strcat(temp, "M"); /* Monsters can't cross this line (Mo) */ + strcat(temp, "M"); /* Monsters can't cross this line (Mo) */ else - strcat(temp, "-"); + strcat(temp, "-"); if (flags & 0x01) - strcat(temp, "I"); /* Impassible (Im) */ + strcat(temp, "I"); /* Impassible (Im) */ else - strcat(temp, "-"); + strcat(temp, "-"); if (strlen(temp) > 13) { - temp[13] = '|'; - temp[14] = '\0'; + temp[13] = '|'; + temp[14] = '\0'; } return temp; #endif @@ -189,27 +189,27 @@ const char *GetLineDefFlagsLongName(int flags) { if (flags & 0x1000) - return "Translucent [Strife]"; + return "Translucent [Strife]"; if (flags & 0x200) - return "Pass-through [Boom]"; + return "Pass-through [Boom]"; if (flags & 0x100) - return "Always shown on the map"; + return "Always shown on the map"; if (flags & 0x80) - return "Never shown on the map"; + return "Never shown on the map"; if (flags & 0x40) - return "Blocks sound"; + return "Blocks sound"; if (flags & 0x20) - return "Secret (shown as normal on the map)"; + return "Secret (shown as normal on the map)"; if (flags & 0x10) - return "Lower texture is \"unpegged\""; + return "Lower texture is \"unpegged\""; if (flags & 0x08) - return "Upper texture is \"unpegged\""; + return "Upper texture is \"unpegged\""; if (flags & 0x04) - return "Two-sided (may be transparent)"; + return "Two-sided (may be transparent)"; if (flags & 0x02) - return "Monsters cannot cross this line"; + return "Monsters cannot cross this line"; if (flags & 0x01) - return "Impassible"; + return "Impassible"; return "UNKNOWN"; } @@ -223,13 +223,13 @@ { /* KLUDGE: To avoid the last element which is bogus */ if (al_ltell(stdef) == al_lcount(stdef) - 1) - al_lrewind(stdef); + al_lrewind(stdef); if (CUR_STDEF != NULL && CUR_STDEF->number == type) - return CUR_STDEF->shortdesc; + return CUR_STDEF->shortdesc; for (al_lrewind(stdef); !al_leol(stdef); al_lstep(stdef)) - if (CUR_STDEF->number == type) - return CUR_STDEF->shortdesc; + if (CUR_STDEF->number == type) + return CUR_STDEF->shortdesc; static char buf[30]; sprintf(buf, "UNKNOWN (%d)", type); return buf; @@ -245,13 +245,13 @@ { /* KLUDGE: To avoid the last element which is bogus */ if (al_ltell(stdef) == al_lcount(stdef) - 1) - al_lrewind(stdef); + al_lrewind(stdef); if (CUR_STDEF != NULL && CUR_STDEF->number == type) - return CUR_STDEF->longdesc; + return CUR_STDEF->longdesc; for (al_lrewind(stdef); !al_leol(stdef); al_lstep(stdef)) - if (CUR_STDEF->number == type) - return CUR_STDEF->longdesc; + if (CUR_STDEF->number == type) + return CUR_STDEF->longdesc; static char buf[30]; sprintf(buf, "UNKNOWN (%d)", type); return buf; diff -r 594dea11ccd9 -r a68786b9c74b src/nop.cc --- a/src/nop.cc Sat Sep 24 15:01:56 2011 +0300 +++ b/src/nop.cc Sat Sep 24 15:59:33 2011 +0300 @@ -1,6 +1,6 @@ /* - * nop.cc - * AYM 1998-06-?? + * nop.cc + * AYM 1998-06-?? */ diff -r 594dea11ccd9 -r a68786b9c74b src/objects.cc --- a/src/objects.cc Sat Sep 24 15:01:56 2011 +0300 +++ b/src/objects.cc Sat Sep 24 15:59:33 2011 +0300 @@ -1,7 +1,7 @@ /* - * objects.cc - * Object handling routines. - * BW & RQ sometime in 1993 or 1994. + * objects.cc + * Object handling routines. + * BW & RQ sometime in 1993 or 1994. */ @@ -43,14 +43,14 @@ /* highlight the selected objects */ -void HighlightSelection(int objtype, SelPtr list) /* SWAP! */ +void HighlightSelection(int objtype, SelPtr list) /* SWAP! */ { SelPtr cur; if (!list) - return; + return; for (cur = list; cur; cur = cur->next) - HighlightObject(objtype, cur->objnum, GREEN); + HighlightObject(objtype, cur->objnum, GREEN); } @@ -63,15 +63,15 @@ switch (objtype) { case OBJ_THINGS: - return NumThings - 1; + return NumThings - 1; case OBJ_LINEDEFS: - return NumLineDefs - 1; + return NumLineDefs - 1; case OBJ_SIDEDEFS: - return NumSideDefs - 1; + return NumSideDefs - 1; case OBJ_VERTICES: - return NumVertices - 1; + return NumVertices - 1; case OBJ_SECTORS: - return NumSectors - 1; + return NumSectors - 1; } return -1; } @@ -80,7 +80,7 @@ /* highlight the selected object */ -void HighlightObject(int objtype, int objnum, int colour) /* SWAP! */ +void HighlightObject(int objtype, int objnum, int colour) /* SWAP! */ { int n, m; @@ -90,87 +90,87 @@ switch (objtype) { case OBJ_THINGS: - m = (get_thing_radius(Things[objnum].type) * 3) / 2; - DrawMapLine(Things[objnum].xpos - m, Things[objnum].ypos - m, - Things[objnum].xpos - m, Things[objnum].ypos + m); - DrawMapLine(Things[objnum].xpos - m, Things[objnum].ypos + m, - Things[objnum].xpos + m, Things[objnum].ypos + m); - DrawMapLine(Things[objnum].xpos + m, Things[objnum].ypos + m, - Things[objnum].xpos + m, Things[objnum].ypos - m); - DrawMapLine(Things[objnum].xpos + m, Things[objnum].ypos - m, - Things[objnum].xpos - m, Things[objnum].ypos - m); - DrawMapArrow(Things[objnum].xpos, Things[objnum].ypos, - Things[objnum].angle * 182); - break; + m = (get_thing_radius(Things[objnum].type) * 3) / 2; + DrawMapLine(Things[objnum].xpos - m, Things[objnum].ypos - m, + Things[objnum].xpos - m, Things[objnum].ypos + m); + DrawMapLine(Things[objnum].xpos - m, Things[objnum].ypos + m, + Things[objnum].xpos + m, Things[objnum].ypos + m); + DrawMapLine(Things[objnum].xpos + m, Things[objnum].ypos + m, + Things[objnum].xpos + m, Things[objnum].ypos - m); + DrawMapLine(Things[objnum].xpos + m, Things[objnum].ypos - m, + Things[objnum].xpos - m, Things[objnum].ypos - m); + DrawMapArrow(Things[objnum].xpos, Things[objnum].ypos, + Things[objnum].angle * 182); + break; case OBJ_LINEDEFS: - n = (Vertices[LineDefs[objnum].start].x - + Vertices[LineDefs[objnum].end].x) / 2; - m = (Vertices[LineDefs[objnum].start].y - + Vertices[LineDefs[objnum].end].y) / 2; - DrawMapLine(n, m, n + (Vertices[LineDefs[objnum].end].y - - Vertices[LineDefs[objnum].start].y) / 3, - m + (Vertices[LineDefs[objnum].start].x - - Vertices[LineDefs[objnum].end].x) / 3); - SetLineThickness(1); - DrawMapVector(Vertices[LineDefs[objnum].start].x, - Vertices[LineDefs[objnum].start].y, - Vertices[LineDefs[objnum].end].x, - Vertices[LineDefs[objnum].end].y); - if (colour != LIGHTRED && LineDefs[objnum].tag > 0) - { - for (m = 0; m < NumSectors; m++) - if (Sectors[m].tag == LineDefs[objnum].tag) - HighlightObject(OBJ_SECTORS, m, LIGHTRED); - } - SetLineThickness(0); - break; + n = (Vertices[LineDefs[objnum].start].x + + Vertices[LineDefs[objnum].end].x) / 2; + m = (Vertices[LineDefs[objnum].start].y + + Vertices[LineDefs[objnum].end].y) / 2; + DrawMapLine(n, m, n + (Vertices[LineDefs[objnum].end].y + - Vertices[LineDefs[objnum].start].y) / 3, + m + (Vertices[LineDefs[objnum].start].x + - Vertices[LineDefs[objnum].end].x) / 3); + SetLineThickness(1); + DrawMapVector(Vertices[LineDefs[objnum].start].x, + Vertices[LineDefs[objnum].start].y, + Vertices[LineDefs[objnum].end].x, + Vertices[LineDefs[objnum].end].y); + if (colour != LIGHTRED && LineDefs[objnum].tag > 0) + { + for (m = 0; m < NumSectors; m++) + if (Sectors[m].tag == LineDefs[objnum].tag) + HighlightObject(OBJ_SECTORS, m, LIGHTRED); + } + SetLineThickness(0); + break; case OBJ_VERTICES: - { - int r = vertex_radius(Scale) * 3 / 2; - int scrx0 = SCREENX(Vertices[objnum].x) - r; - int scrx9 = SCREENX(Vertices[objnum].x) + r; - int scry0 = SCREENY(Vertices[objnum].y) - r; - int scry9 = SCREENY(Vertices[objnum].y) + r; - DrawScreenLine(scrx0, scry0, scrx9, scry0); - DrawScreenLine(scrx9, scry0, scrx9, scry9); - DrawScreenLine(scrx9, scry9, scrx0, scry9); - DrawScreenLine(scrx0, scry9, scrx0, scry0); - } - break; + { + int r = vertex_radius(Scale) * 3 / 2; + int scrx0 = SCREENX(Vertices[objnum].x) - r; + int scrx9 = SCREENX(Vertices[objnum].x) + r; + int scry0 = SCREENY(Vertices[objnum].y) - r; + int scry9 = SCREENY(Vertices[objnum].y) + r; + DrawScreenLine(scrx0, scry0, scrx9, scry0); + DrawScreenLine(scrx9, scry0, scrx9, scry9); + DrawScreenLine(scrx9, scry9, scrx0, scry9); + DrawScreenLine(scrx0, scry9, scrx0, scry0); + } + break; case OBJ_SECTORS: - { - SetLineThickness(1); - const int mapx0 = MAPX(0); - const int mapy0 = MAPY(ScrMaxY); - const int mapx1 = MAPX(ScrMaxX); - const int mapy1 = MAPY(0); - for (n = 0; n < NumLineDefs; n++) - if (LineDefs[n].sidedef1 != -1 - && SideDefs[LineDefs[n].sidedef1].sector == objnum - || LineDefs[n].sidedef2 != -1 - && SideDefs[LineDefs[n].sidedef2].sector == objnum) - { - const struct Vertex *v1 = Vertices + LineDefs[n].start; - const struct Vertex *v2 = Vertices + LineDefs[n].end; - if (v1->x < mapx0 && v2->x < mapx0 - || v1->x > mapx1 && v2->x > mapx1 - || v1->y < mapy0 && v2->y < mapy0 - || v1->y > mapy1 && v2->y > mapy1) - continue; // Off-screen - DrawMapLine(v1->x, v1->y, v2->x, v2->y); - } - if (colour != LIGHTRED && Sectors[objnum].tag > 0) - { - for (m = 0; m < NumLineDefs; m++) - if (LineDefs[m].tag == Sectors[objnum].tag) - HighlightObject(OBJ_LINEDEFS, m, LIGHTRED); - } - SetLineThickness(0); - } - break; + { + SetLineThickness(1); + const int mapx0 = MAPX(0); + const int mapy0 = MAPY(ScrMaxY); + const int mapx1 = MAPX(ScrMaxX); + const int mapy1 = MAPY(0); + for (n = 0; n < NumLineDefs; n++) + if (LineDefs[n].sidedef1 != -1 + && SideDefs[LineDefs[n].sidedef1].sector == objnum + || LineDefs[n].sidedef2 != -1 + && SideDefs[LineDefs[n].sidedef2].sector == objnum) + { + const struct Vertex *v1 = Vertices + LineDefs[n].start; + const struct Vertex *v2 = Vertices + LineDefs[n].end; + if (v1->x < mapx0 && v2->x < mapx0 + || v1->x > mapx1 && v2->x > mapx1 + || v1->y < mapy0 && v2->y < mapy0 + || v1->y > mapy1 && v2->y > mapy1) + continue; // Off-screen + DrawMapLine(v1->x, v1->y, v2->x, v2->y); + } + if (colour != LIGHTRED && Sectors[objnum].tag > 0) + { + for (m = 0; m < NumLineDefs; m++) + if (LineDefs[m].tag == Sectors[objnum].tag) + HighlightObject(OBJ_LINEDEFS, m, LIGHTRED); + } + SetLineThickness(0); + } + break; } /* restore normal write mode */ SetDrawingMode(0); @@ -181,7 +181,7 @@ /* delete an object */ -void DeleteObject(const Objid & obj) /* SWAP! */ +void DeleteObject(const Objid & obj) /* SWAP! */ { SelPtr list; @@ -195,7 +195,7 @@ /* delete a group of objects (*recursive*) */ -void DeleteObjects(int objtype, SelPtr * list) /* SWAP! */ +void DeleteObjects(int objtype, SelPtr * list) /* SWAP! */ { int n, objnum; SelPtr cur; @@ -204,237 +204,237 @@ switch (objtype) { case OBJ_THINGS: - if (*list) - { - things_angles++; - things_types++; - } - while (*list) - { - objnum = (*list)->objnum; - if (objnum < 0 || objnum >= NumThings) // Paranoia - { - nf_bug("attempt to delete non-existent thing #%d", objnum); - goto next_thing; - } - // Delete the thing - NumThings--; - if (NumThings > 0) - { - for (n = objnum; n < NumThings; n++) - Things[n] = Things[n + 1]; - Things = (TPtr) ResizeMemory(Things, - NumThings * - sizeof(struct Thing)); - } - else - { - FreeMemory(Things); - Things = 0; - } - for (cur = (*list)->next; cur; cur = cur->next) - if (cur->objnum > objnum) - cur->objnum--; - next_thing: - UnSelectObject(list, objnum); - } - break; + if (*list) + { + things_angles++; + things_types++; + } + while (*list) + { + objnum = (*list)->objnum; + if (objnum < 0 || objnum >= NumThings) // Paranoia + { + nf_bug("attempt to delete non-existent thing #%d", objnum); + goto next_thing; + } + // Delete the thing + NumThings--; + if (NumThings > 0) + { + for (n = objnum; n < NumThings; n++) + Things[n] = Things[n + 1]; + Things = (TPtr) ResizeMemory(Things, + NumThings * + sizeof(struct Thing)); + } + else + { + FreeMemory(Things); + Things = 0; + } + for (cur = (*list)->next; cur; cur = cur->next) + if (cur->objnum > objnum) + cur->objnum--; + next_thing: + UnSelectObject(list, objnum); + } + break; case OBJ_VERTICES: - if (*list) - MadeMapChanges = 1; - while (*list) - { - objnum = (*list)->objnum; - if (objnum < 0 || objnum >= NumVertices) // Paranoia - { - nf_bug("attempt to delete non-existent vertex #%d", objnum); - goto next_vertex; - } - // Delete the linedefs bound to this vertex and change the references - for (n = 0; n < NumLineDefs; n++) - { - if (LineDefs[n].start == objnum || LineDefs[n].end == objnum) - DeleteObject(Objid(OBJ_LINEDEFS, n--)); - else - { - if (LineDefs[n].start >= objnum) - LineDefs[n].start--; - if (LineDefs[n].end >= objnum) - LineDefs[n].end--; - } - } - // Delete the vertex - NumVertices--; - if (NumVertices > 0) - { - for (n = objnum; n < NumVertices; n++) - Vertices[n] = Vertices[n + 1]; - Vertices = (VPtr) ResizeMemory(Vertices, - NumVertices * - sizeof(struct Vertex)); - } - else - { - FreeMemory(Vertices); - Vertices = 0; - } - for (cur = (*list)->next; cur; cur = cur->next) - if (cur->objnum > objnum) - cur->objnum--; - next_vertex: - UnSelectObject(list, objnum); - } - break; + if (*list) + MadeMapChanges = 1; + while (*list) + { + objnum = (*list)->objnum; + if (objnum < 0 || objnum >= NumVertices) // Paranoia + { + nf_bug("attempt to delete non-existent vertex #%d", objnum); + goto next_vertex; + } + // Delete the linedefs bound to this vertex and change the references + for (n = 0; n < NumLineDefs; n++) + { + if (LineDefs[n].start == objnum || LineDefs[n].end == objnum) + DeleteObject(Objid(OBJ_LINEDEFS, n--)); + else + { + if (LineDefs[n].start >= objnum) + LineDefs[n].start--; + if (LineDefs[n].end >= objnum) + LineDefs[n].end--; + } + } + // Delete the vertex + NumVertices--; + if (NumVertices > 0) + { + for (n = objnum; n < NumVertices; n++) + Vertices[n] = Vertices[n + 1]; + Vertices = (VPtr) ResizeMemory(Vertices, + NumVertices * + sizeof(struct Vertex)); + } + else + { + FreeMemory(Vertices); + Vertices = 0; + } + for (cur = (*list)->next; cur; cur = cur->next) + if (cur->objnum > objnum) + cur->objnum--; + next_vertex: + UnSelectObject(list, objnum); + } + break; case OBJ_LINEDEFS: - /* In DEU, deleting a linedef was not considered to be a - map change. Deleting a _sidedef_ was. In Yadex, - sidedefs are not automatically deleted when the linedef - is because some sidedefs are shared by more than one - linedef. So we need to set MadeMapChanges here. */ - if (*list) - MadeMapChanges = 1; - /* AYM 19980203 I've removed the deletion of sidedefs - because if several linedefs use the same sidedef, this - would lead to trouble. Instead, I let the xref checking - take care of that. */ - while (*list) - { - objnum = (*list)->objnum; - if (objnum < 0 || objnum >= NumLineDefs) // Paranoia - { - nf_bug("attempt to delete non-existent linedef #%d", objnum); - goto next_linedef; - } - // delete the linedef - NumLineDefs--; - if (NumLineDefs > 0) - { - for (n = objnum; n < NumLineDefs; n++) - LineDefs[n] = LineDefs[n + 1]; - LineDefs = (LDPtr) ResizeMemory(LineDefs, - NumLineDefs * - sizeof(struct LineDef)); - } - else - { - FreeMemory(LineDefs); - LineDefs = 0; - } - for (cur = (*list)->next; cur; cur = cur->next) - if (cur->objnum > objnum) - cur->objnum--; - next_linedef: - UnSelectObject(list, objnum); - } - break; + /* In DEU, deleting a linedef was not considered to be a + map change. Deleting a _sidedef_ was. In Yadex, + sidedefs are not automatically deleted when the linedef + is because some sidedefs are shared by more than one + linedef. So we need to set MadeMapChanges here. */ + if (*list) + MadeMapChanges = 1; + /* AYM 19980203 I've removed the deletion of sidedefs + because if several linedefs use the same sidedef, this + would lead to trouble. Instead, I let the xref checking + take care of that. */ + while (*list) + { + objnum = (*list)->objnum; + if (objnum < 0 || objnum >= NumLineDefs) // Paranoia + { + nf_bug("attempt to delete non-existent linedef #%d", objnum); + goto next_linedef; + } + // delete the linedef + NumLineDefs--; + if (NumLineDefs > 0) + { + for (n = objnum; n < NumLineDefs; n++) + LineDefs[n] = LineDefs[n + 1]; + LineDefs = (LDPtr) ResizeMemory(LineDefs, + NumLineDefs * + sizeof(struct LineDef)); + } + else + { + FreeMemory(LineDefs); + LineDefs = 0; + } + for (cur = (*list)->next; cur; cur = cur->next) + if (cur->objnum > objnum) + cur->objnum--; + next_linedef: + UnSelectObject(list, objnum); + } + break; case OBJ_SIDEDEFS: - if (*list) - MadeMapChanges = 1; - while (*list) - { - objnum = (*list)->objnum; - if (objnum < 0 || objnum >= NumSideDefs) // Paranoia - { - nf_bug("attempt to delete non-existent sidedef #%d", objnum); - goto next_sidedef; - } - /* change the linedefs references */ - for (n = 0; n < NumLineDefs; n++) - { - if (LineDefs[n].sidedef1 == objnum) - LineDefs[n].sidedef1 = -1; - else if (LineDefs[n].sidedef1 >= objnum) - LineDefs[n].sidedef1--; - if (LineDefs[n].sidedef2 == objnum) - LineDefs[n].sidedef2 = -1; - else if (LineDefs[n].sidedef2 >= objnum) - LineDefs[n].sidedef2--; - } - /* delete the sidedef */ - NumSideDefs--; - if (NumSideDefs > 0) - { - for (n = objnum; n < NumSideDefs; n++) - SideDefs[n] = SideDefs[n + 1]; - SideDefs = (SDPtr) ResizeMemory(SideDefs, - NumSideDefs * - sizeof(struct SideDef)); - } - else - { - FreeMemory(SideDefs); - SideDefs = 0; - } - for (cur = (*list)->next; cur; cur = cur->next) - if (cur->objnum > objnum) - cur->objnum--; - next_sidedef: - UnSelectObject(list, objnum); - } - break; + if (*list) + MadeMapChanges = 1; + while (*list) + { + objnum = (*list)->objnum; + if (objnum < 0 || objnum >= NumSideDefs) // Paranoia + { + nf_bug("attempt to delete non-existent sidedef #%d", objnum); + goto next_sidedef; + } + /* change the linedefs references */ + for (n = 0; n < NumLineDefs; n++) + { + if (LineDefs[n].sidedef1 == objnum) + LineDefs[n].sidedef1 = -1; + else if (LineDefs[n].sidedef1 >= objnum) + LineDefs[n].sidedef1--; + if (LineDefs[n].sidedef2 == objnum) + LineDefs[n].sidedef2 = -1; + else if (LineDefs[n].sidedef2 >= objnum) + LineDefs[n].sidedef2--; + } + /* delete the sidedef */ + NumSideDefs--; + if (NumSideDefs > 0) + { + for (n = objnum; n < NumSideDefs; n++) + SideDefs[n] = SideDefs[n + 1]; + SideDefs = (SDPtr) ResizeMemory(SideDefs, + NumSideDefs * + sizeof(struct SideDef)); + } + else + { + FreeMemory(SideDefs); + SideDefs = 0; + } + for (cur = (*list)->next; cur; cur = cur->next) + if (cur->objnum > objnum) + cur->objnum--; + next_sidedef: + UnSelectObject(list, objnum); + } + break; case OBJ_SECTORS: - while (*list) - { - objnum = (*list)->objnum; - if (objnum < 0 || objnum >= NumSectors) // Paranoia - { - nf_bug("attempt to delete non-existent sector #%d", objnum); - goto next_sector; - } - // Delete the sidedefs bound to this sector and change the references - // AYM 19980203: Hmm, hope this is OK with multiply used sidedefs... - for (n = 0; n < NumSideDefs; n++) - if (SideDefs[n].sector == objnum) - DeleteObject(Objid(OBJ_SIDEDEFS, n--)); - else if (SideDefs[n].sector >= objnum) - SideDefs[n].sector--; - /* delete the sector */ - NumSectors--; - if (NumSectors > 0) - { - for (n = objnum; n < NumSectors; n++) - Sectors[n] = Sectors[n + 1]; - Sectors = (SPtr) ResizeMemory(Sectors, - NumSectors * - sizeof(struct Sector)); - } - else - { - FreeMemory(Sectors); - Sectors = 0; - } - for (cur = (*list)->next; cur; cur = cur->next) - if (cur->objnum > objnum) - cur->objnum--; - next_sector: - UnSelectObject(list, objnum); - } - break; + while (*list) + { + objnum = (*list)->objnum; + if (objnum < 0 || objnum >= NumSectors) // Paranoia + { + nf_bug("attempt to delete non-existent sector #%d", objnum); + goto next_sector; + } + // Delete the sidedefs bound to this sector and change the references + // AYM 19980203: Hmm, hope this is OK with multiply used sidedefs... + for (n = 0; n < NumSideDefs; n++) + if (SideDefs[n].sector == objnum) + DeleteObject(Objid(OBJ_SIDEDEFS, n--)); + else if (SideDefs[n].sector >= objnum) + SideDefs[n].sector--; + /* delete the sector */ + NumSectors--; + if (NumSectors > 0) + { + for (n = objnum; n < NumSectors; n++) + Sectors[n] = Sectors[n + 1]; + Sectors = (SPtr) ResizeMemory(Sectors, + NumSectors * + sizeof(struct Sector)); + } + else + { + FreeMemory(Sectors); + Sectors = 0; + } + for (cur = (*list)->next; cur; cur = cur->next) + if (cur->objnum > objnum) + cur->objnum--; + next_sector: + UnSelectObject(list, objnum); + } + break; default: - nf_bug("DeleteObjects: bad objtype %d", (int) objtype); + nf_bug("DeleteObjects: bad objtype %d", (int) objtype); } } /* - * InsertObject - * Insert a new object of type <objtype> at map coordinates - * (<xpos>, <ypos>). + * InsertObject + * Insert a new object of type <objtype> at map coordinates + * (<xpos>, <ypos>). * - * If <copyfrom> is a valid object number, the other properties - * of the new object are set from the properties of that object, - * with the exception of sidedef numbers, which are forced - * to OBJ_NO_NONE. + * If <copyfrom> is a valid object number, the other properties + * of the new object are set from the properties of that object, + * with the exception of sidedef numbers, which are forced + * to OBJ_NO_NONE. * - * The object is inserted at the exact coordinates given. - * No snapping to grid is done. + * The object is inserted at the exact coordinates given. + * No snapping to grid is done. */ void InsertObject(obj_type_t objtype, obj_no_t copyfrom, int xpos, int ypos) - /* SWAP! */ + /* SWAP! */ { int last; @@ -442,148 +442,148 @@ switch (objtype) { case OBJ_THINGS: - last = NumThings++; - if (last > 0) - Things = (TPtr) ResizeMemory(Things, - (unsigned long) NumThings * - sizeof(struct Thing)); - else - Things = (TPtr) GetMemory(sizeof(struct Thing)); - Things[last].xpos = xpos; - Things[last].ypos = ypos; - things_angles++; - things_types++; - if (is_obj(copyfrom)) - { - Things[last].type = Things[copyfrom].type; - Things[last].angle = Things[copyfrom].angle; - Things[last].when = Things[copyfrom].when; - } - else - { - Things[last].type = default_thing; - Things[last].angle = 0; - Things[last].when = 0x07; - } - break; + last = NumThings++; + if (last > 0) + Things = (TPtr) ResizeMemory(Things, + (unsigned long) NumThings * + sizeof(struct Thing)); + else + Things = (TPtr) GetMemory(sizeof(struct Thing)); + Things[last].xpos = xpos; + Things[last].ypos = ypos; + things_angles++; + things_types++; + if (is_obj(copyfrom)) + { + Things[last].type = Things[copyfrom].type; + Things[last].angle = Things[copyfrom].angle; + Things[last].when = Things[copyfrom].when; + } + else + { + Things[last].type = default_thing; + Things[last].angle = 0; + Things[last].when = 0x07; + } + break; case OBJ_VERTICES: - last = NumVertices++; - if (last > 0) - Vertices = (VPtr) ResizeMemory(Vertices, - (unsigned long) NumVertices * - sizeof(struct Vertex)); - else - Vertices = (VPtr) GetMemory(sizeof(struct Vertex)); - Vertices[last].x = xpos; - Vertices[last].y = ypos; - if (Vertices[last].x < MapMinX) - MapMinX = Vertices[last].x; - if (Vertices[last].x > MapMaxX) - MapMaxX = Vertices[last].x; - if (Vertices[last].y < MapMinY) - MapMinY = Vertices[last].y; - if (Vertices[last].y > MapMaxY) - MapMaxY = Vertices[last].y; - MadeMapChanges = 1; - break; + last = NumVertices++; + if (last > 0) + Vertices = (VPtr) ResizeMemory(Vertices, + (unsigned long) NumVertices * + sizeof(struct Vertex)); + else + Vertices = (VPtr) GetMemory(sizeof(struct Vertex)); + Vertices[last].x = xpos; + Vertices[last].y = ypos; + if (Vertices[last].x < MapMinX) + MapMinX = Vertices[last].x; + if (Vertices[last].x > MapMaxX) + MapMaxX = Vertices[last].x; + if (Vertices[last].y < MapMinY) + MapMinY = Vertices[last].y; + if (Vertices[last].y > MapMaxY) + MapMaxY = Vertices[last].y; + MadeMapChanges = 1; + break; case OBJ_LINEDEFS: - last = NumLineDefs++; - if (last > 0) - LineDefs = (LDPtr) ResizeMemory(LineDefs, - (unsigned long) NumLineDefs * - sizeof(struct LineDef)); - else - LineDefs = (LDPtr) GetMemory(sizeof(struct LineDef)); - if (is_obj(copyfrom)) - { - LineDefs[last].start = LineDefs[copyfrom].start; - LineDefs[last].end = LineDefs[copyfrom].end; - LineDefs[last].flags = LineDefs[copyfrom].flags; - LineDefs[last].type = LineDefs[copyfrom].type; - LineDefs[last].tag = LineDefs[copyfrom].tag; - } - else - { - LineDefs[last].start = 0; - LineDefs[last].end = NumVertices - 1; - LineDefs[last].flags = 1; - LineDefs[last].type = 0; - LineDefs[last].tag = 0; - } - LineDefs[last].sidedef1 = OBJ_NO_NONE; - LineDefs[last].sidedef2 = OBJ_NO_NONE; - break; + last = NumLineDefs++; + if (last > 0) + LineDefs = (LDPtr) ResizeMemory(LineDefs, + (unsigned long) NumLineDefs * + sizeof(struct LineDef)); + else + LineDefs = (LDPtr) GetMemory(sizeof(struct LineDef)); + if (is_obj(copyfrom)) + { + LineDefs[last].start = LineDefs[copyfrom].start; + LineDefs[last].end = LineDefs[copyfrom].end; + LineDefs[last].flags = LineDefs[copyfrom].flags; + LineDefs[last].type = LineDefs[copyfrom].type; + LineDefs[last].tag = LineDefs[copyfrom].tag; + } + else + { + LineDefs[last].start = 0; + LineDefs[last].end = NumVertices - 1; + LineDefs[last].flags = 1; + LineDefs[last].type = 0; + LineDefs[last].tag = 0; + } + LineDefs[last].sidedef1 = OBJ_NO_NONE; + LineDefs[last].sidedef2 = OBJ_NO_NONE; + break; case OBJ_SIDEDEFS: - last = NumSideDefs++; - if (last > 0) - SideDefs = (SDPtr) ResizeMemory(SideDefs, - (unsigned long) NumSideDefs * - sizeof(struct SideDef)); - else - SideDefs = (SDPtr) GetMemory(sizeof(struct SideDef)); - if (is_obj(copyfrom)) - { - SideDefs[last].xoff = SideDefs[copyfrom].xoff; - SideDefs[last].yoff = SideDefs[copyfrom].yoff; - strncpy(SideDefs[last].tex1, SideDefs[copyfrom].tex1, - WAD_TEX_NAME); - strncpy(SideDefs[last].tex2, SideDefs[copyfrom].tex2, - WAD_TEX_NAME); - strncpy(SideDefs[last].tex3, SideDefs[copyfrom].tex3, - WAD_TEX_NAME); - SideDefs[last].sector = SideDefs[copyfrom].sector; - } - else - { - SideDefs[last].xoff = 0; - SideDefs[last].yoff = 0; - strcpy(SideDefs[last].tex1, "-"); - strcpy(SideDefs[last].tex2, "-"); - strcpy(SideDefs[last].tex3, default_middle_texture); - SideDefs[last].sector = NumSectors - 1; - } - MadeMapChanges = 1; - break; + last = NumSideDefs++; + if (last > 0) + SideDefs = (SDPtr) ResizeMemory(SideDefs, + (unsigned long) NumSideDefs * + sizeof(struct SideDef)); + else + SideDefs = (SDPtr) GetMemory(sizeof(struct SideDef)); + if (is_obj(copyfrom)) + { + SideDefs[last].xoff = SideDefs[copyfrom].xoff; + SideDefs[last].yoff = SideDefs[copyfrom].yoff; + strncpy(SideDefs[last].tex1, SideDefs[copyfrom].tex1, + WAD_TEX_NAME); + strncpy(SideDefs[last].tex2, SideDefs[copyfrom].tex2, + WAD_TEX_NAME); + strncpy(SideDefs[last].tex3, SideDefs[copyfrom].tex3, + WAD_TEX_NAME); + SideDefs[last].sector = SideDefs[copyfrom].sector; + } + else + { + SideDefs[last].xoff = 0; + SideDefs[last].yoff = 0; + strcpy(SideDefs[last].tex1, "-"); + strcpy(SideDefs[last].tex2, "-"); + strcpy(SideDefs[last].tex3, default_middle_texture); + SideDefs[last].sector = NumSectors - 1; + } + MadeMapChanges = 1; + break; case OBJ_SECTORS: - last = NumSectors++; - if (last > 0) - Sectors = (SPtr) ResizeMemory(Sectors, - (unsigned long) NumSectors * - sizeof(struct Sector)); - else - Sectors = (SPtr) GetMemory(sizeof(struct Sector)); - if (is_obj(copyfrom)) - { - Sectors[last].floorh = Sectors[copyfrom].floorh; - Sectors[last].ceilh = Sectors[copyfrom].ceilh; - strncpy(Sectors[last].floort, Sectors[copyfrom].floort, - WAD_FLAT_NAME); - strncpy(Sectors[last].ceilt, Sectors[copyfrom].ceilt, - WAD_FLAT_NAME); - Sectors[last].light = Sectors[copyfrom].light; - Sectors[last].special = Sectors[copyfrom].special; - Sectors[last].tag = Sectors[copyfrom].tag; - } - else - { - Sectors[last].floorh = default_floor_height; - Sectors[last].ceilh = default_ceiling_height; - strncpy(Sectors[last].floort, default_floor_texture, - WAD_FLAT_NAME); - strncpy(Sectors[last].ceilt, default_ceiling_texture, - WAD_FLAT_NAME); - Sectors[last].light = default_light_level; - Sectors[last].special = 0; - Sectors[last].tag = 0; - } - break; + last = NumSectors++; + if (last > 0) + Sectors = (SPtr) ResizeMemory(Sectors, + (unsigned long) NumSectors * + sizeof(struct Sector)); + else + Sectors = (SPtr) GetMemory(sizeof(struct Sector)); + if (is_obj(copyfrom)) + { + Sectors[last].floorh = Sectors[copyfrom].floorh; + Sectors[last].ceilh = Sectors[copyfrom].ceilh; + strncpy(Sectors[last].floort, Sectors[copyfrom].floort, + WAD_FLAT_NAME); + strncpy(Sectors[last].ceilt, Sectors[copyfrom].ceilt, + WAD_FLAT_NAME); + Sectors[last].light = Sectors[copyfrom].light; + Sectors[last].special = Sectors[copyfrom].special; + Sectors[last].tag = Sectors[copyfrom].tag; + } + else + { + Sectors[last].floorh = default_floor_height; + Sectors[last].ceilh = default_ceiling_height; + strncpy(Sectors[last].floort, default_floor_texture, + WAD_FLAT_NAME); + strncpy(Sectors[last].ceilt, default_ceiling_texture, + WAD_FLAT_NAME); + Sectors[last].light = default_light_level; + Sectors[last].special = 0; + Sectors[last].tag = 0; + } + break; default: - nf_bug("InsertObject: bad objtype %d", (int) objtype); + nf_bug("InsertObject: bad objtype %d", (int) objtype); } } @@ -592,7 +592,7 @@ /* check if a (part of a) LineDef is inside a given block */ -bool IsLineDefInside(int ldnum, int x0, int y0, int x1, int y1) /* SWAP - needs Vertices & LineDefs */ +bool IsLineDefInside(int ldnum, int x0, int y0, int x1, int y1) /* SWAP - needs Vertices & LineDefs */ { int lx0 = Vertices[LineDefs[ldnum].start].x; int ly0 = Vertices[LineDefs[ldnum].start].y; @@ -602,40 +602,40 @@ /* do you like mathematics? */ if (lx0 >= x0 && lx0 <= x1 && ly0 >= y0 && ly0 <= y1) - return 1; /* the linedef start is entirely inside the square */ + return 1; /* the linedef start is entirely inside the square */ if (lx1 >= x0 && lx1 <= x1 && ly1 >= y0 && ly1 <= y1) - return 1; /* the linedef end is entirely inside the square */ + return 1; /* the linedef end is entirely inside the square */ if ((ly0 > y0) != (ly1 > y0)) { - i = lx0 + - (int) ((long) (y0 - ly0) * (long) (lx1 - lx0) / - (long) (ly1 - ly0)); - if (i >= x0 && i <= x1) - return true; /* the linedef crosses the y0 side (left) */ + i = lx0 + + (int) ((long) (y0 - ly0) * (long) (lx1 - lx0) / + (long) (ly1 - ly0)); + if (i >= x0 && i <= x1) + return true; /* the linedef crosses the y0 side (left) */ } if ((ly0 > y1) != (ly1 > y1)) { - i = lx0 + - (int) ((long) (y1 - ly0) * (long) (lx1 - lx0) / - (long) (ly1 - ly0)); - if (i >= x0 && i <= x1) - return true; /* the linedef crosses the y1 side (right) */ + i = lx0 + + (int) ((long) (y1 - ly0) * (long) (lx1 - lx0) / + (long) (ly1 - ly0)); + if (i >= x0 && i <= x1) + return true; /* the linedef crosses the y1 side (right) */ } if ((lx0 > x0) != (lx1 > x0)) { - i = ly0 + - (int) ((long) (x0 - lx0) * (long) (ly1 - ly0) / - (long) (lx1 - lx0)); - if (i >= y0 && i <= y1) - return true; /* the linedef crosses the x0 side (down) */ + i = ly0 + + (int) ((long) (x0 - lx0) * (long) (ly1 - ly0) / + (long) (lx1 - lx0)); + if (i >= y0 && i <= y1) + return true; /* the linedef crosses the x0 side (down) */ } if ((lx0 > x1) != (lx1 > x1)) { - i = ly0 + - (int) ((long) (x1 - lx0) * (long) (ly1 - ly0) / - (long) (lx1 - lx0)); - if (i >= y0 && i <= y1) - return true; /* the linedef crosses the x1 side (up) */ + i = ly0 + + (int) ((long) (x1 - lx0) * (long) (ly1 - ly0) / + (long) (lx1 - lx0)); + if (i >= y0 && i <= y1) + return true; /* the linedef crosses the x1 side (up) */ } return false; } @@ -646,7 +646,7 @@ get the sector number of the sidedef opposite to this sidedef (returns -1 if it cannot be found) */ -int GetOppositeSector(int ld1, bool firstside) /* SWAP! */ +int GetOppositeSector(int ld1, bool firstside) /* SWAP! */ { int x0, y0, dx0, dy0; int x1, y1, dx1, dy1; @@ -665,157 +665,157 @@ y1 = (dy0 + y0 + y0) / 2; if (firstside) { - dx1 = dy0; - dy1 = -dx0; + dx1 = dy0; + dy1 = -dx0; } else { - dx1 = -dy0; - dy1 = dx0; + dx1 = -dy0; + dy1 = dx0; } bestld = -1; /* use a parallel to an axis instead of the normal vector (faster method) */ if (abs(dy1) > abs(dx1)) { - if (dy1 > 0) - { - /* get the nearest LineDef in that direction (increasing Y's: North) */ - bestdist = 32767; - bestmdist = 32767; - for (ld2 = 0; ld2 < NumLineDefs; ld2++) - if (ld2 != ld1 && ((Vertices[LineDefs[ld2].start].x > x1) - != (Vertices[LineDefs[ld2].end].x > x1))) - { - x2 = Vertices[LineDefs[ld2].start].x; - y2 = Vertices[LineDefs[ld2].start].y; - dx2 = Vertices[LineDefs[ld2].end].x - x2; - dy2 = Vertices[LineDefs[ld2].end].y - y2; - dist = - y2 + - (int) ((long) (x1 - x2) * (long) dy2 / (long) dx2); - if (dist > y1 - && (dist < bestdist - || (dist == bestdist - && (y2 + dy2 / 2) < bestmdist))) - { - bestld = ld2; - bestdist = dist; - bestmdist = y2 + dy2 / 2; - } - } - } - else - { - /* get the nearest LineDef in that direction (decreasing Y's: South) */ - bestdist = -32767; - bestmdist = -32767; - for (ld2 = 0; ld2 < NumLineDefs; ld2++) - if (ld2 != ld1 && ((Vertices[LineDefs[ld2].start].x > x1) - != (Vertices[LineDefs[ld2].end].x > x1))) - { - x2 = Vertices[LineDefs[ld2].start].x; - y2 = Vertices[LineDefs[ld2].start].y; - dx2 = Vertices[LineDefs[ld2].end].x - x2; - dy2 = Vertices[LineDefs[ld2].end].y - y2; - dist = - y2 + - (int) ((long) (x1 - x2) * (long) dy2 / (long) dx2); - if (dist < y1 - && (dist > bestdist - || (dist == bestdist - && (y2 + dy2 / 2) > bestmdist))) - { - bestld = ld2; - bestdist = dist; - bestmdist = y2 + dy2 / 2; - } - } - } + if (dy1 > 0) + { + /* get the nearest LineDef in that direction (increasing Y's: North) */ + bestdist = 32767; + bestmdist = 32767; + for (ld2 = 0; ld2 < NumLineDefs; ld2++) + if (ld2 != ld1 && ((Vertices[LineDefs[ld2].start].x > x1) + != (Vertices[LineDefs[ld2].end].x > x1))) + { + x2 = Vertices[LineDefs[ld2].start].x; + y2 = Vertices[LineDefs[ld2].start].y; + dx2 = Vertices[LineDefs[ld2].end].x - x2; + dy2 = Vertices[LineDefs[ld2].end].y - y2; + dist = + y2 + + (int) ((long) (x1 - x2) * (long) dy2 / (long) dx2); + if (dist > y1 + && (dist < bestdist + || (dist == bestdist + && (y2 + dy2 / 2) < bestmdist))) + { + bestld = ld2; + bestdist = dist; + bestmdist = y2 + dy2 / 2; + } + } + } + else + { + /* get the nearest LineDef in that direction (decreasing Y's: South) */ + bestdist = -32767; + bestmdist = -32767; + for (ld2 = 0; ld2 < NumLineDefs; ld2++) + if (ld2 != ld1 && ((Vertices[LineDefs[ld2].start].x > x1) + != (Vertices[LineDefs[ld2].end].x > x1))) + { + x2 = Vertices[LineDefs[ld2].start].x; + y2 = Vertices[LineDefs[ld2].start].y; + dx2 = Vertices[LineDefs[ld2].end].x - x2; + dy2 = Vertices[LineDefs[ld2].end].y - y2; + dist = + y2 + + (int) ((long) (x1 - x2) * (long) dy2 / (long) dx2); + if (dist < y1 + && (dist > bestdist + || (dist == bestdist + && (y2 + dy2 / 2) > bestmdist))) + { + bestld = ld2; + bestdist = dist; + bestmdist = y2 + dy2 / 2; + } + } + } } else { - if (dx1 > 0) - { - /* get the nearest LineDef in that direction (increasing X's: East) */ - bestdist = 32767; - bestmdist = 32767; - for (ld2 = 0; ld2 < NumLineDefs; ld2++) - if (ld2 != ld1 && ((Vertices[LineDefs[ld2].start].y > y1) - != (Vertices[LineDefs[ld2].end].y > y1))) - { - x2 = Vertices[LineDefs[ld2].start].x; - y2 = Vertices[LineDefs[ld2].start].y; - dx2 = Vertices[LineDefs[ld2].end].x - x2; - dy2 = Vertices[LineDefs[ld2].end].y - y2; - dist = - x2 + - (int) ((long) (y1 - y2) * (long) dx2 / (long) dy2); - if (dist > x1 - && (dist < bestdist - || (dist == bestdist - && (x2 + dx2 / 2) < bestmdist))) - { - bestld = ld2; - bestdist = dist; - bestmdist = x2 + dx2 / 2; - } - } - } - else - { - /* get the nearest LineDef in that direction (decreasing X's: West) */ - bestdist = -32767; - bestmdist = -32767; - for (ld2 = 0; ld2 < NumLineDefs; ld2++) - if (ld2 != ld1 && ((Vertices[LineDefs[ld2].start].y > y1) - != (Vertices[LineDefs[ld2].end].y > y1))) - { - x2 = Vertices[LineDefs[ld2].start].x; - y2 = Vertices[LineDefs[ld2].start].y; - dx2 = Vertices[LineDefs[ld2].end].x - x2; - dy2 = Vertices[LineDefs[ld2].end].y - y2; - dist = - x2 + - (int) ((long) (y1 - y2) * (long) dx2 / (long) dy2); - if (dist < x1 - && (dist > bestdist - || (dist == bestdist - && (x2 + dx2 / 2) > bestmdist))) - { - bestld = ld2; - bestdist = dist; - bestmdist = x2 + dx2 / 2; - } - } - } + if (dx1 > 0) + { + /* get the nearest LineDef in that direction (increasing X's: East) */ + bestdist = 32767; + bestmdist = 32767; + for (ld2 = 0; ld2 < NumLineDefs; ld2++) + if (ld2 != ld1 && ((Vertices[LineDefs[ld2].start].y > y1) + != (Vertices[LineDefs[ld2].end].y > y1))) + { + x2 = Vertices[LineDefs[ld2].start].x; + y2 = Vertices[LineDefs[ld2].start].y; + dx2 = Vertices[LineDefs[ld2].end].x - x2; + dy2 = Vertices[LineDefs[ld2].end].y - y2; + dist = + x2 + + (int) ((long) (y1 - y2) * (long) dx2 / (long) dy2); + if (dist > x1 + && (dist < bestdist + || (dist == bestdist + && (x2 + dx2 / 2) < bestmdist))) + { + bestld = ld2; + bestdist = dist; + bestmdist = x2 + dx2 / 2; + } + } + } + else + { + /* get the nearest LineDef in that direction (decreasing X's: West) */ + bestdist = -32767; + bestmdist = -32767; + for (ld2 = 0; ld2 < NumLineDefs; ld2++) + if (ld2 != ld1 && ((Vertices[LineDefs[ld2].start].y > y1) + != (Vertices[LineDefs[ld2].end].y > y1))) + { + x2 = Vertices[LineDefs[ld2].start].x; + y2 = Vertices[LineDefs[ld2].start].y; + dx2 = Vertices[LineDefs[ld2].end].x - x2; + dy2 = Vertices[LineDefs[ld2].end].y - y2; + dist = + x2 + + (int) ((long) (y1 - y2) * (long) dx2 / (long) dy2); + if (dist < x1 + && (dist > bestdist + || (dist == bestdist + && (x2 + dx2 / 2) > bestmdist))) + { + bestld = ld2; + bestdist = dist; + bestmdist = x2 + dx2 / 2; + } + } + } } /* no intersection: the LineDef was pointing outwards! */ if (bestld < 0) - return -1; + return -1; /* now look if this LineDef has a SideDef bound to one sector */ if (abs(dy1) > abs(dx1)) { - if ((Vertices[LineDefs[bestld].start].x - < Vertices[LineDefs[bestld].end].x) == (dy1 > 0)) - x0 = LineDefs[bestld].sidedef1; - else - x0 = LineDefs[bestld].sidedef2; + if ((Vertices[LineDefs[bestld].start].x + < Vertices[LineDefs[bestld].end].x) == (dy1 > 0)) + x0 = LineDefs[bestld].sidedef1; + else + x0 = LineDefs[bestld].sidedef2; } else { - if ((Vertices[LineDefs[bestld].start].y - < Vertices[LineDefs[bestld].end].y) != (dx1 > 0)) - x0 = LineDefs[bestld].sidedef1; - else - x0 = LineDefs[bestld].sidedef2; + if ((Vertices[LineDefs[bestld].start].y + < Vertices[LineDefs[bestld].end].y) != (dx1 > 0)) + x0 = LineDefs[bestld].sidedef1; + else + x0 = LineDefs[bestld].sidedef2; } /* there is no SideDef on this side of the LineDef! */ if (x0 < 0) - return -1; + return -1; /* OK, we got it -- return the Sector number */ return SideDefs[x0].sector; @@ -826,7 +826,7 @@ /* copy a group of objects to a new position */ -void CopyObjects(int objtype, SelPtr obj) /* SWAP! */ +void CopyObjects(int objtype, SelPtr obj) /* SWAP! */ { int n, m; SelPtr cur; @@ -834,195 +834,195 @@ SelPtr ref1, ref2; if (!obj) - return; + return; /* copy the object(s) */ switch (objtype) { case OBJ_THINGS: - for (cur = obj; cur; cur = cur->next) - { - InsertObject(OBJ_THINGS, cur->objnum, Things[cur->objnum].xpos, - Things[cur->objnum].ypos); - cur->objnum = NumThings - 1; - } - MadeChanges = 1; - break; + for (cur = obj; cur; cur = cur->next) + { + InsertObject(OBJ_THINGS, cur->objnum, Things[cur->objnum].xpos, + Things[cur->objnum].ypos); + cur->objnum = NumThings - 1; + } + MadeChanges = 1; + break; case OBJ_VERTICES: - for (cur = obj; cur; cur = cur->next) - { - InsertObject(OBJ_VERTICES, cur->objnum, Vertices[cur->objnum].x, - Vertices[cur->objnum].y); - cur->objnum = NumVertices - 1; - } - MadeChanges = 1; - MadeMapChanges = 1; - break; + for (cur = obj; cur; cur = cur->next) + { + InsertObject(OBJ_VERTICES, cur->objnum, Vertices[cur->objnum].x, + Vertices[cur->objnum].y); + cur->objnum = NumVertices - 1; + } + MadeChanges = 1; + MadeMapChanges = 1; + break; case OBJ_LINEDEFS: - list1 = 0; - list2 = 0; + list1 = 0; + list2 = 0; - // Create the linedefs and maybe the sidedefs - for (cur = obj; cur; cur = cur->next) - { - int old = cur->objnum; // No. of original linedef - int New; // No. of duplicate linedef + // Create the linedefs and maybe the sidedefs + for (cur = obj; cur; cur = cur->next) + { + int old = cur->objnum; // No. of original linedef + int New; // No. of duplicate linedef - InsertObject(OBJ_LINEDEFS, old, 0, 0); - New = NumLineDefs - 1; + InsertObject(OBJ_LINEDEFS, old, 0, 0); + New = NumLineDefs - 1; - if (copy_linedef_reuse_sidedefs) - { - /* AYM 1997-07-25: not very orthodox (the New linedef and - the old one use the same sidedefs). but, in the case where - you're copying into the same sector, it's much better than - having to create the New sidedefs manually. plus it saves - space in the .wad and also it makes editing easier (editing - one sidedef impacts all linedefs that use it). */ - LineDefs[New].sidedef1 = LineDefs[old].sidedef1; - LineDefs[New].sidedef2 = LineDefs[old].sidedef2; - } - else - { - /* AYM 1998-11-08: duplicate sidedefs too. - DEU 5.21 just left the sidedef references to -1. */ - if (is_sidedef(LineDefs[old].sidedef1)) - { - InsertObject(OBJ_SIDEDEFS, LineDefs[old].sidedef1, 0, 0); - LineDefs[New].sidedef1 = NumSideDefs - 1; - } - if (is_sidedef(LineDefs[old].sidedef2)) - { - InsertObject(OBJ_SIDEDEFS, LineDefs[old].sidedef2, 0, 0); - LineDefs[New].sidedef2 = NumSideDefs - 1; - } - } - cur->objnum = New; - if (!IsSelected(list1, LineDefs[New].start)) - { - SelectObject(&list1, LineDefs[New].start); - SelectObject(&list2, LineDefs[New].start); - } - if (!IsSelected(list1, LineDefs[New].end)) - { - SelectObject(&list1, LineDefs[New].end); - SelectObject(&list2, LineDefs[New].end); - } - } + if (copy_linedef_reuse_sidedefs) + { + /* AYM 1997-07-25: not very orthodox (the New linedef and + the old one use the same sidedefs). but, in the case where + you're copying into the same sector, it's much better than + having to create the New sidedefs manually. plus it saves + space in the .wad and also it makes editing easier (editing + one sidedef impacts all linedefs that use it). */ + LineDefs[New].sidedef1 = LineDefs[old].sidedef1; + LineDefs[New].sidedef2 = LineDefs[old].sidedef2; + } + else + { + /* AYM 1998-11-08: duplicate sidedefs too. + DEU 5.21 just left the sidedef references to -1. */ + if (is_sidedef(LineDefs[old].sidedef1)) + { + InsertObject(OBJ_SIDEDEFS, LineDefs[old].sidedef1, 0, 0); + LineDefs[New].sidedef1 = NumSideDefs - 1; + } + if (is_sidedef(LineDefs[old].sidedef2)) + { + InsertObject(OBJ_SIDEDEFS, LineDefs[old].sidedef2, 0, 0); + LineDefs[New].sidedef2 = NumSideDefs - 1; + } + } + cur->objnum = New; + if (!IsSelected(list1, LineDefs[New].start)) + { + SelectObject(&list1, LineDefs[New].start); + SelectObject(&list2, LineDefs[New].start); + } + if (!IsSelected(list1, LineDefs[New].end)) + { + SelectObject(&list1, LineDefs[New].end); + SelectObject(&list2, LineDefs[New].end); + } + } - // Create the vertices - CopyObjects(OBJ_VERTICES, list2); + // Create the vertices + CopyObjects(OBJ_VERTICES, list2); - // Update the references to the vertices - for (ref1 = list1, ref2 = list2; - ref1 && ref2; ref1 = ref1->next, ref2 = ref2->next) - { - for (cur = obj; cur; cur = cur->next) - { - if (ref1->objnum == LineDefs[cur->objnum].start) - LineDefs[cur->objnum].start = ref2->objnum; - if (ref1->objnum == LineDefs[cur->objnum].end) - LineDefs[cur->objnum].end = ref2->objnum; - } - } - ForgetSelection(&list1); - ForgetSelection(&list2); - break; + // Update the references to the vertices + for (ref1 = list1, ref2 = list2; + ref1 && ref2; ref1 = ref1->next, ref2 = ref2->next) + { + for (cur = obj; cur; cur = cur->next) + { + if (ref1->objnum == LineDefs[cur->objnum].start) + LineDefs[cur->objnum].start = ref2->objnum; + if (ref1->objnum == LineDefs[cur->objnum].end) + LineDefs[cur->objnum].end = ref2->objnum; + } + } + ForgetSelection(&list1); + ForgetSelection(&list2); + break; case OBJ_SECTORS: - list1 = 0; - list2 = 0; - // Create the linedefs (and vertices) - for (cur = obj; cur; cur = cur->next) - { - for (n = 0; n < NumLineDefs; n++) - if ((((m = LineDefs[n].sidedef1) >= 0 - && SideDefs[m].sector == cur->objnum) - || ((m = LineDefs[n].sidedef2) >= 0 - && SideDefs[m].sector == cur->objnum)) - && !IsSelected(list1, n)) - { - SelectObject(&list1, n); - SelectObject(&list2, n); - } - } - CopyObjects(OBJ_LINEDEFS, list2); - /* create the sidedefs */ - for (ref1 = list1, ref2 = list2; - ref1 && ref2; ref1 = ref1->next, ref2 = ref2->next) - { - if ((n = LineDefs[ref1->objnum].sidedef1) >= 0) - { - InsertObject(OBJ_SIDEDEFS, n, 0, 0); - n = NumSideDefs - 1; - LineDefs[ref2->objnum].sidedef1 = n; - } - if ((m = LineDefs[ref1->objnum].sidedef2) >= 0) - { - InsertObject(OBJ_SIDEDEFS, m, 0, 0); - m = NumSideDefs - 1; - LineDefs[ref2->objnum].sidedef2 = m; - } - ref1->objnum = n; - ref2->objnum = m; - } - /* create the Sectors */ - for (cur = obj; cur; cur = cur->next) - { - InsertObject(OBJ_SECTORS, cur->objnum, 0, 0); - for (ref1 = list1, ref2 = list2; - ref1 && ref2; ref1 = ref1->next, ref2 = ref2->next) - { - if (ref1->objnum >= 0 - && SideDefs[ref1->objnum].sector == cur->objnum) - SideDefs[ref1->objnum].sector = NumSectors - 1; - if (ref2->objnum >= 0 - && SideDefs[ref2->objnum].sector == cur->objnum) - SideDefs[ref2->objnum].sector = NumSectors - 1; - } - cur->objnum = NumSectors - 1; - } - ForgetSelection(&list1); - ForgetSelection(&list2); - break; + list1 = 0; + list2 = 0; + // Create the linedefs (and vertices) + for (cur = obj; cur; cur = cur->next) + { + for (n = 0; n < NumLineDefs; n++) + if ((((m = LineDefs[n].sidedef1) >= 0 + && SideDefs[m].sector == cur->objnum) + || ((m = LineDefs[n].sidedef2) >= 0 + && SideDefs[m].sector == cur->objnum)) + && !IsSelected(list1, n)) + { + SelectObject(&list1, n); + SelectObject(&list2, n); + } + } + CopyObjects(OBJ_LINEDEFS, list2); + /* create the sidedefs */ + for (ref1 = list1, ref2 = list2; + ref1 && ref2; ref1 = ref1->next, ref2 = ref2->next) + { + if ((n = LineDefs[ref1->objnum].sidedef1) >= 0) + { + InsertObject(OBJ_SIDEDEFS, n, 0, 0); + n = NumSideDefs - 1; + LineDefs[ref2->objnum].sidedef1 = n; + } + if ((m = LineDefs[ref1->objnum].sidedef2) >= 0) + { + InsertObject(OBJ_SIDEDEFS, m, 0, 0); + m = NumSideDefs - 1; + LineDefs[ref2->objnum].sidedef2 = m; + } + ref1->objnum = n; + ref2->objnum = m; + } + /* create the Sectors */ + for (cur = obj; cur; cur = cur->next) + { + InsertObject(OBJ_SECTORS, cur->objnum, 0, 0); + for (ref1 = list1, ref2 = list2; + ref1 && ref2; ref1 = ref1->next, ref2 = ref2->next) + { + if (ref1->objnum >= 0 + && SideDefs[ref1->objnum].sector == cur->objnum) + SideDefs[ref1->objnum].sector = NumSectors - 1; + if (ref2->objnum >= 0 + && SideDefs[ref2->objnum].sector == cur->objnum) + SideDefs[ref2->objnum].sector = NumSectors - 1; + } + cur->objnum = NumSectors - 1; + } + ForgetSelection(&list1); + ForgetSelection(&list2); + break; } } /* - * MoveObjectsToCoords - * Move a group of objects to a new position + * MoveObjectsToCoords + * Move a group of objects to a new position * - * You must first call it with obj == NULL and newx and newy - * set to the coordinates of the reference point (E.G. the - * object being dragged). - * Then, every time the object being dragged has changed its - * coordinates, call the it again with newx and newy set to - * the new position and obj set to the selection. + * You must first call it with obj == NULL and newx and newy + * set to the coordinates of the reference point (E.G. the + * object being dragged). + * Then, every time the object being dragged has changed its + * coordinates, call the it again with newx and newy set to + * the new position and obj set to the selection. * - * Returns <>0 iff an object was moved. + * Returns <>0 iff an object was moved. */ -bool MoveObjectsToCoords(int objtype, SelPtr obj, int newx, int newy, int grid) /* SWAP! */ +bool MoveObjectsToCoords(int objtype, SelPtr obj, int newx, int newy, int grid) /* SWAP! */ { int dx, dy; SelPtr cur, vertices; - static int refx, refy; /* previous position */ + static int refx, refy; /* previous position */ if (grid > 0) { - newx = (newx + grid / 2) & ~(grid - 1); - newy = (newy + grid / 2) & ~(grid - 1); + newx = (newx + grid / 2) & ~(grid - 1); + newy = (newy + grid / 2) & ~(grid - 1); } // Only update the reference point ? if (!obj) { - refx = newx; - refy = newy; - return true; + refx = newx; + refy = newy; + return true; } /* compute the displacement */ @@ -1030,45 +1030,45 @@ dy = newy - refy; /* nothing to do? */ if (dx == 0 && dy == 0) - return false; + return false; /* move the object(s) */ switch (objtype) { case OBJ_THINGS: - for (cur = obj; cur; cur = cur->next) - { - Things[cur->objnum].xpos += dx; - Things[cur->objnum].ypos += dy; - } - refx = newx; - refy = newy; - MadeChanges = 1; - break; + for (cur = obj; cur; cur = cur->next) + { + Things[cur->objnum].xpos += dx; + Things[cur->objnum].ypos += dy; + } + refx = newx; + refy = newy; + MadeChanges = 1; + break; case OBJ_VERTICES: - for (cur = obj; cur; cur = cur->next) - { - Vertices[cur->objnum].x += dx; - Vertices[cur->objnum].y += dy; - } - refx = newx; - refy = newy; - MadeChanges = 1; - MadeMapChanges = 1; - break; + for (cur = obj; cur; cur = cur->next) + { + Vertices[cur->objnum].x += dx; + Vertices[cur->objnum].y += dy; + } + refx = newx; + refy = newy; + MadeChanges = 1; + MadeMapChanges = 1; + break; case OBJ_LINEDEFS: - vertices = list_vertices_of_linedefs(obj); - MoveObjectsToCoords(OBJ_VERTICES, vertices, newx, newy, grid); - ForgetSelection(&vertices); - break; + vertices = list_vertices_of_linedefs(obj); + MoveObjectsToCoords(OBJ_VERTICES, vertices, newx, newy, grid); + ForgetSelection(&vertices); + break; case OBJ_SECTORS: - vertices = list_vertices_of_sectors(obj); - MoveObjectsToCoords(OBJ_VERTICES, vertices, newx, newy, grid); - ForgetSelection(&vertices); - break; + vertices = list_vertices_of_sectors(obj); + MoveObjectsToCoords(OBJ_VERTICES, vertices, newx, newy, grid); + ForgetSelection(&vertices); + break; } return true; } @@ -1078,7 +1078,7 @@ /* get the coordinates (approx.) of an object */ -void GetObjectCoords(int objtype, int objnum, int *xpos, int *ypos) /* SWAP! */ +void GetObjectCoords(int objtype, int objnum, int *xpos, int *ypos) /* SWAP! */ { int n, v1, v2, sd1, sd2; long accx, accy, num; @@ -1086,110 +1086,110 @@ switch (objtype) { case OBJ_THINGS: - if (!is_thing(objnum)) // Can't happen - { - nf_bug("GetObjectCoords: bad thing# %d", objnum); - *xpos = 0; - *ypos = 0; - return; - } - *xpos = Things[objnum].xpos; - *ypos = Things[objnum].ypos; - break; + if (!is_thing(objnum)) // Can't happen + { + nf_bug("GetObjectCoords: bad thing# %d", objnum); + *xpos = 0; + *ypos = 0; + return; + } + *xpos = Things[objnum].xpos; + *ypos = Things[objnum].ypos; + break; case OBJ_VERTICES: - if (!is_vertex(objnum)) // Can't happen - { - nf_bug("GetObjectCoords: bad vertex# %d", objnum); - *xpos = 0; - *ypos = 0; - return; - } - *xpos = Vertices[objnum].x; - *ypos = Vertices[objnum].y; - break; + if (!is_vertex(objnum)) // Can't happen + { + nf_bug("GetObjectCoords: bad vertex# %d", objnum); + *xpos = 0; + *ypos = 0; + return; + } + *xpos = Vertices[objnum].x; + *ypos = Vertices[objnum].y; + break; case OBJ_LINEDEFS: - if (!is_linedef(objnum)) // Can't happen - { - nf_bug("GetObjectCoords: bad linedef# %d", objnum); - *xpos = 0; - *ypos = 0; - return; - } - v1 = LineDefs[objnum].start; - v2 = LineDefs[objnum].end; - *xpos = (Vertices[v1].x + Vertices[v2].x) / 2; - *ypos = (Vertices[v1].y + Vertices[v2].y) / 2; - break; + if (!is_linedef(objnum)) // Can't happen + { + nf_bug("GetObjectCoords: bad linedef# %d", objnum); + *xpos = 0; + *ypos = 0; + return; + } + v1 = LineDefs[objnum].start; + v2 = LineDefs[objnum].end; + *xpos = (Vertices[v1].x + Vertices[v2].x) / 2; + *ypos = (Vertices[v1].y + Vertices[v2].y) / 2; + break; case OBJ_SIDEDEFS: - if (!is_sidedef(objnum)) // Can't happen - { - nf_bug("GetObjectCoords: bad sidedef# %d", objnum); - *xpos = 0; - *ypos = 0; - return; - } - for (n = 0; n < NumLineDefs; n++) - if (LineDefs[n].sidedef1 == objnum - || LineDefs[n].sidedef2 == objnum) - { - v1 = LineDefs[n].start; - v2 = LineDefs[n].end; - *xpos = (Vertices[v1].x + Vertices[v2].x) / 2; - *ypos = (Vertices[v1].y + Vertices[v2].y) / 2; - return; - } - *xpos = (MapMinX + MapMaxX) / 2; - *ypos = (MapMinY + MapMaxY) / 2; - // FIXME is the fall through intentional ? -- AYM 2000-11-08 + if (!is_sidedef(objnum)) // Can't happen + { + nf_bug("GetObjectCoords: bad sidedef# %d", objnum); + *xpos = 0; + *ypos = 0; + return; + } + for (n = 0; n < NumLineDefs; n++) + if (LineDefs[n].sidedef1 == objnum + || LineDefs[n].sidedef2 == objnum) + { + v1 = LineDefs[n].start; + v2 = LineDefs[n].end; + *xpos = (Vertices[v1].x + Vertices[v2].x) / 2; + *ypos = (Vertices[v1].y + Vertices[v2].y) / 2; + return; + } + *xpos = (MapMinX + MapMaxX) / 2; + *ypos = (MapMinY + MapMaxY) / 2; + // FIXME is the fall through intentional ? -- AYM 2000-11-08 case OBJ_SECTORS: - if (!is_sector(objnum)) // Can't happen - { - nf_bug("GetObjectCoords: bad sector# %d", objnum); - *xpos = 0; - *ypos = 0; - return; - } - accx = 0L; - accy = 0L; - num = 0L; - for (n = 0; n < NumLineDefs; n++) - { - sd1 = LineDefs[n].sidedef1; - sd2 = LineDefs[n].sidedef2; - v1 = LineDefs[n].start; - v2 = LineDefs[n].end; - if ((sd1 >= 0 && SideDefs[sd1].sector == objnum) - || (sd2 >= 0 && SideDefs[sd2].sector == objnum)) - { - /* if the Sector is closed, all Vertices will be counted twice */ - accx += (long) Vertices[v1].x; - accy += (long) Vertices[v1].y; - num++; - accx += (long) Vertices[v2].x; - accy += (long) Vertices[v2].y; - num++; - } - } - if (num > 0) - { - *xpos = (int) ((accx + num / 2L) / num); - *ypos = (int) ((accy + num / 2L) / num); - } - else - { - *xpos = (MapMinX + MapMaxX) / 2; - *ypos = (MapMinY + MapMaxY) / 2; - } - break; + if (!is_sector(objnum)) // Can't happen + { + nf_bug("GetObjectCoords: bad sector# %d", objnum); + *xpos = 0; + *ypos = 0; + return; + } + accx = 0L; + accy = 0L; + num = 0L; + for (n = 0; n < NumLineDefs; n++) + { + sd1 = LineDefs[n].sidedef1; + sd2 = LineDefs[n].sidedef2; + v1 = LineDefs[n].start; + v2 = LineDefs[n].end; + if ((sd1 >= 0 && SideDefs[sd1].sector == objnum) + || (sd2 >= 0 && SideDefs[sd2].sector == objnum)) + { + /* if the Sector is closed, all Vertices will be counted twice */ + accx += (long) Vertices[v1].x; + accy += (long) Vertices[v1].y; + num++; + accx += (long) Vertices[v2].x; + accy += (long) Vertices[v2].y; + num++; + } + } + if (num > 0) + { + *xpos = (int) ((accx + num / 2L) / num); + *ypos = (int) ((accy + num / 2L) / num); + } + else + { + *xpos = (MapMinX + MapMaxX) / 2; + *ypos = (MapMinY + MapMaxY) / 2; + } + break; default: - nf_bug("GetObjectCoords: bad objtype %d", objtype); // Can't happen - *xpos = 0; - *ypos = 0; + nf_bug("GetObjectCoords: bad objtype %d", objtype); // Can't happen + *xpos = 0; + *ypos = 0; } } @@ -1198,7 +1198,7 @@ /* find a free tag number */ -int FindFreeTag() /* SWAP! */ +int FindFreeTag() /* SWAP! */ { int tag, n; bool ok; @@ -1207,21 +1207,21 @@ ok = false; while (!ok) { - ok = true; - for (n = 0; n < NumLineDefs; n++) - if (LineDefs[n].tag == tag) - { - ok = false; - break; - } - if (ok) - for (n = 0; n < NumSectors; n++) - if (Sectors[n].tag == tag) - { - ok = false; - break; - } - tag++; + ok = true; + for (n = 0; n < NumLineDefs; n++) + if (LineDefs[n].tag == tag) + { + ok = false; + break; + } + if (ok) + for (n = 0; n < NumSectors; n++) + if (Sectors[n].tag == tag) + { + ok = false; + break; + } + tag++; } return tag - 1; } diff -r 594dea11ccd9 -r a68786b9c74b src/objects.h --- a/src/objects.h Sat Sep 24 15:01:56 2011 +0300 +++ b/src/objects.h Sat Sep 24 15:59:33 2011 +0300 @@ -1,10 +1,10 @@ /* - * objects.h - * AYM 2000-11-06 + * objects.h + * AYM 2000-11-06 */ -#ifndef YH_OBJECTS /* DO NOT INSERT ANYTHING BEFORE THIS LINE */ +#ifndef YH_OBJECTS /* DO NOT INSERT ANYTHING BEFORE THIS LINE */ #define YH_OBJECTS diff -r 594dea11ccd9 -r a68786b9c74b src/objid.h --- a/src/objid.h Sat Sep 24 15:01:56 2011 +0300 +++ b/src/objid.h Sat Sep 24 15:59:33 2011 +0300 @@ -1,6 +1,6 @@ /* - * objid.h - object identity class - * AYM 2000-11-06 + * objid.h - object identity class + * AYM 2000-11-06 */ @@ -25,7 +25,7 @@ */ -#ifndef YH_OBJID /* DO NOT INSERT ANYTHING BEFORE THIS LINE */ +#ifndef YH_OBJID /* DO NOT INSERT ANYTHING BEFORE THIS LINE */ #define YH_OBJID @@ -34,18 +34,18 @@ // as an object or not ? The issue could use some thought. // Object types -#define OBJ_NONE 0 -#define OBJ_THINGS 1 -#define OBJ_LINEDEFS 2 -#define OBJ_SIDEDEFS 3 -#define OBJ_VERTICES 4 -#define OBJ_SEGS 5 -#define OBJ_SSECTORS 6 -#define OBJ_NODES 7 -#define OBJ_SECTORS 8 -#define OBJ_REJECT 9 -#define OBJ_BLOCKMAP 10 -#define OBJ_ANY 11 +#define OBJ_NONE 0 +#define OBJ_THINGS 1 +#define OBJ_LINEDEFS 2 +#define OBJ_SIDEDEFS 3 +#define OBJ_VERTICES 4 +#define OBJ_SEGS 5 +#define OBJ_SSECTORS 6 +#define OBJ_NODES 7 +#define OBJ_SECTORS 8 +#define OBJ_REJECT 9 +#define OBJ_BLOCKMAP 10 +#define OBJ_ANY 11 // Special object numbers typedef i16 obj_no_t; @@ -63,46 +63,46 @@ { public: Objid() { - num = -1; - type = OBJ_NONE; + num = -1; + type = OBJ_NONE; } Objid(obj_type_t t, obj_no_t n) { - type = t; - num = n; + type = t; + num = n; } bool operator==(const Objid & other) const { - return other.type == type && other.num == num; + return other.type == type && other.num == num; } bool _is_linedef() const { - return type == OBJ_LINEDEFS && num >= 0; + return type == OBJ_LINEDEFS && num >= 0; } bool _is_sector() const { - return type == OBJ_SECTORS && num >= 0; + return type == OBJ_SECTORS && num >= 0; } bool _is_thing() const { - return type == OBJ_THINGS && num >= 0; + return type == OBJ_THINGS && num >= 0; } bool _is_vertex() const { - return type == OBJ_VERTICES && num >= 0; + return type == OBJ_VERTICES && num >= 0; } bool is_nil() const { - return num < 0 || type == OBJ_NONE; + return num < 0 || type == OBJ_NONE; } bool operator() () const { - return num >= 0 && type != OBJ_NONE; + return num >= 0 && type != OBJ_NONE; } void nil() { - num = -1; - type = OBJ_NONE; + num = -1; + type = OBJ_NONE; } obj_type_t type; obj_no_t num; diff -r 594dea11ccd9 -r a68786b9c74b src/objinfo.cc --- a/src/objinfo.cc Sat Sep 24 15:01:56 2011 +0300 +++ b/src/objinfo.cc Sat Sep 24 15:59:33 2011 +0300 @@ -1,6 +1,6 @@ /* - * objinfo.cc - * AYM 1998-09-20 + * objinfo.cc + * AYM 1998-09-20 */ @@ -32,9 +32,9 @@ #include <algorithm> #include <X11/Xlib.h> #include "disppic.h" -#include "flats.h" // DisplayFloorTexture() -#include "game.h" // THINGDEF_SPECTRAL -#include "gamesky.h" // is_sky() +#include "flats.h" // DisplayFloorTexture() +#include "game.h" // THINGDEF_SPECTRAL +#include "gamesky.h" // is_sky() #include "gfx.h" #include "img.h" #include "imgspect.h" @@ -53,29 +53,29 @@ /* - * Extraf - one item in the list of EDGE extrafloors + * Extraf - one item in the list of EDGE extrafloors */ class Extraf { public: Extraf(obj_no_t sector, wad_name_t & tex, wad_z_t height) { - this->sector = sector; - memcpy(this->tex, &tex, sizeof this->tex); - this->height = height; + this->sector = sector; + memcpy(this->tex, &tex, sizeof this->tex); + this->height = height; } bool operator<(const Extraf & other) const { - if (height < other.height) - return true; - else if (height == other.height && sector < other.sector) - return true; - return false; + if (height < other.height) + return true; + else if (height == other.height && sector < other.sector) + return true; + return false; } - wad_z_t height; // To sort by increasing floor height - obj_no_t sector; // Sector# (for heights, flats and light level) - wad_tex_name_t tex; // Texture (middle tex of first sidedef) + wad_z_t height; // To sort by increasing floor height + obj_no_t sector; // Sector# (for heights, flats and light level) + wad_tex_name_t tex; // Texture (middle tex of first sidedef) }; @@ -85,7 +85,7 @@ objinfo_c::objinfo_c() { for (size_t n = 0; n < MAX_BOXES; n++) - box_disp[n] = false; + box_disp[n] = false; obj_no = OBJ_NO_NONE; obj_no_disp = OBJ_NO_NONE; prev_sector = OBJ_NO_NONE; @@ -100,676 +100,676 @@ int sd2 = OBJ_NO_NONE; int s1 = OBJ_NO_NONE; int s2 = OBJ_NO_NONE; - int x0, y0; // Outer top left corner - int ix0, iy0; // Inner top left corner + int x0, y0; // Outer top left corner + int ix0, iy0; // Inner top left corner int width; int height; // Am I already drawn ? if (!is_obj(obj_no) || obj_no == obj_no_disp && obj_type == obj_type_disp) - return; + return; // Does the box need to be redrawn ? if (obj_type != obj_type_disp) - box_disp[0] = false; + box_disp[0] = false; // The caller should have called set_y1() before ! if (!out_y1) - return; + return; switch (obj_type) { case OBJ_THINGS: - { - const int columns = 27; - width = 2 * BOX_BORDER + 3 * WIDE_HSPACING + columns * FONTW - + 2 * HOLLOW_BORDER + sprite_width; - height = 2 * BOX_BORDER + 2 * WIDE_VSPACING - + y_max((int) (6.5 * FONTH), sprite_height); - x0 = 0; - y0 = out_y1 - height + 1; - ix0 = x0 + BOX_BORDER + WIDE_HSPACING; - iy0 = y0 + BOX_BORDER + WIDE_VSPACING; - int ix1 = x0 + width - 1 - BOX_BORDER - WIDE_HSPACING; - int iy1 = y0 + height - 1 - BOX_BORDER - WIDE_VSPACING; - if (box_disp[0]) - { - push_colour(WINBG); - DrawScreenBox(ix0, iy0, ix0 + columns * FONTW - 1, iy1); - pop_colour(); - } - else - DrawScreenBox3D(x0, y0, x0 + width - 1, y0 + height - 1); - if (obj_no < 0) - { - const char *message = "(no thing selected)"; - set_colour(WINFG_DIM); - DrawScreenText(x0 + (width - FONTW * strlen(message)) / 2, - y0 + (height - FONTH) / 2, message); - break; - } - set_colour(WINTITLE); - DrawScreenText(ix0, iy0, "Thing #%d", obj_no); - const bool invalid_type = !is_thing_type(Things[obj_no].type); - set_colour(WINFG); - DrawScreenText(-1, iy0 + (int) (1.5 * FONTH), 0); - DrawScreenText(-1, -1, "\1Coords:\2 (%d, %d)", - Things[obj_no].xpos, Things[obj_no].ypos); - DrawScreenString(-1, -1, "\1Type: "); - if (invalid_type) - push_colour(CLR_ERROR); - DrawScreenText(-2, -2, "%d", Things[obj_no].type); - if (invalid_type) - pop_colour(); - DrawScreenString(-1, -1, "\1Desc: "); - if (invalid_type) - push_colour(CLR_ERROR); - DrawScreenText(-2, -2, "%.19s", - get_thing_name(Things[obj_no].type)); - if (invalid_type) - pop_colour(); - DrawScreenText(-1, -1, "\1Angle:\2 %s", - GetAngleName(Things[obj_no].angle)); - DrawScreenText(-1, -1, "\1Flags:\2 %s", - GetWhenName(Things[obj_no].when)); + { + const int columns = 27; + width = 2 * BOX_BORDER + 3 * WIDE_HSPACING + columns * FONTW + + 2 * HOLLOW_BORDER + sprite_width; + height = 2 * BOX_BORDER + 2 * WIDE_VSPACING + + y_max((int) (6.5 * FONTH), sprite_height); + x0 = 0; + y0 = out_y1 - height + 1; + ix0 = x0 + BOX_BORDER + WIDE_HSPACING; + iy0 = y0 + BOX_BORDER + WIDE_VSPACING; + int ix1 = x0 + width - 1 - BOX_BORDER - WIDE_HSPACING; + int iy1 = y0 + height - 1 - BOX_BORDER - WIDE_VSPACING; + if (box_disp[0]) + { + push_colour(WINBG); + DrawScreenBox(ix0, iy0, ix0 + columns * FONTW - 1, iy1); + pop_colour(); + } + else + DrawScreenBox3D(x0, y0, x0 + width - 1, y0 + height - 1); + if (obj_no < 0) + { + const char *message = "(no thing selected)"; + set_colour(WINFG_DIM); + DrawScreenText(x0 + (width - FONTW * strlen(message)) / 2, + y0 + (height - FONTH) / 2, message); + break; + } + set_colour(WINTITLE); + DrawScreenText(ix0, iy0, "Thing #%d", obj_no); + const bool invalid_type = !is_thing_type(Things[obj_no].type); + set_colour(WINFG); + DrawScreenText(-1, iy0 + (int) (1.5 * FONTH), 0); + DrawScreenText(-1, -1, "\1Coords:\2 (%d, %d)", + Things[obj_no].xpos, Things[obj_no].ypos); + DrawScreenString(-1, -1, "\1Type: "); + if (invalid_type) + push_colour(CLR_ERROR); + DrawScreenText(-2, -2, "%d", Things[obj_no].type); + if (invalid_type) + pop_colour(); + DrawScreenString(-1, -1, "\1Desc: "); + if (invalid_type) + push_colour(CLR_ERROR); + DrawScreenText(-2, -2, "%.19s", + get_thing_name(Things[obj_no].type)); + if (invalid_type) + pop_colour(); + DrawScreenText(-1, -1, "\1Angle:\2 %s", + GetAngleName(Things[obj_no].angle)); + DrawScreenText(-1, -1, "\1Flags:\2 %s", + GetWhenName(Things[obj_no].when)); - // Show the corresponding sprite - { - int sx1 = ix1 + 1 - HOLLOW_BORDER; - int sy1 = iy1 + 1 - HOLLOW_BORDER; - int sx0 = sx1 + 1 - sprite_width; - int sy0 = sy1 + 1 - sprite_height; - draw_box_border(sx0 - HOLLOW_BORDER, sy0 - HOLLOW_BORDER, - sprite_width + 2 * HOLLOW_BORDER, - sprite_height + 2 * HOLLOW_BORDER, - HOLLOW_BORDER, 0); - const char *sprite_root = - get_thing_sprite(Things[obj_no].type); - char flags = get_thing_flags(Things[obj_no].type); - if (sprite_root == NULL) - { - push_colour(WINBG); - DrawScreenBox(sx0, sy0, sx1, sy1); - pop_colour(); - set_colour(WINFG_DIM); - DrawScreenText(sx0 + (sprite_width - 2 * FONTW) / 2, - sy0 + sprite_height / 2 + 1 - FONTH, "no"); - DrawScreenText(sx0 + (sprite_width - 6 * FONTW) / 2, - sy0 + sprite_height / 2 + 1, "sprite"); - } - else - { - Lump_loc loc; - Img img(sprite_width, sprite_height, false); - Sticker sticker; - wad_res.sprites.loc_by_root(sprite_root, loc); - if (loc.wad == 0 - || LoadPicture(img, sprite_root, loc, INT_MIN, - INT_MIN)) - { - push_colour(WINBG); - DrawScreenBox(sx0, sy0, sx1, sy1); - pop_colour(); - set_colour(CLR_ERROR); - DrawScreenString(sx0 + - (sprite_width - - strlen(sprite_root) * FONTW) / 2, - sy0 + sprite_height / 2 + 1 - - 3 * FONTH / 2, sprite_root); - DrawScreenText(sx0 + (sprite_width - 3 * FONTW) / 2, - sy0 + sprite_height / 2 + 1 - - FONTH / 2, "not"); - DrawScreenText(sx0 + (sprite_width - 5 * FONTW) / 2, - sy0 + sprite_height / 2 + 1 + - FONTH / 2, "found"); - } - else - { - if (flags & THINGDEF_SPECTRAL) - spectrify_img(img); - sticker.load(img, true); - sticker.draw(drw, 't', sx0, sy0); - } - } - } - } - break; + // Show the corresponding sprite + { + int sx1 = ix1 + 1 - HOLLOW_BORDER; + int sy1 = iy1 + 1 - HOLLOW_BORDER; + int sx0 = sx1 + 1 - sprite_width; + int sy0 = sy1 + 1 - sprite_height; + draw_box_border(sx0 - HOLLOW_BORDER, sy0 - HOLLOW_BORDER, + sprite_width + 2 * HOLLOW_BORDER, + sprite_height + 2 * HOLLOW_BORDER, + HOLLOW_BORDER, 0); + const char *sprite_root = + get_thing_sprite(Things[obj_no].type); + char flags = get_thing_flags(Things[obj_no].type); + if (sprite_root == NULL) + { + push_colour(WINBG); + DrawScreenBox(sx0, sy0, sx1, sy1); + pop_colour(); + set_colour(WINFG_DIM); + DrawScreenText(sx0 + (sprite_width - 2 * FONTW) / 2, + sy0 + sprite_height / 2 + 1 - FONTH, "no"); + DrawScreenText(sx0 + (sprite_width - 6 * FONTW) / 2, + sy0 + sprite_height / 2 + 1, "sprite"); + } + else + { + Lump_loc loc; + Img img(sprite_width, sprite_height, false); + Sticker sticker; + wad_res.sprites.loc_by_root(sprite_root, loc); + if (loc.wad == 0 + || LoadPicture(img, sprite_root, loc, INT_MIN, + INT_MIN)) + { + push_colour(WINBG); + DrawScreenBox(sx0, sy0, sx1, sy1); + pop_colour(); + set_colour(CLR_ERROR); + DrawScreenString(sx0 + + (sprite_width - + strlen(sprite_root) * FONTW) / 2, + sy0 + sprite_height / 2 + 1 - + 3 * FONTH / 2, sprite_root); + DrawScreenText(sx0 + (sprite_width - 3 * FONTW) / 2, + sy0 + sprite_height / 2 + 1 - + FONTH / 2, "not"); + DrawScreenText(sx0 + (sprite_width - 5 * FONTW) / 2, + sy0 + sprite_height / 2 + 1 + + FONTH / 2, "found"); + } + else + { + if (flags & THINGDEF_SPECTRAL) + spectrify_img(img); + sticker.load(img, true); + sticker.draw(drw, 't', sx0, sy0); + } + } + } + } + break; case OBJ_LINEDEFS: - // Linedef - width = 2 * BOX_BORDER + 2 * WIDE_HSPACING + 29 * FONTW; - height = 2 * BOX_BORDER + 2 * WIDE_VSPACING + (int) (8.5 * FONTH); - x0 = 0; - y0 = out_y1 - height + 1; - ix0 = x0 + BOX_BORDER + WIDE_HSPACING; - iy0 = y0 + BOX_BORDER + WIDE_VSPACING; - // Ignore box_disp -- always redraw the whole box - DrawScreenBox3D(x0, y0, x0 + width - 1, y0 + height - 1); - if (obj_no >= 0) - { - set_colour(WINTITLE); - DrawScreenText(ix0, iy0, "Linedef #%d", obj_no); - set_colour(WINFG); - DrawScreenText(-1, iy0 + (int) (1.5 * FONTH), - "\1Flags:\2 %.19s", - GetLineDefFlagsName(LineDefs[obj_no].flags)); - DrawScreenText(-1, -1, "\1Type:\2 %3d %.19s", - LineDefs[obj_no].type, - GetLineDefTypeName(LineDefs[obj_no].type)); - { - int tag = LineDefs[obj_no].tag; - int first_sector = NumSectors; - int second_sector = NumSectors; - if (tag != 0) - { - for (int n = 0; n < NumSectors; n++) - if (Sectors[n].tag == tag) - { - if (first_sector >= NumSectors) - first_sector = n; - else - { - second_sector = n; - break; - } - } - } - if (first_sector < NumSectors && second_sector < NumSectors) - DrawScreenText(-1, -1, "\1Tag:\2 %d (#%d+)", tag, - first_sector); - else if (first_sector < NumSectors) - DrawScreenText(-1, -1, "\1Tag:\2 %d (#%d)", tag, - first_sector); - else - DrawScreenText(-1, -1, "\1Tag:\2 %d (none)", tag); - } - s1 = LineDefs[obj_no].start; - s2 = LineDefs[obj_no].end; - DrawScreenText(-1, -1, "\1Vertices:\2 (#%d, #%d)", s1, s2); - n = ComputeDist(Vertices[s2].x - Vertices[s1].x, - Vertices[s2].y - Vertices[s1].y); - DrawScreenText(-1, -1, "\1Length:\2 %d", n); - sd1 = LineDefs[obj_no].sidedef1; - sd2 = LineDefs[obj_no].sidedef2; - DrawScreenText(-1, -1, "\1" "1st sd:\2 #%d", sd1); - DrawScreenText(-1, -1, "\1" "2nd sd:\2 #%d", sd2); - if (sd1 >= 0) - s1 = SideDefs[sd1].sector; - else - s1 = -1; - if (sd2 >= 0) - s2 = SideDefs[sd2].sector; - else - s2 = -1; - } - else - { - const char *message = "(no linedef selected)"; - set_colour(WINFG_DIM); - DrawScreenText(x0 + (width - FONTW * strlen(message)) / 2, - y0 + (height - FONTH) / 2, message); - } + // Linedef + width = 2 * BOX_BORDER + 2 * WIDE_HSPACING + 29 * FONTW; + height = 2 * BOX_BORDER + 2 * WIDE_VSPACING + (int) (8.5 * FONTH); + x0 = 0; + y0 = out_y1 - height + 1; + ix0 = x0 + BOX_BORDER + WIDE_HSPACING; + iy0 = y0 + BOX_BORDER + WIDE_VSPACING; + // Ignore box_disp -- always redraw the whole box + DrawScreenBox3D(x0, y0, x0 + width - 1, y0 + height - 1); + if (obj_no >= 0) + { + set_colour(WINTITLE); + DrawScreenText(ix0, iy0, "Linedef #%d", obj_no); + set_colour(WINFG); + DrawScreenText(-1, iy0 + (int) (1.5 * FONTH), + "\1Flags:\2 %.19s", + GetLineDefFlagsName(LineDefs[obj_no].flags)); + DrawScreenText(-1, -1, "\1Type:\2 %3d %.19s", + LineDefs[obj_no].type, + GetLineDefTypeName(LineDefs[obj_no].type)); + { + int tag = LineDefs[obj_no].tag; + int first_sector = NumSectors; + int second_sector = NumSectors; + if (tag != 0) + { + for (int n = 0; n < NumSectors; n++) + if (Sectors[n].tag == tag) + { + if (first_sector >= NumSectors) + first_sector = n; + else + { + second_sector = n; + break; + } + } + } + if (first_sector < NumSectors && second_sector < NumSectors) + DrawScreenText(-1, -1, "\1Tag:\2 %d (#%d+)", tag, + first_sector); + else if (first_sector < NumSectors) + DrawScreenText(-1, -1, "\1Tag:\2 %d (#%d)", tag, + first_sector); + else + DrawScreenText(-1, -1, "\1Tag:\2 %d (none)", tag); + } + s1 = LineDefs[obj_no].start; + s2 = LineDefs[obj_no].end; + DrawScreenText(-1, -1, "\1Vertices:\2 (#%d, #%d)", s1, s2); + n = ComputeDist(Vertices[s2].x - Vertices[s1].x, + Vertices[s2].y - Vertices[s1].y); + DrawScreenText(-1, -1, "\1Length:\2 %d", n); + sd1 = LineDefs[obj_no].sidedef1; + sd2 = LineDefs[obj_no].sidedef2; + DrawScreenText(-1, -1, "\1" "1st sd:\2 #%d", sd1); + DrawScreenText(-1, -1, "\1" "2nd sd:\2 #%d", sd2); + if (sd1 >= 0) + s1 = SideDefs[sd1].sector; + else + s1 = -1; + if (sd2 >= 0) + s2 = SideDefs[sd2].sector; + else + s2 = -1; + } + else + { + const char *message = "(no linedef selected)"; + set_colour(WINFG_DIM); + DrawScreenText(x0 + (width - FONTW * strlen(message)) / 2, + y0 + (height - FONTH) / 2, message); + } - // 1st sidedef - x0 += width; - width = 2 * BOX_BORDER + 2 * WIDE_HSPACING + 16 * FONTW; - ix0 = x0 + BOX_BORDER + WIDE_HSPACING; - y0 = out_y1 - height + 1; - // Ignore box_disp -- always redraw the whole box - DrawScreenBox3D(x0, y0, x0 + width - 1, y0 + height - 1); - if (obj_no >= 0 && sd1 >= 0) - { - set_colour(WINTITLE); - DrawScreenText(ix0, iy0, "Sidedef1 #%d", sd1); + // 1st sidedef + x0 += width; + width = 2 * BOX_BORDER + 2 * WIDE_HSPACING + 16 * FONTW; + ix0 = x0 + BOX_BORDER + WIDE_HSPACING; + y0 = out_y1 - height + 1; + // Ignore box_disp -- always redraw the whole box + DrawScreenBox3D(x0, y0, x0 + width - 1, y0 + height - 1); + if (obj_no >= 0 && sd1 >= 0) + { + set_colour(WINTITLE); + DrawScreenText(ix0, iy0, "Sidedef1 #%d", sd1); - if (s1 >= 0 && s2 >= 0 && Sectors[s1].ceilh > Sectors[s2].ceilh - && !(is_sky(Sectors[s1].ceilt) && is_sky(Sectors[s2].ceilt))) - { - if (SideDefs[sd1].tex1[0] == '-' - && SideDefs[sd1].tex1[1] == '\0') - set_colour(CLR_ERROR); - else - set_colour(WINFG); - } - else - set_colour(WINFG_DIM); - DrawScreenText(-1, iy0 + (int) (1.5 * FONTH), "\1Upper:\2 %.*s", - WAD_TEX_NAME, SideDefs[sd1].tex1); + if (s1 >= 0 && s2 >= 0 && Sectors[s1].ceilh > Sectors[s2].ceilh + && !(is_sky(Sectors[s1].ceilt) && is_sky(Sectors[s2].ceilt))) + { + if (SideDefs[sd1].tex1[0] == '-' + && SideDefs[sd1].tex1[1] == '\0') + set_colour(CLR_ERROR); + else + set_colour(WINFG); + } + else + set_colour(WINFG_DIM); + DrawScreenText(-1, iy0 + (int) (1.5 * FONTH), "\1Upper:\2 %.*s", + WAD_TEX_NAME, SideDefs[sd1].tex1); - if (sd2 < 0 - && SideDefs[sd1].tex3[0] == '-' - && SideDefs[sd1].tex3[1] == '\0') - set_colour(CLR_ERROR); - else - set_colour(WINFG); - DrawScreenText(-1, -1, - "\1Middle:\2 %.*s", WAD_TEX_NAME, - SideDefs[sd1].tex3); + if (sd2 < 0 + && SideDefs[sd1].tex3[0] == '-' + && SideDefs[sd1].tex3[1] == '\0') + set_colour(CLR_ERROR); + else + set_colour(WINFG); + DrawScreenText(-1, -1, + "\1Middle:\2 %.*s", WAD_TEX_NAME, + SideDefs[sd1].tex3); - if (s1 >= 0 && s2 >= 0 && Sectors[s1].floorh < Sectors[s2].floorh - && !(is_sky(Sectors[s1].floort) - && is_sky(Sectors[s2].floort))) - { - if (SideDefs[sd1].tex2[0] == '-' - && SideDefs[sd1].tex2[1] == '\0') - set_colour(CLR_ERROR); - else - set_colour(WINFG); - } - else - set_colour(WINFG_DIM); - DrawScreenText(-1, -1, "\1Lower:\2 %.*s", - WAD_TEX_NAME, SideDefs[sd1].tex2); + if (s1 >= 0 && s2 >= 0 && Sectors[s1].floorh < Sectors[s2].floorh + && !(is_sky(Sectors[s1].floort) + && is_sky(Sectors[s2].floort))) + { + if (SideDefs[sd1].tex2[0] == '-' + && SideDefs[sd1].tex2[1] == '\0') + set_colour(CLR_ERROR); + else + set_colour(WINFG); + } + else + set_colour(WINFG_DIM); + DrawScreenText(-1, -1, "\1Lower:\2 %.*s", + WAD_TEX_NAME, SideDefs[sd1].tex2); - set_colour(WINFG); - DrawScreenText(-1, -1, "\1X-ofs:\2 %d", SideDefs[sd1].xoff); - DrawScreenText(-1, -1, "\1Y-ofs:\2 %d", SideDefs[sd1].yoff); - DrawScreenText(-1, -1, "\1Sector:\2 #%d", s1); - } - else - { - const char *message = "(no 1st sidedef)"; - set_colour(CLR_ERROR); - DrawScreenText(x0 + (width - FONTW * strlen(message)) / 2, - y0 + (height - FONTH) / 2, message); - } + set_colour(WINFG); + DrawScreenText(-1, -1, "\1X-ofs:\2 %d", SideDefs[sd1].xoff); + DrawScreenText(-1, -1, "\1Y-ofs:\2 %d", SideDefs[sd1].yoff); + DrawScreenText(-1, -1, "\1Sector:\2 #%d", s1); + } + else + { + const char *message = "(no 1st sidedef)"; + set_colour(CLR_ERROR); + DrawScreenText(x0 + (width - FONTW * strlen(message)) / 2, + y0 + (height - FONTH) / 2, message); + } - // 2nd sidedef - x0 += width; - ix0 = x0 + BOX_BORDER + WIDE_HSPACING; - y0 = out_y1 - height + 1; - // Ignore box_disp -- always redraw the whole box - DrawScreenBox3D(x0, y0, x0 + width - 1, y0 + height - 1); - if (obj_no >= 0 && sd2 >= 0) - { - set_colour(WINTITLE); - DrawScreenText(ix0, iy0, "Sidedef2 #%d", sd2); - set_colour(WINFG); - const char *tex_name; + // 2nd sidedef + x0 += width; + ix0 = x0 + BOX_BORDER + WIDE_HSPACING; + y0 = out_y1 - height + 1; + // Ignore box_disp -- always redraw the whole box + DrawScreenBox3D(x0, y0, x0 + width - 1, y0 + height - 1); + if (obj_no >= 0 && sd2 >= 0) + { + set_colour(WINTITLE); + DrawScreenText(ix0, iy0, "Sidedef2 #%d", sd2); + set_colour(WINFG); + const char *tex_name; - tex_name = SideDefs[sd2].tex1; // Upper texture - if (s1 >= 0 && s2 >= 0 && Sectors[s2].ceilh > Sectors[s1].ceilh - && !(is_sky(Sectors[s1].ceilt) && is_sky(Sectors[s2].ceilt))) - { - if (tex_name[0] == '-' && tex_name[1] == '\0') - set_colour(CLR_ERROR); - else - set_colour(WINFG); - } - else - set_colour(WINFG_DIM); - DrawScreenText(-1, iy0 + (int) (1.5 * FONTH), - "\1Upper:\2 %.*s", WAD_TEX_NAME, tex_name); + tex_name = SideDefs[sd2].tex1; // Upper texture + if (s1 >= 0 && s2 >= 0 && Sectors[s2].ceilh > Sectors[s1].ceilh + && !(is_sky(Sectors[s1].ceilt) && is_sky(Sectors[s2].ceilt))) + { + if (tex_name[0] == '-' && tex_name[1] == '\0') + set_colour(CLR_ERROR); + else + set_colour(WINFG); + } + else + set_colour(WINFG_DIM); + DrawScreenText(-1, iy0 + (int) (1.5 * FONTH), + "\1Upper:\2 %.*s", WAD_TEX_NAME, tex_name); - tex_name = SideDefs[sd2].tex3; // Middle texture - set_colour(WINFG); - DrawScreenText(-1, -1, - "\1Middle:\2 %.*s", WAD_TEX_NAME, tex_name); + tex_name = SideDefs[sd2].tex3; // Middle texture + set_colour(WINFG); + DrawScreenText(-1, -1, + "\1Middle:\2 %.*s", WAD_TEX_NAME, tex_name); - tex_name = SideDefs[sd2].tex2; // Lower texture - if (s1 >= 0 && s2 >= 0 && Sectors[s2].floorh < Sectors[s1].floorh - && !(is_sky(Sectors[s1].floort) - && is_sky(Sectors[s2].floort))) - { - if (tex_name[0] == '-' && tex_name[1] == '\0') - set_colour(CLR_ERROR); - else - set_colour(WINFG); - } - else - set_colour(WINFG_DIM); - DrawScreenText(-1, -1, "\1Lower:\2 %.*s", WAD_TEX_NAME, - tex_name); + tex_name = SideDefs[sd2].tex2; // Lower texture + if (s1 >= 0 && s2 >= 0 && Sectors[s2].floorh < Sectors[s1].floorh + && !(is_sky(Sectors[s1].floort) + && is_sky(Sectors[s2].floort))) + { + if (tex_name[0] == '-' && tex_name[1] == '\0') + set_colour(CLR_ERROR); + else + set_colour(WINFG); + } + else + set_colour(WINFG_DIM); + DrawScreenText(-1, -1, "\1Lower:\2 %.*s", WAD_TEX_NAME, + tex_name); - set_colour(WINFG); - DrawScreenText(-1, -1, "\1X-ofs:\2 %d", SideDefs[sd2].xoff); - DrawScreenText(-1, -1, "\1Y-ofs:\2 %d", SideDefs[sd2].yoff); - DrawScreenText(-1, -1, "\1Sector:\2 #%d", s2); - } - else - { - const char *message = "(no 2nd sidedef)"; - // If the "2" flag is set, there must be a second sidedef - if (LineDefs[obj_no].flags & 0x04) // FIXME hard-coded - set_colour(CLR_ERROR); - else - set_colour(WINFG_DIM); - DrawScreenText(x0 + (width - FONTW * strlen(message)) / 2, - y0 + (height - FONTH) / 2, message); - } + set_colour(WINFG); + DrawScreenText(-1, -1, "\1X-ofs:\2 %d", SideDefs[sd2].xoff); + DrawScreenText(-1, -1, "\1Y-ofs:\2 %d", SideDefs[sd2].yoff); + DrawScreenText(-1, -1, "\1Sector:\2 #%d", s2); + } + else + { + const char *message = "(no 2nd sidedef)"; + // If the "2" flag is set, there must be a second sidedef + if (LineDefs[obj_no].flags & 0x04) // FIXME hard-coded + set_colour(CLR_ERROR); + else + set_colour(WINFG_DIM); + DrawScreenText(x0 + (width - FONTW * strlen(message)) / 2, + y0 + (height - FONTH) / 2, message); + } - // Superimposed linedefs - { - Superimposed_ld super; - super.set(obj_no); - obj_no_t l = super.get(); - int iy1; + // Superimposed linedefs + { + Superimposed_ld super; + super.set(obj_no); + obj_no_t l = super.get(); + int iy1; - if (l != -1 || box_disp[3]) - { - x0 += width; - width = 2 * BOX_BORDER + 2 * WIDE_HSPACING + 12 * FONTW; - ix0 = x0 + BOX_BORDER + WIDE_HSPACING; - iy0 = y0 + BOX_BORDER + WIDE_VSPACING; - iy1 = y0 + height - 1 - BOX_BORDER - WIDE_VSPACING; - DrawScreenBox3D(x0, y0, x0 + width - 1, y0 + height - 1); - } - if (l != -1) - { - box_disp[3] = true; - set_colour(WINTITLE); - DrawScreenString(ix0, iy0, "Superimposed"); - set_colour(WINFG); - iy0 += int (1.5 * FONTH); - while (l != -1) - { - if (iy0 + FONTH - 1 <= iy1) - DrawScreenText(ix0, iy0, "#%d", l); - /* Too many linedefs, replace the last one by "(more)". - Not elegant, but it makes the code simpler. */ - else - { - iy0 -= FONTH; - set_colour(WINBG); - DrawScreenBox(ix0, iy0, ix0 + 12 * FONTW - 1, - iy0 + FONTH - 1); - set_colour(WINFG); - DrawScreenString(ix0, iy0, "(more)"); - break; - } - iy0 += FONTH; - l = super.get(); - } - } - } - break; + if (l != -1 || box_disp[3]) + { + x0 += width; + width = 2 * BOX_BORDER + 2 * WIDE_HSPACING + 12 * FONTW; + ix0 = x0 + BOX_BORDER + WIDE_HSPACING; + iy0 = y0 + BOX_BORDER + WIDE_VSPACING; + iy1 = y0 + height - 1 - BOX_BORDER - WIDE_VSPACING; + DrawScreenBox3D(x0, y0, x0 + width - 1, y0 + height - 1); + } + if (l != -1) + { + box_disp[3] = true; + set_colour(WINTITLE); + DrawScreenString(ix0, iy0, "Superimposed"); + set_colour(WINFG); + iy0 += int (1.5 * FONTH); + while (l != -1) + { + if (iy0 + FONTH - 1 <= iy1) + DrawScreenText(ix0, iy0, "#%d", l); + /* Too many linedefs, replace the last one by "(more)". + Not elegant, but it makes the code simpler. */ + else + { + iy0 -= FONTH; + set_colour(WINBG); + DrawScreenBox(ix0, iy0, ix0 + 12 * FONTW - 1, + iy0 + FONTH - 1); + set_colour(WINFG); + DrawScreenString(ix0, iy0, "(more)"); + break; + } + iy0 += FONTH; + l = super.get(); + } + } + } + break; case OBJ_VERTICES: - width = 2 * BOX_BORDER + 2 * WIDE_HSPACING + 29 * FONTW; - height = 2 * BOX_BORDER + 2 * WIDE_VSPACING + (int) (2.5 * FONTH); - x0 = 0; - y0 = out_y1 - height + 1; - ix0 = x0 + BOX_BORDER + WIDE_HSPACING; - iy0 = y0 + BOX_BORDER + WIDE_VSPACING; - // Ignore box_disp -- always redraw the whole box - DrawScreenBox3D(x0, y0, x0 + width - 1, y0 + height - 1); - if (obj_no < 0) - { - const char *message = "(no vertex selected)"; - set_colour(WINFG_DIM); - DrawScreenText(x0 + (width - FONTW * strlen(message)) / 2, - y0 + (height - FONTH) / 2, message); - break; - } - set_colour(WINTITLE); - DrawScreenText(ix0, iy0, "Vertex #%d", obj_no); - set_colour(WINFG); - DrawScreenText(-1, iy0 + (int) (1.5 * FONTH), - "\1Coordinates:\2 (%d, %d)", Vertices[obj_no].x, - Vertices[obj_no].y); - break; + width = 2 * BOX_BORDER + 2 * WIDE_HSPACING + 29 * FONTW; + height = 2 * BOX_BORDER + 2 * WIDE_VSPACING + (int) (2.5 * FONTH); + x0 = 0; + y0 = out_y1 - height + 1; + ix0 = x0 + BOX_BORDER + WIDE_HSPACING; + iy0 = y0 + BOX_BORDER + WIDE_VSPACING; + // Ignore box_disp -- always redraw the whole box + DrawScreenBox3D(x0, y0, x0 + width - 1, y0 + height - 1); + if (obj_no < 0) + { + const char *message = "(no vertex selected)"; + set_colour(WINFG_DIM); + DrawScreenText(x0 + (width - FONTW * strlen(message)) / 2, + y0 + (height - FONTH) / 2, message); + break; + } + set_colour(WINTITLE); + DrawScreenText(ix0, iy0, "Vertex #%d", obj_no); + set_colour(WINFG); + DrawScreenText(-1, iy0 + (int) (1.5 * FONTH), + "\1Coordinates:\2 (%d, %d)", Vertices[obj_no].x, + Vertices[obj_no].y); + break; case OBJ_SECTORS: - { - int x1, y1; - int ix1, iy1; - const int columns = 24; - width = BOX_BORDER - + WIDE_HSPACING - + columns * FONTW - + WIDE_HSPACING - + HOLLOW_BORDER - + DOOM_FLAT_WIDTH - + HOLLOW_BORDER + WIDE_HSPACING + BOX_BORDER; - height = 2 * BOX_BORDER - + 2 * WIDE_VSPACING - + y_max((unsigned) (9.5 * FONTH), - WIDE_HSPACING + 4 * HOLLOW_BORDER + - 2 * DOOM_FLAT_HEIGHT); - x0 = 0; - y0 = out_y1 - height + 1; - x1 = x0 + width - 1; - y1 = y0 + height - 1; - ix0 = x0 + BOX_BORDER + WIDE_HSPACING; - iy0 = y0 + BOX_BORDER + WIDE_VSPACING; - ix1 = x1 - BOX_BORDER - WIDE_HSPACING; - iy1 = y1 - BOX_BORDER - WIDE_VSPACING; - if (box_disp[0]) - { - push_colour(WINBG); - DrawScreenBox(ix0, iy0, ix0 + columns * FONTW - 1, iy1); - pop_colour(); - } - else - DrawScreenBox3D(x0, y0, x1, y1); - if (obj_no < 0) - { - const char *const message = "(no sector selected)"; - set_colour(WINFG_DIM); - DrawScreenText(x0 + (width - FONTW * strlen(message)) / 2, - y0 + (height - FONTH) / 2, message); - break; - } - set_colour(WINTITLE); - DrawScreenText(ix0, iy0, "Sector #%d", obj_no); - set_colour(WINFG); - const struct Sector *sec = Sectors + obj_no; - if (prev_sector >= 0 && prev_sector != obj_no) - { - DrawScreenText(-1, iy0 + (int) (1.5 * FONTH), - "\1Floor:\2 %d (%+d)", - sec->floorh, sec->floorh - prev_floorh); - DrawScreenText(-1, -1, "\1Ceiling:\2 %d (%+d)", - sec->ceilh, sec->ceilh - prev_ceilh); - } - else - { - DrawScreenText(-1, iy0 + (int) (1.5 * FONTH), - "\1Floor:\2 %d", sec->floorh); - DrawScreenText(-1, -1, "\1Ceiling:\2 %d", sec->ceilh); - } - DrawScreenText(-1, -1, "\1Headroom:\2 %d", - sec->ceilh - sec->floorh); - DrawScreenText(-1, -1, "\1Floor:\2 %.*s", WAD_FLAT_NAME, - sec->floort); - DrawScreenText(-1, -1, "\1Ceiling:\2 %.*s", WAD_FLAT_NAME, - sec->ceilt); - DrawScreenText(-1, -1, "\1Light:\2 %d", sec->light); - DrawScreenText(-1, -1, "\1Type:\2 %3d %.14s", - sec->special, GetSectorTypeName(sec->special)); - { - int tag = sec->tag; - int first_ld = NumLineDefs; - int second_ld = NumLineDefs; + { + int x1, y1; + int ix1, iy1; + const int columns = 24; + width = BOX_BORDER + + WIDE_HSPACING + + columns * FONTW + + WIDE_HSPACING + + HOLLOW_BORDER + + DOOM_FLAT_WIDTH + + HOLLOW_BORDER + WIDE_HSPACING + BOX_BORDER; + height = 2 * BOX_BORDER + + 2 * WIDE_VSPACING + + y_max((unsigned) (9.5 * FONTH), + WIDE_HSPACING + 4 * HOLLOW_BORDER + + 2 * DOOM_FLAT_HEIGHT); + x0 = 0; + y0 = out_y1 - height + 1; + x1 = x0 + width - 1; + y1 = y0 + height - 1; + ix0 = x0 + BOX_BORDER + WIDE_HSPACING; + iy0 = y0 + BOX_BORDER + WIDE_VSPACING; + ix1 = x1 - BOX_BORDER - WIDE_HSPACING; + iy1 = y1 - BOX_BORDER - WIDE_VSPACING; + if (box_disp[0]) + { + push_colour(WINBG); + DrawScreenBox(ix0, iy0, ix0 + columns * FONTW - 1, iy1); + pop_colour(); + } + else + DrawScreenBox3D(x0, y0, x1, y1); + if (obj_no < 0) + { + const char *const message = "(no sector selected)"; + set_colour(WINFG_DIM); + DrawScreenText(x0 + (width - FONTW * strlen(message)) / 2, + y0 + (height - FONTH) / 2, message); + break; + } + set_colour(WINTITLE); + DrawScreenText(ix0, iy0, "Sector #%d", obj_no); + set_colour(WINFG); + const struct Sector *sec = Sectors + obj_no; + if (prev_sector >= 0 && prev_sector != obj_no) + { + DrawScreenText(-1, iy0 + (int) (1.5 * FONTH), + "\1Floor:\2 %d (%+d)", + sec->floorh, sec->floorh - prev_floorh); + DrawScreenText(-1, -1, "\1Ceiling:\2 %d (%+d)", + sec->ceilh, sec->ceilh - prev_ceilh); + } + else + { + DrawScreenText(-1, iy0 + (int) (1.5 * FONTH), + "\1Floor:\2 %d", sec->floorh); + DrawScreenText(-1, -1, "\1Ceiling:\2 %d", sec->ceilh); + } + DrawScreenText(-1, -1, "\1Headroom:\2 %d", + sec->ceilh - sec->floorh); + DrawScreenText(-1, -1, "\1Floor:\2 %.*s", WAD_FLAT_NAME, + sec->floort); + DrawScreenText(-1, -1, "\1Ceiling:\2 %.*s", WAD_FLAT_NAME, + sec->ceilt); + DrawScreenText(-1, -1, "\1Light:\2 %d", sec->light); + DrawScreenText(-1, -1, "\1Type:\2 %3d %.14s", + sec->special, GetSectorTypeName(sec->special)); + { + int tag = sec->tag; + int first_ld = NumLineDefs; + int second_ld = NumLineDefs; - if (tag != 0) - { - for (n = 0; n < NumLineDefs; n++) - if (LineDefs[n].tag == tag) - { - if (first_ld >= NumLineDefs) - first_ld = n; - else - { - second_ld = n; - break; - } - } - } - if (first_ld < NumLineDefs && second_ld < NumLineDefs) - DrawScreenText(-1, -1, "\1Tag:\2 %d (#%d+)", tag, - first_ld); - else if (first_ld < NumLineDefs) - DrawScreenText(-1, -1, "\1Tag:\2 %d (#%d)", tag, - first_ld); - else if (tag == 99 || tag == 999) - DrawScreenText(-1, -1, "\1Tag:\2 %d (stairs?)", tag); - else if (tag == 666) - DrawScreenText(-1, -1, "\1Tag:\2 %d (lower@end)", - tag); - else if (tag == 667) - DrawScreenText(-1, -1, "\1Tag:\2 %d (raise@end)", - tag); - else - DrawScreenText(-1, -1, "\1Tag:\2 %d (none)", tag); - } - { - hookfunc_comm_t block; + if (tag != 0) + { + for (n = 0; n < NumLineDefs; n++) + if (LineDefs[n].tag == tag) + { + if (first_ld >= NumLineDefs) + first_ld = n; + else + { + second_ld = n; + break; + } + } + } + if (first_ld < NumLineDefs && second_ld < NumLineDefs) + DrawScreenText(-1, -1, "\1Tag:\2 %d (#%d+)", tag, + first_ld); + else if (first_ld < NumLineDefs) + DrawScreenText(-1, -1, "\1Tag:\2 %d (#%d)", tag, + first_ld); + else if (tag == 99 || tag == 999) + DrawScreenText(-1, -1, "\1Tag:\2 %d (stairs?)", tag); + else if (tag == 666) + DrawScreenText(-1, -1, "\1Tag:\2 %d (lower@end)", + tag); + else if (tag == 667) + DrawScreenText(-1, -1, "\1Tag:\2 %d (raise@end)", + tag); + else + DrawScreenText(-1, -1, "\1Tag:\2 %d (none)", tag); + } + { + hookfunc_comm_t block; - // Display the floor texture in the bottom right corner - block.x1 = ix1; - block.x0 = - block.x1 - (DOOM_FLAT_WIDTH + 2 * HOLLOW_BORDER - 1); - block.y1 = iy1; - block.y0 = - block.y1 - (DOOM_FLAT_HEIGHT + 2 * HOLLOW_BORDER - 1); - block.name = sec->floort; - display_flat_depressed(&block); + // Display the floor texture in the bottom right corner + block.x1 = ix1; + block.x0 = + block.x1 - (DOOM_FLAT_WIDTH + 2 * HOLLOW_BORDER - 1); + block.y1 = iy1; + block.y0 = + block.y1 - (DOOM_FLAT_HEIGHT + 2 * HOLLOW_BORDER - 1); + block.name = sec->floort; + display_flat_depressed(&block); - // Display the ceiling texture above the floor texture - block.y1 = block.y0 - (WIDE_VSPACING + 1); - block.y0 = - block.y1 - (DOOM_FLAT_HEIGHT + 2 * HOLLOW_BORDER - 1); - block.name = sec->ceilt; - display_flat_depressed(&block); - } + // Display the ceiling texture above the floor texture + block.y1 = block.y0 - (WIDE_VSPACING + 1); + block.y0 = + block.y1 - (DOOM_FLAT_HEIGHT + 2 * HOLLOW_BORDER - 1); + block.name = sec->ceilt; + display_flat_depressed(&block); + } - // Show all EDGE extrafloors for this sector - { - x0 += width; - const int columns2 = 16; - const int width2 = BOX_BORDER - + WIDE_HSPACING - + columns2 * FONTW - + WIDE_HSPACING - + HOLLOW_BORDER - + DOOM_FLAT_WIDTH - + HOLLOW_BORDER + WIDE_HSPACING + BOX_BORDER; - std::vector < Extraf > v; - get_extrafloors(v, sec->tag); - size_t e; - for (e = 0; e < v.size() && e + 1 < MAX_BOXES; - e++, x0 += width2) - { - const Extraf & i = v[e]; - obj_no_t dsecno = i.sector; - bool thick = (*i.tex != '\0'); - const struct Sector *dsec = Sectors + dsecno; - x1 = x0 + width2 - 1; - y1 = y0 + height - 1; - ix0 = x0 + BOX_BORDER + WIDE_HSPACING; - iy0 = y0 + BOX_BORDER + WIDE_VSPACING; - ix1 = x1 - BOX_BORDER - WIDE_HSPACING; - iy1 = y1 - BOX_BORDER - WIDE_VSPACING; - if (box_disp[e + 1]) // FIXME - { - push_colour(WINBG); - DrawScreenBox(ix0, iy0, ix0 + columns2 * FONTW - 1, - iy1); - pop_colour(); - } - else - { - DrawScreenBox3D(x0, y0, x1, y1); - box_disp[e + 1] = true; - } - if (!is_sector(dsecno)) // Can't happen - continue; - set_colour(WINTITLE); - if (thick) - DrawScreenText(ix0, iy0, "Thick #%d", dsecno); - else - DrawScreenText(ix0, iy0, "Thin #%d", dsecno); - set_colour(WINFG); - if (thick) - { - DrawScreenText(-1, iy0 + (int) (1.5 * FONTH), - "\1Bottom:\2 %d", dsec->floorh); - DrawScreenText(-1, -1, "\1Top:\2 %d", dsec->ceilh); - DrawScreenText(-1, -1, "\1Thick:\2 %d", - dsec->ceilh - dsec->floorh); - DrawScreenText(-1, -1, "\1Bottom:\2 %.*s", - WAD_FLAT_NAME, dsec->floort); - DrawScreenText(-1, -1, "\1Top:\2 %.*s", - WAD_FLAT_NAME, dsec->ceilt); - } - else - { - DrawScreenText(-1, iy0 + (int) (1.5 * FONTH), - "\1Height:\2 %d", dsec->floorh); - DrawScreenText(-1, -1, "\1Flat:\2 %.*s", - WAD_FLAT_NAME, dsec->floort); - } - DrawScreenText(-1, -1, "\1Shadow:\2 %d", dsec->light); - DrawScreenText(-1, -1, "\1Type:\2 %d", dsec->special); - if (thick) - DrawScreenText(-1, -1, "\1Side:\2 %.*s", - WAD_TEX_NAME, i.tex); - { - hookfunc_comm_t block; + // Show all EDGE extrafloors for this sector + { + x0 += width; + const int columns2 = 16; + const int width2 = BOX_BORDER + + WIDE_HSPACING + + columns2 * FONTW + + WIDE_HSPACING + + HOLLOW_BORDER + + DOOM_FLAT_WIDTH + + HOLLOW_BORDER + WIDE_HSPACING + BOX_BORDER; + std::vector < Extraf > v; + get_extrafloors(v, sec->tag); + size_t e; + for (e = 0; e < v.size() && e + 1 < MAX_BOXES; + e++, x0 += width2) + { + const Extraf & i = v[e]; + obj_no_t dsecno = i.sector; + bool thick = (*i.tex != '\0'); + const struct Sector *dsec = Sectors + dsecno; + x1 = x0 + width2 - 1; + y1 = y0 + height - 1; + ix0 = x0 + BOX_BORDER + WIDE_HSPACING; + iy0 = y0 + BOX_BORDER + WIDE_VSPACING; + ix1 = x1 - BOX_BORDER - WIDE_HSPACING; + iy1 = y1 - BOX_BORDER - WIDE_VSPACING; + if (box_disp[e + 1]) // FIXME + { + push_colour(WINBG); + DrawScreenBox(ix0, iy0, ix0 + columns2 * FONTW - 1, + iy1); + pop_colour(); + } + else + { + DrawScreenBox3D(x0, y0, x1, y1); + box_disp[e + 1] = true; + } + if (!is_sector(dsecno)) // Can't happen + continue; + set_colour(WINTITLE); + if (thick) + DrawScreenText(ix0, iy0, "Thick #%d", dsecno); + else + DrawScreenText(ix0, iy0, "Thin #%d", dsecno); + set_colour(WINFG); + if (thick) + { + DrawScreenText(-1, iy0 + (int) (1.5 * FONTH), + "\1Bottom:\2 %d", dsec->floorh); + DrawScreenText(-1, -1, "\1Top:\2 %d", dsec->ceilh); + DrawScreenText(-1, -1, "\1Thick:\2 %d", + dsec->ceilh - dsec->floorh); + DrawScreenText(-1, -1, "\1Bottom:\2 %.*s", + WAD_FLAT_NAME, dsec->floort); + DrawScreenText(-1, -1, "\1Top:\2 %.*s", + WAD_FLAT_NAME, dsec->ceilt); + } + else + { + DrawScreenText(-1, iy0 + (int) (1.5 * FONTH), + "\1Height:\2 %d", dsec->floorh); + DrawScreenText(-1, -1, "\1Flat:\2 %.*s", + WAD_FLAT_NAME, dsec->floort); + } + DrawScreenText(-1, -1, "\1Shadow:\2 %d", dsec->light); + DrawScreenText(-1, -1, "\1Type:\2 %d", dsec->special); + if (thick) + DrawScreenText(-1, -1, "\1Side:\2 %.*s", + WAD_TEX_NAME, i.tex); + { + hookfunc_comm_t block; - // Display the top texture in the bottom right corner - block.x1 = ix1; - block.x0 = - block.x1 - (DOOM_FLAT_WIDTH + 2 * HOLLOW_BORDER - - 1); - block.y1 = iy1; - block.y0 = - block.y1 - (DOOM_FLAT_HEIGHT + 2 * HOLLOW_BORDER - - 1); - block.name = dsec->floort; - display_flat_depressed(&block); + // Display the top texture in the bottom right corner + block.x1 = ix1; + block.x0 = + block.x1 - (DOOM_FLAT_WIDTH + 2 * HOLLOW_BORDER - + 1); + block.y1 = iy1; + block.y0 = + block.y1 - (DOOM_FLAT_HEIGHT + 2 * HOLLOW_BORDER - + 1); + block.name = dsec->floort; + display_flat_depressed(&block); - // Display the bottom texture above the floor texture - block.y1 = block.y0 - (WIDE_VSPACING + 1); - block.y0 = - block.y1 - (DOOM_FLAT_HEIGHT + 2 * HOLLOW_BORDER - - 1); - if (thick) - { - block.name = dsec->ceilt; - display_flat_depressed(&block); - } - else - { - push_colour(WINBG); - DrawScreenBoxwh(block.x0, block.y0, - DOOM_FLAT_WIDTH + - 2 * HOLLOW_BORDER, - DOOM_FLAT_HEIGHT + - 2 * HOLLOW_BORDER); - pop_colour(); - } - } - } - // Clear out remaining boxes - for (; e + 1 < MAX_BOXES && box_disp[e + 1]; - e++, x0 += width2) - { - x1 = x0 + width2 - 1; - y1 = y0 + height - 1; - ix0 = x0 + BOX_BORDER + WIDE_HSPACING; - iy0 = y0 + BOX_BORDER + WIDE_VSPACING; - ix1 = x1 - BOX_BORDER - WIDE_HSPACING; - iy1 = y1 - BOX_BORDER - WIDE_VSPACING; - push_colour(WINBG); - DrawScreenBox(ix0, iy0, ix1, iy1); - pop_colour(); - } - } - break; - } + // Display the bottom texture above the floor texture + block.y1 = block.y0 - (WIDE_VSPACING + 1); + block.y0 = + block.y1 - (DOOM_FLAT_HEIGHT + 2 * HOLLOW_BORDER - + 1); + if (thick) + { + block.name = dsec->ceilt; + display_flat_depressed(&block); + } + else + { + push_colour(WINBG); + DrawScreenBoxwh(block.x0, block.y0, + DOOM_FLAT_WIDTH + + 2 * HOLLOW_BORDER, + DOOM_FLAT_HEIGHT + + 2 * HOLLOW_BORDER); + pop_colour(); + } + } + } + // Clear out remaining boxes + for (; e + 1 < MAX_BOXES && box_disp[e + 1]; + e++, x0 += width2) + { + x1 = x0 + width2 - 1; + y1 = y0 + height - 1; + ix0 = x0 + BOX_BORDER + WIDE_HSPACING; + iy0 = y0 + BOX_BORDER + WIDE_VSPACING; + ix1 = x1 - BOX_BORDER - WIDE_HSPACING; + iy1 = y1 - BOX_BORDER - WIDE_VSPACING; + push_colour(WINBG); + DrawScreenBox(ix0, iy0, ix1, iy1); + pop_colour(); + } + } + break; + } } if (obj_type == OBJ_SECTORS) { - if (obj_no != prev_sector) - prev_sector = obj_no; - if (obj_no >= 0) - { - prev_floorh = Sectors[obj_no].floorh; - prev_ceilh = Sectors[obj_no].ceilh; - } + if (obj_no != prev_sector) + prev_sector = obj_no; + if (obj_no >= 0) + { + prev_floorh = Sectors[obj_no].floorh; + prev_ceilh = Sectors[obj_no].ceilh; + } } box_disp[0] = true; obj_no_disp = obj_no; @@ -778,43 +778,43 @@ /* - * get_extrafloors - get list of EDGE extrafloors for tag + * get_extrafloors - get list of EDGE extrafloors for tag * - * Put in <v> a list of the extrafloors for tag <tag>, - * sorted by floor height major, sector number minor. The - * previous content of <v> is lost. Each Extraf object in - * <v> is set up in the following way : + * Put in <v> a list of the extrafloors for tag <tag>, + * sorted by floor height major, sector number minor. The + * previous content of <v> is lost. Each Extraf object in + * <v> is set up in the following way : * - * - <sector> is set to the number of the dummy sector, + * - <sector> is set to the number of the dummy sector, * - * - <tex> is set to the side texture of the extrafloor, or - * "" if it's a thin extrafloor, + * - <tex> is set to the side texture of the extrafloor, or + * "" if it's a thin extrafloor, * - * - <height> is the to the floor height of the dummy - * sector. + * - <height> is the to the floor height of the dummy + * sector. */ static void get_extrafloors(std::vector < Extraf > &v, wad_tag_t tag) { v.clear(); for (obj_no_t l = 0; l < NumLineDefs; l++) { - if (LineDefs[l].tag == tag && LineDefs[l].type >= 400 && LineDefs[l].type <= 407) // FIXME - { - obj_no_t sd = LineDefs[l].sidedef1; - if (!is_sidedef(sd) || !is_sector(SideDefs[sd].sector)) // Paranoia - continue; - wad_tex_name_t tex; - if (LineDefs[l].type == 400) - memcpy(tex, SideDefs[sd].tex3, sizeof tex); - else if (LineDefs[l].type == 401) // side_upper - memcpy(tex, SideDefs[sd].tex1, sizeof tex); - else if (LineDefs[l].type == 402) // side_lower - memcpy(tex, SideDefs[sd].tex2, sizeof tex); - else - memset(tex, '\0', sizeof tex); - v.push_back(Extraf(SideDefs[sd].sector, - tex, Sectors[SideDefs[sd].sector].floorh)); - } + if (LineDefs[l].tag == tag && LineDefs[l].type >= 400 && LineDefs[l].type <= 407) // FIXME + { + obj_no_t sd = LineDefs[l].sidedef1; + if (!is_sidedef(sd) || !is_sector(SideDefs[sd].sector)) // Paranoia + continue; + wad_tex_name_t tex; + if (LineDefs[l].type == 400) + memcpy(tex, SideDefs[sd].tex3, sizeof tex); + else if (LineDefs[l].type == 401) // side_upper + memcpy(tex, SideDefs[sd].tex1, sizeof tex); + else if (LineDefs[l].type == 402) // side_lower + memcpy(tex, SideDefs[sd].tex2, sizeof tex); + else + memset(tex, '\0', sizeof tex); + v.push_back(Extraf(SideDefs[sd].sector, + tex, Sectors[SideDefs[sd].sector].floorh)); + } } sort(v.begin(), v.end()); } diff -r 594dea11ccd9 -r a68786b9c74b src/objinfo.h --- a/src/objinfo.h Sat Sep 24 15:01:56 2011 +0300 +++ b/src/objinfo.h Sat Sep 24 15:59:33 2011 +0300 @@ -1,6 +1,6 @@ /* - * objinfo.h - * AYM 1998-09-20 + * objinfo.h + * AYM 1998-09-20 */ @@ -35,53 +35,53 @@ public: objinfo_c(); void set(int obj_type, int obj_no) { - this->obj_no = obj_no; - this->obj_type = obj_type; + this->obj_no = obj_no; + this->obj_type = obj_type; } void set_y1(int y1) { - out_y1 = y1; + out_y1 = y1; } /* Methods declared in edwidget_c */ void unset() { - obj_no = OBJ_NO_NONE; + obj_no = OBJ_NO_NONE; } void draw(); void undraw() { - } // Sorry, I don't know how to undraw myself + } // Sorry, I don't know how to undraw myself int can_undraw() { - return 0; - } // I don't have the ability to undraw myself + return 0; + } // I don't have the ability to undraw myself int need_to_clear() { - return is_obj(obj_no_disp) && !is_obj(obj_no); + return is_obj(obj_no_disp) && !is_obj(obj_no); } void clear() { - for (size_t n = 0; n < MAX_BOXES; n++) - box_disp[n] = false; - obj_no_disp = OBJ_NO_NONE; + for (size_t n = 0; n < MAX_BOXES; n++) + box_disp[n] = false; + obj_no_disp = OBJ_NO_NONE; } private: static const size_t MAX_BOXES = 10; - bool box_disp[MAX_BOXES]; // Is the box already drawn ? - int obj_no; // The no. of the object we should display info about - int obj_type; // The type of the object we should display info about - int obj_no_disp; // The no. and type of the object for which info - int obj_type_disp; // is really displayed. - int prev_sector; // No. of the last sector for which info was displayed - int prev_floorh; // Its floor height. - int prev_ceilh; // Its ceiling height. - int out_y1; // The bottom outer edge of the info window. + bool box_disp[MAX_BOXES]; // Is the box already drawn ? + int obj_no; // The no. of the object we should display info about + int obj_type; // The type of the object we should display info about + int obj_no_disp; // The no. and type of the object for which info + int obj_type_disp; // is really displayed. + int prev_sector; // No. of the last sector for which info was displayed + int prev_floorh; // Its floor height. + int prev_ceilh; // Its ceiling height. + int out_y1; // The bottom outer edge of the info window. }; diff -r 594dea11ccd9 -r a68786b9c74b src/oldmenus.cc --- a/src/oldmenus.cc Sat Sep 24 15:01:56 2011 +0300 +++ b/src/oldmenus.cc Sat Sep 24 15:59:33 2011 +0300 @@ -1,12 +1,12 @@ /* - * oldmenus.cc - * Old-fashioned menu functions, somewhat similar to the - * ones DEU 5.21 had in menus.c. Since they contain an event - * loop of their own, they can't handle expose and configure - * notify events properly. When I have the time, I'll - * replace this system by a modal widgets stack in - * edisplay.cc. - * AYM 1998-12-03 + * oldmenus.cc + * Old-fashioned menu functions, somewhat similar to the + * ones DEU 5.21 had in menus.c. Since they contain an event + * loop of their own, they can't handle expose and configure + * notify events properly. When I have the time, I'll + * replace this system by a modal widgets stack in + * edisplay.cc. + * AYM 1998-12-03 */ @@ -45,12 +45,12 @@ /* - * vDisplayMenu - create a menu from variable arguments and call loop() + * vDisplayMenu - create a menu from variable arguments and call loop() * - * Display and execute a popup menu defined with variable - * arguments. + * Display and execute a popup menu defined with variable + * arguments. * - * Return the same thing as Menu::process_event(). + * Return the same thing as Menu::process_event(). */ int vDisplayMenu(int x0, int y0, const char *title, ...) { @@ -65,62 +65,62 @@ /* - * DisplayMenuList - create a menu from a list and call loop() + * DisplayMenuList - create a menu from a list and call loop() * - * Display and execute a menu contained in a list. Each - * menu item string is obtained by calling (*getstr)() with - * a pointer on the list item. + * Display and execute a menu contained in a list. Each + * menu item string is obtained by calling (*getstr)() with + * a pointer on the list item. * - * Return the number of the selected item (0-based) or -1 - * if exited by [Esc]. + * Return the number of the selected item (0-based) or -1 + * if exited by [Esc]. * - * This function is deprecated. + * This function is deprecated. */ int DisplayMenuList(int x0, - int y0, - const char *menutitle, - al_llist_t * list, - const char *(*getstr) (void *), int *item_no) + int y0, + const char *menutitle, + al_llist_t * list, + const char *(*getstr) (void *), int *item_no) { Menu menu(menutitle, list, getstr); int r = loop(&menu, x0, y0, item_no ? *item_no : 0); if (item_no && r >= 0) - *item_no = r; + *item_no = r; return r; } /* - * DisplayMenuList - create a menu from a Menu_data and call loop() + * DisplayMenuList - create a menu from a Menu_data and call loop() * - * Display and execute a menu contained in a Menu_data. + * Display and execute a menu contained in a Menu_data. * - * Return the number of the selected item (0-based) or -1 - * if exited by [Esc]. + * Return the number of the selected item (0-based) or -1 + * if exited by [Esc]. * - * This function is deprecated. + * This function is deprecated. */ int DisplayMenuList(int x0, - int y0, - const char *menutitle, Menu_data & menudata, int *item_no) + int y0, + const char *menutitle, Menu_data & menudata, int *item_no) { Menu menu(menutitle, menudata); int r = loop(&menu, x0, y0, item_no ? *item_no : 0); if (item_no && r >= 0) - *item_no = r; + *item_no = r; return r; } /* - * loop - display and execute a menu + * loop - display and execute a menu * - * Return the number of the selected item (0-based) or -1 - * if exited by [Esc]. + * Return the number of the selected item (0-based) or -1 + * if exited by [Esc]. * - * This function is nothing more than a quick and dirty - * hack, provided as a stopgap until the widget stack is - * implemented and the code uses it. + * This function is nothing more than a quick and dirty + * hack, provided as a stopgap until the widget stack is + * implemented and the code uses it. */ static int loop(Menu * menu, int x, int y, int item_no) { @@ -131,31 +131,31 @@ menu->set_item_no(item_no); for (;;) { - menu->draw(); - if (has_event()) - { - is.key = get_event(); - // If we had called get_input_status(), XNextEvent() - // would have been called and we wouldn't have to do that. - XFlush(dpy); - } - else - get_input_status(); - if (is.key == YE_EXPOSE) - menu->clear(); // Force menu to redraw itself from scratch - else if (is.key == YE_BUTL_PRESS - && ((int) is.x < menu->get_x0() - || (int) is.x > menu->get_x1() - || (int) is.y < menu->get_y0() - || (int) is.y > menu->get_y1())) - return -1; - else - { - int r = menu->process_event(&is); - if (r == MEN_CANCEL) - return -1; - else if (r >= 0) - return r; - } + menu->draw(); + if (has_event()) + { + is.key = get_event(); + // If we had called get_input_status(), XNextEvent() + // would have been called and we wouldn't have to do that. + XFlush(dpy); + } + else + get_input_status(); + if (is.key == YE_EXPOSE) + menu->clear(); // Force menu to redraw itself from scratch + else if (is.key == YE_BUTL_PRESS + && ((int) is.x < menu->get_x0() + || (int) is.x > menu->get_x1() + || (int) is.y < menu->get_y0() + || (int) is.y > menu->get_y1())) + return -1; + else + { + int r = menu->process_event(&is); + if (r == MEN_CANCEL) + return -1; + else if (r >= 0) + return r; + } } } diff -r 594dea11ccd9 -r a68786b9c74b src/oldmenus.h --- a/src/oldmenus.h Sat Sep 24 15:01:56 2011 +0300 +++ b/src/oldmenus.h Sat Sep 24 15:59:33 2011 +0300 @@ -1,10 +1,10 @@ /* - * oldmenus.h - * AYM 1998-12-04 + * oldmenus.h + * AYM 1998-12-04 */ -#ifndef YH_OLDMENUS /* DO NOT INSERT ANYTHING BEFORE THIS LINE */ +#ifndef YH_OLDMENUS /* DO NOT INSERT ANYTHING BEFORE THIS LINE */ #define YH_OLDMENUS @@ -14,15 +14,15 @@ int vDisplayMenu(int, int, const char *, ...); int DisplayMenuList(int x0, - int y0, - const char *title, - al_llist_t * list, - const char *(*getstr) (void *), int *item_no); + int y0, + const char *title, + al_llist_t * list, + const char *(*getstr) (void *), int *item_no); int DisplayMenuList(int x0, - int y0, - const char *menutitle, - Menu_data & menudata, int *item_no); + int y0, + const char *menutitle, + Menu_data & menudata, int *item_no); #endif /* DO NOT ADD ANYTHING AFTER THIS LINE */ diff -r 594dea11ccd9 -r a68786b9c74b src/palview.cc --- a/src/palview.cc Sat Sep 24 15:01:56 2011 +0300 +++ b/src/palview.cc Sat Sep 24 15:59:33 2011 +0300 @@ -1,7 +1,7 @@ /* - * palview.cc - * Palette (PLAYPAL & COLORMAP) viewer - * AYM 1999-11-11 + * palview.cc + * Palette (PLAYPAL & COLORMAP) viewer + * AYM 1999-11-11 */ @@ -41,8 +41,8 @@ /* - * Palette viewer::run - * The only public method of the palette viewer. + * Palette viewer::run + * The only public method of the palette viewer. */ // One COLORMAP entry. Wrapped in struct to avoid array<->pointer problems @@ -60,93 +60,93 @@ int height = 2 * BOX_BORDER + 3 * WIDE_VSPACING + pheight + 7 * FONTH; int x0 = (ScrMaxX - width) / 2; int y0 = (ScrMaxY - height) / 2; - int nmaps = 0; // Number of entries in the COLORMAP lump + int nmaps = 0; // Number of entries in the COLORMAP lump colormap_entry_t **colormap = 0; rgb_c *playpal = 0; // Load the PLAYPAL lump do { - playpal = new rgb_c[DOOM_COLOURS]; - for (size_t n = 0; n < DOOM_COLOURS; n++) - playpal[n].set(0, 0, 0); - const char *lump_name = "PLAYPAL"; - MDirPtr dir = FindMasterDir(MasterDir, lump_name); - if (dir == NULL) - { - warn("%s: lump not found\n", lump_name); - break; - } - const Wad_file *wf = dir->wadfile; - if (dir->dir.size % (3 * DOOM_COLOURS) != 0) - { - warn("%s has weird size (%ld, not mult of %d), ignoring tail\n", - lump_name, (long) dir->dir.size, (int) (DOOM_COLOURS * 3)); - } - wf->seek(dir->dir.start); - if (wf->error()) - { - warn("%s: seek error\n", lump_name); - break; - } - playpal = new rgb_c[DOOM_COLOURS]; - for (size_t n = 0; n < DOOM_COLOURS; n++) - { - char buf[3]; - wf->read_bytes(buf, sizeof buf); - playpal[n].set(buf[0], buf[1], buf[2]); - } - if (wf->error()) - warn("%s: read error\n", lump_name); + playpal = new rgb_c[DOOM_COLOURS]; + for (size_t n = 0; n < DOOM_COLOURS; n++) + playpal[n].set(0, 0, 0); + const char *lump_name = "PLAYPAL"; + MDirPtr dir = FindMasterDir(MasterDir, lump_name); + if (dir == NULL) + { + warn("%s: lump not found\n", lump_name); + break; + } + const Wad_file *wf = dir->wadfile; + if (dir->dir.size % (3 * DOOM_COLOURS) != 0) + { + warn("%s has weird size (%ld, not mult of %d), ignoring tail\n", + lump_name, (long) dir->dir.size, (int) (DOOM_COLOURS * 3)); + } + wf->seek(dir->dir.start); + if (wf->error()) + { + warn("%s: seek error\n", lump_name); + break; + } + playpal = new rgb_c[DOOM_COLOURS]; + for (size_t n = 0; n < DOOM_COLOURS; n++) + { + char buf[3]; + wf->read_bytes(buf, sizeof buf); + playpal[n].set(buf[0], buf[1], buf[2]); + } + if (wf->error()) + warn("%s: read error\n", lump_name); } while (0); // Load the COLORMAP lump do { - const char *lump_name = "COLORMAP"; - MDirPtr dir = FindMasterDir(MasterDir, lump_name); - if (dir == NULL) - { - warn("%s: lump not found\n", lump_name); - break; - } - const Wad_file *wf = dir->wadfile; - nmaps = dir->dir.size / DOOM_COLOURS; - if ((long) DOOM_COLOURS * nmaps != dir->dir.size) - { - warn("%s: has weird size (%ld, not mult of %d), ignoring tail\n", - lump_name, (long) dir->dir.size, (int) DOOM_COLOURS); - } - if (nmaps > 200) - { - warn("%s has too many (%d) entries, keeping only 200 first\n", - lump_name, nmaps); - nmaps = 200; - } - wf->seek(dir->dir.start); - if (wf->error()) - { - warn("%s: seek error\n", lump_name); - break; - } - colormap = new colormap_entry_t *[nmaps]; - for (int n = 0; n < nmaps; n++) - { - colormap[n] = new colormap_entry_t; - wf->read_bytes(colormap[n]->c, sizeof colormap[n]->c); - } - if (wf->error()) - warn("%s: read error\n", lump_name); + const char *lump_name = "COLORMAP"; + MDirPtr dir = FindMasterDir(MasterDir, lump_name); + if (dir == NULL) + { + warn("%s: lump not found\n", lump_name); + break; + } + const Wad_file *wf = dir->wadfile; + nmaps = dir->dir.size / DOOM_COLOURS; + if ((long) DOOM_COLOURS * nmaps != dir->dir.size) + { + warn("%s: has weird size (%ld, not mult of %d), ignoring tail\n", + lump_name, (long) dir->dir.size, (int) DOOM_COLOURS); + } + if (nmaps > 200) + { + warn("%s has too many (%d) entries, keeping only 200 first\n", + lump_name, nmaps); + nmaps = 200; + } + wf->seek(dir->dir.start); + if (wf->error()) + { + warn("%s: seek error\n", lump_name); + break; + } + colormap = new colormap_entry_t *[nmaps]; + for (int n = 0; n < nmaps; n++) + { + colormap[n] = new colormap_entry_t; + wf->read_bytes(colormap[n]->c, sizeof colormap[n]->c); + } + if (wf->error()) + warn("%s: read error\n", lump_name); } while (0); // On to the real business ix0 = x0 + BOX_BORDER + WIDE_HSPACING; iy0 = y0 + BOX_BORDER + WIDE_VSPACING; - int tx0 = ix0; // Top left corner of text + int tx0 = ix0; // Top left corner of text int ty0 = y0 + BOX_BORDER + 2 * WIDE_VSPACING + pheight; - push_colour(0); // Save current colour + push_colour(0); // Save current colour #define DECIDX(i,n) do { i = (i - n + ncolours) % ncolours; } while (0) #define INCIDX(i,n) do { i = (i + n ) % ncolours; } while (0) int mapno = 0; @@ -164,240 +164,240 @@ for (;;) { - int mi = colormap[mapno]->c[i]; // Mapped index - int ei = mapping ? mi : i; // Effective index - int mapped_to = 0; // N. distinct colours that map to i - for (int n = 0; n < ncolours; n++) - for (int m = 0; m < nmaps; m++) - if (colormap[m]->c[n] == i) - { - mapped_to++; - break; // Don't count the same mapper twice - } - int maps_to = 0; // N. distinct colours that i maps to - { - bitvec_c mappee(ncolours); - for (int m = 0; m < nmaps; m++) - mappee.set(colormap[m]->c[i]); - for (int n = 0; n < ncolours; n++) - if (mappee.get(n)) - maps_to++; - } + int mi = colormap[mapno]->c[i]; // Mapped index + int ei = mapping ? mi : i; // Effective index + int mapped_to = 0; // N. distinct colours that map to i + for (int n = 0; n < ncolours; n++) + for (int m = 0; m < nmaps; m++) + if (colormap[m]->c[n] == i) + { + mapped_to++; + break; // Don't count the same mapper twice + } + int maps_to = 0; // N. distinct colours that i maps to + { + bitvec_c mappee(ncolours); + for (int m = 0; m < nmaps; m++) + mappee.set(colormap[m]->c[i]); + for (int n = 0; n < ncolours; n++) + if (mappee.get(n)) + maps_to++; + } - // Draw the window - if (!(is_drawn & YID_WINDOW)) - { - DrawScreenBox3D(x0, y0, x0 + width - 1, y0 + height - 1); - is_drawn = YID_WINDOW; // Redraw everything else - } + // Draw the window + if (!(is_drawn & YID_WINDOW)) + { + DrawScreenBox3D(x0, y0, x0 + width - 1, y0 + height - 1); + is_drawn = YID_WINDOW; // Redraw everything else + } - // Draw the cursor (frame around the current cell) - { - const int cycle = 800; // 800 ms - unsigned long current_time = y_milliseconds(); - unsigned long elapsed_time = current_time - cursor_time; - cursor_time = current_time; + // Draw the cursor (frame around the current cell) + { + const int cycle = 800; // 800 ms + unsigned long current_time = y_milliseconds(); + unsigned long elapsed_time = current_time - cursor_time; + cursor_time = current_time; #if 0 - cursor_time += elapsed_time - elapsed_time % cycle; // Normalize - elapsed_time = current_time - cursor_time; + cursor_time += elapsed_time - elapsed_time % cycle; // Normalize + elapsed_time = current_time - cursor_time; #endif - cursor_phase = (cursor_phase + elapsed_time) % cycle; - if ((cursor_phase >= cycle / 2) != (display_phase >= cycle / 2)) - is_drawn &= ~YID_CURSOR; - if (!(is_drawn & YID_CURSOR)) - { - draw_cursor(WINFG, cursor_phase >= cycle / 2); - display_phase = cursor_phase; - is_drawn |= YID_CURSOR; - } - } + cursor_phase = (cursor_phase + elapsed_time) % cycle; + if ((cursor_phase >= cycle / 2) != (display_phase >= cycle / 2)) + is_drawn &= ~YID_CURSOR; + if (!(is_drawn & YID_CURSOR)) + { + draw_cursor(WINFG, cursor_phase >= cycle / 2); + display_phase = cursor_phase; + is_drawn |= YID_CURSOR; + } + } - // Draw a (pixels x pixels) square for each colour - if (!(is_drawn & YID_PALETTE)) - { - int x = 0; // Initialized only to prevent GCC from warning - int y = 0; // Initialized only to prevent GCC from warning - for (int n = 0; n < ncolours; n++) - { - if (n % columns == 0) - { - x = ix0; - if (n == 0) - y = iy0; - else - y += pixels + 1; - } - else - x += pixels + 1; + // Draw a (pixels x pixels) square for each colour + if (!(is_drawn & YID_PALETTE)) + { + int x = 0; // Initialized only to prevent GCC from warning + int y = 0; // Initialized only to prevent GCC from warning + for (int n = 0; n < ncolours; n++) + { + if (n % columns == 0) + { + x = ix0; + if (n == 0) + y = iy0; + else + y += pixels + 1; + } + else + x += pixels + 1; - if (game_colour == 0) // If PLAYPAL not found - set_pcolour(0); - else - { - if (mapping) - set_pcolour(game_colour - [colormap[mapno]-> - c[(n + ofs) % ncolours]]); - else - set_pcolour(game_colour[(n + ofs) % ncolours]); - } - DrawScreenBoxwh(x, y, pixels, pixels); - } - is_drawn |= YID_PALETTE; - set_colour(WINFG_DIM); // Just to force the next set_colour() to do sth - } + if (game_colour == 0) // If PLAYPAL not found + set_pcolour(0); + else + { + if (mapping) + set_pcolour(game_colour + [colormap[mapno]-> + c[(n + ofs) % ncolours]]); + else + set_pcolour(game_colour[(n + ofs) % ncolours]); + } + DrawScreenBoxwh(x, y, pixels, pixels); + } + is_drawn |= YID_PALETTE; + set_colour(WINFG_DIM); // Just to force the next set_colour() to do sth + } - // Draw the "caption" - if (!(is_drawn & YID_TEXT)) - { - set_colour(WINBG); - DrawScreenBoxwh(tx0, ty0, pwidth, 7 * FONTH); - set_colour(WINFG); - DrawScreenText(tx0, ty0, "Index %3d", i); - push_colour(mapping ? WINFG : WINFG_DIM); - DrawScreenText(tx0, -1, "Mapped index %3d", mi); - pop_colour(); - DrawScreenText(tx0, -1, "R %3d", playpal[ei].r); - DrawScreenText(tx0, -1, "G %3d", playpal[ei].g); - DrawScreenText(tx0, -1, "B %3d", playpal[ei].b); - DrawScreenText(tx0, -1, "Mapped to by %3d", mapped_to); - DrawScreenText(tx0, -1, "Maps to %3d", maps_to); - push_colour(mapping ? WINFG : WINFG_DIM); - DrawScreenText(tx0 + 18 * FONTW, ty0, "Colormap %3d", mapno); - pop_colour(); - is_drawn |= YID_TEXT; - } + // Draw the "caption" + if (!(is_drawn & YID_TEXT)) + { + set_colour(WINBG); + DrawScreenBoxwh(tx0, ty0, pwidth, 7 * FONTH); + set_colour(WINFG); + DrawScreenText(tx0, ty0, "Index %3d", i); + push_colour(mapping ? WINFG : WINFG_DIM); + DrawScreenText(tx0, -1, "Mapped index %3d", mi); + pop_colour(); + DrawScreenText(tx0, -1, "R %3d", playpal[ei].r); + DrawScreenText(tx0, -1, "G %3d", playpal[ei].g); + DrawScreenText(tx0, -1, "B %3d", playpal[ei].b); + DrawScreenText(tx0, -1, "Mapped to by %3d", mapped_to); + DrawScreenText(tx0, -1, "Maps to %3d", maps_to); + push_colour(mapping ? WINFG : WINFG_DIM); + DrawScreenText(tx0 + 18 * FONTW, ty0, "Colormap %3d", mapno); + pop_colour(); + is_drawn |= YID_TEXT; + } - // Process any events - get_input_status(); - if (is.key == YK_PU) // [Pgup] previous colormap - { - mapno--; - if (mapno < 0) - mapno = nmaps - 1; - is_drawn &= ~(YID_PALETTE | YID_TEXT); - } - else if (is.key == YK_PD) // [Pgdn] next colormap - { - mapno++; - if (mapno >= nmaps) - mapno = 0; - is_drawn &= ~(YID_PALETTE | YID_TEXT); - } - else if (is.key == YK_LEFT) // [Left] previous palette entry - { - draw_cursor(WINBG, false); - DECIDX(i, 1); - is_drawn &= ~(YID_PALETTE | YID_TEXT | YID_CURSOR); - cursor_phase = 0; - } - else if (is.key == YK_RIGHT) // [Right] next palette entry - { - draw_cursor(WINBG, false); - INCIDX(i, 1); - is_drawn &= ~(YID_TEXT | YID_CURSOR); - cursor_phase = 0; - } - else if (is.key == YK_UP) // [Up] previous palette row - { - draw_cursor(WINBG, false); - DECIDX(i, columns); - is_drawn &= ~(YID_TEXT | YID_CURSOR); - cursor_phase = 0; - } - else if (is.key == YK_DOWN) // [Down] next palette row - { - draw_cursor(WINBG, false); - INCIDX(i, columns); - is_drawn &= ~(YID_TEXT | YID_CURSOR); - cursor_phase = 0; - } - else if (is.key == YK_END // [End], [$]: end of current line - || is.key == '$') - { - draw_cursor(WINBG, false); - i += columns - i % columns - 1; - is_drawn &= ~(YID_TEXT | YID_CURSOR); - cursor_phase = 0; - } - else if (is.key == YK_HOME // [Home], [0], [^]: start of cur. line - || is.key == '^' || is.key == '0') - { - draw_cursor(WINBG, false); - i -= i % columns; - is_drawn &= ~(YID_TEXT | YID_CURSOR); - cursor_phase = 0; - } - else if (is.key == YK_RETURN) // [Return]: beginning of next line - { - draw_cursor(WINBG, false); - i += columns - i % columns; - is_drawn &= ~(YID_TEXT | YID_CURSOR); - cursor_phase = 0; - } -#if 0 /* Conflicts with "rotate" */ - else if (is.key == '-') // [-]: beginning of previous line - { - draw_cursor(WINBG, false); - i -= columns + i % columns; - is_drawn &= ~(YID_TEXT | YID_CURSOR); - cursor_phase = 0; - } + // Process any events + get_input_status(); + if (is.key == YK_PU) // [Pgup] previous colormap + { + mapno--; + if (mapno < 0) + mapno = nmaps - 1; + is_drawn &= ~(YID_PALETTE | YID_TEXT); + } + else if (is.key == YK_PD) // [Pgdn] next colormap + { + mapno++; + if (mapno >= nmaps) + mapno = 0; + is_drawn &= ~(YID_PALETTE | YID_TEXT); + } + else if (is.key == YK_LEFT) // [Left] previous palette entry + { + draw_cursor(WINBG, false); + DECIDX(i, 1); + is_drawn &= ~(YID_PALETTE | YID_TEXT | YID_CURSOR); + cursor_phase = 0; + } + else if (is.key == YK_RIGHT) // [Right] next palette entry + { + draw_cursor(WINBG, false); + INCIDX(i, 1); + is_drawn &= ~(YID_TEXT | YID_CURSOR); + cursor_phase = 0; + } + else if (is.key == YK_UP) // [Up] previous palette row + { + draw_cursor(WINBG, false); + DECIDX(i, columns); + is_drawn &= ~(YID_TEXT | YID_CURSOR); + cursor_phase = 0; + } + else if (is.key == YK_DOWN) // [Down] next palette row + { + draw_cursor(WINBG, false); + INCIDX(i, columns); + is_drawn &= ~(YID_TEXT | YID_CURSOR); + cursor_phase = 0; + } + else if (is.key == YK_END // [End], [$]: end of current line + || is.key == '$') + { + draw_cursor(WINBG, false); + i += columns - i % columns - 1; + is_drawn &= ~(YID_TEXT | YID_CURSOR); + cursor_phase = 0; + } + else if (is.key == YK_HOME // [Home], [0], [^]: start of cur. line + || is.key == '^' || is.key == '0') + { + draw_cursor(WINBG, false); + i -= i % columns; + is_drawn &= ~(YID_TEXT | YID_CURSOR); + cursor_phase = 0; + } + else if (is.key == YK_RETURN) // [Return]: beginning of next line + { + draw_cursor(WINBG, false); + i += columns - i % columns; + is_drawn &= ~(YID_TEXT | YID_CURSOR); + cursor_phase = 0; + } +#if 0 /* Conflicts with "rotate" */ + else if (is.key == '-') // [-]: beginning of previous line + { + draw_cursor(WINBG, false); + i -= columns + i % columns; + is_drawn &= ~(YID_TEXT | YID_CURSOR); + cursor_phase = 0; + } #endif - else if (is.key == 'G' // [G], [L]: beginning of last line - || is.key == 'L') - { - draw_cursor(WINBG, false); - i = (lines - 1) * columns; - is_drawn &= ~(YID_TEXT | YID_CURSOR); - cursor_phase = 0; - } - else if (is.key == 'H') // [H] beginning of first line - { - draw_cursor(WINBG, false); - i = 0; - is_drawn &= ~(YID_TEXT | YID_CURSOR); - cursor_phase = 0; - } - else if (is.key == 'm') // [m] toggle mapping - { - mapping = !mapping; - is_drawn &= ~(YID_PALETTE | YID_TEXT); - } - else if (is.key == 'M') // [M] beginning of middle line - { - draw_cursor(WINBG, false); - i = (lines / 2) * columns; - is_drawn &= ~(YID_TEXT | YID_CURSOR); - cursor_phase = 0; - } - else if (is.key == '+' || is.key == '=') // [+] increment offset - { - INCIDX(ofs, 1); - INCIDX(i, 1); - is_drawn &= ~(YID_PALETTE | YID_TEXT); - } - else if (is.key == '-') // [-] decrement offset - { - DECIDX(ofs, 1); - DECIDX(i, 1); - is_drawn &= ~(YID_PALETTE | YID_TEXT); - } - else if (is.key == YK_ESC) // [Esc] quit - { - break; - } - else if (is.key == YE_EXPOSE) - { - is_drawn = 0; // Redraw everything - } - else; + else if (is.key == 'G' // [G], [L]: beginning of last line + || is.key == 'L') + { + draw_cursor(WINBG, false); + i = (lines - 1) * columns; + is_drawn &= ~(YID_TEXT | YID_CURSOR); + cursor_phase = 0; + } + else if (is.key == 'H') // [H] beginning of first line + { + draw_cursor(WINBG, false); + i = 0; + is_drawn &= ~(YID_TEXT | YID_CURSOR); + cursor_phase = 0; + } + else if (is.key == 'm') // [m] toggle mapping + { + mapping = !mapping; + is_drawn &= ~(YID_PALETTE | YID_TEXT); + } + else if (is.key == 'M') // [M] beginning of middle line + { + draw_cursor(WINBG, false); + i = (lines / 2) * columns; + is_drawn &= ~(YID_TEXT | YID_CURSOR); + cursor_phase = 0; + } + else if (is.key == '+' || is.key == '=') // [+] increment offset + { + INCIDX(ofs, 1); + INCIDX(i, 1); + is_drawn &= ~(YID_PALETTE | YID_TEXT); + } + else if (is.key == '-') // [-] decrement offset + { + DECIDX(ofs, 1); + DECIDX(i, 1); + is_drawn &= ~(YID_PALETTE | YID_TEXT); + } + else if (is.key == YK_ESC) // [Esc] quit + { + break; + } + else if (is.key == YE_EXPOSE) + { + is_drawn = 0; // Redraw everything + } + else; } - pop_colour(); // Restore current colour + pop_colour(); // Restore current colour delete[]playpal; for (int n = 0; n < nmaps; n++) - delete colormap[n]; + delete colormap[n]; delete[]colormap; } @@ -412,23 +412,23 @@ const int y1 = y0 + side - 1; if (c == WINBG) { - set_colour(c); - DrawScreenRect(x0, y0, side, side); + set_colour(c); + DrawScreenRect(x0, y0, side, side); } else { - const int l1 = side / 2; - const int l2 = side - l1; - // FIXME this cursor looks ugly - set_colour(phase ? BLACK : WHITE); - DrawScreenLineLen(x0, y0, l1, 0); - DrawScreenLineLen(x0, y0, 0, l1); - DrawScreenLineLen(x1, y1, 0, -l1); - DrawScreenLineLen(x1, y1, -l1, 0); - set_colour(phase ? WHITE : BLACK); - DrawScreenLineLen(x1, y0, -l2, 0); - DrawScreenLineLen(x1, y0, 0, l2); - DrawScreenLineLen(x0, y1, 0, -l2); - DrawScreenLineLen(x0, y1, l2, 0); + const int l1 = side / 2; + const int l2 = side - l1; + // FIXME this cursor looks ugly + set_colour(phase ? BLACK : WHITE); + DrawScreenLineLen(x0, y0, l1, 0); + DrawScreenLineLen(x0, y0, 0, l1); + DrawScreenLineLen(x1, y1, 0, -l1); + DrawScreenLineLen(x1, y1, -l1, 0); + set_colour(phase ? WHITE : BLACK); + DrawScreenLineLen(x1, y0, -l2, 0); + DrawScreenLineLen(x1, y0, 0, l2); + DrawScreenLineLen(x0, y1, 0, -l2); + DrawScreenLineLen(x0, y1, l2, 0); } } diff -r 594dea11ccd9 -r a68786b9c74b src/palview.h --- a/src/palview.h Sat Sep 24 15:01:56 2011 +0300 +++ b/src/palview.h Sat Sep 24 15:59:33 2011 +0300 @@ -1,7 +1,7 @@ /* - * palview.h - * Palette (PLAYPAL & COLORMAP) viewer - * AYM 1999-11-11 + * palview.h + * Palette (PLAYPAL & COLORMAP) viewer + * AYM 1999-11-11 */ diff -r 594dea11ccd9 -r a68786b9c74b src/patchdir.cc --- a/src/patchdir.cc Sat Sep 24 15:01:56 2011 +0300 +++ b/src/patchdir.cc Sat Sep 24 15:59:33 2011 +0300 @@ -1,7 +1,7 @@ /* - * patchdir.cc - * Patch_dir class - * AYM 1999-11-25 + * patchdir.cc + * Patch_dir class + * AYM 1999-11-25 */ @@ -44,7 +44,7 @@ /* - * ctor + * ctor */ Patch_dir::Patch_dir() { @@ -54,19 +54,19 @@ /* - * dtor + * dtor */ Patch_dir::~Patch_dir() { if (pnames != 0) - FreeMemory(pnames); + FreeMemory(pnames); if (!patch_lumps.empty()) - patch_lumps.clear(); + patch_lumps.clear(); } /* - * Patch_dir::refresh + * Patch_dir::refresh */ void Patch_dir::refresh(MDirPtr master_dir) { @@ -74,215 +74,215 @@ And usually is ! */ if (pnames != 0) { - FreeMemory(pnames); - pnames = 0; - npnames = 0; + FreeMemory(pnames); + pnames = 0; + npnames = 0; } if (!patch_lumps.empty()) - patch_lumps.clear(); + patch_lumps.clear(); /* First load PNAMES so that we known in which order we should put the patches in the array. */ { - bool success = false; - const char *lump_name = "PNAMES"; - do - { - MDirPtr dir; - i32 npatches_head = -42; - i32 npatches_body = -42; + bool success = false; + const char *lump_name = "PNAMES"; + do + { + MDirPtr dir; + i32 npatches_head = -42; + i32 npatches_body = -42; - dir = FindMasterDir(master_dir, lump_name); - if (dir == 0) - { - warn("No %s lump, won't be able to render textures\n", - lump_name); - break; - } - i32 pnames_body_size = dir->dir.size - 4; - if (pnames_body_size < 0) - { - warn("Bad %s (negative size %ld), won't be able to render textures\n", lump_name, (long) dir->dir.size); - break; - } - if (pnames_body_size % 8) - { - warn("%s lump has weird size %ld, discarding last %d bytes\n", - (long) dir->dir.size, (int) (pnames_body_size % 8)); - } - npatches_body = pnames_body_size / 8; - const Wad_file *wf = dir->wadfile; - wf->seek(dir->dir.start); - if (wf->error()) - { - warn("%s: seek error\n", lump_name); - break; - } - wf->read_i32(&npatches_head); - if (wf->error()) - { - warn("%s: error reading header\n", lump_name); - break; - } - if (npatches_head > 0 && npatches_head < npatches_body) - npnames = npatches_head; - else - npnames = npatches_body; - if (npatches_head != npatches_body) - { - warn("%s: header says %ld patches, lump size suggests %ld," - " going for %lu\n", - lump_name, long (npatches_head), long (npatches_body), - (unsigned long) npnames); - } - if (npnames > 32767) - { - warn("%s: too big (%lu patches), keeping only first 32767\n", - lump_name, (unsigned long) npnames); - npnames = 32767; - } - pnames = (char *) GetMemory(npnames * WAD_PIC_NAME); - wf->read_bytes(pnames, npnames * WAD_PIC_NAME); - if (wf->error()) - { - warn("%s: error reading names\n", lump_name); - break; - } - success = true; - } - while (0); - if (!success) - warn("%s: errors found, won't be able to render textures\n", - lump_name); + dir = FindMasterDir(master_dir, lump_name); + if (dir == 0) + { + warn("No %s lump, won't be able to render textures\n", + lump_name); + break; + } + i32 pnames_body_size = dir->dir.size - 4; + if (pnames_body_size < 0) + { + warn("Bad %s (negative size %ld), won't be able to render textures\n", lump_name, (long) dir->dir.size); + break; + } + if (pnames_body_size % 8) + { + warn("%s lump has weird size %ld, discarding last %d bytes\n", + (long) dir->dir.size, (int) (pnames_body_size % 8)); + } + npatches_body = pnames_body_size / 8; + const Wad_file *wf = dir->wadfile; + wf->seek(dir->dir.start); + if (wf->error()) + { + warn("%s: seek error\n", lump_name); + break; + } + wf->read_i32(&npatches_head); + if (wf->error()) + { + warn("%s: error reading header\n", lump_name); + break; + } + if (npatches_head > 0 && npatches_head < npatches_body) + npnames = npatches_head; + else + npnames = npatches_body; + if (npatches_head != npatches_body) + { + warn("%s: header says %ld patches, lump size suggests %ld," + " going for %lu\n", + lump_name, long (npatches_head), long (npatches_body), + (unsigned long) npnames); + } + if (npnames > 32767) + { + warn("%s: too big (%lu patches), keeping only first 32767\n", + lump_name, (unsigned long) npnames); + npnames = 32767; + } + pnames = (char *) GetMemory(npnames * WAD_PIC_NAME); + wf->read_bytes(pnames, npnames * WAD_PIC_NAME); + if (wf->error()) + { + warn("%s: error reading names\n", lump_name); + break; + } + success = true; + } + while (0); + if (!success) + warn("%s: errors found, won't be able to render textures\n", + lump_name); } /* Get list of patches in the master directory. Everything that is between P_START/P_END or PP_START/PP_END and that is not a label is supposed to be a patch. */ { - for (MDirPtr dir = master_dir; - dir && (dir = FindMasterDir(dir, "P_START", "PP_START"));) - { - MDirPtr start_label = dir; - const char *end_label = 0; - if (!y_strnicmp(dir->dir.name, "P_START", WAD_NAME)) - end_label = "P_END"; - else if (!y_strnicmp(dir->dir.name, "PP_START", WAD_NAME)) - end_label = "PP_END"; - else - fatal_error("Bad start label \"%.*s\"", (int) WAD_NAME, - dir->dir.name); - //printf ("[%-8.8s ", dir->dir.name); // DEBUG - //fflush (stdout); - dir = dir->next; - for (;; dir = dir->next) - { - if (!dir) - { - warn("%.128s: no matching %s for %.*s\n", - start_label->wadfile->pathname(), - end_label, (int) WAD_NAME, start_label->dir.name); - break; - } - if (!y_strnicmp(dir->dir.name, end_label, WAD_NAME)) - { - if (dir->dir.size != 0) - warn("%.128s: label %.*s has non-zero size %ld\n", - dir->wadfile->pathname(), - (int) WAD_NAME, dir->dir.name, - (long) dir->dir.size); - dir = dir->next; - //printf ("%-8.8s]\n", dir->dir.name); // DEBUG - break; - } - if (dir->dir.start == 0 || dir->dir.size == 0) - { - if (!(toupper(dir->dir.name[0]) == 'P' - && (dir->dir.name[1] == '1' - || dir->dir.name[1] == '2' - || dir->dir.name[1] == '3') - && dir->dir.name[2] == '_' - && - (!y_strnicmp - (dir->dir.name + 3, "START", WAD_NAME - 3) - || !y_strnicmp(dir->dir.name + 3, "END", - WAD_NAME - 3)))) - warn("%.128s: unexpected label \"%.*s\" among patches.\n", dir->wadfile->pathname(), (int) WAD_NAME, dir->dir.name); - continue; - } - //printf ("%-9.8s ", dir->dir.name); fflush (stdout); // DEBUG - wad_flat_name_t name; - memcpy(name, dir->dir.name, sizeof name); - patch_lumps[name] - = Lump_loc(dir->wadfile, dir->dir.start, dir->dir.size); - } - if (dir) - dir = dir->next; - } - //putchar ('\n'); // DEBUG + for (MDirPtr dir = master_dir; + dir && (dir = FindMasterDir(dir, "P_START", "PP_START"));) + { + MDirPtr start_label = dir; + const char *end_label = 0; + if (!y_strnicmp(dir->dir.name, "P_START", WAD_NAME)) + end_label = "P_END"; + else if (!y_strnicmp(dir->dir.name, "PP_START", WAD_NAME)) + end_label = "PP_END"; + else + fatal_error("Bad start label \"%.*s\"", (int) WAD_NAME, + dir->dir.name); + //printf ("[%-8.8s ", dir->dir.name); // DEBUG + //fflush (stdout); + dir = dir->next; + for (;; dir = dir->next) + { + if (!dir) + { + warn("%.128s: no matching %s for %.*s\n", + start_label->wadfile->pathname(), + end_label, (int) WAD_NAME, start_label->dir.name); + break; + } + if (!y_strnicmp(dir->dir.name, end_label, WAD_NAME)) + { + if (dir->dir.size != 0) + warn("%.128s: label %.*s has non-zero size %ld\n", + dir->wadfile->pathname(), + (int) WAD_NAME, dir->dir.name, + (long) dir->dir.size); + dir = dir->next; + //printf ("%-8.8s]\n", dir->dir.name); // DEBUG + break; + } + if (dir->dir.start == 0 || dir->dir.size == 0) + { + if (!(toupper(dir->dir.name[0]) == 'P' + && (dir->dir.name[1] == '1' + || dir->dir.name[1] == '2' + || dir->dir.name[1] == '3') + && dir->dir.name[2] == '_' + && + (!y_strnicmp + (dir->dir.name + 3, "START", WAD_NAME - 3) + || !y_strnicmp(dir->dir.name + 3, "END", + WAD_NAME - 3)))) + warn("%.128s: unexpected label \"%.*s\" among patches.\n", dir->wadfile->pathname(), (int) WAD_NAME, dir->dir.name); + continue; + } + //printf ("%-9.8s ", dir->dir.name); fflush (stdout); // DEBUG + wad_flat_name_t name; + memcpy(name, dir->dir.name, sizeof name); + patch_lumps[name] + = Lump_loc(dir->wadfile, dir->dir.start, dir->dir.size); + } + if (dir) + dir = dir->next; + } + //putchar ('\n'); // DEBUG } #ifdef DEBUG for (Patch_lumps_map::const_iterator i = patch_lumps.begin(); - i != patch_lumps.end(); i++) + i != patch_lumps.end(); i++) { - printf("%-8.8s %p %08lX %ld\n", - i->first._name, i->second.wad, i->second.ofs, i->second.len); + printf("%-8.8s %p %08lX %ld\n", + i->first._name, i->second.wad, i->second.ofs, i->second.len); } #endif } /* - * loc_by_name - * Return the (wad, offset, length) location of the lump - * that contains patch <name>. + * loc_by_name + * Return the (wad, offset, length) location of the lump + * that contains patch <name>. */ void Patch_dir::loc_by_name(const char *name, Lump_loc & loc) { Patch_lumps_map::const_iterator i = patch_lumps.find(name); if (i == patch_lumps.end()) { - loc.wad = 0; - return; + loc.wad = 0; + return; } loc = i->second; } /* - * loc_by_num - * Return the (wad, offset, length) location of the lump - * that contains patch# <num>. + * loc_by_num + * Return the (wad, offset, length) location of the lump + * that contains patch# <num>. */ void Patch_dir::loc_by_num(i16 num, Lump_loc & loc) { wad_pic_name_t *nm = name_for_num(num); if (nm == 0) { - loc.wad = 0; - return; + loc.wad = 0; + return; } loc_by_name((const char *) nm, loc); } /* - * name_for_num - * Return a pointer on the name of the patch of number <num> - * or 0 if no such patch. + * name_for_num + * Return a pointer on the name of the patch of number <num> + * or 0 if no such patch. */ wad_pic_name_t *Patch_dir::name_for_num(i16 num) { - if (num < 0 || (size_t) num >= npnames) // Cast to silence GCC warning - return 0; + if (num < 0 || (size_t) num >= npnames) // Cast to silence GCC warning + return 0; return (wad_pic_name_t *) (pnames + WAD_PIC_NAME * num); } /* - * list - * Put a list of all existing patch lump, sorted by name - * and without duplicates, in <pl>. + * list + * Put a list of all existing patch lump, sorted by name + * and without duplicates, in <pl>. */ void Patch_dir::list(Patch_list & pl) { @@ -315,9 +315,9 @@ Patch_lumps_map::const_iterator i = patch_lumps.begin(); for (size_t n = 0; n < nelements; n++) { - array[n] = new char[WAD_PIC_NAME + 1]; - *array[n] = '\0'; - strncat(array[n], i++->first._name, WAD_PIC_NAME); + array[n] = new char[WAD_PIC_NAME + 1]; + *array[n] = '\0'; + strncat(array[n], i++->first._name, WAD_PIC_NAME); } } @@ -326,9 +326,9 @@ { if (array != 0) { - for (size_t n = 0; n < nelements; n++) - delete[]array[n]; - delete[]array; + for (size_t n = 0; n < nelements; n++) + delete[]array[n]; + delete[]array; } } @@ -360,6 +360,6 @@ bool Pllik_less::operator () (const Pllik & p1, const Pllik & p2) const { - return y_strnicmp((const char *) &p1, (const char *) &p2, - WAD_PIC_NAME) < 0; + return y_strnicmp((const char *) &p1, (const char *) &p2, + WAD_PIC_NAME) < 0; } diff -r 594dea11ccd9 -r a68786b9c74b src/patchdir.h --- a/src/patchdir.h Sat Sep 24 15:01:56 2011 +0300 +++ b/src/patchdir.h Sat Sep 24 15:59:33 2011 +0300 @@ -1,7 +1,7 @@ /* - * patchdir.h - * Patch_dir class - * AYM 1999-11-25 + * patchdir.h + * Patch_dir class + * AYM 1999-11-25 */ @@ -36,42 +36,42 @@ /* - * Patch_dir - * - * The purpose of this class is to hide the details of how - * patches are stored in the wads from Yadex. It provides - * two basic services : + * Patch_dir + * + * The purpose of this class is to hide the details of how + * patches are stored in the wads from Yadex. It provides + * two basic services : * - * - refresh() Must be called every time the directory - * changes in any way. + * - refresh() Must be called every time the directory + * changes in any way. * - * - loc_by_name() Return the lump location (WadPtr, - * offset, length) of a patch by name. Used - * by the patch browser. If the patch does - * not exist, returns a NULL WadPtr. + * - loc_by_name() Return the lump location (WadPtr, + * offset, length) of a patch by name. Used + * by the patch browser. If the patch does + * not exist, returns a NULL WadPtr. * - * - loc_by_num() Return the lump location (WadPtr, - * offset, length) of a patch by number (as - * in TEXTURE[12]). Used by the texture - * browser. If the patch does not exist, - * returns a NULL WadPtr. + * - loc_by_num() Return the lump location (WadPtr, + * offset, length) of a patch by number (as + * in TEXTURE[12]). Used by the texture + * browser. If the patch does not exist, + * returns a NULL WadPtr. * - * - list() Return a Patch_list object that provides - * what InputNameFromListWithFunc() needs - * to browse the patches. I suggest that - * this object be created immediately - * before it's needed and destroyed - * immediately after because it is not - * intended to remain valid across calls to - * refresh(). Ignoring this advice will - * cause some interesting crashes. + * - list() Return a Patch_list object that provides + * what InputNameFromListWithFunc() needs + * to browse the patches. I suggest that + * this object be created immediately + * before it's needed and destroyed + * immediately after because it is not + * intended to remain valid across calls to + * refresh(). Ignoring this advice will + * cause some interesting crashes. * - * The lifetime of this class is about the same as the - * lifetime of Yadex itself. It is instantiated only once. - * After construction, it is "empty". You must call - * refresh() to really initialize it (and call it again - * every time the directory changes in any way or you'll - * get strange results--or worse). + * The lifetime of this class is about the same as the + * lifetime of Yadex itself. It is instantiated only once. + * After construction, it is "empty". You must call + * refresh() to really initialize it (and call it again + * every time the directory changes in any way or you'll + * get strange results--or worse). */ struct Pllik @@ -110,16 +110,16 @@ wad_pic_name_t *name_for_num(i16 num); void list(Patch_list & pl); - private: char *pnames; // The contents of PNAMES + private: char *pnames; // The contents of PNAMES // (block of npnames x 8 chars) - size_t npnames; // Number of entries in PNAMES - Patch_lumps_map patch_lumps; // List of patch lumps, sorted + size_t npnames; // Number of entries in PNAMES + Patch_lumps_map patch_lumps; // List of patch lumps, sorted // by name (no duplicates), with // their location. }; -extern Patch_dir patch_dir; // Only one instance and it's global +extern Patch_dir patch_dir; // Only one instance and it's global #endif /* DO NOT ADD ANYTHING AFTER THIS LINE */ diff -r 594dea11ccd9 -r a68786b9c74b src/pic2img.cc --- a/src/pic2img.cc Sat Sep 24 15:01:56 2011 +0300 +++ b/src/pic2img.cc Sat Sep 24 15:59:33 2011 +0300 @@ -1,8 +1,8 @@ /* - * pic2img.cc - * Loading Doom-format pictures from a wad file. - * See the Unofficial Doom Specs, section [5-1]. - * AYM 1998-??-?? + * pic2img.cc + * Loading Doom-format pictures from a wad file. + * See the Unofficial Doom Specs, section [5-1]. + * AYM 1998-??-?? */ @@ -30,7 +30,7 @@ #include "yadex.h" -#include "gcolour2.h" /* colour0 */ +#include "gcolour2.h" /* colour0 */ #include "pic2img.h" #include "wadfile.h" #include "wads.h" @@ -46,31 +46,31 @@ /* - * LoadPicture - read a picture from a wad file into an Img object + * LoadPicture - read a picture from a wad file into an Img object * - * If img->is_null() is false, LoadPicture() does not allocate the - * buffer itself. The buffer and the picture don't have to have the - * same dimensions. Thanks to this, it can also be used to compose - * textures : you allocate a single buffer for the whole texture - * and then you call LoadPicture() on it once for each patch. - * LoadPicture() takes care of all the necessary clipping. + * If img->is_null() is false, LoadPicture() does not allocate the + * buffer itself. The buffer and the picture don't have to have the + * same dimensions. Thanks to this, it can also be used to compose + * textures : you allocate a single buffer for the whole texture + * and then you call LoadPicture() on it once for each patch. + * LoadPicture() takes care of all the necessary clipping. * - * If img->is_null() is true, LoadPicture() sets the size of img - * to match that of the picture. This is useful in display_pic(). + * If img->is_null() is true, LoadPicture() sets the size of img + * to match that of the picture. This is useful in display_pic(). * - * Return 0 on success, non-zero on failure. + * Return 0 on success, non-zero on failure. * - * If pic_x_offset == INT_MIN, the picture is centred horizontally. - * If pic_y_offset == INT_MIN, the picture is centred vertically. + * If pic_x_offset == INT_MIN, the picture is centred horizontally. + * If pic_y_offset == INT_MIN, the picture is centred vertically. */ -int LoadPicture(Img & img, // Game image to load picture into - const char *picname, // Picture lump name - const Lump_loc & picloc, // Picture lump location - int pic_x_offset, // Coordinates of top left corner of picture - int pic_y_offset, // relative to top left corner of buffer - int *pic_width, // To return the size of the picture - int *pic_height) // (can be NULL) +int LoadPicture(Img & img, // Game image to load picture into + const char *picname, // Picture lump name + const Lump_loc & picloc, // Picture lump location + int pic_x_offset, // Coordinates of top left corner of picture + int pic_y_offset, // relative to top left corner of buffer + int *pic_width, // To return the size of the picture + int *pic_height) // (can be NULL) { MDirPtr dir; i16 pic_width_; @@ -88,99 +88,99 @@ int pic_x1; int pic_y0; int pic_y1; - u8 *buf; /* This variable is set to point to the element of - the image buffer where the top of the current column - should be pasted. It can be off the image buffer! */ + u8 *buf; /* This variable is set to point to the element of + the image buffer where the top of the current column + should be pasted. It can be off the image buffer! */ // Locate the lump where the picture is if (picloc.wad != 0) { - MasterDirectory dirbuf; - dirbuf.wadfile = picloc.wad; - dirbuf.dir.start = picloc.ofs; - dirbuf.dir.size = picloc.len; - dir = &dirbuf; + MasterDirectory dirbuf; + dirbuf.wadfile = picloc.wad; + dirbuf.dir.start = picloc.ofs; + dirbuf.dir.size = picloc.len; + dir = &dirbuf; } else { - dir = (MDirPtr) FindMasterDir(MasterDir, picname); - if (dir == NULL) - { - warn("picture %.*s does not exist.\n", WAD_PIC_NAME, picname); - return 1; - } + dir = (MDirPtr) FindMasterDir(MasterDir, picname); + if (dir == NULL) + { + warn("picture %.*s does not exist.\n", WAD_PIC_NAME, picname); + return 1; + } } // Read the picture header dir->wadfile->seek(dir->dir.start); if (dir->wadfile->error()) { - warn("picture %.*s: can't seek to header, giving up\n", - WAD_PIC_NAME, picname); - return 1; + warn("picture %.*s: can't seek to header, giving up\n", + WAD_PIC_NAME, picname); + return 1; } bool dummy_bytes = dir->wadfile->pic_format() == YGPF_NORMAL; bool long_header = dir->wadfile->pic_format() != YGPF_ALPHA; bool long_offsets = dir->wadfile->pic_format() == YGPF_NORMAL; if (long_header) { - dir->wadfile->read_i16(&pic_width_); - dir->wadfile->read_i16(&pic_height_); - dir->wadfile->read_i16(&pic_intrinsic_x_ofs); // Read but ignored - dir->wadfile->read_i16(&pic_intrinsic_y_ofs); // Read but ignored - if (dir->wadfile->error()) - { - warn("picture %.*s: read error in header, giving up\n", - WAD_PIC_NAME, picname); - return 1; - } + dir->wadfile->read_i16(&pic_width_); + dir->wadfile->read_i16(&pic_height_); + dir->wadfile->read_i16(&pic_intrinsic_x_ofs); // Read but ignored + dir->wadfile->read_i16(&pic_intrinsic_y_ofs); // Read but ignored + if (dir->wadfile->error()) + { + warn("picture %.*s: read error in header, giving up\n", + WAD_PIC_NAME, picname); + return 1; + } } else { - pic_width_ = dir->wadfile->read_u8(); - pic_height_ = dir->wadfile->read_u8(); - pic_intrinsic_x_ofs = dir->wadfile->read_u8(); // Read but ignored - pic_intrinsic_y_ofs = dir->wadfile->read_u8(); // Read but ignored - if (dir->wadfile->error()) - { - warn("picture %.*s: read error in header, giving up\n", - WAD_PIC_NAME, picname); - return 1; - } + pic_width_ = dir->wadfile->read_u8(); + pic_height_ = dir->wadfile->read_u8(); + pic_intrinsic_x_ofs = dir->wadfile->read_u8(); // Read but ignored + pic_intrinsic_y_ofs = dir->wadfile->read_u8(); // Read but ignored + if (dir->wadfile->error()) + { + warn("picture %.*s: read error in header, giving up\n", + WAD_PIC_NAME, picname); + return 1; + } } // If no buffer given by caller, allocate one. if (img.is_null()) { - // Sanity checks - if (pic_width_ < 1 || pic_height_ < 1) - { - warn("picture %.*s: delirious dimensions %dx%d, giving up\n", - WAD_PIC_NAME, picname, (int) pic_width_, (int) pic_height_); - } - const int pic_width_max = 4096; - if (pic_width_ > pic_width_max) - { - warn("picture %.*s: too wide (%d), clipping to %d\n", - WAD_PIC_NAME, picname, (int) pic_width_, pic_width_max); - pic_width_ = pic_width_max; - } - const int pic_height_max = 4096; - if (pic_height_ > pic_height_max) - { - warn("picture %.*s: too high (%d), clipping to %d\n", - WAD_PIC_NAME, picname, (int) pic_height_, pic_height_max); - pic_height_ = pic_height_max; - } - img.resize(pic_width_, pic_height_); + // Sanity checks + if (pic_width_ < 1 || pic_height_ < 1) + { + warn("picture %.*s: delirious dimensions %dx%d, giving up\n", + WAD_PIC_NAME, picname, (int) pic_width_, (int) pic_height_); + } + const int pic_width_max = 4096; + if (pic_width_ > pic_width_max) + { + warn("picture %.*s: too wide (%d), clipping to %d\n", + WAD_PIC_NAME, picname, (int) pic_width_, pic_width_max); + pic_width_ = pic_width_max; + } + const int pic_height_max = 4096; + if (pic_height_ > pic_height_max) + { + warn("picture %.*s: too high (%d), clipping to %d\n", + WAD_PIC_NAME, picname, (int) pic_height_, pic_height_max); + pic_height_ = pic_height_max; + } + img.resize(pic_width_, pic_height_); } int img_width = img.width(); // Centre the picture. if (pic_x_offset == INT_MIN) - pic_x_offset = (img_width - pic_width_) / 2; + pic_x_offset = (img_width - pic_width_) / 2; if (pic_y_offset == INT_MIN) - pic_y_offset = (img.height() - pic_height_) / 2; + pic_y_offset = (img.height() - pic_height_) / 2; /* AYM 19971202: 17 kB is large enough for 128x128 patches. */ #define TEX_COLUMNBUFFERSIZE ((long) 17 * 1024) @@ -195,165 +195,165 @@ NeededOffsets = (i32 *) GetMemory((long) pic_width_ * 4); if (long_offsets) - dir->wadfile->read_i32(NeededOffsets, pic_width_); + dir->wadfile->read_i32(NeededOffsets, pic_width_); else - for (int n = 0; n < pic_width_; n++) - { - i16 ofs; - dir->wadfile->read_i16(&ofs); - NeededOffsets[n] = ofs; - } + for (int n = 0; n < pic_width_; n++) + { + i16 ofs; + dir->wadfile->read_i16(&ofs); + NeededOffsets[n] = ofs; + } if (dir->wadfile->error()) { - warn("picture %.*s: read error in offset table, giving up\n", - WAD_PIC_NAME, picname); - FreeMemory(ColumnData); - FreeMemory(NeededOffsets); - return 1; + warn("picture %.*s: read error in offset table, giving up\n", + WAD_PIC_NAME, picname); + FreeMemory(ColumnData); + FreeMemory(NeededOffsets); + return 1; } // Read first column data, and subsequent column data if (long_offsets && NeededOffsets[0] != 8 + (long) pic_width_ * 4 - || !long_offsets && NeededOffsets[0] != 4 + (long) pic_width_ * 2) + || !long_offsets && NeededOffsets[0] != 4 + (long) pic_width_ * 2) { - dir->wadfile->seek(dir->dir.start + NeededOffsets[0]); - if (dir->wadfile->error()) - { - warn("picture %.*s: can't seek to header, giving up\n", - WAD_PIC_NAME, picname); - FreeMemory(ColumnData); - FreeMemory(NeededOffsets); - return 1; - } + dir->wadfile->seek(dir->dir.start + NeededOffsets[0]); + if (dir->wadfile->error()) + { + warn("picture %.*s: can't seek to header, giving up\n", + WAD_PIC_NAME, picname); + FreeMemory(ColumnData); + FreeMemory(NeededOffsets); + return 1; + } } ActualBufLen = - dir->wadfile->read_vbytes(ColumnData, TEX_COLUMNBUFFERSIZE); + dir->wadfile->read_vbytes(ColumnData, TEX_COLUMNBUFFERSIZE); // FIXME should catch I/O errors // Clip the picture horizontally and vertically pic_x0 = -pic_x_offset; if (pic_x0 < 0) - pic_x0 = 0; + pic_x0 = 0; pic_x1 = img_width - pic_x_offset - 1; if (pic_x1 >= pic_width_) - pic_x1 = pic_width_ - 1; + pic_x1 = pic_width_ - 1; pic_y0 = -pic_y_offset; if (pic_y0 < 0) - pic_y0 = 0; + pic_y0 = 0; pic_y1 = img.height() - pic_y_offset - 1; if (pic_y1 >= pic_height_) - pic_y1 = pic_height_ - 1; + pic_y1 = pic_height_ - 1; // For each (non clipped) column of the picture... for (pic_x = pic_x0, - buf = - img.wbuf() + al_amax(pic_x_offset, 0) + img_width * pic_y_offset; - pic_x <= pic_x1; pic_x++, buf++) + buf = + img.wbuf() + al_amax(pic_x_offset, 0) + img_width * pic_y_offset; + pic_x <= pic_x1; pic_x++, buf++) { - u8 *filedata; + u8 *filedata; - CurrentOffset = NeededOffsets[pic_x]; - ColumnInMemory = CurrentOffset >= NeededOffsets[0] - && CurrentOffset + TEX_COLUMNSIZE <= - NeededOffsets[0] + ActualBufLen; - if (ColumnInMemory) - Column = ColumnData + CurrentOffset - NeededOffsets[0]; - else - { - Column = (u8 *) GetMemory(TEX_COLUMNSIZE); - dir->wadfile->seek(dir->dir.start + CurrentOffset); - if (dir->wadfile->error()) - { - int too_many = add_msg(_MT_BADOFS, (short) pic_x); - FreeMemory(Column); - if (too_many) // This picture has too many errors. Give up. - goto pic_end; - continue; // Give up on this column - } - dir->wadfile->read_vbytes(Column, TEX_COLUMNSIZE); - // FIXME should catch I/O errors - } - filedata = Column; + CurrentOffset = NeededOffsets[pic_x]; + ColumnInMemory = CurrentOffset >= NeededOffsets[0] + && CurrentOffset + TEX_COLUMNSIZE <= + NeededOffsets[0] + ActualBufLen; + if (ColumnInMemory) + Column = ColumnData + CurrentOffset - NeededOffsets[0]; + else + { + Column = (u8 *) GetMemory(TEX_COLUMNSIZE); + dir->wadfile->seek(dir->dir.start + CurrentOffset); + if (dir->wadfile->error()) + { + int too_many = add_msg(_MT_BADOFS, (short) pic_x); + FreeMemory(Column); + if (too_many) // This picture has too many errors. Give up. + goto pic_end; + continue; // Give up on this column + } + dir->wadfile->read_vbytes(Column, TEX_COLUMNSIZE); + // FIXME should catch I/O errors + } + filedata = Column; - // We now have the needed column data, one way or another, so write it + // We now have the needed column data, one way or another, so write it - // For each post of the column... - { - register u8 *post; - for (post = filedata; *post != 0xff;) - { - int post_y_offset; // Y-offset of top of post to origin of buffer - int post_height; // Height of post - int post_pic_y0; // Start and end of non-clipped part of post, - int post_pic_y1; // relative to top of picture - int post_y0; // Start and end of non-clipped part of post, - int post_y1; // relative to top of post + // For each post of the column... + { + register u8 *post; + for (post = filedata; *post != 0xff;) + { + int post_y_offset; // Y-offset of top of post to origin of buffer + int post_height; // Height of post + int post_pic_y0; // Start and end of non-clipped part of post, + int post_pic_y1; // relative to top of picture + int post_y0; // Start and end of non-clipped part of post, + int post_y1; // relative to top of post - if (post - filedata > TEX_COLUMNSIZE) - { - int too_many = add_msg(_MT_TOOLONG, (short) pic_x); - if (too_many) // This picture has too many errors. Give up. - { - if (!ColumnInMemory) - FreeMemory(Column); - goto pic_end; - } - break; // Give up on this column - } + if (post - filedata > TEX_COLUMNSIZE) + { + int too_many = add_msg(_MT_TOOLONG, (short) pic_x); + if (too_many) // This picture has too many errors. Give up. + { + if (!ColumnInMemory) + FreeMemory(Column); + goto pic_end; + } + break; // Give up on this column + } - post_y_offset = *post++; - post_height = *post++; - if (dummy_bytes) - post++; // Skip that dummy byte + post_y_offset = *post++; + post_height = *post++; + if (dummy_bytes) + post++; // Skip that dummy byte - post_pic_y0 = post_y_offset; // Clip the post vertically - if (post_pic_y0 < pic_y0) - post_pic_y0 = pic_y0; + post_pic_y0 = post_y_offset; // Clip the post vertically + if (post_pic_y0 < pic_y0) + post_pic_y0 = pic_y0; - post_pic_y1 = post_y_offset + post_height - 1; - if (post_pic_y1 > pic_y1) - post_pic_y1 = pic_y1; + post_pic_y1 = post_y_offset + post_height - 1; + if (post_pic_y1 > pic_y1) + post_pic_y1 = pic_y1; - post_y0 = post_pic_y0 - post_y_offset; - post_y1 = post_pic_y1 - post_y_offset; + post_y0 = post_pic_y0 - post_y_offset; + post_y1 = post_pic_y1 - post_y_offset; - { // "Paste" the post onto the buffer - register img_pixel_t *b; - register const u8 *p = post + post_y0; - const u8 *const pmax = post + post_y1; - int buf_width = img_width; + { // "Paste" the post onto the buffer + register img_pixel_t *b; + register const u8 *p = post + post_y0; + const u8 *const pmax = post + post_y1; + int buf_width = img_width; - for (b = buf + buf_width * (post_y_offset + post_y0); - p <= pmax; b += buf_width, p++) - { + for (b = buf + buf_width * (post_y_offset + post_y0); + p <= pmax; b += buf_width, p++) + { #ifdef PARANOIA - if (b < img.buf()) - { - nf_bug("Picture %.*s(%d): b < buffer", - WAD_PIC_NAME, picname, (int) pic_x); - goto next_column; - } + if (b < img.buf()) + { + nf_bug("Picture %.*s(%d): b < buffer", + WAD_PIC_NAME, picname, (int) pic_x); + goto next_column; + } #endif - *b = (*p == IMG_TRANSP) ? colour0 : *p; - } - } + *b = (*p == IMG_TRANSP) ? colour0 : *p; + } + } - post += post_height; - if (dummy_bytes) - post++; // Skip the trailing dummy byte - } // Post loop - } + post += post_height; + if (dummy_bytes) + post++; // Skip the trailing dummy byte + } // Post loop + } #ifdef PARANOIA next_column: #endif - if (!ColumnInMemory) - FreeMemory(Column); - } // Column loop + if (!ColumnInMemory) + FreeMemory(Column); + } // Column loop pic_end: FreeMemory(ColumnData); @@ -363,15 +363,15 @@ c->flags |= HOOK_DRAWN; #endif if (pic_width) - *pic_width = pic_width_; + *pic_width = pic_width_; if (pic_height) - *pic_height = pic_height_; + *pic_height = pic_height_; return 0; } /* - * List to hold pending warning messages + * List to hold pending warning messages */ typedef struct { @@ -385,19 +385,19 @@ /* - * add_msg - * Add a warning message to the list + * add_msg + * Add a warning message to the list * - * Return 0 on success, <>0 if the max number of messages - * has been reached. + * Return 0 on success, <>0 if the max number of messages + * has been reached. */ static int add_msg(char type, int arg) { if (_nmsg >= _max_msg) { - if (_nmsg == _max_msg) // Test in case the caller ignores our return value - do_add_msg(_MT_TOOMANY, arg); - return 1; + if (_nmsg == _max_msg) // Test in case the caller ignores our return value + do_add_msg(_MT_TOOMANY, arg); + return 1; } do_add_msg(type, arg); return 0; @@ -406,15 +406,15 @@ static void do_add_msg(char type, int arg) { - if ((_nmsg + 1) % _granularity == 1) // Grow list if necessary + if ((_nmsg + 1) % _granularity == 1) // Grow list if necessary { - _msg_t *new_list = (_msg_t *) realloc(_msg_list, - (_nmsg / _granularity + - 1) * _granularity * - sizeof *_msg_list); - if (new_list == 0) // Not enough memory ? Ignore the new message - return; - _msg_list = new_list; + _msg_t *new_list = (_msg_t *) realloc(_msg_list, + (_nmsg / _granularity + + 1) * _granularity * + sizeof *_msg_list); + if (new_list == 0) // Not enough memory ? Ignore the new message + return; + _msg_list = new_list; } _msg_list[_nmsg].type = type; _msg_list[_nmsg].arg = arg; @@ -424,64 +424,64 @@ /* - * flush_msg - * Output all pending warning messages in an smart fashion + * flush_msg + * Output all pending warning messages in an smart fashion */ static void flush_msg(const char *picname) { if (_nmsg == 0 || _msg_list == 0) - return; + return; for (_msg_type_t t = _MT_BADOFS; t <= _MT_TOOLONG; ((int &) t)++) { - size_t first_msg = AL_ASIZE_T_MAX; - size_t last_msg = AL_ASIZE_T_MAX; - const char *str = "unknown error"; - if (t == _MT_BADOFS) - str = "bad file offset"; - else if (t == _MT_TOOLONG) - str = "post too long"; + size_t first_msg = AL_ASIZE_T_MAX; + size_t last_msg = AL_ASIZE_T_MAX; + const char *str = "unknown error"; + if (t == _MT_BADOFS) + str = "bad file offset"; + else if (t == _MT_TOOLONG) + str = "post too long"; - for (size_t n = 0; n < _nmsg; n++) - { - if (_msg_list[n].type == t) - { - if (first_msg == AL_ASIZE_T_MAX) - { - first_msg = n; - last_msg = n; - } - else - { - if (_msg_list[last_msg].arg != _msg_list[n].arg - 1) - { - warn("picture %.*s(%d", - WAD_PIC_NAME, picname, - (int) _msg_list[first_msg].arg); - if (last_msg != first_msg) - warn("-%d", (int) _msg_list[last_msg].arg); - warn("): %s. Corrupt wad ?\n", str); - first_msg = n; - last_msg = n; - } - else - last_msg = n; - } - } - } - if (first_msg != AL_ASIZE_T_MAX) - { - warn("picture %.*s(%d", - WAD_PIC_NAME, picname, (int) _msg_list[first_msg].arg); - if (last_msg != first_msg) - warn("-%d", (int) _msg_list[last_msg].arg); - warn("): %s. Corrupt wad ?\n", str); - } + for (size_t n = 0; n < _nmsg; n++) + { + if (_msg_list[n].type == t) + { + if (first_msg == AL_ASIZE_T_MAX) + { + first_msg = n; + last_msg = n; + } + else + { + if (_msg_list[last_msg].arg != _msg_list[n].arg - 1) + { + warn("picture %.*s(%d", + WAD_PIC_NAME, picname, + (int) _msg_list[first_msg].arg); + if (last_msg != first_msg) + warn("-%d", (int) _msg_list[last_msg].arg); + warn("): %s. Corrupt wad ?\n", str); + first_msg = n; + last_msg = n; + } + else + last_msg = n; + } + } + } + if (first_msg != AL_ASIZE_T_MAX) + { + warn("picture %.*s(%d", + WAD_PIC_NAME, picname, (int) _msg_list[first_msg].arg); + if (last_msg != first_msg) + warn("-%d", (int) _msg_list[last_msg].arg); + warn("): %s. Corrupt wad ?\n", str); + } } if (_msg_list[_nmsg - 1].type == _MT_TOOMANY) - warn("picture %.*s: too many errors. Giving up.\n", WAD_PIC_NAME, - picname); + warn("picture %.*s: too many errors. Giving up.\n", WAD_PIC_NAME, + picname); _nmsg = 0; free(_msg_list); _msg_list = 0; diff -r 594dea11ccd9 -r a68786b9c74b src/pic2img.h --- a/src/pic2img.h Sat Sep 24 15:01:56 2011 +0300 +++ b/src/pic2img.h Sat Sep 24 15:59:33 2011 +0300 @@ -1,10 +1,10 @@ /* - * pic2img.h - * AYM 1998-??-?? + * pic2img.h + * AYM 1998-??-?? */ -#ifndef YH_PIC2IMG /* DO NOT INSERT ANYTHING BEFORE THIS LINE */ +#ifndef YH_PIC2IMG /* DO NOT INSERT ANYTHING BEFORE THIS LINE */ #define YH_PIC2IMG @@ -20,16 +20,16 @@ int LoadPicture(Img & img, #if 0 - img_pixel_t * buffer, /* Buffer to load picture into */ - int buf_width, /* Dimensions of the buffer */ - int buf_height, + img_pixel_t * buffer, /* Buffer to load picture into */ + int buf_width, /* Dimensions of the buffer */ + int buf_height, #endif - const char *picname, /* Picture lump name */ - const Lump_loc & picloc, /* Picture lump name */ - int pic_x_offset, /* Coordinates of top left corner of picture */ - int pic_y_offset, /* relative to top left corner of buffer. */ - int *pic_width = 0, /* To return the size of the picture */ - int *pic_height = 0); /* (can be NULL) */ + const char *picname, /* Picture lump name */ + const Lump_loc & picloc, /* Picture lump name */ + int pic_x_offset, /* Coordinates of top left corner of picture */ + int pic_y_offset, /* relative to top left corner of buffer. */ + int *pic_width = 0, /* To return the size of the picture */ + int *pic_height = 0); /* (can be NULL) */ #endif /* DO NOT ADD ANYTHING AFTER THIS LINE */ diff -r 594dea11ccd9 -r a68786b9c74b src/prefer.cc --- a/src/prefer.cc Sat Sep 24 15:01:56 2011 +0300 +++ b/src/prefer.cc Sat Sep 24 15:59:33 2011 +0300 @@ -1,6 +1,6 @@ /* - * prefer.cc - * AYM 1998-10-17 + * prefer.cc + * AYM 1998-10-17 */ @@ -53,114 +53,114 @@ width = 2 * BOX_BORDER + 2 * WIDE_HSPACING + 50 * FONTW; height = 2 * BOX_BORDER + 2 * WIDE_VSPACING + (int) (10.5 * FONTH); if (x0 < 0) - x0 = (ScrMaxX + 1 - width) / 2; + x0 = (ScrMaxX + 1 - width) / 2; if (y0 < 0) - y0 = (ScrMaxY + 1 - height) / 2; + y0 = (ScrMaxY + 1 - height) / 2; for (n = 0; n < 9; n++) - menustr[n] = (char *) GetMemory(80); + menustr[n] = (char *) GetMemory(80); sprintf(menustr[8], "Preferences"); sprintf(menustr[0], "Change default middle texture (Current: %.*s)", - (int) WAD_TEX_NAME, default_middle_texture); + (int) WAD_TEX_NAME, default_middle_texture); sprintf(menustr[1], "Change default upper texture (Current: %.*s)", - (int) WAD_TEX_NAME, default_upper_texture); + (int) WAD_TEX_NAME, default_upper_texture); sprintf(menustr[2], "Change default lower texture (Current: %.*s)", - (int) WAD_TEX_NAME, default_lower_texture); + (int) WAD_TEX_NAME, default_lower_texture); sprintf(menustr[3], "Change default floor texture (Current: %.*s)", - (int) WAD_FLAT_NAME, default_floor_texture); + (int) WAD_FLAT_NAME, default_floor_texture); sprintf(menustr[4], "Change default ceiling texture (Current: %.*s)", - (int) WAD_FLAT_NAME, default_ceiling_texture); + (int) WAD_FLAT_NAME, default_ceiling_texture); sprintf(menustr[5], "Change default floor height (Current: %d)", - default_floor_height); + default_floor_height); sprintf(menustr[6], "Change default ceiling height (Current: %d)", - default_ceiling_height); + default_ceiling_height); sprintf(menustr[7], "Change default light level (Current: %d)", - default_light_level); + default_light_level); val = vDisplayMenu(x0, y0, menustr[8], - menustr[0], YK_, 0, - menustr[1], YK_, 0, - menustr[2], YK_, 0, - menustr[3], YK_, 0, - menustr[4], YK_, 0, - menustr[5], YK_, 0, - menustr[6], YK_, 0, menustr[7], YK_, 0, NULL); + menustr[0], YK_, 0, + menustr[1], YK_, 0, + menustr[2], YK_, 0, + menustr[3], YK_, 0, + menustr[4], YK_, 0, + menustr[5], YK_, 0, + menustr[6], YK_, 0, menustr[7], YK_, 0, NULL); for (n = 0; n < 9; n++) - FreeMemory(menustr[n]); + FreeMemory(menustr[n]); int subwin_x0 = x0 + BOX_BORDER + WIDE_HSPACING; int subwin_y0 = - y0 + BOX_BORDER + WIDE_VSPACING + (int) ((1.5 + val) * FONTH); + y0 + BOX_BORDER + WIDE_VSPACING + (int) ((1.5 + val) * FONTH); switch (val) { case 1: - strcpy(texname, default_middle_texture); - ChooseWallTexture(subwin_x0, subwin_y0, "Choose a wall texture", - NumWTexture, WTexture, texname); - if (strlen(texname) > 0) - strcpy(default_middle_texture, texname); - break; + strcpy(texname, default_middle_texture); + ChooseWallTexture(subwin_x0, subwin_y0, "Choose a wall texture", + NumWTexture, WTexture, texname); + if (strlen(texname) > 0) + strcpy(default_middle_texture, texname); + break; case 2: - strcpy(texname, default_upper_texture); - ChooseWallTexture(subwin_x0, subwin_y0, "Choose a wall texture", - NumWTexture, WTexture, texname); - if (strlen(texname) > 0) - strcpy(default_upper_texture, texname); - break; + strcpy(texname, default_upper_texture); + ChooseWallTexture(subwin_x0, subwin_y0, "Choose a wall texture", + NumWTexture, WTexture, texname); + if (strlen(texname) > 0) + strcpy(default_upper_texture, texname); + break; case 3: - strcpy(texname, default_lower_texture); - ChooseWallTexture(subwin_x0, subwin_y0, "Choose a wall texture", - NumWTexture, WTexture, texname); - if (strlen(texname) > 0) - strcpy(default_lower_texture, texname); - break; + strcpy(texname, default_lower_texture); + ChooseWallTexture(subwin_x0, subwin_y0, "Choose a wall texture", + NumWTexture, WTexture, texname); + if (strlen(texname) > 0) + strcpy(default_lower_texture, texname); + break; case 4: - { - strcpy(flatname, default_floor_texture); - char **flat_names - = (char **) GetMemory(NumFTexture * sizeof *flat_names); - for (size_t n = 0; n < NumFTexture; n++) - flat_names[n] = flat_list[n].name; - ChooseFloorTexture(subwin_x0, subwin_y0, "Choose a floor texture", - NumFTexture, flat_names, flatname); - FreeMemory(flat_names); - if (strlen(flatname) > 0) - strcpy(default_floor_texture, flatname); - break; - } + { + strcpy(flatname, default_floor_texture); + char **flat_names + = (char **) GetMemory(NumFTexture * sizeof *flat_names); + for (size_t n = 0; n < NumFTexture; n++) + flat_names[n] = flat_list[n].name; + ChooseFloorTexture(subwin_x0, subwin_y0, "Choose a floor texture", + NumFTexture, flat_names, flatname); + FreeMemory(flat_names); + if (strlen(flatname) > 0) + strcpy(default_floor_texture, flatname); + break; + } case 5: - { - strcpy(flatname, default_ceiling_texture); - char **flat_names - = (char **) GetMemory(NumFTexture * sizeof *flat_names); - for (size_t n = 0; n < NumFTexture; n++) - flat_names[n] = flat_list[n].name; - ChooseFloorTexture(subwin_x0, subwin_y0, - "Choose a ceiling texture", NumFTexture, - flat_names, flatname); - FreeMemory(flat_names); - if (strlen(flatname) > 0) - strcpy(default_ceiling_texture, flatname); - break; - } + { + strcpy(flatname, default_ceiling_texture); + char **flat_names + = (char **) GetMemory(NumFTexture * sizeof *flat_names); + for (size_t n = 0; n < NumFTexture; n++) + flat_names[n] = flat_list[n].name; + ChooseFloorTexture(subwin_x0, subwin_y0, + "Choose a ceiling texture", NumFTexture, + flat_names, flatname); + FreeMemory(flat_names); + if (strlen(flatname) > 0) + strcpy(default_ceiling_texture, flatname); + break; + } case 6: - val = - InputIntegerValue(x0 + 42, subwin_y0, -512, 511, - default_floor_height); - if (val != IIV_CANCEL) - default_floor_height = val; - break; + val = + InputIntegerValue(x0 + 42, subwin_y0, -512, 511, + default_floor_height); + if (val != IIV_CANCEL) + default_floor_height = val; + break; case 7: - val = - InputIntegerValue(x0 + 42, subwin_y0, -512, 511, - default_ceiling_height); - if (val != IIV_CANCEL) - default_ceiling_height = val; - break; + val = + InputIntegerValue(x0 + 42, subwin_y0, -512, 511, + default_ceiling_height); + if (val != IIV_CANCEL) + default_ceiling_height = val; + break; case 8: - val = - InputIntegerValue(x0 + 42, subwin_y0, 0, 255, - default_light_level); - if (val != IIV_CANCEL) - default_light_level = val; - break; + val = + InputIntegerValue(x0 + 42, subwin_y0, 0, 255, + default_light_level); + if (val != IIV_CANCEL) + default_light_level = val; + break; } } diff -r 594dea11ccd9 -r a68786b9c74b src/prefer.h --- a/src/prefer.h Sat Sep 24 15:01:56 2011 +0300 +++ b/src/prefer.h Sat Sep 24 15:59:33 2011 +0300 @@ -1,6 +1,6 @@ /* - * prefer.h - * AYM 1998-10-17 + * prefer.h + * AYM 1998-10-17 */ diff -r 594dea11ccd9 -r a68786b9c74b src/r_images.cc --- a/src/r_images.cc Sat Sep 24 15:01:56 2011 +0300 +++ b/src/r_images.cc Sat Sep 24 15:59:33 2011 +0300 @@ -1,6 +1,6 @@ /* - * r_images.cc - * AJA 2002-04-23 (based on textures.cc and flats.cc) + * r_images.cc + * AJA 2002-04-23 (based on textures.cc and flats.cc) */ @@ -32,7 +32,7 @@ #include <X11/Xlib.h> #endif #include "dialog.h" -#include "game.h" /* yg_picture_format */ +#include "game.h" /* yg_picture_format */ #include "gfx.h" #include "levels.h" #include "lists.h" @@ -50,15 +50,15 @@ /* - * flat_list_entry_match - * Function used by bsearch() to locate a particular - * flat in the FTexture. + * flat_list_entry_match + * Function used by bsearch() to locate a particular + * flat in the FTexture. */ static int flat_list_entry_match(const void *key, const void *flat_list_entry) { return y_strnicmp((const char *) key, - ((const flat_list_entry_t *) flat_list_entry)->name, - WAD_FLAT_NAME); + ((const flat_list_entry_t *) flat_list_entry)->name, + WAD_FLAT_NAME); } @@ -73,13 +73,13 @@ name[WAD_FLAT_NAME] = 0; flat_list_entry_t *flat = (flat_list_entry_t *) - bsearch(name, flat_list, NumFTexture, sizeof *flat_list, - flat_list_entry_match); + bsearch(name, flat_list, NumFTexture, sizeof *flat_list, + flat_list_entry_match); - if (!flat) // Not found in list - return 0; + if (!flat) // Not found in list + return 0; - int width = DOOM_FLAT_WIDTH; // Big deal ! + int width = DOOM_FLAT_WIDTH; // Big deal ! int height = DOOM_FLAT_HEIGHT; const Wad_file *wadfile = flat->wadfile; @@ -100,15 +100,15 @@ Img *Tex2Img(const wad_tex_name_t & texname) { - MDirPtr dir = 0; /* main directory pointer to the TEXTURE* entries */ - i32 *offsets; /* array of offsets to texture names */ - int n; /* general counter */ - i16 width, height; /* size of the texture */ - i16 npatches; /* number of wall patches used to build this texture */ - i32 numtex; /* number of texture names in TEXTURE* list */ - i32 texofs; /* offset in the wad file to the texture data */ - char tname[WAD_TEX_NAME + 1]; /* texture name */ - char picname[WAD_PIC_NAME + 1]; /* wall patch name */ + MDirPtr dir = 0; /* main directory pointer to the TEXTURE* entries */ + i32 *offsets; /* array of offsets to texture names */ + int n; /* general counter */ + i16 width, height; /* size of the texture */ + i16 npatches; /* number of wall patches used to build this texture */ + i32 numtex; /* number of texture names in TEXTURE* list */ + i32 texofs; /* offset in the wad file to the texture data */ + char tname[WAD_TEX_NAME + 1]; /* texture name */ + char picname[WAD_PIC_NAME + 1]; /* wall patch name */ bool have_dummy_bytes; int header_size; int item_size; @@ -120,147 +120,147 @@ // Iwad-dependant details if (yg_texture_format == YGTF_NAMELESS) { - have_dummy_bytes = true; - header_size = 14; - item_size = 10; + have_dummy_bytes = true; + header_size = 14; + item_size = 10; } else if (yg_texture_format == YGTF_NORMAL) { - have_dummy_bytes = true; - header_size = 14; - item_size = 10; + have_dummy_bytes = true; + header_size = 14; + item_size = 10; } else if (yg_texture_format == YGTF_STRIFE11) { - have_dummy_bytes = false; - header_size = 10; - item_size = 6; + have_dummy_bytes = false; + header_size = 10; + item_size = 6; } else { - nf_bug("Bad texture format %d.", (int) yg_texture_format); - return 0; + nf_bug("Bad texture format %d.", (int) yg_texture_format); + return 0; } /* offset for texture we want. */ texofs = 0; // Doom alpha 0.4 : "TEXTURES", no names if (yg_texture_lumps == YGTL_TEXTURES - && yg_texture_format == YGTF_NAMELESS) + && yg_texture_format == YGTF_NAMELESS) { - dir = FindMasterDir(MasterDir, "TEXTURES"); - if (dir != NULL) - { - dir->wadfile->seek(dir->dir.start); - dir->wadfile->read_i32(&numtex); - if (WAD_TEX_NAME < 7) - nf_bug("WAD_TEX_NAME too small"); // Sanity - if (!y_strnicmp(name, "TEX", 3) - && isdigit(name[3]) - && isdigit(name[4]) - && isdigit(name[5]) && isdigit(name[6]) && name[7] == '\0') - { - long num; - if (sscanf(name + 3, "%4ld", &num) == 1 - && num >= 0 && num < numtex) - { - dir->wadfile->seek(dir->dir.start + 4 + 4 * num); - dir->wadfile->read_i32(&texofs); - texofs += dir->dir.start; - } - } - } + dir = FindMasterDir(MasterDir, "TEXTURES"); + if (dir != NULL) + { + dir->wadfile->seek(dir->dir.start); + dir->wadfile->read_i32(&numtex); + if (WAD_TEX_NAME < 7) + nf_bug("WAD_TEX_NAME too small"); // Sanity + if (!y_strnicmp(name, "TEX", 3) + && isdigit(name[3]) + && isdigit(name[4]) + && isdigit(name[5]) && isdigit(name[6]) && name[7] == '\0') + { + long num; + if (sscanf(name + 3, "%4ld", &num) == 1 + && num >= 0 && num < numtex) + { + dir->wadfile->seek(dir->dir.start + 4 + 4 * num); + dir->wadfile->read_i32(&texofs); + texofs += dir->dir.start; + } + } + } } // Doom alpha 0.5 : only "TEXTURES" else if (yg_texture_lumps == YGTL_TEXTURES - && (yg_texture_format == YGTF_NORMAL - || yg_texture_format == YGTF_STRIFE11)) + && (yg_texture_format == YGTF_NORMAL + || yg_texture_format == YGTF_STRIFE11)) { - // Is it in TEXTURES ? - dir = FindMasterDir(MasterDir, "TEXTURES"); - if (dir != NULL) // (Theoretically, it should always exist) - { - dir->wadfile->seek(dir->dir.start); - dir->wadfile->read_i32(&numtex); - /* read in the offsets for texture1 names and info. */ - offsets = (i32 *) GetMemory((long) numtex * 4); - dir->wadfile->read_i32(offsets, numtex); - for (n = 0; n < numtex && !texofs; n++) - { - dir->wadfile->seek(dir->dir.start + offsets[n]); - dir->wadfile->read_bytes(&tname, WAD_TEX_NAME); - if (!y_strnicmp(tname, name, WAD_TEX_NAME)) - texofs = dir->dir.start + offsets[n]; - } - FreeMemory(offsets); - } + // Is it in TEXTURES ? + dir = FindMasterDir(MasterDir, "TEXTURES"); + if (dir != NULL) // (Theoretically, it should always exist) + { + dir->wadfile->seek(dir->dir.start); + dir->wadfile->read_i32(&numtex); + /* read in the offsets for texture1 names and info. */ + offsets = (i32 *) GetMemory((long) numtex * 4); + dir->wadfile->read_i32(offsets, numtex); + for (n = 0; n < numtex && !texofs; n++) + { + dir->wadfile->seek(dir->dir.start + offsets[n]); + dir->wadfile->read_bytes(&tname, WAD_TEX_NAME); + if (!y_strnicmp(tname, name, WAD_TEX_NAME)) + texofs = dir->dir.start + offsets[n]; + } + FreeMemory(offsets); + } } // Other iwads : "TEXTURE1" and "TEXTURE2" else if (yg_texture_lumps == YGTL_NORMAL - && (yg_texture_format == YGTF_NORMAL - || yg_texture_format == YGTF_STRIFE11)) + && (yg_texture_format == YGTF_NORMAL + || yg_texture_format == YGTF_STRIFE11)) { - // Is it in TEXTURE1 ? - dir = FindMasterDir(MasterDir, "TEXTURE1"); - if (dir != NULL) // (Theoretically, it should always exist) - { - dir->wadfile->seek(dir->dir.start); - dir->wadfile->read_i32(&numtex); - /* read in the offsets for texture1 names and info. */ - offsets = (i32 *) GetMemory((long) numtex * 4); - dir->wadfile->read_i32(offsets, numtex); - for (n = 0; n < numtex && !texofs; n++) - { - dir->wadfile->seek(dir->dir.start + offsets[n]); - dir->wadfile->read_bytes(&tname, WAD_TEX_NAME); - if (!y_strnicmp(tname, name, WAD_TEX_NAME)) - texofs = dir->dir.start + offsets[n]; - } - FreeMemory(offsets); - } - // Well, then is it in TEXTURE2 ? - if (texofs == 0) - { - dir = FindMasterDir(MasterDir, "TEXTURE2"); - if (dir != NULL) // Doom II has no TEXTURE2 - { - dir->wadfile->seek(dir->dir.start); - dir->wadfile->read_i32(&numtex); - /* read in the offsets for texture2 names */ - offsets = (i32 *) GetMemory((long) numtex * 4); - dir->wadfile->read_i32(offsets, numtex); - for (n = 0; n < numtex && !texofs; n++) - { - dir->wadfile->seek(dir->dir.start + offsets[n]); - dir->wadfile->read_bytes(&tname, WAD_TEX_NAME); - if (!y_strnicmp(tname, name, WAD_TEX_NAME)) - texofs = dir->dir.start + offsets[n]; - } - FreeMemory(offsets); - } - } + // Is it in TEXTURE1 ? + dir = FindMasterDir(MasterDir, "TEXTURE1"); + if (dir != NULL) // (Theoretically, it should always exist) + { + dir->wadfile->seek(dir->dir.start); + dir->wadfile->read_i32(&numtex); + /* read in the offsets for texture1 names and info. */ + offsets = (i32 *) GetMemory((long) numtex * 4); + dir->wadfile->read_i32(offsets, numtex); + for (n = 0; n < numtex && !texofs; n++) + { + dir->wadfile->seek(dir->dir.start + offsets[n]); + dir->wadfile->read_bytes(&tname, WAD_TEX_NAME); + if (!y_strnicmp(tname, name, WAD_TEX_NAME)) + texofs = dir->dir.start + offsets[n]; + } + FreeMemory(offsets); + } + // Well, then is it in TEXTURE2 ? + if (texofs == 0) + { + dir = FindMasterDir(MasterDir, "TEXTURE2"); + if (dir != NULL) // Doom II has no TEXTURE2 + { + dir->wadfile->seek(dir->dir.start); + dir->wadfile->read_i32(&numtex); + /* read in the offsets for texture2 names */ + offsets = (i32 *) GetMemory((long) numtex * 4); + dir->wadfile->read_i32(offsets, numtex); + for (n = 0; n < numtex && !texofs; n++) + { + dir->wadfile->seek(dir->dir.start + offsets[n]); + dir->wadfile->read_bytes(&tname, WAD_TEX_NAME); + if (!y_strnicmp(tname, name, WAD_TEX_NAME)) + texofs = dir->dir.start + offsets[n]; + } + FreeMemory(offsets); + } + } } else - nf_bug("Invalid texture_format/texture_lumps combination."); + nf_bug("Invalid texture_format/texture_lumps combination."); /* texture name not found */ if (texofs == 0) - return 0; + return 0; /* read the info for this texture */ i32 header_ofs; if (yg_texture_format == YGTF_NAMELESS) - header_ofs = texofs; + header_ofs = texofs; else - header_ofs = texofs + WAD_TEX_NAME; + header_ofs = texofs + WAD_TEX_NAME; dir->wadfile->seek(header_ofs + 4); dir->wadfile->read_i16(&width); dir->wadfile->read_i16(&height); if (have_dummy_bytes) { - i16 dummy; - dir->wadfile->read_i16(&dummy); - dir->wadfile->read_i16(&dummy); + i16 dummy; + dir->wadfile->read_i16(&dummy); + dir->wadfile->read_i16(&dummy); } dir->wadfile->read_i16(&npatches); @@ -271,48 +271,48 @@ made of. */ for (n = 0; n < npatches; n++) { - i16 xofs, yofs; // offset in texture space for the patch - i16 pnameind; // index of patch in PNAMES + i16 xofs, yofs; // offset in texture space for the patch + i16 pnameind; // index of patch in PNAMES - dir->wadfile->seek(header_ofs + header_size + (long) n * item_size); - dir->wadfile->read_i16(&xofs); - dir->wadfile->read_i16(&yofs); - dir->wadfile->read_i16(&pnameind); + dir->wadfile->seek(header_ofs + header_size + (long) n * item_size); + dir->wadfile->read_i16(&xofs); + dir->wadfile->read_i16(&yofs); + dir->wadfile->read_i16(&pnameind); - if (have_dummy_bytes) - { - i16 stepdir; - i16 colormap; - dir->wadfile->read_i16(&stepdir); // Always 1, unused. - dir->wadfile->read_i16(&colormap); // Always 0, unused. - } + if (have_dummy_bytes) + { + i16 stepdir; + i16 colormap; + dir->wadfile->read_i16(&stepdir); // Always 1, unused. + dir->wadfile->read_i16(&colormap); // Always 0, unused. + } - /* AYM 1998-08-08: Yes, that's weird but that's what Doom - does. Without these two lines, the few textures that have - patches with negative y-offsets (BIGDOOR7, SKY1, TEKWALL1, - TEKWALL5 and a few others) would not look in the texture - viewer quite like in Doom. This should be mentioned in - the UDS, by the way. */ - if (yofs < 0) - yofs = 0; + /* AYM 1998-08-08: Yes, that's weird but that's what Doom + does. Without these two lines, the few textures that have + patches with negative y-offsets (BIGDOOR7, SKY1, TEKWALL1, + TEKWALL5 and a few others) would not look in the texture + viewer quite like in Doom. This should be mentioned in + the UDS, by the way. */ + if (yofs < 0) + yofs = 0; - Lump_loc loc; - { - wad_pic_name_t *wname = patch_dir.name_for_num(pnameind); - if (wname == 0) - { - warn("texture \"%.*s\": patch %2d has bad index %d.\n", - WAD_TEX_NAME, tname, (int) n, (int) pnameind); - continue; - } - patch_dir.loc_by_name((const char *) *wname, loc); - *picname = '\0'; - strncat(picname, (const char *) *wname, sizeof picname - 1); - } + Lump_loc loc; + { + wad_pic_name_t *wname = patch_dir.name_for_num(pnameind); + if (wname == 0) + { + warn("texture \"%.*s\": patch %2d has bad index %d.\n", + WAD_TEX_NAME, tname, (int) n, (int) pnameind); + continue; + } + patch_dir.loc_by_name((const char *) *wname, loc); + *picname = '\0'; + strncat(picname, (const char *) *wname, sizeof picname - 1); + } - if (LoadPicture(*texbuf, picname, loc, xofs, yofs, 0, 0)) - warn("texture \"%.*s\": patch \"%.*s\" not found.\n", - WAD_TEX_NAME, tname, WAD_PIC_NAME, picname); + if (LoadPicture(*texbuf, picname, loc, xofs, yofs, 0, 0)) + warn("texture \"%.*s\": patch \"%.*s\" not found.\n", + WAD_TEX_NAME, tname, WAD_PIC_NAME, picname); } return texbuf; @@ -329,7 +329,7 @@ flat_map_t::iterator P = flats.find(f_str); if (P != flats.end()) - return P->second; + return P->second; // flat not in the list yet. Add it. @@ -347,14 +347,14 @@ Img *ImageCache::GetTex(const wad_tex_name_t & tname) { if (tname[0] == 0 || tname[0] == '-') - return 0; + return 0; std::string t_str = WadToString(tname); tex_map_t::iterator P = textures.find(t_str); if (P != textures.end()) - return P->second; + return P->second; // texture not in the list yet. Add it. @@ -374,7 +374,7 @@ sprite_map_t::iterator P = sprites.find(type); if (P != sprites.end()) - return P->second; + return P->second; // sprite not in the list yet. Add it. @@ -383,15 +383,15 @@ const char *sprite_root = get_thing_sprite(type); if (sprite_root) { - Lump_loc loc; - wad_res.sprites.loc_by_root(sprite_root, loc); - result = new Img(); + Lump_loc loc; + wad_res.sprites.loc_by_root(sprite_root, loc); + result = new Img(); - if (LoadPicture(*result, sprite_root, loc, 0, 0) != 0) - { - delete result; - result = 0; - } + if (LoadPicture(*result, sprite_root, loc, 0, 0) != 0) + { + delete result; + result = 0; + } } // note that a NULL image is OK. Our renderer will just ignore the diff -r 594dea11ccd9 -r a68786b9c74b src/r_images.h --- a/src/r_images.h Sat Sep 24 15:01:56 2011 +0300 +++ b/src/r_images.h Sat Sep 24 15:59:33 2011 +0300 @@ -1,10 +1,10 @@ /* - * r_images.h - * AJA 2002-04-27 + * r_images.h + * AJA 2002-04-27 */ -#ifndef YH_R_IMAGES /* DO NOT INSERT ANYTHING BEFORE THIS LINE */ +#ifndef YH_R_IMAGES /* DO NOT INSERT ANYTHING BEFORE THIS LINE */ #define YH_R_IMAGES @@ -26,39 +26,39 @@ static std::string WadToString(const wad_flat_name_t & fname) { - int len; + int len; - for (len = 0; len < WAD_NAME && fname[len]; len++) - { - } + for (len = 0; len < WAD_NAME && fname[len]; len++) + { + } - return std::string(fname, len); + return std::string(fname, len); } static void DeleteFlat(const flat_map_t::value_type & P) { - delete P.second; + delete P.second; } static void DeleteTex(const tex_map_t::value_type & P) { - delete P.second; + delete P.second; } static void DeleteSprite(const sprite_map_t::value_type & P) { - delete P.second; + delete P.second; } ~ImageCache() { - std::for_each(flats.begin(), flats.end(), DeleteFlat); - std::for_each(textures.begin(), textures.end(), DeleteTex); - std::for_each(sprites.begin(), sprites.end(), DeleteSprite); + std::for_each(flats.begin(), flats.end(), DeleteFlat); + std::for_each(textures.begin(), textures.end(), DeleteTex); + std::for_each(sprites.begin(), sprites.end(), DeleteSprite); - flats.clear(); - textures.clear(); - sprites.clear(); + flats.clear(); + textures.clear(); + sprites.clear(); } Img *GetFlat(const wad_flat_name_t & fname); diff -r 594dea11ccd9 -r a68786b9c74b src/r_render.cc --- a/src/r_render.cc Sat Sep 24 15:01:56 2011 +0300 +++ b/src/r_render.cc Sat Sep 24 15:59:33 2011 +0300 @@ -1,7 +1,7 @@ /* - * r_render.cc - * 3D Rendering - * AJA 2002-04-21 + * r_render.cc + * 3D Rendering + * AJA 2002-04-21 */ @@ -92,61 +92,61 @@ Y_View() { - memset(this, 0, sizeof *this); + memset(this, 0, sizeof *this); } void SetAngle(float new_ang) { - angle = new_ang; + angle = new_ang; - if (angle >= TWOPI) - angle -= TWOPI; - else if (angle < 0) - angle += TWOPI; + if (angle >= TWOPI) + angle -= TWOPI; + else if (angle < 0) + angle += TWOPI; - Sin = sin(angle); - Cos = cos(angle); + Sin = sin(angle); + Cos = cos(angle); } void CalcViewZ() { - Objid o; - GetCurObject(o, OBJ_SECTORS, int (x), int (y)); - int secnum = o.num; - if (secnum >= 0) - z = Sectors[secnum].floorh + EYE_HEIGHT; + Objid o; + GetCurObject(o, OBJ_SECTORS, int (x), int (y)); + int secnum = o.num; + if (secnum >= 0) + z = Sectors[secnum].floorh + EYE_HEIGHT; } void ClearScreen() { - memset(screen->wbuf(), colour0, sw * sh); + memset(screen->wbuf(), colour0, sw * sh); } void PutScreen(int x, int y) { - DrawScreenBox3D(x, y, x + BOX_BORDER * 2 + sw, - y + BOX_BORDER * 2 + sh); + DrawScreenBox3D(x, y, x + BOX_BORDER * 2 + sw, + y + BOX_BORDER * 2 + sh); - Sticker sticker(*screen, true); + Sticker sticker(*screen, true); - sticker.draw(drw, 't', x + BOX_BORDER, y + BOX_BORDER); + sticker.draw(drw, 't', x + BOX_BORDER, y + BOX_BORDER); } void FindThingFloors() { - thing_floors = new int[NumThings]; + thing_floors = new int[NumThings]; - for (int i = 0; i < NumThings; i++) - { - Objid o; - GetCurObject(o, OBJ_SECTORS, Things[i].xpos, Things[i].ypos); - int secnum = o.num; + for (int i = 0; i < NumThings; i++) + { + Objid o; + GetCurObject(o, OBJ_SECTORS, Things[i].xpos, Things[i].ypos); + int secnum = o.num; - if (secnum < 0) - thing_floors[i] = 0; - else - thing_floors[i] = Sectors[secnum].floorh; - } + if (secnum < 0) + thing_floors[i] = 0; + else + thing_floors[i] = Sectors[secnum].floorh; + } } }; @@ -159,9 +159,9 @@ public: enum { - K_INVIS = 0, - K_FLAT, - K_TEXTURE + K_INVIS = 0, + K_FLAT, + K_TEXTURE }; int kind; @@ -169,12 +169,12 @@ // heights for the surface (h1 is above h2). Img *img; - img_pixel_t col; /* used if img is zero */ + img_pixel_t col; /* used if img is zero */ enum { - SOLID_ABOVE = 1, - SOLID_BELOW = 2 + SOLID_ABOVE = 1, + SOLID_BELOW = 2 }; int y_clip; @@ -182,35 +182,35 @@ DrawSurf() { - kind = K_INVIS; - img = 0; + kind = K_INVIS; + img = 0; } void FindFlat(const wad_flat_name_t & fname, Sector * sec) { - if (view.texturing) - { - img = view.im_ch->GetFlat(fname); + if (view.texturing) + { + img = view.im_ch->GetFlat(fname); - if (img != 0) - return; - } - col = 0x70 + ((sec - Sectors) % 48); + if (img != 0) + return; + } + col = 0x70 + ((sec - Sectors) % 48); } void FindTex(const wad_tex_name_t & tname, LineDef * ld) { - if (view.texturing) - { - img = view.im_ch->GetTex(tname); + if (view.texturing) + { + img = view.im_ch->GetTex(tname); - if (img != 0) - return; - } - col = 0x30 + ((ld - LineDefs) % 64); + if (img != 0) + return; + } + col = 0x30 + ((ld - LineDefs) % 64); - if (col >= 0x60) - col += 0x70; + if (col >= 0x60) + col += 0x70; } }; @@ -265,151 +265,151 @@ struct MidDistCmp { - inline bool operator() (const DrawWall * A, const DrawWall * B) const - { - return A->mid_iz > B->mid_iz; - } + inline bool operator() (const DrawWall * A, const DrawWall * B) const + { + return A->mid_iz > B->mid_iz; + } }; struct DistCmp { - inline bool operator() (const DrawWall * A, const DrawWall * B) const - { - if (fabs(A->cur_iz - B->cur_iz) < IZ_EPSILON) - return A->diz > B->diz; + inline bool operator() (const DrawWall * A, const DrawWall * B) const + { + if (fabs(A->cur_iz - B->cur_iz) < IZ_EPSILON) + return A->diz > B->diz; - return A->cur_iz > B->cur_iz; - } + return A->cur_iz > B->cur_iz; + } }; struct SX1Cmp { - inline bool operator() (const DrawWall * A, const DrawWall * B) const - { - return A->sx1 < B->sx1; - } + inline bool operator() (const DrawWall * A, const DrawWall * B) const + { + return A->sx1 < B->sx1; + } - inline bool operator() (const DrawWall * A, int x) const - { - return A->sx1 < x; - } + inline bool operator() (const DrawWall * A, int x) const + { + return A->sx1 < x; + } - inline bool operator() (int x, const DrawWall * A) const - { - return x < A->sx1; - } + inline bool operator() (int x, const DrawWall * A) const + { + return x < A->sx1; + } }; struct SX2Less { - int x; + int x; - SX2Less(int _x):x(_x) - { - } + SX2Less(int _x):x(_x) + { + } - inline bool operator() (const DrawWall * A) const - { - return A->sx2 < x; - } + inline bool operator() (const DrawWall * A) const + { + return A->sx2 < x; + } }; /* methods */ void ComputeWallSurface() { - Sector *front = sec; - Sector *back = 0; + Sector *front = sec; + Sector *back = 0; - if (is_obj(side ? ld->sidedef1 : ld->sidedef2)) - { - SideDef *bsd = SideDefs + (side ? ld->sidedef1 : ld->sidedef2); + if (is_obj(side ? ld->sidedef1 : ld->sidedef2)) + { + SideDef *bsd = SideDefs + (side ? ld->sidedef1 : ld->sidedef2); - if (is_obj(bsd->sector)) - back = Sectors + bsd->sector; - } + if (is_obj(bsd->sector)) + back = Sectors + bsd->sector; + } - bool sky_upper = back && is_sky(front->ceilt) && is_sky(back->ceilt); + bool sky_upper = back && is_sky(front->ceilt) && is_sky(back->ceilt); - if ((front->ceilh > view.z || is_sky(front->ceilt)) && !sky_upper) - { - ceil.kind = DrawSurf::K_FLAT; - ceil.h1 = +99999; - ceil.h2 = front->ceilh; - ceil.tex_h = ceil.h2; - ceil.y_clip = DrawSurf::SOLID_ABOVE; + if ((front->ceilh > view.z || is_sky(front->ceilt)) && !sky_upper) + { + ceil.kind = DrawSurf::K_FLAT; + ceil.h1 = +99999; + ceil.h2 = front->ceilh; + ceil.tex_h = ceil.h2; + ceil.y_clip = DrawSurf::SOLID_ABOVE; - if (is_sky(front->ceilt)) - ceil.col = sky_colour; - else - ceil.FindFlat(front->ceilt, front); - } + if (is_sky(front->ceilt)) + ceil.col = sky_colour; + else + ceil.FindFlat(front->ceilt, front); + } - if (front->floorh < view.z) - { - floor.kind = DrawSurf::K_FLAT; - floor.h1 = front->floorh; - floor.h2 = -99999; - floor.tex_h = floor.h1; - floor.y_clip = DrawSurf::SOLID_BELOW; + if (front->floorh < view.z) + { + floor.kind = DrawSurf::K_FLAT; + floor.h1 = front->floorh; + floor.h2 = -99999; + floor.tex_h = floor.h1; + floor.y_clip = DrawSurf::SOLID_BELOW; - if (is_sky(front->floort)) - floor.col = sky_colour; - else - floor.FindFlat(front->floort, front); - } + if (is_sky(front->floort)) + floor.col = sky_colour; + else + floor.FindFlat(front->floort, front); + } - if (!back) - { - /* ONE-sided line */ + if (!back) + { + /* ONE-sided line */ - lower.kind = DrawSurf::K_TEXTURE; - lower.h1 = front->ceilh; - lower.h2 = front->floorh; - lower.y_clip = DrawSurf::SOLID_ABOVE | DrawSurf::SOLID_BELOW; + lower.kind = DrawSurf::K_TEXTURE; + lower.h1 = front->ceilh; + lower.h2 = front->floorh; + lower.y_clip = DrawSurf::SOLID_ABOVE | DrawSurf::SOLID_BELOW; - lower.FindTex(sd->tex3, ld); + lower.FindTex(sd->tex3, ld); - if (lower.img && (ld->flags & ML_LOWER_UNPEGGED)) - lower.tex_h = lower.h2 + lower.img->height(); - else - lower.tex_h = lower.h1; - } - else - { - /* TWO-sided line */ + if (lower.img && (ld->flags & ML_LOWER_UNPEGGED)) + lower.tex_h = lower.h2 + lower.img->height(); + else + lower.tex_h = lower.h1; + } + else + { + /* TWO-sided line */ - if (back->ceilh < front->ceilh && !sky_upper) - { - upper.kind = DrawSurf::K_TEXTURE; - upper.h1 = front->ceilh; - upper.h2 = back->ceilh; - upper.tex_h = upper.h1; - upper.y_clip = DrawSurf::SOLID_ABOVE; + if (back->ceilh < front->ceilh && !sky_upper) + { + upper.kind = DrawSurf::K_TEXTURE; + upper.h1 = front->ceilh; + upper.h2 = back->ceilh; + upper.tex_h = upper.h1; + upper.y_clip = DrawSurf::SOLID_ABOVE; - upper.FindTex(sd->tex1, ld); + upper.FindTex(sd->tex1, ld); - if (upper.img && !(ld->flags & ML_UPPER_UNPEGGED)) - upper.tex_h = upper.h2 + upper.img->height(); - else - upper.tex_h = upper.h1; - } + if (upper.img && !(ld->flags & ML_UPPER_UNPEGGED)) + upper.tex_h = upper.h2 + upper.img->height(); + else + upper.tex_h = upper.h1; + } - if (back->floorh > front->floorh) - { - lower.kind = DrawSurf::K_TEXTURE; - lower.h1 = back->floorh; - lower.h2 = front->floorh; - lower.y_clip = DrawSurf::SOLID_BELOW; + if (back->floorh > front->floorh) + { + lower.kind = DrawSurf::K_TEXTURE; + lower.h1 = back->floorh; + lower.h2 = front->floorh; + lower.y_clip = DrawSurf::SOLID_BELOW; - lower.FindTex(sd->tex2, ld); + lower.FindTex(sd->tex2, ld); - if (ld->flags & ML_LOWER_UNPEGGED) - lower.tex_h = front->ceilh; - else - lower.tex_h = lower.h1; - } - } + if (ld->flags & ML_LOWER_UNPEGGED) + lower.tex_h = front->ceilh; + else + lower.tex_h = lower.h1; + } + } } }; @@ -434,691 +434,691 @@ static void DeleteWall(DrawWall * P) { - delete P; + delete P; } ~RendInfo() { - std::for_each(walls.begin(), walls.end(), DeleteWall); + std::for_each(walls.begin(), walls.end(), DeleteWall); - walls.clear(); - active.clear(); + walls.clear(); + active.clear(); } void InitDepthBuf(int width) { - depth_x.resize(width); + depth_x.resize(width); - std::fill_n(depth_x.begin(), width, 0); + std::fill_n(depth_x.begin(), width, 0); } static inline float PointToAngle(float x, float y) { - if (-0.01 < x && x < 0.01) - return (y > 0) ? HALFPI : (3 * HALFPI); + if (-0.01 < x && x < 0.01) + return (y > 0) ? HALFPI : (3 * HALFPI); - float angle = atan2(y, x); + float angle = atan2(y, x); - if (angle < 0) - angle += TWOPI; + if (angle < 0) + angle += TWOPI; - return angle; + return angle; } static inline int AngleToX(float ang) { - float t = tan(HALFPI - ang); + float t = tan(HALFPI - ang); - int x = int (view.sw * t); + int x = int (view.sw * t); - x = (view.sw + x) / 2; + x = (view.sw + x) / 2; - if (x < 0) - x = 0; - else if (x > view.sw) - x = view.sw; + if (x < 0) + x = 0; + else if (x > view.sw) + x = view.sw; - return x; + return x; } static inline float XToAngle(int x) { - x = x * 2 - view.sw; + x = x * 2 - view.sw; - float ang = HALFPI + atan(x / float (view.sw)); + float ang = HALFPI + atan(x / float (view.sw)); - if (ang < 0) - ang = 0; - else if (ang > ONEPI) - ang = ONEPI; + if (ang < 0) + ang = 0; + else if (ang > ONEPI) + ang = ONEPI; - return ang; + return ang; } static inline int DeltaToX(double iz, float tx) { - int x = int (view.sw * tx * iz); + int x = int (view.sw * tx * iz); - x = (x + view.sw) / 2; + x = (x + view.sw) / 2; - return x; + return x; } static inline float XToDelta(int x, double iz) { - x = x * 2 - view.sw; + x = x * 2 - view.sw; - float tx = x / iz / view.sw; + float tx = x / iz / view.sw; - return tx; + return tx; } static inline int DistToY(double iz, int sec_h) { - if (sec_h > 32770) - return -9999; + if (sec_h > 32770) + return -9999; - if (sec_h < -32770) - return +9999; + if (sec_h < -32770) + return +9999; - sec_h -= view.z; + sec_h -= view.z; - int y = int (view.sh * sec_h * iz * Y_SLOPE); + int y = int (view.sh * sec_h * iz * Y_SLOPE); - y = (view.sh - y) / 2; + y = (view.sh - y) / 2; - return y; + return y; } static inline float YToDist(int y, int sec_h) { - sec_h -= view.z; + sec_h -= view.z; - y = y * 2 - view.sh; + y = y * 2 - view.sh; - if (y == 0) - return 999999; + if (y == 0) + return 999999; - return view.sh * sec_h * Y_SLOPE / y; + return view.sh * sec_h * Y_SLOPE / y; } static inline float YToSecH(int y, double iz) { - y = y * 2 - view.sh; + y = y * 2 - view.sh; - return view.z - (float (y) / view.sh / iz / Y_SLOPE); + return view.z - (float (y) / view.sh / iz / Y_SLOPE); } void AddLine(int linenum) { - LineDef *ld = LineDefs + linenum; + LineDef *ld = LineDefs + linenum; - if (!is_obj(ld->start) || !is_obj(ld->end)) - return; + if (!is_obj(ld->start) || !is_obj(ld->end)) + return; - float x1 = Vertices[ld->start].x - view.x; - float y1 = Vertices[ld->start].y - view.y; - float x2 = Vertices[ld->end].x - view.x; - float y2 = Vertices[ld->end].y - view.y; + float x1 = Vertices[ld->start].x - view.x; + float y1 = Vertices[ld->start].y - view.y; + float x2 = Vertices[ld->end].x - view.x; + float y2 = Vertices[ld->end].y - view.y; - float tx1 = x1 * view.Sin - y1 * view.Cos; - float ty1 = x1 * view.Cos + y1 * view.Sin; - float tx2 = x2 * view.Sin - y2 * view.Cos; - float ty2 = x2 * view.Cos + y2 * view.Sin; + float tx1 = x1 * view.Sin - y1 * view.Cos; + float ty1 = x1 * view.Cos + y1 * view.Sin; + float tx2 = x2 * view.Sin - y2 * view.Cos; + float ty2 = x2 * view.Cos + y2 * view.Sin; - // reject line if complete behind viewplane - if (ty1 <= 0 && ty2 <= 0) - return; + // reject line if complete behind viewplane + if (ty1 <= 0 && ty2 <= 0) + return; - float angle1 = PointToAngle(tx1, ty1); - float angle2 = PointToAngle(tx2, ty2); - float span = angle1 - angle2; + float angle1 = PointToAngle(tx1, ty1); + float angle2 = PointToAngle(tx2, ty2); + float span = angle1 - angle2; - if (span < 0) - span += TWOPI; + if (span < 0) + span += TWOPI; - int side = 0; - SideDef *sd; + int side = 0; + SideDef *sd; - if (span >= ONEPI) - side = 1; + if (span >= ONEPI) + side = 1; - // ignore the line when there is no facing sidedef - if (!is_obj(side ? ld->sidedef2 : ld->sidedef1)) - return; + // ignore the line when there is no facing sidedef + if (!is_obj(side ? ld->sidedef2 : ld->sidedef1)) + return; - sd = SideDefs + (side ? ld->sidedef2 : ld->sidedef1); + sd = SideDefs + (side ? ld->sidedef2 : ld->sidedef1); - if (!is_obj(sd->sector)) - return; + if (!is_obj(sd->sector)) + return; - if (side == 1) - { - float tmp = angle1; - angle1 = angle2; - angle2 = tmp; - } + if (side == 1) + { + float tmp = angle1; + angle1 = angle2; + angle2 = tmp; + } - // clip angles to view volume + // clip angles to view volume - float base_ang = angle1; + float base_ang = angle1; - float leftclip = (3 * ONEPI / 4); - float rightclip = ONEPI / 4; + float leftclip = (3 * ONEPI / 4); + float rightclip = ONEPI / 4; - float tspan1 = angle1 - rightclip; - float tspan2 = leftclip - angle2; + float tspan1 = angle1 - rightclip; + float tspan2 = leftclip - angle2; - if (tspan1 < 0) - tspan1 += TWOPI; - if (tspan2 < 0) - tspan2 += TWOPI; + if (tspan1 < 0) + tspan1 += TWOPI; + if (tspan2 < 0) + tspan2 += TWOPI; - if (tspan1 > HALFPI) - { - // Totally off the left edge? - if (tspan2 >= ONEPI) - return; + if (tspan1 > HALFPI) + { + // Totally off the left edge? + if (tspan2 >= ONEPI) + return; - angle1 = leftclip; - } + angle1 = leftclip; + } - if (tspan2 > HALFPI) - { - // Totally off the left edge? - if (tspan1 >= ONEPI) - return; + if (tspan2 > HALFPI) + { + // Totally off the left edge? + if (tspan1 >= ONEPI) + return; - angle2 = rightclip; - } + angle2 = rightclip; + } - // convert angles to on-screen X positions - int sx1 = AngleToX(angle1); - int sx2 = AngleToX(angle2) - 1; + // convert angles to on-screen X positions + int sx1 = AngleToX(angle1); + int sx2 = AngleToX(angle2) - 1; - if (sx1 > sx2) - return; + if (sx1 > sx2) + return; - // compute distance from eye to wall - float wdx = x2 - x1; - float wdy = y2 - y1; + // compute distance from eye to wall + float wdx = x2 - x1; + float wdy = y2 - y1; - float wlen = sqrt(wdx * wdx + wdy * wdy); - float dist = fabs((y1 * wdx / wlen) - (x1 * wdy / wlen)); + float wlen = sqrt(wdx * wdx + wdy * wdy); + float dist = fabs((y1 * wdx / wlen) - (x1 * wdy / wlen)); - if (dist < 0.01) - return; + if (dist < 0.01) + return; - // compute normal of wall (translated coords) - float normal; + // compute normal of wall (translated coords) + float normal; - if (side == 1) - normal = PointToAngle(ty2 - ty1, tx1 - tx2); - else - normal = PointToAngle(ty1 - ty2, tx2 - tx1); + if (side == 1) + normal = PointToAngle(ty2 - ty1, tx1 - tx2); + else + normal = PointToAngle(ty1 - ty2, tx2 - tx1); - // compute inverse distances - double iz1 = cos(normal - angle1) / dist / cos(HALFPI - angle1); - double iz2 = cos(normal - angle2) / dist / cos(HALFPI - angle2); + // compute inverse distances + double iz1 = cos(normal - angle1) / dist / cos(HALFPI - angle1); + double iz2 = cos(normal - angle2) / dist / cos(HALFPI - angle2); - double diz = (iz2 - iz1) / y_max(1, sx2 - sx1); + double diz = (iz2 - iz1) / y_max(1, sx2 - sx1); - // create drawwall structure + // create drawwall structure - DrawWall *dw = new DrawWall; + DrawWall *dw = new DrawWall; - dw->th = 0; - dw->ld = ld; - dw->sd = sd; - dw->sec = Sectors + sd->sector; + dw->th = 0; + dw->ld = ld; + dw->sd = sd; + dw->sec = Sectors + sd->sector; - dw->side = side; + dw->side = side; - dw->base_ang = base_ang; - dw->ang1 = angle1; - dw->dang = (angle2 - angle1) / y_max(1, sx2 - sx1); + dw->base_ang = base_ang; + dw->ang1 = angle1; + dw->dang = (angle2 - angle1) / y_max(1, sx2 - sx1); - dw->dist = dist; - dw->normal = normal; - dw->t_dist = tan(base_ang - normal) * dist; + dw->dist = dist; + dw->normal = normal; + dw->t_dist = tan(base_ang - normal) * dist; - dw->iz1 = iz1; - dw->diz = diz; - dw->mid_iz = iz1 + (sx2 - sx1 + 1) * diz / 2; + dw->iz1 = iz1; + dw->diz = diz; + dw->mid_iz = iz1 + (sx2 - sx1 + 1) * diz / 2; - dw->sx1 = sx1; - dw->sx2 = sx2; + dw->sx1 = sx1; + dw->sx2 = sx2; - walls.push_back(dw); + walls.push_back(dw); } void AddThing(int thingnum) { - Thing *th = Things + thingnum; + Thing *th = Things + thingnum; - float x = th->xpos - view.x; - float y = th->ypos - view.y; + float x = th->xpos - view.x; + float y = th->ypos - view.y; - float tx = x * view.Sin - y * view.Cos; - float ty = x * view.Cos + y * view.Sin; + float tx = x * view.Sin - y * view.Cos; + float ty = x * view.Cos + y * view.Sin; - // reject sprite if complete behind viewplane - if (ty < 4) - return; + // reject sprite if complete behind viewplane + if (ty < 4) + return; - Img *sprite = view.im_ch->GetSprite(th->type); - if (!sprite) - return; + Img *sprite = view.im_ch->GetSprite(th->type); + if (!sprite) + return; - float tx1 = tx - sprite->width() / 2.0; - float tx2 = tx + sprite->width() / 2.0; + float tx1 = tx - sprite->width() / 2.0; + float tx2 = tx + sprite->width() / 2.0; - double iz = 1 / ty; + double iz = 1 / ty; - int sx1 = DeltaToX(iz, tx1); - int sx2 = DeltaToX(iz, tx2) - 1; + int sx1 = DeltaToX(iz, tx1); + int sx2 = DeltaToX(iz, tx2) - 1; - if (sx1 < 0) - sx1 = 0; + if (sx1 < 0) + sx1 = 0; - if (sx2 >= view.sw) - sx2 = view.sw - 1; + if (sx2 >= view.sw) + sx2 = view.sw - 1; - if (sx1 > sx2) - return; + if (sx1 > sx2) + return; - int h2 = view.thing_floors[thingnum]; - int h1 = h2 + sprite->height(); + int h2 = view.thing_floors[thingnum]; + int h1 = h2 + sprite->height(); - // create drawwall structure + // create drawwall structure - DrawWall *dw = new DrawWall; + DrawWall *dw = new DrawWall; - dw->th = th; - dw->ld = 0; - dw->sd = 0; - dw->sec = 0; + dw->th = th; + dw->ld = 0; + dw->sd = 0; + dw->sec = 0; - dw->spr_tx1 = tx1; + dw->spr_tx1 = tx1; - dw->ang1 = dw->dang = 0; + dw->ang1 = dw->dang = 0; - dw->iz1 = dw->mid_iz = iz; - dw->diz = 0; + dw->iz1 = dw->mid_iz = iz; + dw->diz = 0; - dw->sx1 = sx1; - dw->sx2 = sx2; + dw->sx1 = sx1; + dw->sx2 = sx2; - dw->ceil.img = sprite; - dw->ceil.h1 = h1; - dw->ceil.h2 = h2; + dw->ceil.img = sprite; + dw->ceil.h1 = h1; + dw->ceil.h2 = h2; - walls.push_back(dw); + walls.push_back(dw); } void ComputeSurfaces() { - DrawWall::vec_t::iterator S; + DrawWall::vec_t::iterator S; - for (S = walls.begin(); S != walls.end(); S++) - if ((*S)->ld) - (*S)->ComputeWallSurface(); + for (S = walls.begin(); S != walls.end(); S++) + if ((*S)->ld) + (*S)->ComputeWallSurface(); } void ClipSolids() { - // perform a rough depth sort of the walls and sprites. + // perform a rough depth sort of the walls and sprites. - std::sort(walls.begin(), walls.end(), DrawWall::MidDistCmp()); + std::sort(walls.begin(), walls.end(), DrawWall::MidDistCmp()); - // go forwards, from closest to furthest away + // go forwards, from closest to furthest away - DrawWall::vec_t::iterator S; + DrawWall::vec_t::iterator S; - for (S = walls.begin(); S != walls.end(); S++) - { - DrawWall *dw = (*S); + for (S = walls.begin(); S != walls.end(); S++) + { + DrawWall *dw = (*S); - if (!dw) - continue; + if (!dw) + continue; - int one_sided = dw->ld && !is_obj(dw->ld->sidedef2); - int vis_count = dw->sx2 - dw->sx1 + 1; + int one_sided = dw->ld && !is_obj(dw->ld->sidedef2); + int vis_count = dw->sx2 - dw->sx1 + 1; - for (int x = dw->sx1; x <= dw->sx2; x++) - { - double iz = dw->iz1 + (dw->diz * (x - dw->sx1)); + for (int x = dw->sx1; x <= dw->sx2; x++) + { + double iz = dw->iz1 + (dw->diz * (x - dw->sx1)); - if (iz < depth_x[x]) - vis_count--; - else if (one_sided) - depth_x[x] = iz; - } + if (iz < depth_x[x]) + vis_count--; + else if (one_sided) + depth_x[x] = iz; + } - if (vis_count == 0) - { - delete dw; - (*S) = 0; - } - } + if (vis_count == 0) + { + delete dw; + (*S) = 0; + } + } - // remove null pointers + // remove null pointers - S = std::remove(walls.begin(), walls.end(), (DrawWall *) 0); + S = std::remove(walls.begin(), walls.end(), (DrawWall *) 0); - walls.erase(S, walls.end()); + walls.erase(S, walls.end()); } void RenderFlatColumn(DrawWall * dw, DrawSurf & surf, - int x, int y1, int y2) + int x, int y1, int y2) { - img_pixel_t *buf = view.screen->wbuf(); - img_pixel_t *wbuf = surf.img->wbuf(); + img_pixel_t *buf = view.screen->wbuf(); + img_pixel_t *wbuf = surf.img->wbuf(); - int tw = surf.img->width(); - int th = surf.img->height(); + int tw = surf.img->width(); + int th = surf.img->height(); - float ang = XToAngle(x); - float modv = cos(ang - HALFPI); + float ang = XToAngle(x); + float modv = cos(ang - HALFPI); - float t_cos = cos(ONEPI + -view.angle + ang) / modv; - float t_sin = sin(ONEPI + -view.angle + ang) / modv; + float t_cos = cos(ONEPI + -view.angle + ang) / modv; + float t_sin = sin(ONEPI + -view.angle + ang) / modv; - buf += x + y1 * view.sw; + buf += x + y1 * view.sw; - for (; y1 <= y2; y1++, buf += view.sw) - { - float dist = YToDist(y1, surf.tex_h); + for (; y1 <= y2; y1++, buf += view.sw) + { + float dist = YToDist(y1, surf.tex_h); - int tx = int (view.x + t_sin * dist) & (tw - 1); - int ty = int (-view.y - t_cos * dist) & (th - 1); + int tx = int (view.x + t_sin * dist) & (tw - 1); + int ty = int (-view.y - t_cos * dist) & (th - 1); - *buf = wbuf[ty * tw + tx]; - } + *buf = wbuf[ty * tw + tx]; + } } void RenderTexColumn(DrawWall * dw, DrawSurf & surf, - int x, int y1, int y2) + int x, int y1, int y2) { - img_pixel_t *buf = view.screen->wbuf(); - img_pixel_t *wbuf = surf.img->wbuf(); + img_pixel_t *buf = view.screen->wbuf(); + img_pixel_t *wbuf = surf.img->wbuf(); - int tw = surf.img->width(); - int th = surf.img->height(); + int tw = surf.img->width(); + int th = surf.img->height(); - /* compute texture X coord */ + /* compute texture X coord */ - int tx = int (dw->t_dist - tan(dw->cur_ang - dw->normal) * dw->dist); + int tx = int (dw->t_dist - tan(dw->cur_ang - dw->normal) * dw->dist); - tx = (dw->sd->xoff + tx) & (tw - 1); + tx = (dw->sd->xoff + tx) & (tw - 1); - /* compute texture Y coords */ + /* compute texture Y coords */ - float base_h = surf.tex_h + dw->sd->yoff; + float base_h = surf.tex_h + dw->sd->yoff; - float h1 = base_h - YToSecH(y1, dw->cur_iz); - float dh = base_h - YToSecH(y2, dw->cur_iz); + float h1 = base_h - YToSecH(y1, dw->cur_iz); + float dh = base_h - YToSecH(y2, dw->cur_iz); - dh = (dh - h1) / y_max(1, y2 - y1); + dh = (dh - h1) / y_max(1, y2 - y1); - buf += x + y1 * view.sw; - wbuf += tx; + buf += x + y1 * view.sw; + wbuf += tx; - for (; y1 <= y2; y1++, h1 += dh, buf += view.sw) - { - int ty = int (h1) % th; + for (; y1 <= y2; y1++, h1 += dh, buf += view.sw) + { + int ty = int (h1) % th; - // handle negative values (use % twice) - ty = (ty + th) % th; + // handle negative values (use % twice) + ty = (ty + th) % th; - *buf = wbuf[ty * tw]; - } + *buf = wbuf[ty * tw]; + } } void RenderSolidColumn(DrawWall * w, DrawSurf & surf, - int x, int y1, int y2) + int x, int y1, int y2) { - img_pixel_t *buf = view.screen->wbuf(); + img_pixel_t *buf = view.screen->wbuf(); - buf += x + y1 * view.sw; + buf += x + y1 * view.sw; - for (; y1 <= y2; y1++, buf += view.sw) - { - *buf = surf.col; - } + for (; y1 <= y2; y1++, buf += view.sw) + { + *buf = surf.col; + } } inline void RenderWallSurface(DrawWall * dw, DrawSurf & surf, int x) { - if (surf.kind == DrawSurf::K_INVIS) - return; + if (surf.kind == DrawSurf::K_INVIS) + return; - int y1 = DistToY(dw->cur_iz, surf.h1); - int y2 = DistToY(dw->cur_iz, surf.h2) - 1; + int y1 = DistToY(dw->cur_iz, surf.h1); + int y2 = DistToY(dw->cur_iz, surf.h2) - 1; - if (y1 < open_y1) - y1 = open_y1; + if (y1 < open_y1) + y1 = open_y1; - if (y2 > open_y2) - y2 = open_y2; + if (y2 > open_y2) + y2 = open_y2; - if (y1 > y2) - return; + if (y1 > y2) + return; - /* clip the open region */ + /* clip the open region */ - if (surf.y_clip & DrawSurf::SOLID_ABOVE) - if (y2 > open_y1) - open_y1 = y2; + if (surf.y_clip & DrawSurf::SOLID_ABOVE) + if (y2 > open_y1) + open_y1 = y2; - if (surf.y_clip & DrawSurf::SOLID_BELOW) - if (y1 < open_y2) - open_y2 = y1; + if (surf.y_clip & DrawSurf::SOLID_BELOW) + if (y1 < open_y2) + open_y2 = y1; - /* fill pixels */ + /* fill pixels */ - if (!surf.img) - { - RenderSolidColumn(dw, surf, x, y1, y2); - } - else - switch (surf.kind) - { - case DrawSurf::K_FLAT: - RenderFlatColumn(dw, surf, x, y1, y2); - break; + if (!surf.img) + { + RenderSolidColumn(dw, surf, x, y1, y2); + } + else + switch (surf.kind) + { + case DrawSurf::K_FLAT: + RenderFlatColumn(dw, surf, x, y1, y2); + break; - case DrawSurf::K_TEXTURE: - RenderTexColumn(dw, surf, x, y1, y2); - break; - } + case DrawSurf::K_TEXTURE: + RenderTexColumn(dw, surf, x, y1, y2); + break; + } } inline void RenderSprite(DrawWall * dw, int x) { - int y1 = DistToY(dw->cur_iz, dw->ceil.h1); - int y2 = DistToY(dw->cur_iz, dw->ceil.h2) - 1; + int y1 = DistToY(dw->cur_iz, dw->ceil.h1); + int y2 = DistToY(dw->cur_iz, dw->ceil.h2) - 1; - if (y1 < dw->oy1) - y1 = dw->oy1; + if (y1 < dw->oy1) + y1 = dw->oy1; - if (y2 > dw->oy2) - y2 = dw->oy2; + if (y2 > dw->oy2) + y2 = dw->oy2; - if (y1 > y2) - return; + if (y1 > y2) + return; - /* fill pixels */ + /* fill pixels */ - img_pixel_t *buf = view.screen->wbuf(); - img_pixel_t *wbuf = dw->ceil.img->wbuf(); + img_pixel_t *buf = view.screen->wbuf(); + img_pixel_t *wbuf = dw->ceil.img->wbuf(); - int tw = dw->ceil.img->width(); - int th = dw->ceil.img->height(); + int tw = dw->ceil.img->width(); + int th = dw->ceil.img->height(); - int tx = int (XToDelta(x, dw->cur_iz) - dw->spr_tx1); + int tx = int (XToDelta(x, dw->cur_iz) - dw->spr_tx1); - if (tx < 0 || tx >= tw) - return; + if (tx < 0 || tx >= tw) + return; - float h1 = dw->ceil.h1 - YToSecH(y1, dw->cur_iz); - float dh = dw->ceil.h1 - YToSecH(y2, dw->cur_iz); + float h1 = dw->ceil.h1 - YToSecH(y1, dw->cur_iz); + float dh = dw->ceil.h1 - YToSecH(y2, dw->cur_iz); - dh = (dh - h1) / y_max(1, y2 - y1); + dh = (dh - h1) / y_max(1, y2 - y1); - buf += x + y1 * view.sw; - wbuf += tx; + buf += x + y1 * view.sw; + wbuf += tx; - for (; y1 <= y2; y1++, h1 += dh, buf += view.sw) - { - int ty = int (h1); + for (; y1 <= y2; y1++, h1 += dh, buf += view.sw) + { + int ty = int (h1); - if (ty < 0 || ty >= th) - continue; + if (ty < 0 || ty >= th) + continue; - img_pixel_t pix = wbuf[ty * tw]; + img_pixel_t pix = wbuf[ty * tw]; - if (pix != IMG_TRANSP) - *buf = pix; - } + if (pix != IMG_TRANSP) + *buf = pix; + } } void UpdateActiveList(int x) { - DrawWall::vec_t::iterator S, E, P; + DrawWall::vec_t::iterator S, E, P; - bool changes = false; + bool changes = false; - // remove walls that have finished. + // remove walls that have finished. - S = active.begin(); - E = active.end(); + S = active.begin(); + E = active.end(); - S = std::remove_if(S, E, DrawWall::SX2Less(x)); + S = std::remove_if(S, E, DrawWall::SX2Less(x)); - if (S != E) - { - active.erase(S, E); - changes = true; - } + if (S != E) + { + active.erase(S, E); + changes = true; + } - // add new walls that start in this column. + // add new walls that start in this column. - S = walls.begin(); - E = walls.end(); + S = walls.begin(); + E = walls.end(); - S = std::lower_bound(S, E, x, DrawWall::SX1Cmp()); - E = std::upper_bound(S, E, x, DrawWall::SX1Cmp()); + S = std::lower_bound(S, E, x, DrawWall::SX1Cmp()); + E = std::upper_bound(S, E, x, DrawWall::SX1Cmp()); - if (S != E) - changes = true; + if (S != E) + changes = true; - for (; S != E; S++) - { - active.push_back(*S); - } + for (; S != E; S++) + { + active.push_back(*S); + } - // calculate new depth values + // calculate new depth values - S = active.begin(); - E = active.end(); + S = active.begin(); + E = active.end(); - for (P = S; (P != E); P++) - { - DrawWall *dw = (*P); + for (P = S; (P != E); P++) + { + DrawWall *dw = (*P); - dw->cur_iz = dw->iz1 + dw->diz * (x - dw->sx1); + dw->cur_iz = dw->iz1 + dw->diz * (x - dw->sx1); - if (P != S && (*(P - 1))->cur_iz < dw->cur_iz) - changes = true; + if (P != S && (*(P - 1))->cur_iz < dw->cur_iz) + changes = true; - dw->cur_ang = dw->ang1 + dw->dang * (x - dw->sx1); - } + dw->cur_ang = dw->ang1 + dw->dang * (x - dw->sx1); + } - // if there are changes, re-sort the active list... + // if there are changes, re-sort the active list... - if (changes) - { - std::sort(active.begin(), active.end(), DrawWall::DistCmp()); - } + if (changes) + { + std::sort(active.begin(), active.end(), DrawWall::DistCmp()); + } } void RenderWalls() { - // sort walls by their starting column, to allow binary search. + // sort walls by their starting column, to allow binary search. - std::sort(walls.begin(), walls.end(), DrawWall::SX1Cmp()); + std::sort(walls.begin(), walls.end(), DrawWall::SX1Cmp()); - active.clear(); + active.clear(); - for (int x = 0; x < view.sw; x++) - { - // clear vertical depth buffer + for (int x = 0; x < view.sw; x++) + { + // clear vertical depth buffer - open_y1 = 0; - open_y2 = view.sh - 1; + open_y1 = 0; + open_y2 = view.sh - 1; - UpdateActiveList(x); + UpdateActiveList(x); - // render, front to back + // render, front to back - DrawWall::vec_t::iterator S, E, P; + DrawWall::vec_t::iterator S, E, P; - S = active.begin(); - E = active.end(); + S = active.begin(); + E = active.end(); - for (P = S; P != E; P++) - { - DrawWall *dw = (*P); + for (P = S; P != E; P++) + { + DrawWall *dw = (*P); - // for things, just remember the open space - if (dw->th) - { - dw->oy1 = open_y1; - dw->oy2 = open_y2; - continue; - } + // for things, just remember the open space + if (dw->th) + { + dw->oy1 = open_y1; + dw->oy2 = open_y2; + continue; + } - RenderWallSurface(dw, dw->ceil, x); - RenderWallSurface(dw, dw->floor, x); - RenderWallSurface(dw, dw->upper, x); - RenderWallSurface(dw, dw->lower, x); + RenderWallSurface(dw, dw->ceil, x); + RenderWallSurface(dw, dw->floor, x); + RenderWallSurface(dw, dw->upper, x); + RenderWallSurface(dw, dw->lower, x); - if (open_y1 >= open_y2) - break; - } + if (open_y1 >= open_y2) + break; + } - // now render things, back to front + // now render things, back to front - if (P == E) - P--; + if (P == E) + P--; - for (; P != (S - 1); P--) - { - DrawWall *dw = (*P); + for (; P != (S - 1); P--) + { + DrawWall *dw = (*P); - if (dw->th) - RenderSprite(dw, x); - } - } + if (dw->th) + RenderSprite(dw, x); + } + } } void DoRender3D() { - view.ClearScreen(); + view.ClearScreen(); - InitDepthBuf(view.sw); + InitDepthBuf(view.sw); - for (int i = 0; i < NumLineDefs; i++) - AddLine(i); + for (int i = 0; i < NumLineDefs; i++) + AddLine(i); - if (view.sprites) - for (int j = 0; j < NumThings; j++) - AddThing(j); + if (view.sprites) + for (int j = 0; j < NumThings; j++) + AddThing(j); - ClipSolids(); - ComputeSurfaces(); - RenderWalls(); + ClipSolids(); + ComputeSurfaces(); + RenderWalls(); } }; @@ -1126,8 +1126,8 @@ static Thing *FindPlayer(int typenum) { for (int i = 0; i < NumThings; i++) - if (Things[i].type == typenum) - return Things + i; + if (Things[i].type == typenum) + return Things + i; return 0; } @@ -1141,32 +1141,32 @@ { if (!view.p_type) { - view.p_type = THING_PLAYER1; - view.px = 99999; + view.p_type = THING_PLAYER1; + view.px = 99999; } Thing *player = FindPlayer(view.p_type); if (!player) { - if (view.p_type != THING_DEATHMATCH) - view.p_type = THING_DEATHMATCH; + if (view.p_type != THING_DEATHMATCH) + view.p_type = THING_DEATHMATCH; - player = FindPlayer(view.p_type); + player = FindPlayer(view.p_type); - if (!player) - return; + if (!player) + return; } if (view.px != player->xpos || view.py != player->ypos) { - // if player moved, re-create view parameters + // if player moved, re-create view parameters - view.x = view.px = player->xpos; - view.y = view.py = player->ypos; + view.x = view.px = player->xpos; + view.y = view.py = player->ypos; - view.CalcViewZ(); - view.SetAngle(player->angle * ONEPI / 180.0); + view.CalcViewZ(); + view.SetAngle(player->angle * ONEPI / 180.0); } /* create image */ @@ -1175,8 +1175,8 @@ view.sh = 400; view.screen = - new Img((unsigned short int) view.sw, (unsigned short int) view.sh, - false); + new Img((unsigned short int) view.sw, (unsigned short int) view.sh, + false); view.im_ch = new ImageCache; view.FindThingFloors(); @@ -1187,93 +1187,93 @@ for (;;) { - /* render image */ + /* render image */ - if (Redraw) - { - if (view.walking) - view.CalcViewZ(); + if (Redraw) + { + if (view.walking) + view.CalcViewZ(); - RendInfo rend; + RendInfo rend; - rend.DoRender3D(); + rend.DoRender3D(); - view.PutScreen(40, 40); + view.PutScreen(40, 40); - Redraw = false; - } + Redraw = false; + } - /* handle keypress */ + /* handle keypress */ - int key = get_key(); + int key = get_key(); - if (key == YK_ESC || key == 'q') - break; + if (key == YK_ESC || key == 'q') + break; - if ((key & ~YK_SHIFT) == YK_LEFT) - { - view.SetAngle(view.angle + ONEPI / ((key & YK_SHIFT) ? 4 : 8)); - Redraw = true; - } - else if ((key & ~YK_SHIFT) == YK_RIGHT) - { - view.SetAngle(view.angle - ONEPI / ((key & YK_SHIFT) ? 4 : 8)); - Redraw = true; - } - else if ((key & ~YK_SHIFT) == YK_UP) - { - view.x += view.Cos * ((key & YK_SHIFT) ? 192 : 32); - view.y += view.Sin * ((key & YK_SHIFT) ? 192 : 32); - Redraw = true; - } - else if ((key & ~YK_SHIFT) == YK_DOWN) - { - view.x -= view.Cos * ((key & YK_SHIFT) ? 192 : 32); - view.y -= view.Sin * ((key & YK_SHIFT) ? 192 : 32); - Redraw = true; - } - else if (key == 'n' || key == 'N') - { - view.x -= view.Sin * ((key == 'N') ? 192 : 32); - view.y += view.Cos * ((key == 'N') ? 192 : 32); - Redraw = true; - } - else if (key == 'm' || key == 'M') - { - view.x += view.Sin * ((key == 'M') ? 192 : 32); - view.y -= view.Cos * ((key == 'M') ? 192 : 32); - Redraw = true; - } - else if (key == 'd' || key == 'D') - { - view.z += (key == 'D') ? 128 : 32; - Redraw = true; - } - else if (key == 'c' || key == 'C') - { - view.z -= (key == 'C') ? 128 : 32; - Redraw = true; - } - else if (key == 't') - { - view.texturing = !view.texturing; - Redraw = true; - } - else if (key == 's') - { - view.sprites = !view.sprites; - Redraw = true; - } - else if (key == 'w') - { - view.walking = !view.walking; - Redraw = true; - } - else if (key) - { - // key no good, get another one - Beep(); - } + if ((key & ~YK_SHIFT) == YK_LEFT) + { + view.SetAngle(view.angle + ONEPI / ((key & YK_SHIFT) ? 4 : 8)); + Redraw = true; + } + else if ((key & ~YK_SHIFT) == YK_RIGHT) + { + view.SetAngle(view.angle - ONEPI / ((key & YK_SHIFT) ? 4 : 8)); + Redraw = true; + } + else if ((key & ~YK_SHIFT) == YK_UP) + { + view.x += view.Cos * ((key & YK_SHIFT) ? 192 : 32); + view.y += view.Sin * ((key & YK_SHIFT) ? 192 : 32); + Redraw = true; + } + else if ((key & ~YK_SHIFT) == YK_DOWN) + { + view.x -= view.Cos * ((key & YK_SHIFT) ? 192 : 32); + view.y -= view.Sin * ((key & YK_SHIFT) ? 192 : 32); + Redraw = true; + } + else if (key == 'n' || key == 'N') + { + view.x -= view.Sin * ((key == 'N') ? 192 : 32); + view.y += view.Cos * ((key == 'N') ? 192 : 32); + Redraw = true; + } + else if (key == 'm' || key == 'M') + { + view.x += view.Sin * ((key == 'M') ? 192 : 32); + view.y -= view.Cos * ((key == 'M') ? 192 : 32); + Redraw = true; + } + else if (key == 'd' || key == 'D') + { + view.z += (key == 'D') ? 128 : 32; + Redraw = true; + } + else if (key == 'c' || key == 'C') + { + view.z -= (key == 'C') ? 128 : 32; + Redraw = true; + } + else if (key == 't') + { + view.texturing = !view.texturing; + Redraw = true; + } + else if (key == 's') + { + view.sprites = !view.sprites; + Redraw = true; + } + else if (key == 'w') + { + view.walking = !view.walking; + Redraw = true; + } + else if (key) + { + // key no good, get another one + Beep(); + } } /* all done */ diff -r 594dea11ccd9 -r a68786b9c74b src/r_render.h --- a/src/r_render.h Sat Sep 24 15:01:56 2011 +0300 +++ b/src/r_render.h Sat Sep 24 15:59:33 2011 +0300 @@ -1,10 +1,10 @@ /* - * r_render.h - * AJA 2002-04-27 + * r_render.h + * AJA 2002-04-27 */ -#ifndef YH_R_RENDER /* DO NOT INSERT ANYTHING BEFORE THIS LINE */ +#ifndef YH_R_RENDER /* DO NOT INSERT ANYTHING BEFORE THIS LINE */ #define YH_R_RENDER diff -r 594dea11ccd9 -r a68786b9c74b src/record.h --- a/src/record.h Sat Sep 24 15:01:56 2011 +0300 +++ b/src/record.h Sat Sep 24 15:59:33 2011 +0300 @@ -1,10 +1,10 @@ /* - * record.h - record events for later playback - * AYM 2000-05-17 + * record.h - record events for later playback + * AYM 2000-05-17 */ -#ifndef YH_RECORD /* DO NOT INSERT ANYTHING BEFORE THIS LINE */ +#ifndef YH_RECORD /* DO NOT INSERT ANYTHING BEFORE THIS LINE */ #define YH_RECORD diff -r 594dea11ccd9 -r a68786b9c74b src/rgb.h --- a/src/rgb.h Sat Sep 24 15:01:56 2011 +0300 +++ b/src/rgb.h Sat Sep 24 15:59:33 2011 +0300 @@ -1,6 +1,6 @@ /* - * rgb.h - * AYM 1998-11-28 + * rgb.h + * AYM 1998-11-28 */ @@ -27,8 +27,8 @@ */ -#ifndef YH_RGB /* Prevent multiple inclusion */ -#define YH_RGB /* Prevent multiple inclusion */ +#ifndef YH_RGB /* Prevent multiple inclusion */ +#define YH_RGB /* Prevent multiple inclusion */ class rgb_c @@ -40,24 +40,24 @@ // Must be defined before rbg_c (r, g, b) void set(u8 red, u8 green, u8 blue) { - r = red; - g = green; - b = blue; + r = red; + g = green; + b = blue; } rgb_c(u8 red, u8 green, u8 blue) { - set(red, green, blue); + set(red, green, blue); } int operator ==(const rgb_c & rgb2) const { - return rgb2.r == r && rgb2.g == g && rgb2.b == b; + return rgb2.r == r && rgb2.g == g && rgb2.b == b; } int operator -(const rgb_c & rgb2) const { - return abs(rgb2.r - r) + abs(rgb2.g - g) + abs(rgb2.b - b); + return abs(rgb2.r - r) + abs(rgb2.g - g) + abs(rgb2.b - b); } u8 r; diff -r 594dea11ccd9 -r a68786b9c74b src/rgbbmp.h --- a/src/rgbbmp.h Sat Sep 24 15:01:56 2011 +0300 +++ b/src/rgbbmp.h Sat Sep 24 15:59:33 2011 +0300 @@ -1,12 +1,12 @@ /* - * rgbbmp.h - * Rgbbmp - An RGB bitmap image class. + * rgbbmp.h + * Rgbbmp - An RGB bitmap image class. * - * This is a simple bitmap where each pixel is an RGB - * triplet. Each component is coded as an 8-bit unsigned - * integer (of type u8). + * This is a simple bitmap where each pixel is an RGB + * triplet. Each component is coded as an 8-bit unsigned + * integer (of type u8). * - * AYM 1999-06-06 + * AYM 1999-06-06 */ @@ -49,93 +49,93 @@ { public:Rgbbmp() { - _width = 0; - _height = 0; - pixel = 0; + _width = 0; + _height = 0; + pixel = 0; } - void resize(int width, int height) // Must be defined before first use + void resize(int width, int height) // Must be defined before first use { - _width = width; - _height = height; - if (pixel) - delete[]pixel; - if (width * height > 0) - pixel = new Rgbbmp_pixel_t[width * height]; - else - pixel = 0; + _width = width; + _height = height; + if (pixel) + delete[]pixel; + if (width * height > 0) + pixel = new Rgbbmp_pixel_t[width * height]; + else + pixel = 0; }; Rgbbmp(int width, int height) { - pixel = 0; - resize(width, height); + pixel = 0; + resize(width, height); } ~Rgbbmp() { - if (pixel) - delete[]pixel; + if (pixel) + delete[]pixel; } int width() const { - return _width; + return _width; } int height() const { - return _height; + return _height; } void clear() { - if (pixel) - memset(pixel, 0, _width * _height * sizeof *pixel); + if (pixel) + memset(pixel, 0, _width * _height * sizeof *pixel); } void get(int x, int y, u8 & r, u8 & g, u8 & b) const { - r = pixel[y * _width + x].r; - g = pixel[y * _width + x].g; - b = pixel[y * _width + x].b; + r = pixel[y * _width + x].r; + g = pixel[y * _width + x].g; + b = pixel[y * _width + x].b; } u8 get_r(int x, int y) const { - return pixel[y * _width + x].r; + return pixel[y * _width + x].r; } u8 get_g(int x, int y) const { - return pixel[y * _width + x].g; + return pixel[y * _width + x].g; } u8 get_b(int x, int y) const { - return pixel[y * _width + x].b; + return pixel[y * _width + x].b; } void set(int x, int y, u8 r, u8 g, u8 b) { - pixel[y * _width + x].r = r; - pixel[y * _width + x].g = g; - pixel[y * _width + x].b = b; + pixel[y * _width + x].r = r; + pixel[y * _width + x].g = g; + pixel[y * _width + x].b = b; } void set_r(int x, int y, u8 r) { - pixel[y * _width + x].r = r; + pixel[y * _width + x].r = r; } void set_g(int x, int y, u8 g) { - pixel[y * _width + x].g = g; + pixel[y * _width + x].g = g; } void set_b(int x, int y, u8 b) { - pixel[y * _width + x].b = b; + pixel[y * _width + x].b = b; } private: diff -r 594dea11ccd9 -r a68786b9c74b src/s_centre.cc --- a/src/s_centre.cc Sat Sep 24 15:01:56 2011 +0300 +++ b/src/s_centre.cc Sat Sep 24 15:59:33 2011 +0300 @@ -1,6 +1,6 @@ /* - * s_centre.cc - * AYM 1998-11-22 + * s_centre.cc + * AYM 1998-11-22 */ @@ -35,12 +35,12 @@ /* - * centre_of_sector - * Return the coordinates of the centre of a sector. + * centre_of_sector + * Return the coordinates of the centre of a sector. * - * FIXME The algorithm is desesperatingly simple-minded and - * does not take into account concave sectors and sectors - * that are enclosed by several distinct paths of linedefs. + * FIXME The algorithm is desesperatingly simple-minded and + * does not take into account concave sectors and sectors + * that are enclosed by several distinct paths of linedefs. */ void centre_of_sector(obj_no_t s, int *x, int *y) { @@ -50,29 +50,29 @@ int nitems = 0; for (size_t n = 0; n < vertices->nelements(); n++) - if (vertices->get(n)) - { - x_sum += Vertices[n].x; - y_sum += Vertices[n].y; - nitems++; - } + if (vertices->get(n)) + { + x_sum += Vertices[n].x; + y_sum += Vertices[n].y; + nitems++; + } if (nitems == 0) { - *x = 0; - *y = 0; + *x = 0; + *y = 0; } else { - *x = (int) (x_sum / nitems); - *y = (int) (y_sum / nitems); + *x = (int) (x_sum / nitems); + *y = (int) (y_sum / nitems); } delete vertices; } /* - * centre_of_sectors - * Return the coordinates of the centre of a group of sectors. + * centre_of_sectors + * Return the coordinates of the centre of a group of sectors. */ void centre_of_sectors(SelPtr list, int *x, int *y) { @@ -87,21 +87,21 @@ y_sum = 0; nitems = 0; for (n = 0; n < NumVertices; n++) - if (vertices->get(n)) - { - x_sum += Vertices[n].x; - y_sum += Vertices[n].y; - nitems++; - } + if (vertices->get(n)) + { + x_sum += Vertices[n].x; + y_sum += Vertices[n].y; + nitems++; + } if (nitems == 0) { - *x = 0; - *y = 0; + *x = 0; + *y = 0; } else { - *x = (int) (x_sum / nitems); - *y = (int) (y_sum / nitems); + *x = (int) (x_sum / nitems); + *y = (int) (y_sum / nitems); } delete vertices; } diff -r 594dea11ccd9 -r a68786b9c74b src/s_centre.h --- a/src/s_centre.h Sat Sep 24 15:01:56 2011 +0300 +++ b/src/s_centre.h Sat Sep 24 15:59:33 2011 +0300 @@ -1,6 +1,6 @@ /* - * s_centre.h - * AYM 1998-11-22 + * s_centre.h + * AYM 1998-11-22 */ diff -r 594dea11ccd9 -r a68786b9c74b src/s_door.cc --- a/src/s_door.cc Sat Sep 24 15:01:56 2011 +0300 +++ b/src/s_door.cc Sat Sep 24 15:59:33 2011 +0300 @@ -1,7 +1,7 @@ /* - * s_door.cc - * Make door from sector - * AYM 1998-02-03 + * s_door.cc + * Make door from sector + * AYM 1998-02-03 */ @@ -39,7 +39,7 @@ turn a sector into a door: change the linedefs and sidedefs */ -void MakeDoorFromSector(int sector) /* SWAP! */ +void MakeDoorFromSector(int sector) /* SWAP! */ { int sd1, sd2; int n, s; @@ -52,91 +52,91 @@ /* build lists of linedefs that border the sector */ for (n = 0; n < NumLineDefs; n++) { - sd1 = LineDefs[n].sidedef1; - sd2 = LineDefs[n].sidedef2; - if (sd1 >= 0 && sd2 >= 0) - { - if (SideDefs[sd2].sector == sector) - { - SelectObject(&ldok, n); /* already ok */ - s++; - } - if (SideDefs[sd1].sector == sector) - { - SelectObject(&ldflip, n); /* must be flipped */ - s++; - } - } - else if (sd1 >= 0 && sd2 < 0) - { - if (SideDefs[sd1].sector == sector) - SelectObject(&ld1s, n); /* wall (one-sided) */ - } + sd1 = LineDefs[n].sidedef1; + sd2 = LineDefs[n].sidedef2; + if (sd1 >= 0 && sd2 >= 0) + { + if (SideDefs[sd2].sector == sector) + { + SelectObject(&ldok, n); /* already ok */ + s++; + } + if (SideDefs[sd1].sector == sector) + { + SelectObject(&ldflip, n); /* must be flipped */ + s++; + } + } + else if (sd1 >= 0 && sd2 < 0) + { + if (SideDefs[sd1].sector == sector) + SelectObject(&ld1s, n); /* wall (one-sided) */ + } } /* a normal door has two sides... */ if (s < 2) { - Beep(); - Notify(-1, -1, "The door must be connected to two other Sectors.", - NULL); - ForgetSelection(&ldok); - ForgetSelection(&ldflip); - ForgetSelection(&ld1s); - return; + Beep(); + Notify(-1, -1, "The door must be connected to two other Sectors.", + NULL); + ForgetSelection(&ldok); + ForgetSelection(&ldflip); + ForgetSelection(&ld1s); + return; } if ((s > 2) - && !(Expert - || Confirm(-1, -1, "The door will have more than two sides.", - "Do you still want to create it?"))) + && !(Expert + || Confirm(-1, -1, "The door will have more than two sides.", + "Do you still want to create it?"))) { - ForgetSelection(&ldok); - ForgetSelection(&ldflip); - ForgetSelection(&ld1s); - return; + ForgetSelection(&ldok); + ForgetSelection(&ldflip); + ForgetSelection(&ld1s); + return; } /* flip the linedefs that have the wrong orientation */ if (ldflip != NULL) - FlipLineDefs(ldflip, 1); + FlipLineDefs(ldflip, 1); /* merge the two selection lists */ while (ldflip != NULL) { - if (!IsSelected(ldok, ldflip->objnum)) - SelectObject(&ldok, ldflip->objnum); - UnSelectObject(&ldflip, ldflip->objnum); + if (!IsSelected(ldok, ldflip->objnum)) + SelectObject(&ldok, ldflip->objnum); + UnSelectObject(&ldflip, ldflip->objnum); } /* change the linedefs and sidedefs */ while (ldok != NULL) { - /* give the "normal door" type and flags to the linedef */ - n = ldok->objnum; - LineDefs[n].type = 1; - LineDefs[n].flags = 0x04; - sd1 = LineDefs[n].sidedef1; /* outside */ - sd2 = LineDefs[n].sidedef2; /* inside */ - /* adjust the textures for the sidedefs */ - if (strncmp(SideDefs[sd1].tex3, "-", WAD_TEX_NAME)) - { - if (!strncmp(SideDefs[sd1].tex1, "-", WAD_TEX_NAME)) - strncpy(SideDefs[sd1].tex1, SideDefs[sd1].tex3, WAD_TEX_NAME); - strncpy(SideDefs[sd1].tex3, "-", WAD_TEX_NAME); - } - if (!strncmp(SideDefs[sd1].tex1, "-", WAD_TEX_NAME)) - strncpy(SideDefs[sd1].tex1, "BIGDOOR2", WAD_TEX_NAME); - strncpy(SideDefs[sd2].tex3, "-", WAD_TEX_NAME); - UnSelectObject(&ldok, n); + /* give the "normal door" type and flags to the linedef */ + n = ldok->objnum; + LineDefs[n].type = 1; + LineDefs[n].flags = 0x04; + sd1 = LineDefs[n].sidedef1; /* outside */ + sd2 = LineDefs[n].sidedef2; /* inside */ + /* adjust the textures for the sidedefs */ + if (strncmp(SideDefs[sd1].tex3, "-", WAD_TEX_NAME)) + { + if (!strncmp(SideDefs[sd1].tex1, "-", WAD_TEX_NAME)) + strncpy(SideDefs[sd1].tex1, SideDefs[sd1].tex3, WAD_TEX_NAME); + strncpy(SideDefs[sd1].tex3, "-", WAD_TEX_NAME); + } + if (!strncmp(SideDefs[sd1].tex1, "-", WAD_TEX_NAME)) + strncpy(SideDefs[sd1].tex1, "BIGDOOR2", WAD_TEX_NAME); + strncpy(SideDefs[sd2].tex3, "-", WAD_TEX_NAME); + UnSelectObject(&ldok, n); } while (ld1s != NULL) { - /* give the "door side" flags to the linedef */ - n = ld1s->objnum; - LineDefs[n].flags = 0x11; - sd1 = LineDefs[n].sidedef1; - /* adjust the textures for the sidedef */ - if (!strncmp(SideDefs[sd1].tex3, "-", WAD_TEX_NAME)) - strncpy(SideDefs[sd1].tex3, "DOORTRAK", WAD_TEX_NAME); - strncpy(SideDefs[sd1].tex1, "-", WAD_TEX_NAME); - strncpy(SideDefs[sd1].tex2, "-", WAD_TEX_NAME); - UnSelectObject(&ld1s, n); + /* give the "door side" flags to the linedef */ + n = ld1s->objnum; + LineDefs[n].flags = 0x11; + sd1 = LineDefs[n].sidedef1; + /* adjust the textures for the sidedef */ + if (!strncmp(SideDefs[sd1].tex3, "-", WAD_TEX_NAME)) + strncpy(SideDefs[sd1].tex3, "DOORTRAK", WAD_TEX_NAME); + strncpy(SideDefs[sd1].tex1, "-", WAD_TEX_NAME); + strncpy(SideDefs[sd1].tex2, "-", WAD_TEX_NAME); + UnSelectObject(&ld1s, n); } /* adjust the ceiling height */ Sectors[sector].ceilh = Sectors[sector].floorh; diff -r 594dea11ccd9 -r a68786b9c74b src/s_lift.cc --- a/src/s_lift.cc Sat Sep 24 15:01:56 2011 +0300 +++ b/src/s_lift.cc Sat Sep 24 15:59:33 2011 +0300 @@ -1,7 +1,7 @@ /* - * s_lift.cc - * Make lift from sector - * AYM 1998-02-03 + * s_lift.cc + * Make lift from sector + * AYM 1998-02-03 */ @@ -40,7 +40,7 @@ turn a Sector into a lift: change the linedefs and sidedefs */ -void MakeLiftFromSector(int sector) /* SWAP! */ +void MakeLiftFromSector(int sector) /* SWAP! */ { int sd1, sd2; int n, s, tag; @@ -55,52 +55,52 @@ /* build lists of linedefs that border the Sector */ for (n = 0; n < NumLineDefs; n++) { - sd1 = LineDefs[n].sidedef1; - sd2 = LineDefs[n].sidedef2; - if (sd1 >= 0 && sd2 >= 0) - { - if (SideDefs[sd2].sector == sector) - { - SelectObject(&ldok, n); /* already ok */ - s = SideDefs[sd1].sector; - if (s != sector && !IsSelected(sect, s)) - SelectObject(§, s); - } - if (SideDefs[sd1].sector == sector) - { - SelectObject(&ldflip, n); /* will be flipped */ - s = SideDefs[sd2].sector; - if (s != sector && !IsSelected(sect, s)) - SelectObject(§, s); - } - } - else if (sd1 >= 0 && sd2 < 0) - { - if (SideDefs[sd1].sector == sector) - SelectObject(&ld1s, n); /* wall (one-sided) */ - } + sd1 = LineDefs[n].sidedef1; + sd2 = LineDefs[n].sidedef2; + if (sd1 >= 0 && sd2 >= 0) + { + if (SideDefs[sd2].sector == sector) + { + SelectObject(&ldok, n); /* already ok */ + s = SideDefs[sd1].sector; + if (s != sector && !IsSelected(sect, s)) + SelectObject(§, s); + } + if (SideDefs[sd1].sector == sector) + { + SelectObject(&ldflip, n); /* will be flipped */ + s = SideDefs[sd2].sector; + if (s != sector && !IsSelected(sect, s)) + SelectObject(§, s); + } + } + else if (sd1 >= 0 && sd2 < 0) + { + if (SideDefs[sd1].sector == sector) + SelectObject(&ld1s, n); /* wall (one-sided) */ + } } /* there must be a way to go on the lift... */ if (sect == NULL) { - Beep(); - Notify(-1, -1, - "The lift must be connected to at least one other Sector.", - NULL); - ForgetSelection(&ldok); - ForgetSelection(&ldflip); - ForgetSelection(&ld1s); - return; + Beep(); + Notify(-1, -1, + "The lift must be connected to at least one other Sector.", + NULL); + ForgetSelection(&ldok); + ForgetSelection(&ldflip); + ForgetSelection(&ld1s); + return; } /* flip the linedefs that have the wrong orientation */ if (ldflip != NULL) - FlipLineDefs(ldflip, 1); + FlipLineDefs(ldflip, 1); /* merge the two selection lists */ while (ldflip != NULL) { - if (!IsSelected(ldok, ldflip->objnum)) - SelectObject(&ldok, ldflip->objnum); - UnSelectObject(&ldflip, ldflip->objnum); + if (!IsSelected(ldok, ldflip->objnum)) + SelectObject(&ldok, ldflip->objnum); + UnSelectObject(&ldflip, ldflip->objnum); } /* find a free tag number */ @@ -111,20 +111,20 @@ maxh = -32767; for (curs = sect; curs; curs = curs->next) { - if (Sectors[curs->objnum].floorh < minh) - minh = Sectors[curs->objnum].floorh; - if (Sectors[curs->objnum].floorh > maxh) - maxh = Sectors[curs->objnum].floorh; + if (Sectors[curs->objnum].floorh < minh) + minh = Sectors[curs->objnum].floorh; + if (Sectors[curs->objnum].floorh > maxh) + maxh = Sectors[curs->objnum].floorh; } ForgetSelection(§); /* change the lift's floor height if necessary */ if (Sectors[sector].floorh < maxh) - Sectors[sector].floorh = maxh; + Sectors[sector].floorh = maxh; /* change the lift's ceiling height if necessary */ if (Sectors[sector].ceilh < maxh + DOOM_PLAYER_HEIGHT) - Sectors[sector].ceilh = maxh + DOOM_PLAYER_HEIGHT; + Sectors[sector].ceilh = maxh + DOOM_PLAYER_HEIGHT; /* assign the new tag number to the lift */ Sectors[sector].tag = tag; @@ -132,74 +132,74 @@ /* change the linedefs and sidedefs */ while (ldok != NULL) { - /* give the "lower lift" type and flags to the linedef */ - n = ldok->objnum; - LineDefs[n].type = 62; /* lower lift (switch) */ - LineDefs[n].flags = 0x04; - LineDefs[n].tag = tag; - sd1 = LineDefs[n].sidedef1; /* outside */ - sd2 = LineDefs[n].sidedef2; /* inside */ - /* adjust the textures for the sidedef visible from the outside */ - if (strncmp(SideDefs[sd1].tex3, "-", WAD_TEX_NAME)) - { - if (!strncmp(SideDefs[sd1].tex2, "-", WAD_TEX_NAME)) - strncpy(SideDefs[sd1].tex2, SideDefs[sd1].tex3, WAD_TEX_NAME); - strncpy(SideDefs[sd1].tex3, "-", WAD_TEX_NAME); - } - if (!strncmp(SideDefs[sd1].tex2, "-", WAD_TEX_NAME)) - strncpy(SideDefs[sd1].tex2, "SHAWN2", WAD_TEX_NAME); - /* adjust the textures for the sidedef visible from the lift */ - strncpy(SideDefs[sd2].tex3, "-", WAD_TEX_NAME); - s = SideDefs[sd1].sector; - if (Sectors[s].floorh > minh) - { - if (strncmp(SideDefs[sd2].tex3, "-", WAD_TEX_NAME)) - { - if (!strncmp(SideDefs[sd2].tex2, "-", WAD_TEX_NAME)) - strncpy(SideDefs[sd2].tex2, SideDefs[sd1].tex3, - WAD_TEX_NAME); - strncpy(SideDefs[sd2].tex3, "-", WAD_TEX_NAME); - } - if (!strncmp(SideDefs[sd2].tex2, "-", WAD_TEX_NAME)) - strncpy(SideDefs[sd2].tex2, "SHAWN2", WAD_TEX_NAME); - } - else - { - strncpy(SideDefs[sd2].tex2, "-", WAD_TEX_NAME); - } - strncpy(SideDefs[sd2].tex3, "-", WAD_TEX_NAME); - /* if the ceiling of the sector is lower than that of the lift */ - if (Sectors[s].ceilh < Sectors[sector].ceilh) - { - if (strncmp(SideDefs[sd2].tex1, "-", WAD_TEX_NAME)) - strncpy(SideDefs[sd2].tex1, default_upper_texture, - WAD_TEX_NAME); - } - /* if the floor of the sector is above the lift */ - if (Sectors[s].floorh >= Sectors[sector].floorh) - { - LineDefs[n].type = 88; /* lower lift (walk through) */ - /* flip it, just for fun */ - curs = NULL; - SelectObject(&curs, n); - FlipLineDefs(curs, 1); - ForgetSelection(&curs); - } - /* done with this linedef */ - UnSelectObject(&ldok, n); + /* give the "lower lift" type and flags to the linedef */ + n = ldok->objnum; + LineDefs[n].type = 62; /* lower lift (switch) */ + LineDefs[n].flags = 0x04; + LineDefs[n].tag = tag; + sd1 = LineDefs[n].sidedef1; /* outside */ + sd2 = LineDefs[n].sidedef2; /* inside */ + /* adjust the textures for the sidedef visible from the outside */ + if (strncmp(SideDefs[sd1].tex3, "-", WAD_TEX_NAME)) + { + if (!strncmp(SideDefs[sd1].tex2, "-", WAD_TEX_NAME)) + strncpy(SideDefs[sd1].tex2, SideDefs[sd1].tex3, WAD_TEX_NAME); + strncpy(SideDefs[sd1].tex3, "-", WAD_TEX_NAME); + } + if (!strncmp(SideDefs[sd1].tex2, "-", WAD_TEX_NAME)) + strncpy(SideDefs[sd1].tex2, "SHAWN2", WAD_TEX_NAME); + /* adjust the textures for the sidedef visible from the lift */ + strncpy(SideDefs[sd2].tex3, "-", WAD_TEX_NAME); + s = SideDefs[sd1].sector; + if (Sectors[s].floorh > minh) + { + if (strncmp(SideDefs[sd2].tex3, "-", WAD_TEX_NAME)) + { + if (!strncmp(SideDefs[sd2].tex2, "-", WAD_TEX_NAME)) + strncpy(SideDefs[sd2].tex2, SideDefs[sd1].tex3, + WAD_TEX_NAME); + strncpy(SideDefs[sd2].tex3, "-", WAD_TEX_NAME); + } + if (!strncmp(SideDefs[sd2].tex2, "-", WAD_TEX_NAME)) + strncpy(SideDefs[sd2].tex2, "SHAWN2", WAD_TEX_NAME); + } + else + { + strncpy(SideDefs[sd2].tex2, "-", WAD_TEX_NAME); + } + strncpy(SideDefs[sd2].tex3, "-", WAD_TEX_NAME); + /* if the ceiling of the sector is lower than that of the lift */ + if (Sectors[s].ceilh < Sectors[sector].ceilh) + { + if (strncmp(SideDefs[sd2].tex1, "-", WAD_TEX_NAME)) + strncpy(SideDefs[sd2].tex1, default_upper_texture, + WAD_TEX_NAME); + } + /* if the floor of the sector is above the lift */ + if (Sectors[s].floorh >= Sectors[sector].floorh) + { + LineDefs[n].type = 88; /* lower lift (walk through) */ + /* flip it, just for fun */ + curs = NULL; + SelectObject(&curs, n); + FlipLineDefs(curs, 1); + ForgetSelection(&curs); + } + /* done with this linedef */ + UnSelectObject(&ldok, n); } while (ld1s != NULL) { - /* these are the lift walls (one-sided) */ - n = ld1s->objnum; - LineDefs[n].flags = 0x01; - sd1 = LineDefs[n].sidedef1; - /* adjust the textures for the sidedef */ - if (!strncmp(SideDefs[sd1].tex3, "-", WAD_TEX_NAME)) - strncpy(SideDefs[sd1].tex3, default_middle_texture, WAD_TEX_NAME); - strncpy(SideDefs[sd1].tex1, "-", WAD_TEX_NAME); - strncpy(SideDefs[sd1].tex2, "-", WAD_TEX_NAME); - UnSelectObject(&ld1s, n); + /* these are the lift walls (one-sided) */ + n = ld1s->objnum; + LineDefs[n].flags = 0x01; + sd1 = LineDefs[n].sidedef1; + /* adjust the textures for the sidedef */ + if (!strncmp(SideDefs[sd1].tex3, "-", WAD_TEX_NAME)) + strncpy(SideDefs[sd1].tex3, default_middle_texture, WAD_TEX_NAME); + strncpy(SideDefs[sd1].tex1, "-", WAD_TEX_NAME); + strncpy(SideDefs[sd1].tex2, "-", WAD_TEX_NAME); + UnSelectObject(&ld1s, n); } } diff -r 594dea11ccd9 -r a68786b9c74b src/s_linedefs.cc --- a/src/s_linedefs.cc Sat Sep 24 15:01:56 2011 +0300 +++ b/src/s_linedefs.cc Sat Sep 24 15:59:33 2011 +0300 @@ -1,6 +1,6 @@ /* - * s_linedefs.cc - * AYM 1998-11-22 + * s_linedefs.cc + * AYM 1998-11-22 */ @@ -37,70 +37,70 @@ /* - * linedefs_of_sector - * Return a bit vector of all linedefs used by the sector. - * It's up to the caller to delete the bit vector after use. + * linedefs_of_sector + * Return a bit vector of all linedefs used by the sector. + * It's up to the caller to delete the bit vector after use. */ bitvec_c *linedefs_of_sector(obj_no_t s) { bitvec_c *linedefs = new bitvec_c(NumLineDefs); for (int n = 0; n < NumLineDefs; n++) - if (is_sidedef(LineDefs[n].sidedef1) - && SideDefs[LineDefs[n].sidedef1].sector == s - || is_sidedef(LineDefs[n].sidedef2) - && SideDefs[LineDefs[n].sidedef2].sector == s) - linedefs->set(n); + if (is_sidedef(LineDefs[n].sidedef1) + && SideDefs[LineDefs[n].sidedef1].sector == s + || is_sidedef(LineDefs[n].sidedef2) + && SideDefs[LineDefs[n].sidedef2].sector == s) + linedefs->set(n); return linedefs; } /* - * linedefs_of_sectors - * Return a bit vector of all linedefs used by the sectors. - * It's up to the caller to delete the bit vector after use. + * linedefs_of_sectors + * Return a bit vector of all linedefs used by the sectors. + * It's up to the caller to delete the bit vector after use. */ bitvec_c *linedefs_of_sectors(SelPtr list) { bitvec_c *sectors = list_to_bitvec(list, NumSectors); bitvec_c *linedefs = new bitvec_c(NumLineDefs); for (int n = 0; n < NumLineDefs; n++) - if (is_sidedef(LineDefs[n].sidedef1) - && sectors->get(SideDefs[LineDefs[n].sidedef1].sector) - || is_sidedef(LineDefs[n].sidedef2) - && sectors->get(SideDefs[LineDefs[n].sidedef2].sector)) - linedefs->set(n); + if (is_sidedef(LineDefs[n].sidedef1) + && sectors->get(SideDefs[LineDefs[n].sidedef1].sector) + || is_sidedef(LineDefs[n].sidedef2) + && sectors->get(SideDefs[LineDefs[n].sidedef2].sector)) + linedefs->set(n); delete sectors; return linedefs; } /* - * linedefs_of_sector - * Returns the number of linedefs that face sector <s> - * and, if that number is greater than zero, sets <array> - * to point on a newly allocated array filled with the - * numbers of those linedefs. It's up to the caller to - * delete[] the array after use. + * linedefs_of_sector + * Returns the number of linedefs that face sector <s> + * and, if that number is greater than zero, sets <array> + * to point on a newly allocated array filled with the + * numbers of those linedefs. It's up to the caller to + * delete[] the array after use. */ int linedefs_of_sector(obj_no_t s, obj_no_t * &array) { int count = 0; for (int n = 0; n < NumLineDefs; n++) - if (is_sidedef(LineDefs[n].sidedef1) - && SideDefs[LineDefs[n].sidedef1].sector == s - || is_sidedef(LineDefs[n].sidedef2) - && SideDefs[LineDefs[n].sidedef2].sector == s) - count++; + if (is_sidedef(LineDefs[n].sidedef1) + && SideDefs[LineDefs[n].sidedef1].sector == s + || is_sidedef(LineDefs[n].sidedef2) + && SideDefs[LineDefs[n].sidedef2].sector == s) + count++; if (count > 0) { - array = new obj_no_t[count]; - count = 0; - for (int n = 0; n < NumLineDefs; n++) - if (is_sidedef(LineDefs[n].sidedef1) - && SideDefs[LineDefs[n].sidedef1].sector == s - || is_sidedef(LineDefs[n].sidedef2) - && SideDefs[LineDefs[n].sidedef2].sector == s) - array[count++] = n; + array = new obj_no_t[count]; + count = 0; + for (int n = 0; n < NumLineDefs; n++) + if (is_sidedef(LineDefs[n].sidedef1) + && SideDefs[LineDefs[n].sidedef1].sector == s + || is_sidedef(LineDefs[n].sidedef2) + && SideDefs[LineDefs[n].sidedef2].sector == s) + array[count++] = n; } return count; } diff -r 594dea11ccd9 -r a68786b9c74b src/s_linedefs.h --- a/src/s_linedefs.h Sat Sep 24 15:01:56 2011 +0300 +++ b/src/s_linedefs.h Sat Sep 24 15:59:33 2011 +0300 @@ -1,6 +1,6 @@ /* - * s_linedefs.h - * AYM 1998-11-22 + * s_linedefs.h + * AYM 1998-11-22 */ diff -r 594dea11ccd9 -r a68786b9c74b src/s_merge.cc --- a/src/s_merge.cc Sat Sep 24 15:01:56 2011 +0300 +++ b/src/s_merge.cc Sat Sep 24 15:59:33 2011 +0300 @@ -1,7 +1,7 @@ /* - * s_merge.cc - * Merge sectors - * AYM 1998-02-03 + * s_merge.cc + * Merge sectors + * AYM 1998-02-03 */ @@ -40,7 +40,7 @@ merge two or more Sectors into one */ -void MergeSectors(SelPtr * slist) /* SWAP! */ +void MergeSectors(SelPtr * slist) /* SWAP! */ { SelPtr cur; int n, olds, news; @@ -52,12 +52,12 @@ /* change all SideDefs references to the other Sectors */ for (cur = *slist; cur; cur = cur->next) { - olds = cur->objnum; - for (n = 0; n < NumSideDefs; n++) - { - if (SideDefs[n].sector == olds) - SideDefs[n].sector = news; - } + olds = cur->objnum; + for (n = 0; n < NumSideDefs; n++) + { + if (SideDefs[n].sector == olds) + SideDefs[n].sector = news; + } } /* delete the Sectors */ @@ -73,7 +73,7 @@ delete one or several two-sided LineDefs and join the two Sectors */ -void DeleteLineDefsJoinSectors(SelPtr * ldlist) /* SWAP! */ +void DeleteLineDefsJoinSectors(SelPtr * ldlist) /* SWAP! */ { SelPtr cur, slist; int sd1, sd2; @@ -83,39 +83,39 @@ /* first, do the tests for all LineDefs */ for (cur = *ldlist; cur; cur = cur->next) { - sd1 = LineDefs[cur->objnum].sidedef1; - sd2 = LineDefs[cur->objnum].sidedef2; - if (sd1 < 0 || sd2 < 0) - { - Beep(); - sprintf(msg, "ERROR: Linedef #%d has only one side", cur->objnum); - Notify(-1, -1, msg, NULL); - return; - } - s1 = SideDefs[sd1].sector; - s2 = SideDefs[sd2].sector; - if (s1 < 0 || s2 < 0) - { - Beep(); - sprintf(msg, "ERROR: Linedef #%d has two sides, but one", - cur->objnum); - Notify(-1, -1, msg, "side is not bound to any sector"); - return; - } + sd1 = LineDefs[cur->objnum].sidedef1; + sd2 = LineDefs[cur->objnum].sidedef2; + if (sd1 < 0 || sd2 < 0) + { + Beep(); + sprintf(msg, "ERROR: Linedef #%d has only one side", cur->objnum); + Notify(-1, -1, msg, NULL); + return; + } + s1 = SideDefs[sd1].sector; + s2 = SideDefs[sd2].sector; + if (s1 < 0 || s2 < 0) + { + Beep(); + sprintf(msg, "ERROR: Linedef #%d has two sides, but one", + cur->objnum); + Notify(-1, -1, msg, "side is not bound to any sector"); + return; + } } /* then join the Sectors and delete the LineDefs */ for (cur = *ldlist; cur; cur = cur->next) { - sd1 = LineDefs[cur->objnum].sidedef1; - sd2 = LineDefs[cur->objnum].sidedef2; - s1 = SideDefs[sd1].sector; - s2 = SideDefs[sd2].sector; - slist = NULL; - SelectObject(&slist, s2); - SelectObject(&slist, s1); - MergeSectors(&slist); - ForgetSelection(&slist); + sd1 = LineDefs[cur->objnum].sidedef1; + sd2 = LineDefs[cur->objnum].sidedef2; + s1 = SideDefs[sd1].sector; + s2 = SideDefs[sd2].sector; + slist = NULL; + SelectObject(&slist, s2); + SelectObject(&slist, s1); + MergeSectors(&slist); + ForgetSelection(&slist); } DeleteObjects(OBJ_LINEDEFS, ldlist); } diff -r 594dea11ccd9 -r a68786b9c74b src/s_misc.cc --- a/src/s_misc.cc Sat Sep 24 15:01:56 2011 +0300 +++ b/src/s_misc.cc Sat Sep 24 15:59:33 2011 +0300 @@ -1,7 +1,7 @@ /* - * s_misc.cc - * Misc. operations on sectors - * AYM 1998-02-03 + * s_misc.cc + * Misc. operations on sectors + * AYM 1998-02-03 */ @@ -44,14 +44,14 @@ Distribute sector floor heights */ -void DistributeSectorFloors(SelPtr obj) /* SWAP! */ +void DistributeSectorFloors(SelPtr obj) /* SWAP! */ { SelPtr cur; int n, num, floor1h, floor2h; num = 0; for (cur = obj; cur->next; cur = cur->next) - num++; + num++; floor1h = Sectors[obj->objnum].floorh; floor2h = Sectors[cur->objnum].floorh; @@ -59,8 +59,8 @@ n = 0; for (cur = obj; cur; cur = cur->next) { - Sectors[cur->objnum].floorh = floor1h + n * (floor2h - floor1h) / num; - n++; + Sectors[cur->objnum].floorh = floor1h + n * (floor2h - floor1h) / num; + n++; } MadeChanges = 1; } @@ -71,14 +71,14 @@ Distribute sector ceiling heights */ -void DistributeSectorCeilings(SelPtr obj) /* SWAP! */ +void DistributeSectorCeilings(SelPtr obj) /* SWAP! */ { SelPtr cur; int n, num, ceil1h, ceil2h; num = 0; for (cur = obj; cur->next; cur = cur->next) - num++; + num++; ceil1h = Sectors[obj->objnum].ceilh; ceil2h = Sectors[cur->objnum].ceilh; @@ -86,8 +86,8 @@ n = 0; for (cur = obj; cur; cur = cur->next) { - Sectors[cur->objnum].ceilh = ceil1h + n * (ceil2h - ceil1h) / num; - n++; + Sectors[cur->objnum].ceilh = ceil1h + n * (ceil2h - ceil1h) / num; + n++; } MadeChanges = 1; } @@ -100,10 +100,10 @@ void RaiseOrLowerSectors(SelPtr obj) { SelPtr cur; - int x0; // left hand (x) window start - int y0; // top (y) window start - int key; // holds value returned by InputInteger - int delta = 0; // user input for delta + int x0; // left hand (x) window start + int y0; // top (y) window start + int key; // holds value returned by InputInteger + int delta = 0; // user input for delta x0 = (ScrMaxX - 25 - 44 * FONTW) / 2; @@ -111,24 +111,24 @@ DrawScreenBox3D(x0, y0, x0 + 25 + 44 * FONTW, y0 + 7 * FONTH); set_colour(WHITE); DrawScreenText(x0 + 10, y0 + FONTH, - "Enter number of units to raise the ceilings"); + "Enter number of units to raise the ceilings"); DrawScreenText(x0 + 10, y0 + 2 * FONTH, - "and floors of selected sectors by."); + "and floors of selected sectors by."); DrawScreenText(x0 + 10, y0 + 3 * FONTH, "A negative number lowers them."); while (1) { - key = InputInteger(x0 + 10, y0 + 5 * FONTH, &delta, -32768, 32767); - if (key == YK_RETURN || key == YK_ESC) - break; - Beep(); + key = InputInteger(x0 + 10, y0 + 5 * FONTH, &delta, -32768, 32767); + if (key == YK_RETURN || key == YK_ESC) + break; + Beep(); } if (key == YK_ESC) - return; + return; for (cur = obj; cur != NULL; cur = cur->next) { - Sectors[cur->objnum].ceilh += delta; - Sectors[cur->objnum].floorh += delta; + Sectors[cur->objnum].ceilh += delta; + Sectors[cur->objnum].floorh += delta; } MadeChanges = 1; } @@ -141,10 +141,10 @@ void BrightenOrDarkenSectors(SelPtr obj) { SelPtr cur; - int x0; // left hand (x) window start - int y0; // top (y) window start - int key; // holds value returned by InputInteger - int delta = 0; // user input for delta + int x0; // left hand (x) window start + int y0; // top (y) window start + int key; // holds value returned by InputInteger + int delta = 0; // user input for delta x0 = (ScrMaxX - 25 - 44 * FONTW) / 2; @@ -154,24 +154,24 @@ DrawScreenText(x0 + 10, y0 + FONTH, "Enter number of units to brighten"); DrawScreenText(x0 + 10, y0 + 2 * FONTH, "the selected sectors by."); DrawScreenText(x0 + 10, y0 + 3 * FONTH, - "A negative number darkens them."); + "A negative number darkens them."); while (1) { - key = InputInteger(x0 + 10, y0 + 5 * FONTH, &delta, -255, 255); - if (key == YK_RETURN || key == YK_ESC) - break; - Beep(); + key = InputInteger(x0 + 10, y0 + 5 * FONTH, &delta, -255, 255); + if (key == YK_RETURN || key == YK_ESC) + break; + Beep(); } if (key == YK_ESC) - return; + return; for (cur = obj; cur != NULL; cur = cur->next) { - int light; - light = Sectors[cur->objnum].light + delta; - light = y_max(light, 0); - light = y_min(light, 255); - Sectors[cur->objnum].light = light; + int light; + light = Sectors[cur->objnum].light + delta; + light = y_max(light, 0); + light = y_min(light, 255); + Sectors[cur->objnum].light = light; } MadeChanges = 1; } @@ -182,34 +182,34 @@ int n, m, curx; int best_match = -1; - curx = 32767; // Oh yes, one more hard-coded constant! + curx = 32767; // Oh yes, one more hard-coded constant! for (n = 0; n < NumLineDefs; n++) - if ((Vertices[LineDefs[n].start].y > y) - != (Vertices[LineDefs[n].end].y > y)) - { - int lx0 = Vertices[LineDefs[n].start].x; - int ly0 = Vertices[LineDefs[n].start].y; - int lx1 = Vertices[LineDefs[n].end].x; - int ly1 = Vertices[LineDefs[n].end].y; - m = lx0 + (int) ((long) (y - ly0) * (long) (lx1 - lx0) - / (long) (ly1 - ly0)); - if (m >= x && m < curx) - { - curx = m; - best_match = n; - } - } + if ((Vertices[LineDefs[n].start].y > y) + != (Vertices[LineDefs[n].end].y > y)) + { + int lx0 = Vertices[LineDefs[n].start].x; + int ly0 = Vertices[LineDefs[n].start].y; + int lx1 = Vertices[LineDefs[n].end].x; + int ly1 = Vertices[LineDefs[n].end].y; + m = lx0 + (int) ((long) (y - ly0) * (long) (lx1 - lx0) + / (long) (ly1 - ly0)); + if (m >= x && m < curx) + { + curx = m; + best_match = n; + } + } /* now look if this linedef has a sidedef bound to one sector */ if (best_match < 0) - return OBJ_NO_NONE; + return OBJ_NO_NONE; if (Vertices[LineDefs[best_match].start].y - > Vertices[LineDefs[best_match].end].y) - side = 1; + > Vertices[LineDefs[best_match].end].y) + side = 1; else - side = 2; + side = 2; return best_match; } @@ -230,23 +230,23 @@ int c_dy = Vertices[B].y - Vertices[C].y; double AB_angle = (a_dx == 0) ? (a_dy >= 0 ? 90 : -90) : - atan2(a_dy, a_dx) * 180 / M_PI; + atan2(a_dy, a_dx) * 180 / M_PI; double CB_angle = (c_dx == 0) ? (c_dy >= 0 ? 90 : -90) : - atan2(c_dy, c_dx) * 180 / M_PI; + atan2(c_dy, c_dx) * 180 / M_PI; double result = CB_angle - AB_angle; if (result >= 360) - result -= 360; + result -= 360; while (result < 0) - result += 360; + result += 360; #if (DEBUG_ANGLE) fprintf(stderr, "ANGLE %1.6f (%d,%d) -> (%d,%d) -> (%d,%d)\n", - result, Vertices[A].x, Vertices[A].y, - Vertices[B].x, Vertices[B].y, Vertices[C].x, Vertices[C].y); + result, Vertices[A].x, Vertices[A].y, + Vertices[B].x, Vertices[B].y, Vertices[C].x, Vertices[C].y); #endif return result; @@ -262,102 +262,102 @@ #define DEBUG_PATH 0 static int select_sides_in_closed_path(bitvec_c & ld_side1, - bitvec_c & ld_side2, int line, - int side) + bitvec_c & ld_side2, int line, + int side) { int cur_vert, prev_vert, final_vert; if (side == 1) { - ld_side1.set(line); - cur_vert = LineDefs[line].end; - prev_vert = final_vert = LineDefs[line].start; + ld_side1.set(line); + cur_vert = LineDefs[line].end; + prev_vert = final_vert = LineDefs[line].start; } else { - ld_side2.set(line); - cur_vert = LineDefs[line].start; - prev_vert = final_vert = LineDefs[line].end; + ld_side2.set(line); + cur_vert = LineDefs[line].start; + prev_vert = final_vert = LineDefs[line].end; } #if (DEBUG_PATH) fprintf(stderr, "PATH: line %d side %d cur %d final %d\n", - line, side, cur_vert, final_vert); + line, side, cur_vert, final_vert); #endif while (cur_vert != final_vert) { - int next_line = OBJ_NO_NONE; - int next_vert = OBJ_NO_NONE; - int next_side; - double best_angle = 999; + int next_line = OBJ_NO_NONE; + int next_vert = OBJ_NO_NONE; + int next_side; + double best_angle = 999; - // Look for the next linedef in the path. It's the linedef that - // uses the current vertex and is not the current one. + // Look for the next linedef in the path. It's the linedef that + // uses the current vertex and is not the current one. - for (int n = 0; n < NumLineDefs; n++) - { - if (n == line) - continue; + for (int n = 0; n < NumLineDefs; n++) + { + if (n == line) + continue; - int other_vert; - int which_side; + int other_vert; + int which_side; - if (LineDefs[n].start == cur_vert) - { - other_vert = LineDefs[n].end; - which_side = 1; - } - else if (LineDefs[n].end == cur_vert) - { - other_vert = LineDefs[n].start; - which_side = 2; - } - else - continue; + if (LineDefs[n].start == cur_vert) + { + other_vert = LineDefs[n].end; + which_side = 1; + } + else if (LineDefs[n].end == cur_vert) + { + other_vert = LineDefs[n].start; + which_side = 2; + } + else + continue; - // found adjoining linedef + // found adjoining linedef - double angle = angle_between_linedefs(prev_vert, cur_vert, - other_vert); + double angle = angle_between_linedefs(prev_vert, cur_vert, + other_vert); - if (!is_obj(next_line) || angle < best_angle) - { - next_line = n; - next_vert = other_vert; - next_side = which_side; + if (!is_obj(next_line) || angle < best_angle) + { + next_line = n; + next_vert = other_vert; + next_side = which_side; - best_angle = angle; - } + best_angle = angle; + } - // Continue the search - } + // Continue the search + } - line = next_line; - side = next_side; + line = next_line; + side = next_side; #if (DEBUG_PATH) - fprintf(stderr, "PATH NEXT: line %d side %d vert %d angle %1.6f\n", - line, side, next_vert, best_angle); + fprintf(stderr, "PATH NEXT: line %d side %d vert %d angle %1.6f\n", + line, side, next_vert, best_angle); #endif - // None ? Path cannot be closed - if (!is_obj(line)) - return 0; + // None ? Path cannot be closed + if (!is_obj(line)) + return 0; - // Line already seen ? Under normal circumstances this won't - // happen, but it _can_ happen and indicates a non-closed - // structure - if (ld_side1.get(line) || ld_side2.get(line)) - return 0; + // Line already seen ? Under normal circumstances this won't + // happen, but it _can_ happen and indicates a non-closed + // structure + if (ld_side1.get(line) || ld_side2.get(line)) + return 0; - if (side == 1) - ld_side1.set(line); - else - ld_side2.set(line); + if (side == 1) + ld_side1.set(line); + else + ld_side2.set(line); - prev_vert = cur_vert; - cur_vert = next_vert; + prev_vert = cur_vert; + cur_vert = next_vert; } #if (DEBUG_PATH) @@ -372,55 +372,55 @@ reference. Will create a new sidedef if necessary. */ static void super_set_sector_on_side(int line, wad_sdn_t & side, - wad_sdn_t & other, int side_no, - int sector) + wad_sdn_t & other, int side_no, + int sector) { if (is_obj(side) && SideDefs[side].sector == sector) { - // there was no change. - return; + // there was no change. + return; } int must_flip = 0; if (!is_obj(side)) { - // if we're adding a sidedef to a line that has no sides, and - // the sidedef would be the 2nd one, then flip the linedef. - // Thus we don't end up with invalid lines -- i.e. ones with a - // left side but no right side. + // if we're adding a sidedef to a line that has no sides, and + // the sidedef would be the 2nd one, then flip the linedef. + // Thus we don't end up with invalid lines -- i.e. ones with a + // left side but no right side. - if (!is_obj(other) && side_no == 2) - must_flip = 1; + if (!is_obj(other) && side_no == 2) + must_flip = 1; - InsertObject(OBJ_SIDEDEFS, OBJ_NO_NONE, 0, 0); - side = NumSideDefs - 1; + InsertObject(OBJ_SIDEDEFS, OBJ_NO_NONE, 0, 0); + side = NumSideDefs - 1; - // if we're adding a second side to the linedef, clear out some - // of the properties that aren't needed anymore: middle texture, - // two-sided flag, and impassible flag. + // if we're adding a second side to the linedef, clear out some + // of the properties that aren't needed anymore: middle texture, + // two-sided flag, and impassible flag. - if (is_obj(other)) - { - strncpy(SideDefs[side].tex3, "-", WAD_TEX_NAME); - strncpy(SideDefs[other].tex3, "-", WAD_TEX_NAME); + if (is_obj(other)) + { + strncpy(SideDefs[side].tex3, "-", WAD_TEX_NAME); + strncpy(SideDefs[other].tex3, "-", WAD_TEX_NAME); - LineDefs[line].flags |= 4; // Set the 2S bit - LineDefs[line].flags &= ~1; // Clear the Im bit - } + LineDefs[line].flags |= 4; // Set the 2S bit + LineDefs[line].flags &= ~1; // Clear the Im bit + } } SideDefs[side].sector = sector; if (must_flip) { - int temp = LineDefs[line].start; - LineDefs[line].start = LineDefs[line].end; - LineDefs[line].end = temp; + int temp = LineDefs[line].start; + LineDefs[line].start = LineDefs[line].end; + LineDefs[line].end = temp; - temp = side; - side = other; - other = temp; + temp = side; + side = other; + other = temp; } MadeChanges = 1; @@ -431,16 +431,16 @@ { for (int line = 0; line < NumLineDefs; line++) { - int side1 = LineDefs[line].sidedef1; - int side2 = LineDefs[line].sidedef2; + int side1 = LineDefs[line].sidedef1; + int side2 = LineDefs[line].sidedef2; - if (ld_side1.get(line)) - if (is_obj(side2)) - return SideDefs[side2].sector; + if (ld_side1.get(line)) + if (is_obj(side2)) + return SideDefs[side2].sector; - if (ld_side2.get(line)) - if (is_obj(side1)) - return SideDefs[side1].sector; + if (ld_side2.get(line)) + if (is_obj(side1)) + return SideDefs[side1].sector; } return OBJ_NO_NONE; @@ -468,24 +468,24 @@ if (!is_obj(line)) { - Beep(); - sprintf(msg_buf, "Chosen area is not closed"); - Notify(-1, -1, msg_buf, NULL); - return; + Beep(); + sprintf(msg_buf, "Chosen area is not closed"); + Notify(-1, -1, msg_buf, NULL); + return; } bitvec_c ld_side1(NumLineDefs); bitvec_c ld_side2(NumLineDefs); int closed = select_sides_in_closed_path(ld_side1, ld_side2, - line, side); + line, side); if (!closed) { - Beep(); - sprintf(msg_buf, "Area chosen is not closed"); - Notify(-1, -1, msg_buf, NULL); - return; + Beep(); + sprintf(msg_buf, "Area chosen is not closed"); + Notify(-1, -1, msg_buf, NULL); + return; } // -AJA- FIXME: look for "islands", closed linedef paths that lie @@ -496,20 +496,20 @@ if (!is_obj(new_sec)) { - int model = super_find_sector_model(ld_side1, ld_side2); - InsertObject(OBJ_SECTORS, model, 0, 0); - new_sec = NumSectors - 1; + int model = super_find_sector_model(ld_side1, ld_side2); + InsertObject(OBJ_SECTORS, model, 0, 0); + new_sec = NumSectors - 1; } for (line = 0; line < NumLineDefs; line++) { - if (ld_side1.get(line)) - super_set_sector_on_side(line, LineDefs[line].sidedef1, - LineDefs[line].sidedef2, 1, new_sec); + if (ld_side1.get(line)) + super_set_sector_on_side(line, LineDefs[line].sidedef1, + LineDefs[line].sidedef2, 1, new_sec); - else if (ld_side2.get(line)) - super_set_sector_on_side(line, LineDefs[line].sidedef2, - LineDefs[line].sidedef1, 2, new_sec); + else if (ld_side2.get(line)) + super_set_sector_on_side(line, LineDefs[line].sidedef2, + LineDefs[line].sidedef1, 2, new_sec); } } diff -r 594dea11ccd9 -r a68786b9c74b src/s_prop.cc --- a/src/s_prop.cc Sat Sep 24 15:01:56 2011 +0300 +++ b/src/s_prop.cc Sat Sep 24 15:59:33 2011 +0300 @@ -1,9 +1,9 @@ /* - * s_prop.cc - * Sector properties - * Some of this was originally in editobj.c. It was moved here to - * improve overlay granularity (therefore memory consumption). - * AYM 1998-02-07 + * s_prop.cc + * Sector properties + * Some of this was originally in editobj.c. It was moved here to + * improve overlay granularity (therefore memory consumption). + * AYM 1998-02-07 */ @@ -54,7 +54,7 @@ /* - * Menu_data_st::Menu_data_st - ctor + * Menu_data_st::Menu_data_st - ctor */ Menu_data_st::Menu_data_st(al_llist_t * list):list(list) { @@ -63,7 +63,7 @@ /* - * Menu_data_st::nitems - return the number of items + * Menu_data_st::nitems - return the number of items */ size_t Menu_data_st::nitems() const { @@ -72,31 +72,31 @@ /* - * Menu_data_st::operator[] - return the nth item + * Menu_data_st::operator[] - return the nth item */ const char *Menu_data_st::operator[] (size_t n) const { - if (al_lseek(list, n, SEEK_SET) != 0) - { - sprintf(buf, "BUG: al_lseek(%p, %lu): %s", - (void *) list, - (unsigned long) n, al_astrerror(al_aerrno)); - return buf; - } - const stdef_t *ptr = (const stdef_t *) al_lptr(list); - if (ptr == NULL) - sprintf(buf, "BUG: al_lptr(%p): %s", - (void *) list, al_astrerror(al_aerrno)); - else - sprintf(buf, "%2d - %.70s", ptr->number, ptr->longdesc); - return buf; + if (al_lseek(list, n, SEEK_SET) != 0) + { + sprintf(buf, "BUG: al_lseek(%p, %lu): %s", + (void *) list, + (unsigned long) n, al_astrerror(al_aerrno)); + return buf; + } + const stdef_t *ptr = (const stdef_t *) al_lptr(list); + if (ptr == NULL) + sprintf(buf, "BUG: al_lptr(%p): %s", + (void *) list, al_astrerror(al_aerrno)); + else + sprintf(buf, "%2d - %.70s", ptr->number, ptr->longdesc); + return buf; } /* - * SectorProperties - * Sector properties "dialog" + * SectorProperties + * Sector properties "dialog" */ void SectorProperties(int x0, int y0, SelPtr obj) { @@ -107,149 +107,149 @@ int subwin_y0; for (n = 0; n < 8; n++) - menustr[n] = (char *) GetMemory(60); + menustr[n] = (char *) GetMemory(60); sprintf(menustr[7], "Edit sector #%d", obj->objnum); sprintf(menustr[0], "Change floor height (Current: %d)", - Sectors[obj->objnum].floorh); + Sectors[obj->objnum].floorh); sprintf(menustr[1], "Change ceiling height (Current: %d)", - Sectors[obj->objnum].ceilh); + Sectors[obj->objnum].ceilh); sprintf(menustr[2], "Change floor texture (Current: %.*s)", - (int) WAD_FLAT_NAME, Sectors[obj->objnum].floort); + (int) WAD_FLAT_NAME, Sectors[obj->objnum].floort); sprintf(menustr[3], "Change ceiling texture (Current: %.*s)", - (int) WAD_FLAT_NAME, Sectors[obj->objnum].ceilt); + (int) WAD_FLAT_NAME, Sectors[obj->objnum].ceilt); sprintf(menustr[4], "Change light level (Current: %d)", - Sectors[obj->objnum].light); + Sectors[obj->objnum].light); sprintf(menustr[5], "Change type (Current: %d)", - Sectors[obj->objnum].special); + Sectors[obj->objnum].special); sprintf(menustr[6], "Change linedef tag (Current: %d)", - Sectors[obj->objnum].tag); + Sectors[obj->objnum].tag); val = vDisplayMenu(x0, y0, menustr[7], - menustr[0], YK_, 0, - menustr[1], YK_, 0, - menustr[2], YK_, 0, - menustr[3], YK_, 0, - menustr[4], YK_, 0, - menustr[5], YK_, 0, menustr[6], YK_, 0, NULL); + menustr[0], YK_, 0, + menustr[1], YK_, 0, + menustr[2], YK_, 0, + menustr[3], YK_, 0, + menustr[4], YK_, 0, + menustr[5], YK_, 0, menustr[6], YK_, 0, NULL); for (n = 0; n < 8; n++) - FreeMemory(menustr[n]); + FreeMemory(menustr[n]); subwin_y0 = y0 + BOX_BORDER + (2 + val) * FONTH; switch (val) { case 1: - val = InputIntegerValue(x0 + 42, subwin_y0, -32768, 32767, - Sectors[obj->objnum].floorh); - if (val != IIV_CANCEL) - { - for (cur = obj; cur; cur = cur->next) - Sectors[cur->objnum].floorh = val; - MadeChanges = 1; - } - break; + val = InputIntegerValue(x0 + 42, subwin_y0, -32768, 32767, + Sectors[obj->objnum].floorh); + if (val != IIV_CANCEL) + { + for (cur = obj; cur; cur = cur->next) + Sectors[cur->objnum].floorh = val; + MadeChanges = 1; + } + break; case 2: - val = InputIntegerValue(x0 + 42, subwin_y0, -32768, 32767, - Sectors[obj->objnum].ceilh); - if (val != IIV_CANCEL) - { - for (cur = obj; cur; cur = cur->next) - Sectors[cur->objnum].ceilh = val; - MadeChanges = 1; - } - break; + val = InputIntegerValue(x0 + 42, subwin_y0, -32768, 32767, + Sectors[obj->objnum].ceilh); + if (val != IIV_CANCEL) + { + for (cur = obj; cur; cur = cur->next) + Sectors[cur->objnum].ceilh = val; + MadeChanges = 1; + } + break; case 3: - { - *texname = '\0'; - strncat(texname, Sectors[obj->objnum].floort, WAD_FLAT_NAME); - char **flat_names = - (char **) GetMemory(NumFTexture * sizeof *flat_names); - for (size_t n = 0; n < NumFTexture; n++) - flat_names[n] = flat_list[n].name; - ChooseFloorTexture(x0 + 42, subwin_y0, "Choose a floor texture", - NumFTexture, flat_names, texname); - FreeMemory(flat_names); - if (strlen(texname) > 0) - { - for (cur = obj; cur; cur = cur->next) - strncpy(Sectors[cur->objnum].floort, texname, - WAD_FLAT_NAME); - MadeChanges = 1; - } - break; - } + { + *texname = '\0'; + strncat(texname, Sectors[obj->objnum].floort, WAD_FLAT_NAME); + char **flat_names = + (char **) GetMemory(NumFTexture * sizeof *flat_names); + for (size_t n = 0; n < NumFTexture; n++) + flat_names[n] = flat_list[n].name; + ChooseFloorTexture(x0 + 42, subwin_y0, "Choose a floor texture", + NumFTexture, flat_names, texname); + FreeMemory(flat_names); + if (strlen(texname) > 0) + { + for (cur = obj; cur; cur = cur->next) + strncpy(Sectors[cur->objnum].floort, texname, + WAD_FLAT_NAME); + MadeChanges = 1; + } + break; + } case 4: - { - *texname = '\0'; - strncat(texname, Sectors[obj->objnum].ceilt, WAD_FLAT_NAME); - char **flat_names = - (char **) GetMemory(NumFTexture * sizeof *flat_names); - for (size_t n = 0; n < NumFTexture; n++) - flat_names[n] = flat_list[n].name; - ChooseFloorTexture(x0 + 42, subwin_y0, "Choose a ceiling texture", - NumFTexture, flat_names, texname); - FreeMemory(flat_names); - if (strlen(texname) > 0) - { - for (cur = obj; cur; cur = cur->next) - strncpy(Sectors[cur->objnum].ceilt, texname, - WAD_FLAT_NAME); - MadeChanges = 1; - } - break; - } + { + *texname = '\0'; + strncat(texname, Sectors[obj->objnum].ceilt, WAD_FLAT_NAME); + char **flat_names = + (char **) GetMemory(NumFTexture * sizeof *flat_names); + for (size_t n = 0; n < NumFTexture; n++) + flat_names[n] = flat_list[n].name; + ChooseFloorTexture(x0 + 42, subwin_y0, "Choose a ceiling texture", + NumFTexture, flat_names, texname); + FreeMemory(flat_names); + if (strlen(texname) > 0) + { + for (cur = obj; cur; cur = cur->next) + strncpy(Sectors[cur->objnum].ceilt, texname, + WAD_FLAT_NAME); + MadeChanges = 1; + } + break; + } case 5: - val = InputIntegerValue(x0 + 42, subwin_y0, 0, 255, - Sectors[obj->objnum].light); - if (val != IIV_CANCEL) - { - for (cur = obj; cur; cur = cur->next) - Sectors[cur->objnum].light = val; - MadeChanges = 1; - } - break; + val = InputIntegerValue(x0 + 42, subwin_y0, 0, 255, + Sectors[obj->objnum].light); + if (val != IIV_CANCEL) + { + for (cur = obj; cur; cur = cur->next) + Sectors[cur->objnum].light = val; + MadeChanges = 1; + } + break; case 6: - { - val = 0; - Menu_data_st menudata(stdef); - if (DisplayMenuList - (x0 + 42, subwin_y0, "Select type", menudata, &val) < 0) - break; - // KLUDGE last element of stdef means "enter value" - if (val == al_lcount(stdef) - 1) - { - val = InputIntegerValue(x0 + 84, - subwin_y0 + BOX_BORDER + (3 + - val) * - FONTH, -32768, 32767, 0); - if (val == IIV_CANCEL) // [Esc] - break; - } - else - { - if (al_lseek(stdef, val, SEEK_SET)) - fatal_error("%s SP1 (%s)\n", - msg_unexpected, al_astrerror(al_aerrno)); - val = CUR_STDEF->number; - } - for (cur = obj; cur; cur = cur->next) - Sectors[cur->objnum].special = val; - MadeChanges = 1; - break; - } + { + val = 0; + Menu_data_st menudata(stdef); + if (DisplayMenuList + (x0 + 42, subwin_y0, "Select type", menudata, &val) < 0) + break; + // KLUDGE last element of stdef means "enter value" + if (val == al_lcount(stdef) - 1) + { + val = InputIntegerValue(x0 + 84, + subwin_y0 + BOX_BORDER + (3 + + val) * + FONTH, -32768, 32767, 0); + if (val == IIV_CANCEL) // [Esc] + break; + } + else + { + if (al_lseek(stdef, val, SEEK_SET)) + fatal_error("%s SP1 (%s)\n", + msg_unexpected, al_astrerror(al_aerrno)); + val = CUR_STDEF->number; + } + for (cur = obj; cur; cur = cur->next) + Sectors[cur->objnum].special = val; + MadeChanges = 1; + break; + } case 7: - val = InputIntegerValue(x0 + 42, subwin_y0, -32768, 32767, - Sectors[obj->objnum].tag); - if (val != IIV_CANCEL) - { - for (cur = obj; cur; cur = cur->next) - Sectors[cur->objnum].tag = val; - MadeChanges = 1; - } - break; + val = InputIntegerValue(x0 + 42, subwin_y0, -32768, 32767, + Sectors[obj->objnum].tag); + if (val != IIV_CANCEL) + { + for (cur = obj; cur; cur = cur->next) + Sectors[cur->objnum].tag = val; + MadeChanges = 1; + } + break; } } @@ -264,28 +264,28 @@ for (cur = sectors; cur; cur = cur->next) { - if (!is_obj(cur->objnum)) - continue; + if (!is_obj(cur->objnum)) + continue; - strncpy(Sectors[cur->objnum].floort, Sectors[src_sector].floort, - WAD_FLAT_NAME); - strncpy(Sectors[cur->objnum].ceilt, Sectors[src_sector].ceilt, - WAD_FLAT_NAME); + strncpy(Sectors[cur->objnum].floort, Sectors[src_sector].floort, + WAD_FLAT_NAME); + strncpy(Sectors[cur->objnum].ceilt, Sectors[src_sector].ceilt, + WAD_FLAT_NAME); - Sectors[cur->objnum].floorh = Sectors[src_sector].floorh; - Sectors[cur->objnum].ceilh = Sectors[src_sector].ceilh; - Sectors[cur->objnum].light = Sectors[src_sector].light; - Sectors[cur->objnum].special = Sectors[src_sector].special; - Sectors[cur->objnum].tag = Sectors[src_sector].tag; + Sectors[cur->objnum].floorh = Sectors[src_sector].floorh; + Sectors[cur->objnum].ceilh = Sectors[src_sector].ceilh; + Sectors[cur->objnum].light = Sectors[src_sector].light; + Sectors[cur->objnum].special = Sectors[src_sector].special; + Sectors[cur->objnum].tag = Sectors[src_sector].tag; - MadeChanges = 1; + MadeChanges = 1; } } /* - * InputSectorType - * Let the user select a sector type number and return it - * Returns 0 if OK, <>0 if cancelled + * InputSectorType + * Let the user select a sector type number and return it + * Returns 0 if OK, <>0 if cancelled */ int InputSectorType(int x0, int y0, int *number) { @@ -294,25 +294,25 @@ *number = 0; Menu_data_st menudata(stdef); if (DisplayMenuList(x0, y0, "Select type", menudata, &val) < 0) - return 1; + return 1; // KLUDGE last element of stdef means "enter value" if (val == al_lcount(stdef) - 1) { - val = InputIntegerValue(x0 + 84, - y0 + BOX_BORDER + (3 + val) * FONTH, - -32768, 32767, 0); - if (val == IIV_CANCEL) // [Esc] - return 1; + val = InputIntegerValue(x0 + 84, + y0 + BOX_BORDER + (3 + val) * FONTH, + -32768, 32767, 0); + if (val == IIV_CANCEL) // [Esc] + return 1; } else { - if (al_lseek(stdef, val, SEEK_SET)) - fatal_error("%s SP1 (%s)\n", - msg_unexpected, al_astrerror(al_aerrno)); - val = CUR_STDEF->number; + if (al_lseek(stdef, val, SEEK_SET)) + fatal_error("%s SP1 (%s)\n", + msg_unexpected, al_astrerror(al_aerrno)); + val = CUR_STDEF->number; } if (val < 0) - return 1; //unsuccessful + return 1; //unsuccessful *number = val; - return 0; //successful + return 0; //successful } diff -r 594dea11ccd9 -r a68786b9c74b src/s_slice.cc --- a/src/s_slice.cc Sat Sep 24 15:01:56 2011 +0300 +++ b/src/s_slice.cc Sat Sep 24 15:59:33 2011 +0300 @@ -1,7 +1,7 @@ /* - * s_slice.cc - * Cut a slice out of a sector - * AYM 2001-09-11 + * s_slice.cc + * Cut a slice out of a sector + * AYM 2001-09-11 */ @@ -37,7 +37,7 @@ #include "s_slice.h" -class Secref // Reference to a sector +class Secref // Reference to a sector { public:Secref():linedef1('\0'), linedef2('\0') { @@ -48,7 +48,7 @@ /* - * sector_slice - cut a slice out of a sector + * sector_slice - cut a slice out of a sector */ void sector_slice(obj_no_t linedef1, obj_no_t linedef2) { @@ -82,30 +82,30 @@ How do you decide to which vertex of L2 should the start vertex of L1 be linked ? */ - if (!is_linedef(linedef1)) // Paranoia + if (!is_linedef(linedef1)) // Paranoia { - char buf[100]; - y_snprintf(buf, sizeof buf, - "First argument is not a valid linedef number"); - Notify(-1, -1, buf, 0); - return; + char buf[100]; + y_snprintf(buf, sizeof buf, + "First argument is not a valid linedef number"); + Notify(-1, -1, buf, 0); + return; } - if (!is_linedef(linedef2)) // Paranoia + if (!is_linedef(linedef2)) // Paranoia { - char buf[100]; - y_snprintf(buf, sizeof buf, - "Second argument is not a valid linedef number"); - Notify(-1, -1, buf, 0); - return; + char buf[100]; + y_snprintf(buf, sizeof buf, + "Second argument is not a valid linedef number"); + Notify(-1, -1, buf, 0); + return; } if (linedef1 == linedef2) { - char buf[100]; - y_snprintf(buf, sizeof buf, "Both arguments are the same linedef"); - Notify(-1, -1, buf, 0); - return; + char buf[100]; + y_snprintf(buf, sizeof buf, "Both arguments are the same linedef"); + Notify(-1, -1, buf, 0); + return; } obj_no_t l1start = LineDefs[linedef1].start; @@ -114,13 +114,13 @@ obj_no_t l2end = LineDefs[linedef2].end; if (l1start == l2start && l1end == l2end - || l1start == l2end && l1end == l2start) + || l1start == l2end && l1end == l2start) { - char buf[100]; - y_snprintf(buf, sizeof buf, "Linedefs %d and %d are superimposed", - int (linedef1), int (linedef2)); - Notify(-1, -1, buf, 0); - return; + char buf[100]; + y_snprintf(buf, sizeof buf, "Linedefs %d and %d are superimposed", + int (linedef1), int (linedef2)); + Notify(-1, -1, buf, 0); + return; } obj_no_t l1sdr = LineDefs[linedef1].sidedef1; @@ -135,122 +135,122 @@ if (is_sector(l1sr) && is_sector(l1sl) && l1sr == l1sl) { - char buf[100]; - y_snprintf(buf, sizeof buf, - "Linedef %d has both sides in the same sector", - int (linedef1)); - Notify(-1, -1, buf, 0); - return; + char buf[100]; + y_snprintf(buf, sizeof buf, + "Linedef %d has both sides in the same sector", + int (linedef1)); + Notify(-1, -1, buf, 0); + return; } if (is_sector(l2sr) && is_sector(l2sl) && l2sr == l2sl) { - char buf[100]; - y_snprintf(buf, sizeof buf, - "Linedef %d has both sides in the same sector", - int (linedef2)); - Notify(-1, -1, buf, 0); - return; + char buf[100]; + y_snprintf(buf, sizeof buf, + "Linedef %d has both sides in the same sector", + int (linedef2)); + Notify(-1, -1, buf, 0); + return; } // Verify that the linedefs have exactly one sector in common typedef std::map < obj_no_t, Secref > secref_list_t; secref_list_t secref; if (is_sector(l1sr)) - secref[l1sr].linedef1 = 'r'; + secref[l1sr].linedef1 = 'r'; if (is_sector(l1sl)) - secref[l1sl].linedef1 = 'l'; + secref[l1sl].linedef1 = 'l'; if (is_sector(l2sr)) - secref[l2sr].linedef2 = 'r'; + secref[l2sr].linedef2 = 'r'; if (is_sector(l2sl)) - secref[l2sl].linedef2 = 'l'; + secref[l2sl].linedef2 = 'l'; obj_no_t sector; int count = 0; for (secref_list_t::iterator i = secref.begin(); i != secref.end(); i++) { - if (i->second.linedef1 != '\0' && i->second.linedef2 != '\0') - { - sector = i->first; - count++; - } + if (i->second.linedef1 != '\0' && i->second.linedef2 != '\0') + { + sector = i->first; + count++; + } } if (count < 1) { - char buf[100]; - y_snprintf(buf, sizeof buf, - "Linedefs %d and %d don't face the same sector", - int (linedef1), int (linedef2)); - Notify(-1, -1, buf, 0); - return; + char buf[100]; + y_snprintf(buf, sizeof buf, + "Linedefs %d and %d don't face the same sector", + int (linedef1), int (linedef2)); + Notify(-1, -1, buf, 0); + return; } if (count > 1) { - char buf[100]; - y_snprintf(buf, sizeof buf, - "Linedefs %d and %d have more than one sector in common", - int (linedef1), int (linedef2)); - Notify(-1, -1, buf, 0); - return; + char buf[100]; + y_snprintf(buf, sizeof buf, + "Linedefs %d and %d have more than one sector in common", + int (linedef1), int (linedef2)); + Notify(-1, -1, buf, 0); + return; } // Insert new sector between linedefs - obj_no_t la0, la1; // Start and end of the first linedef (the + obj_no_t la0, la1; // Start and end of the first linedef (the // one that goes from linedef1 to linedef2) - obj_no_t lb0, lb1; // Start and end of the second linedef (the + obj_no_t lb0, lb1; // Start and end of the second linedef (the // one that goes from linedef2 to linedef1) char side = secref[sector].linedef1; if (side == 'r') { - la0 = l1end; - lb1 = l1start; + la0 = l1end; + lb1 = l1start; } else if (side == 'l') { - la0 = l1start; - lb1 = l1end; + la0 = l1start; + lb1 = l1end; } - else // Can't happen + else // Can't happen { - nf_bug("sector %d: linedef1 = %02Xh", int (sector), side); - return; + nf_bug("sector %d: linedef1 = %02Xh", int (sector), side); + return; } side = secref[sector].linedef2; if (side == 'r') { - la1 = l2start; - lb0 = l2end; + la1 = l2start; + lb0 = l2end; } else if (side == 'l') { - la1 = l2end; - lb0 = l2start; + la1 = l2end; + lb0 = l2start; } - else // Can't happen + else // Can't happen { - nf_bug("sector %d: linedef2 = %02Xh", int (sector), side); - return; + nf_bug("sector %d: linedef2 = %02Xh", int (sector), side); + return; } // Verify that there's no linedef already between linedef1 and linedef2 { - for (int n = 0; n < NumLineDefs; n++) - { - if (n == linedef1 || n == linedef2) - continue; - if (LineDefs[n].start == la0 && LineDefs[n].end == la1 - || LineDefs[n].start == la1 && LineDefs[n].end == la0 - || LineDefs[n].start == lb0 && LineDefs[n].end == lb1 - || LineDefs[n].start == lb1 && LineDefs[n].end == lb0) - { - char buf[100]; - y_snprintf(buf, sizeof buf, - "A linedef already exists between linedefs %d and %d (linedef %d)", - int (linedef1), int (linedef2), int (n)); - Notify(-1, -1, buf, 0); - return; - } - } + for (int n = 0; n < NumLineDefs; n++) + { + if (n == linedef1 || n == linedef2) + continue; + if (LineDefs[n].start == la0 && LineDefs[n].end == la1 + || LineDefs[n].start == la1 && LineDefs[n].end == la0 + || LineDefs[n].start == lb0 && LineDefs[n].end == lb1 + || LineDefs[n].start == lb1 && LineDefs[n].end == lb0) + { + char buf[100]; + y_snprintf(buf, sizeof buf, + "A linedef already exists between linedefs %d and %d (linedef %d)", + int (linedef1), int (linedef2), int (n)); + Notify(-1, -1, buf, 0); + return; + } + } } // Create new sector @@ -259,50 +259,50 @@ // Create new linedef from linedef1 to linedef2 if (la0 != la1) { - InsertObject(OBJ_LINEDEFS, -1, 0, 0); - LineDefs[NumLineDefs - 1].start = la0; - LineDefs[NumLineDefs - 1].end = la1; - LineDefs[NumLineDefs - 1].flags = 4; - InsertObject(OBJ_SIDEDEFS, -1, 0, 0); // Right sidedef - SideDefs[NumSideDefs - 1].sector = NumSectors - 1; // Redundant - strncpy(SideDefs[NumSideDefs - 1].tex3, "-", 8); - LineDefs[NumLineDefs - 1].sidedef1 = NumSideDefs - 1; - InsertObject(OBJ_SIDEDEFS, -1, 0, 0); // Left sidedef - SideDefs[NumSideDefs - 1].sector = sector; - strncpy(SideDefs[NumSideDefs - 1].tex3, "-", 8); - LineDefs[NumLineDefs - 1].sidedef2 = NumSideDefs - 1; + InsertObject(OBJ_LINEDEFS, -1, 0, 0); + LineDefs[NumLineDefs - 1].start = la0; + LineDefs[NumLineDefs - 1].end = la1; + LineDefs[NumLineDefs - 1].flags = 4; + InsertObject(OBJ_SIDEDEFS, -1, 0, 0); // Right sidedef + SideDefs[NumSideDefs - 1].sector = NumSectors - 1; // Redundant + strncpy(SideDefs[NumSideDefs - 1].tex3, "-", 8); + LineDefs[NumLineDefs - 1].sidedef1 = NumSideDefs - 1; + InsertObject(OBJ_SIDEDEFS, -1, 0, 0); // Left sidedef + SideDefs[NumSideDefs - 1].sector = sector; + strncpy(SideDefs[NumSideDefs - 1].tex3, "-", 8); + LineDefs[NumLineDefs - 1].sidedef2 = NumSideDefs - 1; } // Create new linedef from linedef2 to linedef1 if (lb0 != lb1) { - InsertObject(OBJ_LINEDEFS, -1, 0, 0); - LineDefs[NumLineDefs - 1].start = lb0; - LineDefs[NumLineDefs - 1].end = lb1; - LineDefs[NumLineDefs - 1].flags = 4; - InsertObject(OBJ_SIDEDEFS, -1, 0, 0); // Right sidedef - SideDefs[NumSideDefs - 1].sector = NumSectors - 1; // Redundant - strncpy(SideDefs[NumSideDefs - 1].tex3, "-", 8); - LineDefs[NumLineDefs - 1].sidedef1 = NumSideDefs - 1; - InsertObject(OBJ_SIDEDEFS, -1, 0, 0); // Left sidedef - SideDefs[NumSideDefs - 1].sector = sector; - strncpy(SideDefs[NumSideDefs - 1].tex3, "-", 8); - LineDefs[NumLineDefs - 1].sidedef2 = NumSideDefs - 1; + InsertObject(OBJ_LINEDEFS, -1, 0, 0); + LineDefs[NumLineDefs - 1].start = lb0; + LineDefs[NumLineDefs - 1].end = lb1; + LineDefs[NumLineDefs - 1].flags = 4; + InsertObject(OBJ_SIDEDEFS, -1, 0, 0); // Right sidedef + SideDefs[NumSideDefs - 1].sector = NumSectors - 1; // Redundant + strncpy(SideDefs[NumSideDefs - 1].tex3, "-", 8); + LineDefs[NumLineDefs - 1].sidedef1 = NumSideDefs - 1; + InsertObject(OBJ_SIDEDEFS, -1, 0, 0); // Left sidedef + SideDefs[NumSideDefs - 1].sector = sector; + strncpy(SideDefs[NumSideDefs - 1].tex3, "-", 8); + LineDefs[NumLineDefs - 1].sidedef2 = NumSideDefs - 1; } // Adjust sector references for linedef1 side = secref[sector].linedef1; if (side == 'r') - SideDefs[LineDefs[linedef1].sidedef1].sector = NumSectors - 1; + SideDefs[LineDefs[linedef1].sidedef1].sector = NumSectors - 1; else if (side == 'l') - SideDefs[LineDefs[linedef1].sidedef2].sector = NumSectors - 1; + SideDefs[LineDefs[linedef1].sidedef2].sector = NumSectors - 1; // Adjust sector references for linedef2 side = secref[sector].linedef2; if (side == 'r') - SideDefs[LineDefs[linedef2].sidedef1].sector = NumSectors - 1; + SideDefs[LineDefs[linedef2].sidedef1].sector = NumSectors - 1; else if (side == 'l') - SideDefs[LineDefs[linedef2].sidedef2].sector = NumSectors - 1; + SideDefs[LineDefs[linedef2].sidedef2].sector = NumSectors - 1; MadeChanges = 1; MadeMapChanges = 1; diff -r 594dea11ccd9 -r a68786b9c74b src/s_slice.h --- a/src/s_slice.h Sat Sep 24 15:01:56 2011 +0300 +++ b/src/s_slice.h Sat Sep 24 15:59:33 2011 +0300 @@ -1,10 +1,10 @@ /* - * s_slice.h - * AYM 2001-09-13 + * s_slice.h + * AYM 2001-09-13 */ -#ifndef YH_S_SLICE /* DO NOT INSERT ANYTHING BEFORE THIS LINE */ +#ifndef YH_S_SLICE /* DO NOT INSERT ANYTHING BEFORE THIS LINE */ #define YH_S_SLICE diff -r 594dea11ccd9 -r a68786b9c74b src/s_split.cc --- a/src/s_split.cc Sat Sep 24 15:01:56 2011 +0300 +++ b/src/s_split.cc Sat Sep 24 15:59:33 2011 +0300 @@ -1,7 +1,7 @@ /* - * s_split.cc - * Split sectors - * AYM 1998-02-03 + * s_split.cc + * Split sectors + * AYM 1998-02-03 */ @@ -43,7 +43,7 @@ split a sector in two, adding a new linedef between the two vertices */ -void SplitSector(int vertex1, int vertex2) /* SWAP! */ +void SplitSector(int vertex1, int vertex2) /* SWAP! */ { SelPtr llist; int curv, s, l, sd; @@ -55,16 +55,16 @@ /* Check if there is a sector between the two vertices (in the middle) */ Objid o; GetCurObject(o, OBJ_SECTORS, - (Vertices[vertex1].x + Vertices[vertex2].x) / 2, - (Vertices[vertex1].y + Vertices[vertex2].y) / 2); + (Vertices[vertex1].x + Vertices[vertex2].x) / 2, + (Vertices[vertex1].y + Vertices[vertex2].y) / 2); s = o.num; if (s < 0) { - Beep(); - sprintf(msg1, "There is no sector between vertex #%d and vertex #%d", - vertex1, vertex2); - Notify(-1, -1, msg1, NULL); - return; + Beep(); + sprintf(msg1, "There is no sector between vertex #%d and vertex #%d", + vertex1, vertex2); + Notify(-1, -1, msg1, NULL); + return; } /* Check if there is a closed path from <vertex1> to <vertex2>, @@ -72,66 +72,66 @@ the set of linedefs that face sector <s>. */ obj_no_t *ld_numbers; int nlinedefs = linedefs_of_sector(s, ld_numbers); - if (nlinedefs < 1) // Can't happen + if (nlinedefs < 1) // Can't happen { - nf_bug("SplitSector: no linedef for sector %d\n", s); - return; + nf_bug("SplitSector: no linedef for sector %d\n", s); + return; } llist = NULL; curv = vertex1; while (curv != vertex2) { - printf("%d\n", curv); - int n; - for (n = 0; n < nlinedefs; n++) - { - if (IsSelected(llist, ld_numbers[n])) - continue; // Already been there - const LDPtr ld = LineDefs + ld_numbers[n]; - if (ld->start == curv - && is_sidedef(ld->sidedef1) - && SideDefs[ld->sidedef1].sector == s) - { - curv = ld->end; - SelectObject(&llist, ld_numbers[n]); - break; - } - if (ld->end == curv - && is_sidedef(ld->sidedef2) - && SideDefs[ld->sidedef2].sector == s) - { - curv = ld->start; - SelectObject(&llist, ld_numbers[n]); - break; - } - } - if (n >= nlinedefs) - { - Beep(); - sprintf(msg1, - "Cannot find a closed path from vertex #%d to vertex #%d", - vertex1, vertex2); - if (curv == vertex1) - sprintf(msg2, "There is no sidedef starting from vertex #%d" - " on sector #%d", vertex1, s); - else - sprintf(msg2, "Check if sector #%d is closed" - " (cannot go past vertex #%d)", s, curv); - Notify(-1, -1, msg1, msg2); - ForgetSelection(&llist); - delete[]ld_numbers; - return; - } - if (curv == vertex1) - { - Beep(); - sprintf(msg1, "Vertex #%d is not on the same sector (#%d)" - " as vertex #%d", vertex2, s, vertex1); - Notify(-1, -1, msg1, NULL); - ForgetSelection(&llist); - delete[]ld_numbers; - return; - } + printf("%d\n", curv); + int n; + for (n = 0; n < nlinedefs; n++) + { + if (IsSelected(llist, ld_numbers[n])) + continue; // Already been there + const LDPtr ld = LineDefs + ld_numbers[n]; + if (ld->start == curv + && is_sidedef(ld->sidedef1) + && SideDefs[ld->sidedef1].sector == s) + { + curv = ld->end; + SelectObject(&llist, ld_numbers[n]); + break; + } + if (ld->end == curv + && is_sidedef(ld->sidedef2) + && SideDefs[ld->sidedef2].sector == s) + { + curv = ld->start; + SelectObject(&llist, ld_numbers[n]); + break; + } + } + if (n >= nlinedefs) + { + Beep(); + sprintf(msg1, + "Cannot find a closed path from vertex #%d to vertex #%d", + vertex1, vertex2); + if (curv == vertex1) + sprintf(msg2, "There is no sidedef starting from vertex #%d" + " on sector #%d", vertex1, s); + else + sprintf(msg2, "Check if sector #%d is closed" + " (cannot go past vertex #%d)", s, curv); + Notify(-1, -1, msg1, msg2); + ForgetSelection(&llist); + delete[]ld_numbers; + return; + } + if (curv == vertex1) + { + Beep(); + sprintf(msg1, "Vertex #%d is not on the same sector (#%d)" + " as vertex #%d", vertex2, s, vertex1); + Notify(-1, -1, msg1, NULL); + ForgetSelection(&llist); + delete[]ld_numbers; + return; + } } delete[]ld_numbers; /* now, the list of linedefs for the new sector is in llist */ @@ -153,30 +153,30 @@ /* bind all linedefs in llist to the new sector */ while (llist) { - sd = LineDefs[llist->objnum].sidedef1; - if (sd < 0 || SideDefs[sd].sector != s) - sd = LineDefs[llist->objnum].sidedef2; - SideDefs[sd].sector = NumSectors - 1; - UnSelectObject(&llist, llist->objnum); + sd = LineDefs[llist->objnum].sidedef1; + if (sd < 0 || SideDefs[sd].sector != s) + sd = LineDefs[llist->objnum].sidedef2; + SideDefs[sd].sector = NumSectors - 1; + UnSelectObject(&llist, llist->objnum); } /* second check... useful for sectors within sectors */ for (l = 0; l < NumLineDefs; l++) { - sd = LineDefs[l].sidedef1; - if (sd >= 0 && SideDefs[sd].sector == s) - { - curv = GetOppositeSector(l, 1); - if (curv == NumSectors - 1) - SideDefs[sd].sector = NumSectors - 1; - } - sd = LineDefs[l].sidedef2; - if (sd >= 0 && SideDefs[sd].sector == s) - { - curv = GetOppositeSector(l, 0); - if (curv == NumSectors - 1) - SideDefs[sd].sector = NumSectors - 1; - } + sd = LineDefs[l].sidedef1; + if (sd >= 0 && SideDefs[sd].sector == s) + { + curv = GetOppositeSector(l, 1); + if (curv == NumSectors - 1) + SideDefs[sd].sector = NumSectors - 1; + } + sd = LineDefs[l].sidedef2; + if (sd >= 0 && SideDefs[sd].sector == s) + { + curv = GetOppositeSector(l, 0); + if (curv == NumSectors - 1) + SideDefs[sd].sector = NumSectors - 1; + } } MadeChanges = 1; @@ -189,7 +189,7 @@ split two linedefs, then split the sector and add a new linedef between the new vertices */ -void SplitLineDefsAndSector(int linedef1, int linedef2) /* SWAP! */ +void SplitLineDefsAndSector(int linedef1, int linedef2) /* SWAP! */ { SelPtr llist; int s1, s2, s3, s4; @@ -201,22 +201,22 @@ s3 = LineDefs[linedef2].sidedef1; s4 = LineDefs[linedef2].sidedef2; if (s1 >= 0) - s1 = SideDefs[s1].sector; + s1 = SideDefs[s1].sector; if (s2 >= 0) - s2 = SideDefs[s2].sector; + s2 = SideDefs[s2].sector; if (s3 >= 0) - s3 = SideDefs[s3].sector; + s3 = SideDefs[s3].sector; if (s4 >= 0) - s4 = SideDefs[s4].sector; + s4 = SideDefs[s4].sector; if ((s1 < 0 || (s1 != s3 && s1 != s4)) - && (s2 < 0 || (s2 != s3 && s2 != s4))) + && (s2 < 0 || (s2 != s3 && s2 != s4))) { - Beep(); - sprintf(msg, - "Linedefs #%d and #%d are not adjacent to the same sector", - linedef1, linedef2); - Notify(-1, -1, msg, NULL); - return; + Beep(); + sprintf(msg, + "Linedefs #%d and #%d are not adjacent to the same sector", + linedef1, linedef2); + Notify(-1, -1, msg, NULL); + return; } /* split the two linedefs and create two new vertices */ llist = NULL; diff -r 594dea11ccd9 -r a68786b9c74b src/s_swapf.cc --- a/src/s_swapf.cc Sat Sep 24 15:01:56 2011 +0300 +++ b/src/s_swapf.cc Sat Sep 24 15:59:33 2011 +0300 @@ -1,7 +1,7 @@ /* - * s_swapf.cc - * Swap floor and ceiling flats of sectors - * AYM 2000-08-12 + * s_swapf.cc + * Swap floor and ceiling flats of sectors + * AYM 2000-08-12 */ @@ -37,12 +37,12 @@ { for (SelPtr cur = list; cur != NULL; cur = cur->next) { - wad_flat_name_t tmp; - struct Sector *s = Sectors + cur->objnum; + wad_flat_name_t tmp; + struct Sector *s = Sectors + cur->objnum; - memcpy(tmp, s->floort, sizeof tmp); - memcpy(s->floort, s->ceilt, sizeof s->floort); - memcpy(s->ceilt, tmp, sizeof s->ceilt); - MadeChanges = 1; + memcpy(tmp, s->floort, sizeof tmp); + memcpy(s->floort, s->ceilt, sizeof s->floort); + memcpy(s->ceilt, tmp, sizeof s->ceilt); + MadeChanges = 1; } } diff -r 594dea11ccd9 -r a68786b9c74b src/s_swapf.h --- a/src/s_swapf.h Sat Sep 24 15:01:56 2011 +0300 +++ b/src/s_swapf.h Sat Sep 24 15:59:33 2011 +0300 @@ -1,7 +1,7 @@ /* - * s_swapf.h - * Swap floor and ceiling flats of sectors - * AYM 2000-08-12 + * s_swapf.h + * Swap floor and ceiling flats of sectors + * AYM 2000-08-12 */ diff -r 594dea11ccd9 -r a68786b9c74b src/s_vertices.cc --- a/src/s_vertices.cc Sat Sep 24 15:01:56 2011 +0300 +++ b/src/s_vertices.cc Sat Sep 24 15:59:33 2011 +0300 @@ -1,6 +1,6 @@ /* - * s_vertices.cc - * AYM 1998-11-22 + * s_vertices.cc + * AYM 1998-11-22 */ @@ -37,9 +37,9 @@ /* - * bv_vertices_of_sector - * Return a bit vector of all vertices used by a sector. - * It's up to the caller to delete the bit vector after use. + * bv_vertices_of_sector + * Return a bit vector of all vertices used by a sector. + * It's up to the caller to delete the bit vector after use. */ bitvec_c *bv_vertices_of_sector(obj_no_t s) { @@ -51,14 +51,14 @@ /* - * bv_vertices_of_sectors - * Return a bit vector of all vertices used by the sectors. - * It's up to the caller to delete the bit vector after use. + * bv_vertices_of_sectors + * Return a bit vector of all vertices used by the sectors. + * It's up to the caller to delete the bit vector after use. */ bitvec_c *bv_vertices_of_sectors(SelPtr list) { - bitvec_c *linedefs; // Linedefs used by the sectors - bitvec_c *vertices; // Vertices used by the linedefs + bitvec_c *linedefs; // Linedefs used by the sectors + bitvec_c *vertices; // Vertices used by the linedefs linedefs = linedefs_of_sectors(list); vertices = bv_vertices_of_linedefs(linedefs); @@ -68,9 +68,9 @@ /* - * list_vertices_of_sectors - * Return a list of all vertices used by the sectors. - * It's up to the caller to delete the list after use. + * list_vertices_of_sectors + * Return a list of all vertices used by the sectors. + * It's up to the caller to delete the list after use. */ SelPtr list_vertices_of_sectors(SelPtr list) { @@ -81,8 +81,8 @@ vertices_bitvec = bv_vertices_of_sectors(list); for (n = 0; n < vertices_bitvec->nelements(); n++) { - if (vertices_bitvec->get(n)) - SelectObject(&vertices_list, n); + if (vertices_bitvec->get(n)) + SelectObject(&vertices_list, n); } delete vertices_bitvec; return vertices_list; diff -r 594dea11ccd9 -r a68786b9c74b src/s_vertices.h --- a/src/s_vertices.h Sat Sep 24 15:01:56 2011 +0300 +++ b/src/s_vertices.h Sat Sep 24 15:59:33 2011 +0300 @@ -1,6 +1,6 @@ /* - * s_vertices.h - * AYM 1998-11-22 + * s_vertices.h + * AYM 1998-11-22 */ diff -r 594dea11ccd9 -r a68786b9c74b src/sanity.cc --- a/src/sanity.cc Sat Sep 24 15:01:56 2011 +0300 +++ b/src/sanity.cc Sat Sep 24 15:59:33 2011 +0300 @@ -1,7 +1,7 @@ /* - * sanity.cc - * Sanity checks - * AYM 1998-06-14 + * sanity.cc + * Sanity checks + * AYM 1998-06-14 */ @@ -34,29 +34,29 @@ /* - * check_types + * check_types * - * Sanity checks about the sizes and properties of certain types. - * Useful when porting. + * Sanity checks about the sizes and properties of certain types. + * Useful when porting. */ -#define assert_size(type,size) \ - do \ - { \ - if (sizeof (type) != size) \ - fatal_error ("sizeof " #type " is %d (should be " #size ")", \ - (int) sizeof (type)); \ - } \ +#define assert_size(type,size) \ + do \ + { \ + if (sizeof (type) != size) \ + fatal_error ("sizeof " #type " is %d (should be " #size ")", \ + (int) sizeof (type)); \ + } \ while (0) -#define assert_wrap(type,high,low) \ - do \ - { \ - type n = high; \ - if (++n != low) \ +#define assert_wrap(type,high,low) \ + do \ + { \ + type n = high; \ + if (++n != low) \ fatal_error ("Type " #type " wraps around to %lu (should be " #low ")",\ - (unsigned long) n); \ - } \ + (unsigned long) n); \ + } \ while (0) void check_types() @@ -82,10 +82,10 @@ /* - * check_charset + * check_charset * - * If this test fails on your platform, send me a postcard - * from your galaxy. + * If this test fails on your platform, send me a postcard + * from your galaxy. */ void check_charset() { @@ -93,21 +93,21 @@ character set even worse than EBCDIC (yet unseen). */ if ('0' + 1 != '1' - || '1' + 1 != '2' - || '2' + 1 != '3' - || '3' + 1 != '4' - || '4' + 1 != '5' - || '5' + 1 != '6' - || '6' + 1 != '7' - || '7' + 1 != '8' - || '8' + 1 != '9' - || 'a' + 1 != 'b' - || 'b' + 1 != 'c' - || 'c' + 1 != 'd' - || 'd' + 1 != 'e' - || 'e' + 1 != 'f' - || 'A' + 1 != 'B' - || 'B' + 1 != 'C' - || 'C' + 1 != 'D' || 'D' + 1 != 'E' || 'E' + 1 != 'F') - fatal_error("This platform uses a terminally broken character set"); + || '1' + 1 != '2' + || '2' + 1 != '3' + || '3' + 1 != '4' + || '4' + 1 != '5' + || '5' + 1 != '6' + || '6' + 1 != '7' + || '7' + 1 != '8' + || '8' + 1 != '9' + || 'a' + 1 != 'b' + || 'b' + 1 != 'c' + || 'c' + 1 != 'd' + || 'd' + 1 != 'e' + || 'e' + 1 != 'f' + || 'A' + 1 != 'B' + || 'B' + 1 != 'C' + || 'C' + 1 != 'D' || 'D' + 1 != 'E' || 'E' + 1 != 'F') + fatal_error("This platform uses a terminally broken character set"); } diff -r 594dea11ccd9 -r a68786b9c74b src/sanity.h --- a/src/sanity.h Sat Sep 24 15:01:56 2011 +0300 +++ b/src/sanity.h Sat Sep 24 15:59:33 2011 +0300 @@ -1,6 +1,6 @@ /* - * sanity.h - * AYM 1998-11-25 + * sanity.h + * AYM 1998-11-25 */ diff -r 594dea11ccd9 -r a68786b9c74b src/scrnshot.cc --- a/src/scrnshot.cc Sat Sep 24 15:01:56 2011 +0300 +++ b/src/scrnshot.cc Sat Sep 24 15:59:33 2011 +0300 @@ -1,9 +1,9 @@ /* - * scrnshot.cc - * This module contains the function ScreenShot() which is called - * whenever you press shift-F1 in edit mode. It is only a wrapper - * for the gifsave library. - * AYM 1997-08-20 + * scrnshot.cc + * This module contains the function ScreenShot() which is called + * whenever you press shift-F1 in edit mode. It is only a wrapper + * for the gifsave library. + * AYM 1997-08-20 */ @@ -45,7 +45,7 @@ void ScreenShot(void) #if defined Y_UNIX { - return; // FIXME + return; // FIXME } #elif defined Y_DOS { @@ -59,26 +59,26 @@ LogMessage("Writing screen shot to file yadex.gif\n"); r = GIF_Create("yadex.gif", ShotWidth, ShotHeight, 16, 3); if (r != GIF_OK) - LogMessage("GIF_Create error %d\n", r); - GIF_SetColor(0, 0, 0, 0); // BLACK - GIF_SetColor(1, 0, 0, 4); // BLUE - GIF_SetColor(2, 0, 4, 0); // GREEN - GIF_SetColor(3, 0, 4, 4); // CYAN - GIF_SetColor(4, 4, 0, 0); // RED - GIF_SetColor(5, 4, 0, 4); // MAGENTA - GIF_SetColor(6, 4, 3, 0); // BROWN - GIF_SetColor(7, 4, 4, 4); // LIGHTGREY - GIF_SetColor(8, 2, 2, 2); // DARKGREY - GIF_SetColor(9, 0, 0, 7); // LIGHTBLUE - GIF_SetColor(10, 0, 7, 0); // LIGHTGREEN - GIF_SetColor(11, 0, 7, 7); // LIGHTCYAN - GIF_SetColor(12, 7, 0, 0); // LIGHTRED - GIF_SetColor(13, 7, 0, 7); // LIGHTMAGENTA - GIF_SetColor(14, 7, 7, 0); // YELLOW - GIF_SetColor(15, 7, 7, 7); // WHITE + LogMessage("GIF_Create error %d\n", r); + GIF_SetColor(0, 0, 0, 0); // BLACK + GIF_SetColor(1, 0, 0, 4); // BLUE + GIF_SetColor(2, 0, 4, 0); // GREEN + GIF_SetColor(3, 0, 4, 4); // CYAN + GIF_SetColor(4, 4, 0, 0); // RED + GIF_SetColor(5, 4, 0, 4); // MAGENTA + GIF_SetColor(6, 4, 3, 0); // BROWN + GIF_SetColor(7, 4, 4, 4); // LIGHTGREY + GIF_SetColor(8, 2, 2, 2); // DARKGREY + GIF_SetColor(9, 0, 0, 7); // LIGHTBLUE + GIF_SetColor(10, 0, 7, 0); // LIGHTGREEN + GIF_SetColor(11, 0, 7, 7); // LIGHTCYAN + GIF_SetColor(12, 7, 0, 0); // LIGHTRED + GIF_SetColor(13, 7, 0, 7); // LIGHTMAGENTA + GIF_SetColor(14, 7, 7, 0); // YELLOW + GIF_SetColor(15, 7, 7, 7); // WHITE r = GIF_CompressImage(0, 17, ShotWidth, ShotHeight, ShotGetPixel); if (r != GIF_OK) - LogMessage("GIF_CompressImage error %d\n", r); + LogMessage("GIF_CompressImage error %d\n", r); r = GIF_Close(); LogMessage("GIF_Close returned %d\n", r); } diff -r 594dea11ccd9 -r a68786b9c74b src/selbox.cc --- a/src/selbox.cc Sat Sep 24 15:01:56 2011 +0300 +++ b/src/selbox.cc Sat Sep 24 15:59:33 2011 +0300 @@ -1,7 +1,7 @@ /* - * selbox.cc - * Selection box stuff. - * AYM 1998-07-04 + * selbox.cc + * Selection box stuff. + * AYM 1998-07-04 */ @@ -64,13 +64,13 @@ void selbox_c::get_corners(int *x1, int *y1, int *x2, int *y2) { if (x1 != NULL) - *x1 = this->x1; + *x1 = this->x1; if (y1 != NULL) - *y1 = this->y1; + *y1 = this->y1; if (x2 != NULL) - *x2 = this->x2; + *x2 = this->x2; if (y2 != NULL) - *y2 = this->y2; + *y2 = this->y2; } @@ -84,19 +84,19 @@ { if ((flags & flags_1st_corner_set) && (flags & flags_2nd_corner_set)) { - set_colour(CYAN); - SetDrawingMode(1); - DrawMapLine(x1, y1, x1, y2); - DrawMapLine(x1, y2, x2, y2); - DrawMapLine(x2, y2, x2, y1); - DrawMapLine(x2, y1, x1, y1); - SetDrawingMode(0); - /* Those are needed by undraw() */ - x1_disp = x1; - y1_disp = y1; - x2_disp = x2; - y2_disp = y2; - flags |= flags_displayed; + set_colour(CYAN); + SetDrawingMode(1); + DrawMapLine(x1, y1, x1, y2); + DrawMapLine(x1, y2, x2, y2); + DrawMapLine(x2, y2, x2, y1); + DrawMapLine(x2, y1, x1, y1); + SetDrawingMode(0); + /* Those are needed by undraw() */ + x1_disp = x1; + y1_disp = y1; + x2_disp = x2; + y2_disp = y2; + flags |= flags_displayed; } } @@ -105,14 +105,14 @@ { if (flags & flags_displayed) { - set_colour(CYAN); - SetDrawingMode(1); - DrawMapLine(x1_disp, y1_disp, x1_disp, y2_disp); - DrawMapLine(x1_disp, y2_disp, x2_disp, y2_disp); - DrawMapLine(x2_disp, y2_disp, x2_disp, y1_disp); - DrawMapLine(x2_disp, y1_disp, x1_disp, y1_disp); - SetDrawingMode(0); - flags &= ~flags_displayed; + set_colour(CYAN); + SetDrawingMode(1); + DrawMapLine(x1_disp, y1_disp, x1_disp, y2_disp); + DrawMapLine(x1_disp, y2_disp, x2_disp, y2_disp); + DrawMapLine(x2_disp, y2_disp, x2_disp, y1_disp); + DrawMapLine(x2_disp, y1_disp, x1_disp, y1_disp); + SetDrawingMode(0); + flags &= ~flags_displayed; } } diff -r 594dea11ccd9 -r a68786b9c74b src/selbox.h --- a/src/selbox.h Sat Sep 24 15:01:56 2011 +0300 +++ b/src/selbox.h Sat Sep 24 15:59:33 2011 +0300 @@ -1,8 +1,8 @@ /* - * selbox.h - * Selection box stuff. - * Header for selbox.c - * AYM 1998-07-04 + * selbox.h + * Selection box stuff. + * Header for selbox.c + * AYM 1998-07-04 */ @@ -12,7 +12,7 @@ class selbox_c:public edwidget_c { public: - /* Methods used by edit_t */ + /* Methods used by edit_t */ selbox_c(); void set_1st_corner(int x, int y); void set_2nd_corner(int x, int y); @@ -25,25 +25,25 @@ int can_undraw() { - return 1; - } // I have the ability to undraw myself + return 1; + } // I have the ability to undraw myself int need_to_clear() { - return 0; - } // I know how to undraw myself. + return 0; + } // I know how to undraw myself. void clear(); private: - int x1; /* Coordinates of the first corner */ + int x1; /* Coordinates of the first corner */ int y1; - int x2; /* Coordinates of the second corner */ + int x2; /* Coordinates of the second corner */ int y2; - int x1_disp; /* x1 and y1 as they were last time draw() was called */ + int x1_disp; /* x1 and y1 as they were last time draw() was called */ int y1_disp; - int x2_disp; /* x2 and y2 as they were last time draw() was called */ + int x2_disp; /* x2 and y2 as they were last time draw() was called */ int y2_disp; int flags; }; diff -r 594dea11ccd9 -r a68786b9c74b src/selectn.cc --- a/src/selectn.cc Sat Sep 24 15:01:56 2011 +0300 +++ b/src/selectn.cc Sat Sep 24 15:59:33 2011 +0300 @@ -1,7 +1,7 @@ /* - * selectn.cc - * Selection stuff - * AYM 1998-10-23 + * selectn.cc + * Selection stuff + * AYM 1998-10-23 */ @@ -35,26 +35,26 @@ /* - * IsSelected - test if an object is in a selection list + * IsSelected - test if an object is in a selection list * - * FIXME change the identifier - * FIXME slow + * FIXME change the identifier + * FIXME slow */ bool IsSelected(SelPtr list, int objnum) { SelPtr cur; for (cur = list; cur; cur = cur->next) - if (cur->objnum == objnum) - return true; + if (cur->objnum == objnum) + return true; return false; } /* - * DumpSelection - list the contents of a selection + * DumpSelection - list the contents of a selection * - * FIXME change the identifier + * FIXME change the identifier */ void DumpSelection(SelPtr list) { @@ -63,22 +63,22 @@ printf("Selection:"); for (n = 0, cur = list; cur; cur = cur->next, n++) - printf(" %d", cur->objnum); + printf(" %d", cur->objnum); printf(" (%d)\n", n); } /* - * SelectObject - add an object to a selection list + * SelectObject - add an object to a selection list * - * FIXME change the identifier + * FIXME change the identifier */ void SelectObject(SelPtr * list, int objnum) { SelPtr cur; if (!is_obj(objnum)) - fatal_error("BUG: SelectObject called with %d", objnum); + fatal_error("BUG: SelectObject called with %d", objnum); cur = (SelPtr) GetMemory(sizeof(struct SelectionList)); cur->next = *list; cur->objnum = objnum; @@ -87,10 +87,10 @@ /* - * select_unselect_obj - add or remove an object from a selection list + * select_unselect_obj - add or remove an object from a selection list * - * If the object is not in the selection list, add it. If - * it already is, remove it. + * If the object is not in the selection list, add it. If + * it already is, remove it. */ void select_unselect_obj(SelPtr * list, int objnum) { @@ -98,22 +98,22 @@ SelPtr prev; if (!is_obj(objnum)) - fatal_error("s/u_obj called with %d", objnum); + fatal_error("s/u_obj called with %d", objnum); for (prev = NULL, cur = *list; cur != NULL; prev = cur, cur = cur->next) - // Already selected: unselect it. - if (cur->objnum == objnum) - { - if (prev != NULL) - prev->next = cur->next; - else - *list = cur->next; - FreeMemory(cur); - if (prev != NULL) - cur = prev->next; - else - cur = (SelPtr) NULL; - return; - } + // Already selected: unselect it. + if (cur->objnum == objnum) + { + if (prev != NULL) + prev->next = cur->next; + else + *list = cur->next; + FreeMemory(cur); + if (prev != NULL) + cur = prev->next; + else + cur = (SelPtr) NULL; + return; + } // Not selected: select it. cur = (SelPtr) GetMemory(sizeof(struct SelectionList)); @@ -124,45 +124,45 @@ /* - * UnSelectObject - remove an object from a selection list + * UnSelectObject - remove an object from a selection list * - * FIXME change the identifier + * FIXME change the identifier */ void UnSelectObject(SelPtr * list, int objnum) { SelPtr cur, prev; if (!is_obj(objnum)) - fatal_error("BUG: UnSelectObject called with %d", objnum); + fatal_error("BUG: UnSelectObject called with %d", objnum); prev = 0; cur = *list; while (cur) { - if (cur->objnum == objnum) - { - if (prev) - prev->next = cur->next; - else - *list = cur->next; - FreeMemory(cur); - if (prev) - cur = prev->next; - else - cur = 0; - } - else - { - prev = cur; - cur = cur->next; - } + if (cur->objnum == objnum) + { + if (prev) + prev->next = cur->next; + else + *list = cur->next; + FreeMemory(cur); + if (prev) + cur = prev->next; + else + cur = 0; + } + else + { + prev = cur; + cur = cur->next; + } } } /* - * ForgetSelection - clear a selection list + * ForgetSelection - clear a selection list * - * FIXME change the identifier + * FIXME change the identifier */ void ForgetSelection(SelPtr * list) { @@ -171,19 +171,19 @@ cur = *list; while (cur) { - prev = cur; - cur = cur->next; - FreeMemory(prev); + prev = cur; + cur = cur->next; + FreeMemory(prev); } *list = 0; } /* - * list_to_bitvec - make a bit vector from a list + * list_to_bitvec - make a bit vector from a list * - * The bit vector has <bitvec_size> elements. It's up to - * the caller to delete the new bit vector after use. + * The bit vector has <bitvec_size> elements. It's up to + * the caller to delete the new bit vector after use. */ bitvec_c *list_to_bitvec(SelPtr list, size_t bitvec_size) { @@ -192,23 +192,23 @@ bitvec = new bitvec_c(bitvec_size); for (cur = list; cur; cur = cur->next) - bitvec->set(cur->objnum); + bitvec->set(cur->objnum); return bitvec; } /* - * bitvec_to_list - make a list from a bitvec object + * bitvec_to_list - make a list from a bitvec object * - * The items are inserted in the list from first to last - * (i.e. item N in the bitvec is inserted before item N+1). - * It's up to the caller to delete the new list after use. + * The items are inserted in the list from first to last + * (i.e. item N in the bitvec is inserted before item N+1). + * It's up to the caller to delete the new list after use. */ SelPtr bitvec_to_list(const bitvec_c & b) { SelPtr list = 0; for (size_t n = 0; n < b.nelements(); n++) - if (b.get(n)) - SelectObject(&list, n); + if (b.get(n)) + SelectObject(&list, n); return list; } diff -r 594dea11ccd9 -r a68786b9c74b src/selectn.h --- a/src/selectn.h Sat Sep 24 15:01:56 2011 +0300 +++ b/src/selectn.h Sat Sep 24 15:59:33 2011 +0300 @@ -1,11 +1,11 @@ /* - * selectn.h - * Selection stuff - * AYM 1998-10-23 + * selectn.h + * Selection stuff + * AYM 1998-10-23 */ -#ifndef YH_SELECTN /* DO NOT INSERT ANYTHING BEFORE THIS LINE */ +#ifndef YH_SELECTN /* DO NOT INSERT ANYTHING BEFORE THIS LINE */ #define YH_SELECTN @@ -16,8 +16,8 @@ typedef struct SelectionList *SelPtr; struct SelectionList { - SelPtr next; // Next in list - int objnum; // Object number + SelPtr next; // Next in list + int objnum; // Object number }; bool IsSelected(SelPtr, int); diff -r 594dea11ccd9 -r a68786b9c74b src/selpath.cc --- a/src/selpath.cc Sat Sep 24 15:01:56 2011 +0300 +++ b/src/selpath.cc Sat Sep 24 15:59:33 2011 +0300 @@ -1,7 +1,7 @@ /* - * selpath.cc - * Select all linedefs that form a path. - * AYM 1999-03-24 + * selpath.cc + * Select all linedefs that form a path. + * AYM 1999-03-24 */ @@ -37,32 +37,32 @@ static void select_linedefs_in_half_path(bitvec_c & sel, - bitvec_c & ldseen, - int linedef_no, - int vertex_no, sel_op_t mode); + bitvec_c & ldseen, + int linedef_no, + int vertex_no, sel_op_t mode); static void select_1s_linedefs_in_half_path(bitvec_c & sel, - bitvec_c & ldseen, - int linedef_no, - int vertex_no, sel_op_t mode); + bitvec_c & ldseen, + int linedef_no, + int vertex_no, sel_op_t mode); /* - * select_linedefs_path - * Add to selection <list> all linedefs in the same path as - * linedef <linedef_no>, stopping at forks. If <mode> is not - * YS_ADD but YS_REMOVE, those linedefs are removed from - * the selection. If <mode> is YS_TOGGLE, each linedef is - * removed if it was already in the selection, otherwise - * added. + * select_linedefs_path + * Add to selection <list> all linedefs in the same path as + * linedef <linedef_no>, stopping at forks. If <mode> is not + * YS_ADD but YS_REMOVE, those linedefs are removed from + * the selection. If <mode> is YS_TOGGLE, each linedef is + * removed if it was already in the selection, otherwise + * added. */ void select_linedefs_path(SelPtr * list, int linedef_no, sel_op_t mode) { bitvec_c *ldsel = list_to_bitvec(*list, NumLineDefs); - bitvec_c ldseen(NumLineDefs); // Linedef already seen ? + bitvec_c ldseen(NumLineDefs); // Linedef already seen ? - if (!is_obj(linedef_no)) // Sanity check - fatal_error("select_linedef_path called with bad linedef_no=%d", - linedef_no); + if (!is_obj(linedef_no)) // Sanity check + fatal_error("select_linedef_path called with bad linedef_no=%d", + linedef_no); LDPtr ld = LineDefs + linedef_no; ldsel->frob(linedef_no, (bitvec_op_t) mode); @@ -76,18 +76,18 @@ /* - * select_linedefs_in_half_path - * The routine looks for all linedefs other than linedef_no - * that use vertex vertex_no. If there are none or more - * than one, the search stop there and the function returns - * without doing nothing. If there is exactly one, it is - * added to the list sel and the function recursively calls - * itself on the other vertex of that linedef. + * select_linedefs_in_half_path + * The routine looks for all linedefs other than linedef_no + * that use vertex vertex_no. If there are none or more + * than one, the search stop there and the function returns + * without doing nothing. If there is exactly one, it is + * added to the list sel and the function recursively calls + * itself on the other vertex of that linedef. */ static void select_linedefs_in_half_path(bitvec_c & ldsel, - bitvec_c & ldseen, - int linedef_no, - int vertex_no, sel_op_t mode) + bitvec_c & ldseen, + int linedef_no, + int vertex_no, sel_op_t mode) { int next_linedef_no = OBJ_NO_NONE; int next_vertex_no = OBJ_NO_NONE; @@ -97,69 +97,69 @@ // linedef_no. for (int n = 0; n < NumLineDefs; n++) { - if (n == linedef_no) - continue; - if (LineDefs[n].start == vertex_no) - { - if (is_obj(next_linedef_no)) - return; // There is a fork in the path. Stop here. - // Continue search at the other end of the linedef - next_vertex_no = LineDefs[n].end; - next_linedef_no = n; - } - if (LineDefs[n].end == vertex_no) - { - if (is_obj(next_linedef_no)) - return; // There is a fork in the path. Stop here. - // Continue search at the other end of the linedef - next_vertex_no = LineDefs[n].start; - next_linedef_no = n; - } + if (n == linedef_no) + continue; + if (LineDefs[n].start == vertex_no) + { + if (is_obj(next_linedef_no)) + return; // There is a fork in the path. Stop here. + // Continue search at the other end of the linedef + next_vertex_no = LineDefs[n].end; + next_linedef_no = n; + } + if (LineDefs[n].end == vertex_no) + { + if (is_obj(next_linedef_no)) + return; // There is a fork in the path. Stop here. + // Continue search at the other end of the linedef + next_vertex_no = LineDefs[n].start; + next_linedef_no = n; + } } - if (!is_obj(next_linedef_no)) // None ? Reached end of path. - return; + if (!is_obj(next_linedef_no)) // None ? Reached end of path. + return; // Already seen the next linedef ? The path must be // closed. No need to do like the Dupondt. if (ldseen.get(next_linedef_no)) - return; + return; ldsel.frob(next_linedef_no, (bitvec_op_t) mode); ldseen.set(next_linedef_no); select_linedefs_in_half_path(ldsel, ldseen, next_linedef_no, - next_vertex_no, mode); + next_vertex_no, mode); } /* - * select_1s_linedefs_path + * select_1s_linedefs_path * - * Add to selection <list> all linedefs in the same path as - * linedef <linedef_no>, stopping at forks. If <mode> is not - * YS_ADD but YS_REMOVE, those linedefs are removed from - * the selection. If <mode> is YS_TOGGLE, each linedef is - * removed if it was already in the selection, otherwise - * added. + * Add to selection <list> all linedefs in the same path as + * linedef <linedef_no>, stopping at forks. If <mode> is not + * YS_ADD but YS_REMOVE, those linedefs are removed from + * the selection. If <mode> is YS_TOGGLE, each linedef is + * removed if it was already in the selection, otherwise + * added. */ void select_1s_linedefs_path(SelPtr * list, int linedef_no, sel_op_t mode) { bitvec_c *ldsel = list_to_bitvec(*list, NumLineDefs); - bitvec_c ldseen(NumLineDefs); // Linedef already seen ? + bitvec_c ldseen(NumLineDefs); // Linedef already seen ? - if (!is_obj(linedef_no)) // Sanity check - fatal_error("select_linedef_path called with bad linedef_no=%d", - linedef_no); + if (!is_obj(linedef_no)) // Sanity check + fatal_error("select_linedef_path called with bad linedef_no=%d", + linedef_no); LDPtr ld = LineDefs + linedef_no; - if (!is_obj(ld->sidedef1) // The first linedef is not single-sided. Quit. - || is_obj(ld->sidedef2)) - goto byebye; + if (!is_obj(ld->sidedef1) // The first linedef is not single-sided. Quit. + || is_obj(ld->sidedef2)) + goto byebye; ldsel->frob(linedef_no, (bitvec_op_t) mode); ldseen.set(linedef_no); select_1s_linedefs_in_half_path(*ldsel, ldseen, linedef_no, ld->start, - mode); + mode); select_1s_linedefs_in_half_path(*ldsel, ldseen, linedef_no, ld->end, - mode); + mode); ForgetSelection(list); *list = bitvec_to_list(*ldsel); byebye: @@ -168,14 +168,14 @@ /* - * select_1s_linedefs_in_half_path - * Like select_linedefs_in_half_path() except that only - * single-sided linedefs are selected. + * select_1s_linedefs_in_half_path + * Like select_linedefs_in_half_path() except that only + * single-sided linedefs are selected. */ static void select_1s_linedefs_in_half_path(bitvec_c & ldsel, - bitvec_c & ldseen, - int linedef_no, - int vertex_no, sel_op_t mode) + bitvec_c & ldseen, + int linedef_no, + int vertex_no, sel_op_t mode) { int next_linedef_no = OBJ_NO_NONE; int next_vertex_no = OBJ_NO_NONE; @@ -185,37 +185,37 @@ // linedef_no. for (int n = 0; n < NumLineDefs; n++) { - if (n == linedef_no) - continue; - if (LineDefs[n].start == vertex_no - && is_obj(LineDefs[n].sidedef1) && !is_obj(LineDefs[n].sidedef2)) - { - if (is_obj(next_linedef_no)) - return; // There is a fork in the path. Stop here. - // Continue search at the other end of the linedef - next_vertex_no = LineDefs[n].end; - next_linedef_no = n; - } - if (LineDefs[n].end == vertex_no - && is_obj(LineDefs[n].sidedef1) && !is_obj(LineDefs[n].sidedef2)) - { - if (is_obj(next_linedef_no)) - return; // There is a fork in the path. Stop here. - // Continue search at the other end of the linedef - next_vertex_no = LineDefs[n].start; - next_linedef_no = n; - } + if (n == linedef_no) + continue; + if (LineDefs[n].start == vertex_no + && is_obj(LineDefs[n].sidedef1) && !is_obj(LineDefs[n].sidedef2)) + { + if (is_obj(next_linedef_no)) + return; // There is a fork in the path. Stop here. + // Continue search at the other end of the linedef + next_vertex_no = LineDefs[n].end; + next_linedef_no = n; + } + if (LineDefs[n].end == vertex_no + && is_obj(LineDefs[n].sidedef1) && !is_obj(LineDefs[n].sidedef2)) + { + if (is_obj(next_linedef_no)) + return; // There is a fork in the path. Stop here. + // Continue search at the other end of the linedef + next_vertex_no = LineDefs[n].start; + next_linedef_no = n; + } } - if (!is_obj(next_linedef_no)) // None ? Reached end of path. - return; + if (!is_obj(next_linedef_no)) // None ? Reached end of path. + return; // Already seen the next linedef ? The path must be // closed. No need to do like the Dupondt. if (ldseen.get(next_linedef_no)) - return; + return; ldsel.frob(next_linedef_no, (bitvec_op_t) mode); ldseen.set(next_linedef_no); select_1s_linedefs_in_half_path(ldsel, ldseen, next_linedef_no, - next_vertex_no, mode); + next_vertex_no, mode); } diff -r 594dea11ccd9 -r a68786b9c74b src/selpath.h --- a/src/selpath.h Sat Sep 24 15:01:56 2011 +0300 +++ b/src/selpath.h Sat Sep 24 15:59:33 2011 +0300 @@ -1,7 +1,7 @@ /* - * selpath.h - * Select linedefs in path. - * AYM 1999-03-24 + * selpath.h + * Select linedefs in path. + * AYM 1999-03-24 */ diff -r 594dea11ccd9 -r a68786b9c74b src/selrect.cc --- a/src/selrect.cc Sat Sep 24 15:01:56 2011 +0300 +++ b/src/selrect.cc Sat Sep 24 15:59:33 2011 +0300 @@ -1,6 +1,6 @@ /* - * selrect.cc - * AYM 1999-03-24 + * selrect.cc + * AYM 1999-03-24 */ @@ -38,109 +38,109 @@ select all objects inside a given box */ -void SelectObjectsInBox(SelPtr * list, int objtype, int x0, int y0, int x1, int y1) /* SWAP! */ +void SelectObjectsInBox(SelPtr * list, int objtype, int x0, int y0, int x1, int y1) /* SWAP! */ { int n, m; if (x1 < x0) { - n = x0; - x0 = x1; - x1 = n; + n = x0; + x0 = x1; + x1 = n; } if (y1 < y0) { - n = y0; - y0 = y1; - y1 = n; + n = y0; + y0 = y1; + y1 = n; } switch (objtype) { case OBJ_THINGS: - for (n = 0; n < NumThings; n++) - if (Things[n].xpos >= x0 && Things[n].xpos <= x1 - && Things[n].ypos >= y0 && Things[n].ypos <= y1) - select_unselect_obj(list, n); - break; + for (n = 0; n < NumThings; n++) + if (Things[n].xpos >= x0 && Things[n].xpos <= x1 + && Things[n].ypos >= y0 && Things[n].ypos <= y1) + select_unselect_obj(list, n); + break; case OBJ_VERTICES: - for (n = 0; n < NumVertices; n++) - if (Vertices[n].x >= x0 && Vertices[n].x <= x1 - && Vertices[n].y >= y0 && Vertices[n].y <= y1) - select_unselect_obj(list, n); - break; + for (n = 0; n < NumVertices; n++) + if (Vertices[n].x >= x0 && Vertices[n].x <= x1 + && Vertices[n].y >= y0 && Vertices[n].y <= y1) + select_unselect_obj(list, n); + break; case OBJ_LINEDEFS: - for (n = 0; n < NumLineDefs; n++) - { - /* the two ends of the line must be in the box */ - m = LineDefs[n].start; - if (Vertices[m].x < x0 || Vertices[m].x > x1 - || Vertices[m].y < y0 || Vertices[m].y > y1) - continue; - m = LineDefs[n].end; - if (Vertices[m].x < x0 || Vertices[m].x > x1 - || Vertices[m].y < y0 || Vertices[m].y > y1) - continue; - select_unselect_obj(list, n); - } - break; + for (n = 0; n < NumLineDefs; n++) + { + /* the two ends of the line must be in the box */ + m = LineDefs[n].start; + if (Vertices[m].x < x0 || Vertices[m].x > x1 + || Vertices[m].y < y0 || Vertices[m].y > y1) + continue; + m = LineDefs[n].end; + if (Vertices[m].x < x0 || Vertices[m].x > x1 + || Vertices[m].y < y0 || Vertices[m].y > y1) + continue; + select_unselect_obj(list, n); + } + break; case OBJ_SECTORS: - { - signed char *sector_status; - LDPtr ld; + { + signed char *sector_status; + LDPtr ld; - sector_status = (signed char *) GetMemory(NumSectors); - memset(sector_status, 0, NumSectors); - for (n = 0, ld = LineDefs; n < NumLineDefs; n++, ld++) - { - VPtr v1, v2; - int s1, s2; + sector_status = (signed char *) GetMemory(NumSectors); + memset(sector_status, 0, NumSectors); + for (n = 0, ld = LineDefs; n < NumLineDefs; n++, ld++) + { + VPtr v1, v2; + int s1, s2; - v1 = Vertices + ld->start; - v2 = Vertices + ld->end; + v1 = Vertices + ld->start; + v2 = Vertices + ld->end; - // Get the numbers of the sectors on both sides of the linedef - if (is_sidedef(ld->sidedef1) - && is_sector(SideDefs[ld->sidedef1].sector)) - s1 = SideDefs[ld->sidedef1].sector; - else - s1 = OBJ_NO_NONE; - if (is_sidedef(ld->sidedef2) - && is_sector(SideDefs[ld->sidedef2].sector)) - s2 = SideDefs[ld->sidedef2].sector; - else - s2 = OBJ_NO_NONE; + // Get the numbers of the sectors on both sides of the linedef + if (is_sidedef(ld->sidedef1) + && is_sector(SideDefs[ld->sidedef1].sector)) + s1 = SideDefs[ld->sidedef1].sector; + else + s1 = OBJ_NO_NONE; + if (is_sidedef(ld->sidedef2) + && is_sector(SideDefs[ld->sidedef2].sector)) + s2 = SideDefs[ld->sidedef2].sector; + else + s2 = OBJ_NO_NONE; - // The linedef is entirely within bounds. - // The sectors it touches _might_ be within bounds too. - if (v1->x >= x0 && v1->x <= x1 - && v1->y >= y0 && v1->y <= y1 - && v2->x >= x0 && v2->x <= x1 - && v2->y >= y0 && v2->y <= y1) - { - if (is_sector(s1) && sector_status[s1] >= 0) - sector_status[s1] = 1; - if (is_sector(s2) && sector_status[s2] >= 0) - sector_status[s2] = 1; - } + // The linedef is entirely within bounds. + // The sectors it touches _might_ be within bounds too. + if (v1->x >= x0 && v1->x <= x1 + && v1->y >= y0 && v1->y <= y1 + && v2->x >= x0 && v2->x <= x1 + && v2->y >= y0 && v2->y <= y1) + { + if (is_sector(s1) && sector_status[s1] >= 0) + sector_status[s1] = 1; + if (is_sector(s2) && sector_status[s2] >= 0) + sector_status[s2] = 1; + } - // It's not. The sectors it touches _can't_ be within bounds. - else - { - if (is_sector(s1)) - sector_status[s1] = -1; - if (is_sector(s2)) - sector_status[s2] = -1; - } - } + // It's not. The sectors it touches _can't_ be within bounds. + else + { + if (is_sector(s1)) + sector_status[s1] = -1; + if (is_sector(s2)) + sector_status[s2] = -1; + } + } - // Now select all the sectors we found to be within bounds - ForgetSelection(list); - for (n = 0; n < NumSectors; n++) - if (sector_status[n] > 0) - SelectObject(list, n); - FreeMemory(sector_status); - } - break; + // Now select all the sectors we found to be within bounds + ForgetSelection(list); + for (n = 0; n < NumSectors; n++) + if (sector_status[n] > 0) + SelectObject(list, n); + FreeMemory(sector_status); + } + break; } } diff -r 594dea11ccd9 -r a68786b9c74b src/serialnum.cc --- a/src/serialnum.cc Sat Sep 24 15:01:56 2011 +0300 +++ b/src/serialnum.cc Sat Sep 24 15:59:33 2011 +0300 @@ -1,7 +1,7 @@ /* - * serialnum.cc - * Serial_num class - * AYM 2000-04-06 + * serialnum.cc + * Serial_num class + * AYM 2000-04-06 */ @@ -40,7 +40,7 @@ /* - * stale - call this to check whether a serial number has become stale + * stale - call this to check whether a serial number has become stale */ bool Serial_num::outdated(const serial_num_t & token) { @@ -49,7 +49,7 @@ /* - * update - get the revision number + * update - get the revision number */ void Serial_num::update(serial_num_t & token) { @@ -59,19 +59,19 @@ /* - * bump - call this to increment the revision number + * bump - call this to increment the revision number */ void Serial_num::bump() { /* If no one uses the current serial number, bumping it would be a waste of S/N space. */ if (!serial_is_used) - return; + return; serial_no++; serial_is_used = false; - if (serial_no == 0) // Extremely unlikely to ever happen + if (serial_no == 0) // Extremely unlikely to ever happen { - nf_bug("Serial_num(%p)::serial_no wrapped around", this); + nf_bug("Serial_num(%p)::serial_no wrapped around", this); } } diff -r 594dea11ccd9 -r a68786b9c74b src/serialnum.h --- a/src/serialnum.h Sat Sep 24 15:01:56 2011 +0300 +++ b/src/serialnum.h Sat Sep 24 15:59:33 2011 +0300 @@ -1,7 +1,7 @@ /* - * serialnum.h - * Serial_num class - * AYM 2000-04-06 + * serialnum.h + * Serial_num class + * AYM 2000-04-06 */ @@ -28,7 +28,7 @@ */ -#ifndef YH_SERIALNUM /* DO NOT INSERT ANYTHING BEFORE THIS LINE */ +#ifndef YH_SERIALNUM /* DO NOT INSERT ANYTHING BEFORE THIS LINE */ #define YH_SERIALNUM diff -r 594dea11ccd9 -r a68786b9c74b src/spot.h --- a/src/spot.h Sat Sep 24 15:01:56 2011 +0300 +++ b/src/spot.h Sat Sep 24 15:59:33 2011 +0300 @@ -1,6 +1,6 @@ /* - * spot.h - * AYM 1998-12-14 + * spot.h + * AYM 1998-12-14 */ @@ -34,19 +34,19 @@ class spot_c:public edwidget_c { public: - /* - * Specific to this class - */ + /* + * Specific to this class + */ spot_c() { - visible = 0; - visible_disp = 0; + visible = 0; + visible_disp = 0; } void set(int x, int y) { - this->x = x; - this->y = y; - visible = 1; + this->x = x; + this->y = y; + visible = 1; } /* @@ -54,48 +54,48 @@ */ void unset() { - visible = 0; + visible = 0; } void draw() { - if (visible && (!visible_disp || x_disp != x || y_disp != y)) - { - SetDrawingMode(1); - push_colour(LIGHTGREEN); - draw_map_point(x, y); - pop_colour(); - SetDrawingMode(0); - visible_disp = 1; - x_disp = x; - y_disp = y; - } + if (visible && (!visible_disp || x_disp != x || y_disp != y)) + { + SetDrawingMode(1); + push_colour(LIGHTGREEN); + draw_map_point(x, y); + pop_colour(); + SetDrawingMode(0); + visible_disp = 1; + x_disp = x; + y_disp = y; + } } void undraw() { - if (visible_disp) - { - SetDrawingMode(1); - push_colour(LIGHTGREEN); - draw_map_point(x_disp, y_disp); - pop_colour(); - SetDrawingMode(0); - visible_disp = 0; - } + if (visible_disp) + { + SetDrawingMode(1); + push_colour(LIGHTGREEN); + draw_map_point(x_disp, y_disp); + pop_colour(); + SetDrawingMode(0); + visible_disp = 0; + } } int can_undraw() { - return 1; + return 1; } int need_to_clear() { - return 0; + return 0; } void clear() { - visible_disp = 0; + visible_disp = 0; } private: diff -r 594dea11ccd9 -r a68786b9c74b src/spritdir.cc --- a/src/spritdir.cc Sat Sep 24 15:01:56 2011 +0300 +++ b/src/spritdir.cc Sat Sep 24 15:59:33 2011 +0300 @@ -1,6 +1,6 @@ /* - * spritdir.cc - Sprite_dir class - * AYM 2000-06-01 + * spritdir.cc - Sprite_dir class + * AYM 2000-06-01 */ @@ -37,8 +37,8 @@ /* - * Sprite_dir::loc_by_root - find sprite by prefix - * + * Sprite_dir::loc_by_root - find sprite by prefix + * * Return the (wad, offset, length) location of the first * lump by alphabetical order whose name begins with * <name>. If not found, set loc.wad to 0. @@ -46,20 +46,20 @@ void Sprite_dir::loc_by_root(const char *name, Lump_loc & loc) { if (dependency->outdated()) - refresh(); + refresh(); /* Caller asked for same lump twice in a row. Save us a second search. */ if (have_prev && !y_strnicmp(name, name_prev, WAD_NAME)) { - loc = loc_prev; - return; + loc = loc_prev; + return; } Lump_map::const_iterator i = lump_map.lower_bound(name); have_prev = true; if (i == lump_map.end() || y_strnicmp(name, i->first.name, strlen(name))) - loc.wad = loc_prev.wad = 0; + loc.wad = loc_prev.wad = 0; else - loc = loc_prev = i->second; + loc = loc_prev = i->second; } diff -r 594dea11ccd9 -r a68786b9c74b src/spritdir.h --- a/src/spritdir.h Sat Sep 24 15:01:56 2011 +0300 +++ b/src/spritdir.h Sat Sep 24 15:59:33 2011 +0300 @@ -1,7 +1,7 @@ /* - * spritdir.h - * Sprite_dir class - * AYM 2000-05-31 + * spritdir.h + * Sprite_dir class + * AYM 2000-05-31 */ @@ -28,7 +28,7 @@ */ -#ifndef YH_SPRITDIR /* DO NOT INSERT ANYTHING BEFORE THIS LINE */ +#ifndef YH_SPRITDIR /* DO NOT INSERT ANYTHING BEFORE THIS LINE */ #define YH_SPRITDIR @@ -36,11 +36,11 @@ /* - * Sprite_dir + * Sprite_dir * - * This is a specialization of Lump_dir that has an - * additional method : loc_by_root() which retrieves the - * first entry whose name begins with the argument. + * This is a specialization of Lump_dir that has an + * additional method : loc_by_root() which retrieves the + * first entry whose name begins with the argument. */ diff -r 594dea11ccd9 -r a68786b9c74b src/sticker.cc --- a/src/sticker.cc Sat Sep 24 15:01:56 2011 +0300 +++ b/src/sticker.cc Sat Sep 24 15:59:33 2011 +0300 @@ -1,6 +1,6 @@ /* - * sticker.cc - Sticker class - * AYM 2000-07-06 + * sticker.cc - Sticker class + * AYM 2000-07-06 */ @@ -29,7 +29,7 @@ #include "yadex.h" #include <X11/Xlib.h> -#include <X11/Xutil.h> // XDestroyImage +#include <X11/Xutil.h> // XDestroyImage #include "gcolour2.h" #include "gcolour3.h" #include "gfx.h" @@ -49,14 +49,14 @@ bool has_data; int width; int height; - XImage *ximage; // Used only if opaque - Pixmap pixmap; // Used only if not opaque - Pixmap mask; // Used only if not opaque + XImage *ximage; // Used only if opaque + Pixmap pixmap; // Used only if not opaque + Pixmap mask; // Used only if not opaque }; /* - * Sticker::Sticker - create an empty Sticker + * Sticker::Sticker - create an empty Sticker */ Sticker::Sticker() { @@ -65,7 +65,7 @@ /* - * Sticker::Sticker - create a Sticker from an Img + * Sticker::Sticker - create a Sticker from an Img */ Sticker::Sticker(const Img & img, bool opaque) { @@ -75,7 +75,7 @@ /* - * Sticker::~Sticker - destroy a Sticker + * Sticker::~Sticker - destroy a Sticker */ Sticker::~Sticker() { @@ -84,7 +84,7 @@ /* - * Sticker::is_clear - tells whether a sprite is "empty" + * Sticker::is_clear - tells whether a sprite is "empty" */ bool Sticker::is_clear() { @@ -93,7 +93,7 @@ /* - * Sticker::clear - clear a Sticker + * Sticker::clear - clear a Sticker */ void Sticker::clear() { @@ -102,7 +102,7 @@ /* - * Sticker::load - load an Img into a Sticker + * Sticker::load - load an Img into a Sticker */ void Sticker::load(const Img & img, bool opaque) { @@ -111,26 +111,26 @@ /* - * Sticker::draw - draw a Sticker + * Sticker::draw - draw a Sticker */ void Sticker::draw(Drawable drw, char grav, int x, int y) { if (!priv->has_data) - return; + return; int x0 = grav == 'c' ? x - priv->width / 2 : x; int y0 = grav == 'c' ? y - priv->height / 2 : y; if (priv->opaque) { - XPutImage(dpy, drw, gc, priv->ximage, 0, 0, - x0, y0, priv->width, priv->height); + XPutImage(dpy, drw, gc, priv->ximage, 0, 0, + x0, y0, priv->width, priv->height); } else { - XSetClipMask(dpy, gc, priv->mask); - XSetClipOrigin(dpy, gc, x0, y0); - XCopyArea(dpy, priv->pixmap, drw, gc, 0, 0, priv->width, - priv->height, x0, y0); - XSetClipMask(dpy, gc, None); + XSetClipMask(dpy, gc, priv->mask); + XSetClipOrigin(dpy, gc, x0, y0); + XCopyArea(dpy, priv->pixmap, drw, gc, 0, 0, priv->width, + priv->height, x0, y0); + XSetClipMask(dpy, gc, None); } } @@ -151,16 +151,16 @@ { if (has_data) { - if (opaque) - { - XDestroyImage(ximage); // Also frees buf. - } - else - { - XFreePixmap(dpy, pixmap); - XFreePixmap(dpy, mask); - } - has_data = false; + if (opaque) + { + XDestroyImage(ximage); // Also frees buf. + } + else + { + XFreePixmap(dpy, pixmap); + XFreePixmap(dpy, mask); + } + has_data = false; } } @@ -173,259 +173,259 @@ width = img.width(); height = img.height(); if (width < 1 || height < 1) - return; // Can't create Pixmaps with null dimensions... + return; // Can't create Pixmaps with null dimensions... if (opaque) { - ximage = make_ximage(img); - if (ximage != 0) - has_data = true; + ximage = make_ximage(img); + if (ximage != 0) + has_data = true; } else { - // Create a pixmap and copy the image onto it. - pixmap = XCreatePixmap(dpy, win, width, height, win_depth); - XImage *image = make_ximage(img); - if (image != 0) - { - XPutImage(dpy, pixmap, gc, image, 0, 0, 0, 0, width, height); - XDestroyImage(image); - } + // Create a pixmap and copy the image onto it. + pixmap = XCreatePixmap(dpy, win, width, height, win_depth); + XImage *image = make_ximage(img); + if (image != 0) + { + XPutImage(dpy, pixmap, gc, image, 0, 0, 0, 0, width, height); + XDestroyImage(image); + } - // Create the mask pixmap and copy the silhouette onto it. - mask = XCreatePixmap(dpy, win, width, height, 1); - XImage *mask_image = make_bitmap(img); - if (mask_image != 0) - { - GC mask_gc = XCreateGC(dpy, mask, 0, 0); - XSetBackground(dpy, mask_gc, 0); - XSetForeground(dpy, mask_gc, 1); - XPutImage(dpy, mask, mask_gc, mask_image, 0, 0, 0, 0, width, - height); - XFreeGC(dpy, mask_gc); - XDestroyImage(mask_image); - } + // Create the mask pixmap and copy the silhouette onto it. + mask = XCreatePixmap(dpy, win, width, height, 1); + XImage *mask_image = make_bitmap(img); + if (mask_image != 0) + { + GC mask_gc = XCreateGC(dpy, mask, 0, 0); + XSetBackground(dpy, mask_gc, 0); + XSetForeground(dpy, mask_gc, 1); + XPutImage(dpy, mask, mask_gc, mask_image, 0, 0, 0, 0, width, + height); + XFreeGC(dpy, mask_gc); + XDestroyImage(mask_image); + } - has_data = true; + has_data = true; } } /* - * Sticker_priv:ximage - create XImage from Img + * Sticker_priv:ximage - create XImage from Img * - * Return pointer to XImage on success, null pointer on - * failure. + * Return pointer to XImage on success, null pointer on + * failure. */ XImage *Sticker_priv::make_ximage(const Img & img) { // How many bytes per line do we need ? size_t bytes_per_line = width * ximage_bpp; - if (ximage_quantum == 0) // Paranoia + if (ximage_quantum == 0) // Paranoia { - nf_bug("ximage_quantum == 0"); - ximage_quantum = 1; + nf_bug("ximage_quantum == 0"); + ximage_quantum = 1; } size_t padding = 0; while (bytes_per_line % ximage_quantum) { - bytes_per_line++; - padding++; + bytes_per_line++; + padding++; } u8 *buf = (u8 *) GetMemory((unsigned long) bytes_per_line * height); if (!buf) { - err("Not enough memory to display %dx%d image", width, height); - return 0; + err("Not enough memory to display %dx%d image", width, height); + return 0; } // Copy the Img onto the XImage. const img_pixel_t *image_end = img.buf() + width * height; if (ximage_bpp == 1) { - register const img_pixel_t *image_ptr; - register u8 *buf_ptr = (u8 *) buf; - if (padding == 0) - { - for (image_ptr = img.buf(); image_ptr < image_end; image_ptr++) - *buf_ptr++ = (u8) game_colour[*image_ptr]; - } - else - { - const img_pixel_t *image_line_end; - int img_width = width; - for (image_ptr = image_line_end = img.buf(); - image_ptr < image_end;) - { - image_line_end += img_width; - for (; image_ptr < image_line_end; image_ptr++) - *buf_ptr++ = (u8) game_colour[*image_ptr]; - buf_ptr += padding; // Line padding - } - } + register const img_pixel_t *image_ptr; + register u8 *buf_ptr = (u8 *) buf; + if (padding == 0) + { + for (image_ptr = img.buf(); image_ptr < image_end; image_ptr++) + *buf_ptr++ = (u8) game_colour[*image_ptr]; + } + else + { + const img_pixel_t *image_line_end; + int img_width = width; + for (image_ptr = image_line_end = img.buf(); + image_ptr < image_end;) + { + image_line_end += img_width; + for (; image_ptr < image_line_end; image_ptr++) + *buf_ptr++ = (u8) game_colour[*image_ptr]; + buf_ptr += padding; // Line padding + } + } } else if (ximage_bpp == 2) { - register const img_pixel_t *image_ptr; - register u16 *buf_ptr = (u16 *) buf; - if (cpu_big_endian == x_server_big_endian) - { - if (padding == 0) - { - for (image_ptr = img.buf(); image_ptr < image_end; - image_ptr++) - *buf_ptr++ = (u16) game_colour[*image_ptr]; - } - else - { - const img_pixel_t *image_line_end; - int img_width = width; - for (image_ptr = image_line_end = img.buf(); - image_ptr < image_end;) - { - image_line_end += img_width; - for (; image_ptr < image_line_end; image_ptr++) - *buf_ptr++ = (u16) game_colour[*image_ptr]; - buf_ptr = (u16 *) ((char *) buf_ptr + padding); // Line padding - } - } - } - else // Different endiannesses so swap bytes - { - if (padding == 0) - { - for (image_ptr = img.buf(); image_ptr < image_end; - image_ptr++) - *buf_ptr++ = (u16) ((game_colour[*image_ptr] >> 8) // Assume game_colour unsigned - | (game_colour[*image_ptr] << 8)); - } - else - { - const img_pixel_t *image_line_end; - int img_width = width; - for (image_ptr = image_line_end = img.buf(); - image_ptr < image_end;) - { - image_line_end += img_width; - for (; image_ptr < image_line_end; image_ptr++) - *buf_ptr++ = (u16) ((game_colour[*image_ptr] >> 8) // Assume game_colour uns. - | (game_colour[*image_ptr] << 8)); - buf_ptr = (u16 *) ((char *) buf_ptr + padding); // Line padding - } - } - } + register const img_pixel_t *image_ptr; + register u16 *buf_ptr = (u16 *) buf; + if (cpu_big_endian == x_server_big_endian) + { + if (padding == 0) + { + for (image_ptr = img.buf(); image_ptr < image_end; + image_ptr++) + *buf_ptr++ = (u16) game_colour[*image_ptr]; + } + else + { + const img_pixel_t *image_line_end; + int img_width = width; + for (image_ptr = image_line_end = img.buf(); + image_ptr < image_end;) + { + image_line_end += img_width; + for (; image_ptr < image_line_end; image_ptr++) + *buf_ptr++ = (u16) game_colour[*image_ptr]; + buf_ptr = (u16 *) ((char *) buf_ptr + padding); // Line padding + } + } + } + else // Different endiannesses so swap bytes + { + if (padding == 0) + { + for (image_ptr = img.buf(); image_ptr < image_end; + image_ptr++) + *buf_ptr++ = (u16) ((game_colour[*image_ptr] >> 8) // Assume game_colour unsigned + | (game_colour[*image_ptr] << 8)); + } + else + { + const img_pixel_t *image_line_end; + int img_width = width; + for (image_ptr = image_line_end = img.buf(); + image_ptr < image_end;) + { + image_line_end += img_width; + for (; image_ptr < image_line_end; image_ptr++) + *buf_ptr++ = (u16) ((game_colour[*image_ptr] >> 8) // Assume game_colour uns. + | (game_colour[*image_ptr] << 8)); + buf_ptr = (u16 *) ((char *) buf_ptr + padding); // Line padding + } + } + } } else if (ximage_bpp == 3) { - const pv24_t *const pixel_value = game_colour_24.lut(); - register const img_pixel_t *image_ptr; - register pv24_t *buf_ptr = (pv24_t *) buf; - if (padding == 0) - { - for (image_ptr = img.buf(); image_ptr < image_end; image_ptr++) - memcpy(buf_ptr++, pixel_value + *image_ptr, sizeof *buf_ptr); - } - else - { - const img_pixel_t *image_line_end; - int img_width = width; - for (image_ptr = image_line_end = img.buf(); - image_ptr < image_end;) - { - image_line_end += img_width; - for (; image_ptr < image_line_end; image_ptr++) - memcpy(buf_ptr++, pixel_value + *image_ptr, - sizeof *buf_ptr); - buf_ptr = (pv24_t *) ((char *) buf_ptr + padding); // Line padding - } - } + const pv24_t *const pixel_value = game_colour_24.lut(); + register const img_pixel_t *image_ptr; + register pv24_t *buf_ptr = (pv24_t *) buf; + if (padding == 0) + { + for (image_ptr = img.buf(); image_ptr < image_end; image_ptr++) + memcpy(buf_ptr++, pixel_value + *image_ptr, sizeof *buf_ptr); + } + else + { + const img_pixel_t *image_line_end; + int img_width = width; + for (image_ptr = image_line_end = img.buf(); + image_ptr < image_end;) + { + image_line_end += img_width; + for (; image_ptr < image_line_end; image_ptr++) + memcpy(buf_ptr++, pixel_value + *image_ptr, + sizeof *buf_ptr); + buf_ptr = (pv24_t *) ((char *) buf_ptr + padding); // Line padding + } + } } else if (ximage_bpp == 4) { - register const img_pixel_t *image_ptr; - register u32 *buf_ptr = (u32 *) buf; - if (cpu_big_endian == x_server_big_endian) - { - if (padding == 0) - { - for (image_ptr = img.buf(); image_ptr < image_end; - image_ptr++) - *buf_ptr++ = (u32) game_colour[*image_ptr]; - } - else - { - const img_pixel_t *image_line_end; - int img_width = width; - for (image_ptr = image_line_end = img.buf(); - image_ptr < image_end;) - { - image_line_end += img_width; - for (; image_ptr < image_line_end; image_ptr++) - *buf_ptr++ = (u32) game_colour[*image_ptr]; - buf_ptr = (u32 *) ((char *) buf_ptr + padding); // Line padding - } - } - } - else // Different endiannesses so swap bytes - { - if (padding == 0) - { - for (image_ptr = img.buf(); image_ptr < image_end; image_ptr++) - *buf_ptr++ = (u32) ((game_colour[*image_ptr] >> 24) | - ((game_colour[*image_ptr] >> 8) & 0x0000ff00) | - ((game_colour[*image_ptr] << 8) & 0x00ff0000) | - (game_colour[*image_ptr] << 24)); - } - else - { - const img_pixel_t *image_line_end; - int img_width = width; - for (image_ptr = image_line_end = img.buf(); - image_ptr < image_end;) - { - image_line_end += img_width; - for (; image_ptr < image_line_end; image_ptr++) - *buf_ptr++ = (u32) ((game_colour[*image_ptr] >> 24) // Assume game_colour uns. - | (game_colour[*image_ptr] >> 8) & - 0x0000ff00 | - (game_colour[*image_ptr] << 8) & - 0x00ff0000 | - (game_colour[*image_ptr] << 24)); - buf_ptr = (u32 *) ((char *) buf_ptr + padding); // Line padding - } - } - } + register const img_pixel_t *image_ptr; + register u32 *buf_ptr = (u32 *) buf; + if (cpu_big_endian == x_server_big_endian) + { + if (padding == 0) + { + for (image_ptr = img.buf(); image_ptr < image_end; + image_ptr++) + *buf_ptr++ = (u32) game_colour[*image_ptr]; + } + else + { + const img_pixel_t *image_line_end; + int img_width = width; + for (image_ptr = image_line_end = img.buf(); + image_ptr < image_end;) + { + image_line_end += img_width; + for (; image_ptr < image_line_end; image_ptr++) + *buf_ptr++ = (u32) game_colour[*image_ptr]; + buf_ptr = (u32 *) ((char *) buf_ptr + padding); // Line padding + } + } + } + else // Different endiannesses so swap bytes + { + if (padding == 0) + { + for (image_ptr = img.buf(); image_ptr < image_end; image_ptr++) + *buf_ptr++ = (u32) ((game_colour[*image_ptr] >> 24) | + ((game_colour[*image_ptr] >> 8) & 0x0000ff00) | + ((game_colour[*image_ptr] << 8) & 0x00ff0000) | + (game_colour[*image_ptr] << 24)); + } + else + { + const img_pixel_t *image_line_end; + int img_width = width; + for (image_ptr = image_line_end = img.buf(); + image_ptr < image_end;) + { + image_line_end += img_width; + for (; image_ptr < image_line_end; image_ptr++) + *buf_ptr++ = (u32) ((game_colour[*image_ptr] >> 24) // Assume game_colour uns. + | (game_colour[*image_ptr] >> 8) & + 0x0000ff00 | + (game_colour[*image_ptr] << 8) & + 0x00ff0000 | + (game_colour[*image_ptr] << 24)); + buf_ptr = (u32 *) ((char *) buf_ptr + padding); // Line padding + } + } + } } XImage *ximage = XCreateImage(dpy, win_vis, win_depth, ZPixmap, 0, - (char *) buf, width, height, 8, - bytes_per_line); + (char *) buf, width, height, 8, + bytes_per_line); if (ximage == 0) { - err("XCreateImage() returned NULL"); - FreeMemory(buf); + err("XCreateImage() returned NULL"); + FreeMemory(buf); } else { - if (ximage->byte_order == LSBFirst && !x_server_big_endian - || ximage->byte_order == MSBFirst && x_server_big_endian) - ; // OK - else - warn("image byte_order %d doesn't match X server endianness\n", - ximage->byte_order); + if (ximage->byte_order == LSBFirst && !x_server_big_endian + || ximage->byte_order == MSBFirst && x_server_big_endian) + ; // OK + else + warn("image byte_order %d doesn't match X server endianness\n", + ximage->byte_order); } return ximage; } /* - * Sticker_priv::make_bitmap - create 1-bpp XImage from Img + * Sticker_priv::make_bitmap - create 1-bpp XImage from Img * - * Return pointer on XImage on success, null pointer on - * failure. + * Return pointer on XImage on success, null pointer on + * failure. */ XImage *Sticker_priv::make_bitmap(const Img & img) { @@ -433,168 +433,168 @@ int height = img.height(); // How many bytes per line do we need ? - if (CHAR_BIT != 8) // Pure paranoia + if (CHAR_BIT != 8) // Pure paranoia { - nf_bug("Panic: CHAR_BIT != 8 (%d)", (int) CHAR_BIT); - return 0; + nf_bug("Panic: CHAR_BIT != 8 (%d)", (int) CHAR_BIT); + return 0; } const size_t bitmap_pad = BitmapPad(dpy); const size_t bytes_per_line = (width + bitmap_pad - 1) / bitmap_pad - * bitmap_pad / CHAR_BIT; + * bitmap_pad / CHAR_BIT; u8 *buf = (u8 *) GetMemory((unsigned long) bytes_per_line * height); if (!buf) { - err("Not enough memory to display %dx%d image", width, height); - return 0; + err("Not enough memory to display %dx%d image", width, height); + return 0; } // Copy the "profile" of the Img onto the XImage { - int bitmap_bit_order = BitmapBitOrder(dpy); - register u8 *buf_ptr = (u8 *) buf; - const int IMG_TRANSP = 0; - const img_pixel_t *image_ptr = img.buf(); - const img_pixel_t *const image_end = image_ptr + width * height; + int bitmap_bit_order = BitmapBitOrder(dpy); + register u8 *buf_ptr = (u8 *) buf; + const int IMG_TRANSP = 0; + const img_pixel_t *image_ptr = img.buf(); + const img_pixel_t *const image_end = image_ptr + width * height; - while (image_ptr < image_end) - { - register const u8 *src = image_ptr; - const u8 *const stop1 = src + width - 7; - const u8 *const stop2 = image_ptr + width; - u8 *dest = buf_ptr; - if (bitmap_bit_order == LSBFirst) - { - while (src < stop1) - { - register u8 d = 0; - if (*src++ != IMG_TRANSP) - d |= 1; - if (*src++ != IMG_TRANSP) - d |= 2; - if (*src++ != IMG_TRANSP) - d |= 4; - if (*src++ != IMG_TRANSP) - d |= 8; - if (*src++ != IMG_TRANSP) - d |= 16; - if (*src++ != IMG_TRANSP) - d |= 32; - if (*src++ != IMG_TRANSP) - d |= 64; - if (*src++ != IMG_TRANSP) - d |= 128; - *dest++ = d; - } - if (src < stop2) - { - register u8 d = 0; - if (*src++ != IMG_TRANSP) - d |= 1; - if (src >= stop2) - goto eol_le; - if (*src++ != IMG_TRANSP) - d |= 2; - if (src >= stop2) - goto eol_le; - if (*src++ != IMG_TRANSP) - d |= 4; - if (src >= stop2) - goto eol_le; - if (*src++ != IMG_TRANSP) - d |= 8; - if (src >= stop2) - goto eol_le; - if (*src++ != IMG_TRANSP) - d |= 16; - if (src >= stop2) - goto eol_le; - if (*src++ != IMG_TRANSP) - d |= 32; - if (src >= stop2) - goto eol_le; - if (*src++ != IMG_TRANSP) - d |= 64; - if (src >= stop2) - goto eol_le; - if (*src++ != IMG_TRANSP) - d |= 128; - eol_le: - *dest = d; - } - } - else if (bitmap_bit_order == MSBFirst) - { - while (src < stop1) - { - register u8 d = 0; - if (*src++ != IMG_TRANSP) - d |= 128; - if (*src++ != IMG_TRANSP) - d |= 64; - if (*src++ != IMG_TRANSP) - d |= 32; - if (*src++ != IMG_TRANSP) - d |= 16; - if (*src++ != IMG_TRANSP) - d |= 8; - if (*src++ != IMG_TRANSP) - d |= 4; - if (*src++ != IMG_TRANSP) - d |= 2; - if (*src++ != IMG_TRANSP) - d |= 1; - *dest++ = d; - } - if (src < stop2) - { - register u8 d = 0; - if (*src++ != IMG_TRANSP) - d |= 128; - if (src >= stop2) - goto eol_be; - if (*src++ != IMG_TRANSP) - d |= 64; - if (src >= stop2) - goto eol_be; - if (*src++ != IMG_TRANSP) - d |= 32; - if (src >= stop2) - goto eol_be; - if (*src++ != IMG_TRANSP) - d |= 16; - if (src >= stop2) - goto eol_be; - if (*src++ != IMG_TRANSP) - d |= 8; - if (src >= stop2) - goto eol_be; - if (*src++ != IMG_TRANSP) - d |= 4; - if (src >= stop2) - goto eol_be; - if (*src++ != IMG_TRANSP) - d |= 2; - if (src >= stop2) - goto eol_be; - if (*src++ != IMG_TRANSP) - d |= 1; - eol_be: - *dest = d; - } - } - buf_ptr += bytes_per_line; - image_ptr += width; - } + while (image_ptr < image_end) + { + register const u8 *src = image_ptr; + const u8 *const stop1 = src + width - 7; + const u8 *const stop2 = image_ptr + width; + u8 *dest = buf_ptr; + if (bitmap_bit_order == LSBFirst) + { + while (src < stop1) + { + register u8 d = 0; + if (*src++ != IMG_TRANSP) + d |= 1; + if (*src++ != IMG_TRANSP) + d |= 2; + if (*src++ != IMG_TRANSP) + d |= 4; + if (*src++ != IMG_TRANSP) + d |= 8; + if (*src++ != IMG_TRANSP) + d |= 16; + if (*src++ != IMG_TRANSP) + d |= 32; + if (*src++ != IMG_TRANSP) + d |= 64; + if (*src++ != IMG_TRANSP) + d |= 128; + *dest++ = d; + } + if (src < stop2) + { + register u8 d = 0; + if (*src++ != IMG_TRANSP) + d |= 1; + if (src >= stop2) + goto eol_le; + if (*src++ != IMG_TRANSP) + d |= 2; + if (src >= stop2) + goto eol_le; + if (*src++ != IMG_TRANSP) + d |= 4; + if (src >= stop2) + goto eol_le; + if (*src++ != IMG_TRANSP) + d |= 8; + if (src >= stop2) + goto eol_le; + if (*src++ != IMG_TRANSP) + d |= 16; + if (src >= stop2) + goto eol_le; + if (*src++ != IMG_TRANSP) + d |= 32; + if (src >= stop2) + goto eol_le; + if (*src++ != IMG_TRANSP) + d |= 64; + if (src >= stop2) + goto eol_le; + if (*src++ != IMG_TRANSP) + d |= 128; + eol_le: + *dest = d; + } + } + else if (bitmap_bit_order == MSBFirst) + { + while (src < stop1) + { + register u8 d = 0; + if (*src++ != IMG_TRANSP) + d |= 128; + if (*src++ != IMG_TRANSP) + d |= 64; + if (*src++ != IMG_TRANSP) + d |= 32; + if (*src++ != IMG_TRANSP) + d |= 16; + if (*src++ != IMG_TRANSP) + d |= 8; + if (*src++ != IMG_TRANSP) + d |= 4; + if (*src++ != IMG_TRANSP) + d |= 2; + if (*src++ != IMG_TRANSP) + d |= 1; + *dest++ = d; + } + if (src < stop2) + { + register u8 d = 0; + if (*src++ != IMG_TRANSP) + d |= 128; + if (src >= stop2) + goto eol_be; + if (*src++ != IMG_TRANSP) + d |= 64; + if (src >= stop2) + goto eol_be; + if (*src++ != IMG_TRANSP) + d |= 32; + if (src >= stop2) + goto eol_be; + if (*src++ != IMG_TRANSP) + d |= 16; + if (src >= stop2) + goto eol_be; + if (*src++ != IMG_TRANSP) + d |= 8; + if (src >= stop2) + goto eol_be; + if (*src++ != IMG_TRANSP) + d |= 4; + if (src >= stop2) + goto eol_be; + if (*src++ != IMG_TRANSP) + d |= 2; + if (src >= stop2) + goto eol_be; + if (*src++ != IMG_TRANSP) + d |= 1; + eol_be: + *dest = d; + } + } + buf_ptr += bytes_per_line; + image_ptr += width; + } } XImage *ximage = XCreateImage(dpy, win_vis, 1, XYBitmap, 0, - (char *) buf, width, height, bitmap_pad, - bytes_per_line); + (char *) buf, width, height, bitmap_pad, + bytes_per_line); if (ximage == 0) { - err("XCreateImage() returned NULL"); - FreeMemory(buf); - return 0; + err("XCreateImage() returned NULL"); + FreeMemory(buf); + return 0; } return ximage; } diff -r 594dea11ccd9 -r a68786b9c74b src/sticker.h --- a/src/sticker.h Sat Sep 24 15:01:56 2011 +0300 +++ b/src/sticker.h Sat Sep 24 15:59:33 2011 +0300 @@ -1,6 +1,6 @@ /* - * sticker.h - Sticker class - * AYM 2000-07-06 + * sticker.h - Sticker class + * AYM 2000-07-06 */ @@ -18,7 +18,7 @@ void load(const Img & img, bool opaque); void draw(Drawable drw, char grav, int x, int y); - private:Sticker(const Sticker &); // Too lazy to implement it - Sticker & operator=(const Sticker &); // Too lazy to implement it + private:Sticker(const Sticker &); // Too lazy to implement it + Sticker & operator=(const Sticker &); // Too lazy to implement it Sticker_priv *priv; }; diff -r 594dea11ccd9 -r a68786b9c74b src/t_centre.cc --- a/src/t_centre.cc Sat Sep 24 15:01:56 2011 +0300 +++ b/src/t_centre.cc Sat Sep 24 15:59:33 2011 +0300 @@ -1,6 +1,6 @@ /* - * t_centre.cc - * AYM 1998-11-22 + * t_centre.cc + * AYM 1998-11-22 */ @@ -35,8 +35,8 @@ /* - * centre_of_things - * Return the coordinates of the centre of a group of things. + * centre_of_things + * Return the coordinates of the centre of a group of things. */ void centre_of_things(SelPtr list, int *x, int *y) { @@ -49,17 +49,17 @@ y_sum = 0; for (nitems = 0, cur = list; cur; cur = cur->next, nitems++) { - x_sum += Things[cur->objnum].xpos; - y_sum += Things[cur->objnum].ypos; + x_sum += Things[cur->objnum].xpos; + y_sum += Things[cur->objnum].ypos; } if (nitems == 0) { - *x = 0; - *y = 0; + *x = 0; + *y = 0; } else { - *x = (int) (x_sum / nitems); - *y = (int) (y_sum / nitems); + *x = (int) (x_sum / nitems); + *y = (int) (y_sum / nitems); } } diff -r 594dea11ccd9 -r a68786b9c74b src/t_centre.h --- a/src/t_centre.h Sat Sep 24 15:01:56 2011 +0300 +++ b/src/t_centre.h Sat Sep 24 15:59:33 2011 +0300 @@ -1,6 +1,6 @@ /* - * t_centre.h - * AYM 1998-11-22 + * t_centre.h + * AYM 1998-11-22 */ diff -r 594dea11ccd9 -r a68786b9c74b src/t_flags.cc --- a/src/t_flags.cc Sat Sep 24 15:01:56 2011 +0300 +++ b/src/t_flags.cc Sat Sep 24 15:59:33 2011 +0300 @@ -1,6 +1,6 @@ /* - * t_flags.cc - * AYM 1998-12-21 + * t_flags.cc + * AYM 1998-12-21 */ @@ -34,10 +34,10 @@ /* - * frob_things_flags - set/reset/toggle things flags + * frob_things_flags - set/reset/toggle things flags * - * For all the things in <list>, apply the operator <op> - * with the operand <operand> on the flags field. + * For all the things in <list>, apply the operator <op> + * with the operand <operand> on the flags field. */ void frob_things_flags(SelPtr list, int op, int operand) { @@ -45,23 +45,23 @@ i16 mask; if (op == YO_CLEAR || op == YO_SET || op == YO_TOGGLE) - mask = 1 << operand; + mask = 1 << operand; else - mask = operand; + mask = operand; for (cur = list; cur; cur = cur->next) { - if (op == YO_CLEAR) - Things[cur->objnum].when &= ~mask; - else if (op == YO_SET) - Things[cur->objnum].when |= mask; - else if (op == YO_TOGGLE) - Things[cur->objnum].when ^= mask; - else - { - nf_bug("frob_things_flags: op=%02X", op); - return; - } + if (op == YO_CLEAR) + Things[cur->objnum].when &= ~mask; + else if (op == YO_SET) + Things[cur->objnum].when |= mask; + else if (op == YO_TOGGLE) + Things[cur->objnum].when ^= mask; + else + { + nf_bug("frob_things_flags: op=%02X", op); + return; + } } MadeChanges = 1; } diff -r 594dea11ccd9 -r a68786b9c74b src/t_flags.h --- a/src/t_flags.h Sat Sep 24 15:01:56 2011 +0300 +++ b/src/t_flags.h Sat Sep 24 15:59:33 2011 +0300 @@ -1,6 +1,6 @@ /* - * t_flags.h - * AYM 1998-12-22 + * t_flags.h + * AYM 1998-12-22 */ diff -r 594dea11ccd9 -r a68786b9c74b src/t_prop.cc --- a/src/t_prop.cc Sat Sep 24 15:01:56 2011 +0300 +++ b/src/t_prop.cc Sat Sep 24 15:59:33 2011 +0300 @@ -1,9 +1,9 @@ /* - * t_prop.c - * Thing properties - * Some of this was originally in editobj.c. It was moved here to - * improve overlay granularity (therefore memory consumption). - * AYM 1998-02-07 + * t_prop.c + * Thing properties + * Some of this was originally in editobj.c. It was moved here to + * improve overlay granularity (therefore memory consumption). + * AYM 1998-02-07 */ @@ -43,7 +43,7 @@ /* - * Private functions prototypes + * Private functions prototypes */ int InputThingType(int x0, int y0, int *number); static const char *PrintThinggroup(void *ptr); @@ -51,9 +51,9 @@ /* - * ThingProperties - * Thing properties dialog. Called by EditObjectsInfo. Was part of - * EditObjectsInfo in editobj.c + * ThingProperties + * Thing properties dialog. Called by EditObjectsInfo. Was part of + * EditObjectsInfo in editobj.c */ void ThingProperties(int x0, int y0, SelPtr obj) { @@ -63,192 +63,192 @@ int subwin_y0; for (n = 0; n < 6; n++) - menustr[n] = (char *) GetMemory(60); + menustr[n] = (char *) GetMemory(60); sprintf(menustr[5], "Edit thing #%d", obj->objnum); sprintf(menustr[0], "Change type (Current: %s)", - get_thing_name(Things[obj->objnum].type)); + get_thing_name(Things[obj->objnum].type)); sprintf(menustr[1], "Change angle (Current: %s)", - GetAngleName(Things[obj->objnum].angle)); + GetAngleName(Things[obj->objnum].angle)); sprintf(menustr[2], "Change flags (Current: %s)", - GetWhenName(Things[obj->objnum].when)); + GetWhenName(Things[obj->objnum].when)); sprintf(menustr[3], "Change X position (Current: %d)", - Things[obj->objnum].xpos); + Things[obj->objnum].xpos); sprintf(menustr[4], "Change Y position (Current: %d)", - Things[obj->objnum].ypos); + Things[obj->objnum].ypos); val = vDisplayMenu(x0, y0, menustr[5], - menustr[0], YK_, 0, - menustr[1], YK_, 0, - menustr[2], YK_, 0, - menustr[3], YK_, 0, menustr[4], YK_, 0, NULL); + menustr[0], YK_, 0, + menustr[1], YK_, 0, + menustr[2], YK_, 0, + menustr[3], YK_, 0, menustr[4], YK_, 0, NULL); for (n = 0; n < 6; n++) - FreeMemory(menustr[n]); + FreeMemory(menustr[n]); subwin_y0 = y0 + BOX_BORDER + (2 + val) * FONTH; switch (val) { case 1: - if (!InputThingType(x0, subwin_y0, &val)) - { - for (cur = obj; cur; cur = cur->next) - Things[cur->objnum].type = val; - things_types++; - MadeChanges = 1; - } - break; + if (!InputThingType(x0, subwin_y0, &val)) + { + for (cur = obj; cur; cur = cur->next) + Things[cur->objnum].type = val; + things_types++; + MadeChanges = 1; + } + break; case 2: - switch (vDisplayMenu(x0 + 42, subwin_y0, "Select angle", - "North", YK_, 0, - "NorthEast", YK_, 0, - "East", YK_, 0, - "SouthEast", YK_, 0, - "South", YK_, 0, - "SouthWest", YK_, 0, - "West", YK_, 0, "NorthWest", YK_, 0, NULL)) - { - case 1: - for (cur = obj; cur; cur = cur->next) - Things[cur->objnum].angle = 90; - things_angles++; - MadeChanges = 1; - break; + switch (vDisplayMenu(x0 + 42, subwin_y0, "Select angle", + "North", YK_, 0, + "NorthEast", YK_, 0, + "East", YK_, 0, + "SouthEast", YK_, 0, + "South", YK_, 0, + "SouthWest", YK_, 0, + "West", YK_, 0, "NorthWest", YK_, 0, NULL)) + { + case 1: + for (cur = obj; cur; cur = cur->next) + Things[cur->objnum].angle = 90; + things_angles++; + MadeChanges = 1; + break; - case 2: - for (cur = obj; cur; cur = cur->next) - Things[cur->objnum].angle = 45; - things_angles++; - MadeChanges = 1; - break; + case 2: + for (cur = obj; cur; cur = cur->next) + Things[cur->objnum].angle = 45; + things_angles++; + MadeChanges = 1; + break; - case 3: - for (cur = obj; cur; cur = cur->next) - Things[cur->objnum].angle = 0; - things_angles++; - MadeChanges = 1; - break; + case 3: + for (cur = obj; cur; cur = cur->next) + Things[cur->objnum].angle = 0; + things_angles++; + MadeChanges = 1; + break; - case 4: - for (cur = obj; cur; cur = cur->next) - Things[cur->objnum].angle = 315; - things_angles++; - MadeChanges = 1; - break; + case 4: + for (cur = obj; cur; cur = cur->next) + Things[cur->objnum].angle = 315; + things_angles++; + MadeChanges = 1; + break; - case 5: - for (cur = obj; cur; cur = cur->next) - Things[cur->objnum].angle = 270; - things_angles++; - MadeChanges = 1; - break; + case 5: + for (cur = obj; cur; cur = cur->next) + Things[cur->objnum].angle = 270; + things_angles++; + MadeChanges = 1; + break; - case 6: - for (cur = obj; cur; cur = cur->next) - Things[cur->objnum].angle = 225; - things_angles++; - MadeChanges = 1; - break; + case 6: + for (cur = obj; cur; cur = cur->next) + Things[cur->objnum].angle = 225; + things_angles++; + MadeChanges = 1; + break; - case 7: - for (cur = obj; cur; cur = cur->next) - Things[cur->objnum].angle = 180; - things_angles++; - MadeChanges = 1; - break; + case 7: + for (cur = obj; cur; cur = cur->next) + Things[cur->objnum].angle = 180; + things_angles++; + MadeChanges = 1; + break; - case 8: - for (cur = obj; cur; cur = cur->next) - Things[cur->objnum].angle = 135; - things_angles++; - MadeChanges = 1; - break; - } - break; + case 8: + for (cur = obj; cur; cur = cur->next) + Things[cur->objnum].angle = 135; + things_angles++; + MadeChanges = 1; + break; + } + break; case 3: - val = - vDisplayMenu(x0 + 42, subwin_y0, "Choose the difficulty level(s)", - "D12 (Easy only)", YK_, 0, - "D3 (Medium only)", YK_, 0, - "D12, D3 (Easy and Medium)", YK_, 0, - "D45 (Hard only)", YK_, 0, - "D12, D45 (Easy and Hard)", YK_, 0, - "D3, D45 (Medium and Hard)", YK_, 0, - "D12, D3, D45 (Easy, Medium, Hard)", YK_, 0, - "Toggle \"Deaf/Ambush\" bit", YK_, 0, - "Toggle \"Multi-player only\" bit", YK_, 0, - "(Enter number)", YK_, 0, NULL); - switch (val) - { - case 1: - case 2: - case 3: - case 4: - case 5: - case 6: - case 7: - for (cur = obj; cur; cur = cur->next) - Things[cur->objnum].when = - (Things[cur->objnum].when & 0x18) | val; - MadeChanges = 1; - break; + val = + vDisplayMenu(x0 + 42, subwin_y0, "Choose the difficulty level(s)", + "D12 (Easy only)", YK_, 0, + "D3 (Medium only)", YK_, 0, + "D12, D3 (Easy and Medium)", YK_, 0, + "D45 (Hard only)", YK_, 0, + "D12, D45 (Easy and Hard)", YK_, 0, + "D3, D45 (Medium and Hard)", YK_, 0, + "D12, D3, D45 (Easy, Medium, Hard)", YK_, 0, + "Toggle \"Deaf/Ambush\" bit", YK_, 0, + "Toggle \"Multi-player only\" bit", YK_, 0, + "(Enter number)", YK_, 0, NULL); + switch (val) + { + case 1: + case 2: + case 3: + case 4: + case 5: + case 6: + case 7: + for (cur = obj; cur; cur = cur->next) + Things[cur->objnum].when = + (Things[cur->objnum].when & 0x18) | val; + MadeChanges = 1; + break; - case 8: - for (cur = obj; cur; cur = cur->next) - Things[cur->objnum].when ^= 0x08; - MadeChanges = 1; - break; + case 8: + for (cur = obj; cur; cur = cur->next) + Things[cur->objnum].when ^= 0x08; + MadeChanges = 1; + break; - case 9: - for (cur = obj; cur; cur = cur->next) - Things[cur->objnum].when ^= 0x10; - MadeChanges = 1; - break; + case 9: + for (cur = obj; cur; cur = cur->next) + Things[cur->objnum].when ^= 0x10; + MadeChanges = 1; + break; - case 10: - val = InputIntegerValue(x0 + 84, - subwin_y0 + BOX_BORDER + (3 + - val) * FONTH, 0, - 65535, Things[obj->objnum].when); - if (val != IIV_CANCEL) - { - for (cur = obj; cur; cur = cur->next) - Things[cur->objnum].when = val; - MadeChanges = 1; - } - break; - } - break; + case 10: + val = InputIntegerValue(x0 + 84, + subwin_y0 + BOX_BORDER + (3 + + val) * FONTH, 0, + 65535, Things[obj->objnum].when); + if (val != IIV_CANCEL) + { + for (cur = obj; cur; cur = cur->next) + Things[cur->objnum].when = val; + MadeChanges = 1; + } + break; + } + break; case 4: - val = InputIntegerValue(x0 + 42, subwin_y0, MapMinX, MapMaxX, - Things[obj->objnum].xpos); - if (val != IIV_CANCEL) - { - n = val - Things[obj->objnum].xpos; - for (cur = obj; cur; cur = cur->next) - Things[cur->objnum].xpos += n; - MadeChanges = 1; - } - break; + val = InputIntegerValue(x0 + 42, subwin_y0, MapMinX, MapMaxX, + Things[obj->objnum].xpos); + if (val != IIV_CANCEL) + { + n = val - Things[obj->objnum].xpos; + for (cur = obj; cur; cur = cur->next) + Things[cur->objnum].xpos += n; + MadeChanges = 1; + } + break; case 5: - val = InputIntegerValue(x0 + 42, subwin_y0, MapMinY, MapMaxY, - Things[obj->objnum].ypos); - if (val != IIV_CANCEL) - { - n = val - Things[obj->objnum].ypos; - for (cur = obj; cur; cur = cur->next) - Things[cur->objnum].ypos += n; - MadeChanges = 1; - } - break; + val = InputIntegerValue(x0 + 42, subwin_y0, MapMinY, MapMaxY, + Things[obj->objnum].ypos); + if (val != IIV_CANCEL) + { + n = val - Things[obj->objnum].ypos; + for (cur = obj; cur; cur = cur->next) + Things[cur->objnum].ypos += n; + MadeChanges = 1; + } + break; } } /* - * InputThingType - * Let the user select a thing number and return it. - * Returns 0 if OK, <>0 if cancelled + * InputThingType + * Let the user select a thing number and return it. + * Returns 0 if OK, <>0 if cancelled */ int InputThingType(int x0, int y0, int *number) { @@ -259,78 +259,78 @@ for (;;) { - /* First let user select a thinggroup */ - if (DisplayMenuList(x0 + 42, y0, "Select group", thinggroup, - PrintThinggroup, &tgno) < 0) - return 1; - if (al_lseek(thinggroup, tgno, SEEK_SET)) - fatal_error("%s ITT1 (%s)", msg_unexpected, - al_astrerror(al_aerrno)); - tg = CUR_THINGGROUP->thinggroup; + /* First let user select a thinggroup */ + if (DisplayMenuList(x0 + 42, y0, "Select group", thinggroup, + PrintThinggroup, &tgno) < 0) + return 1; + if (al_lseek(thinggroup, tgno, SEEK_SET)) + fatal_error("%s ITT1 (%s)", msg_unexpected, + al_astrerror(al_aerrno)); + tg = CUR_THINGGROUP->thinggroup; - /* KLUDGE: Special thinggroup THING_FREE means "enter number". - Don't look for this thinggroup in the .ygd file : LoadGameDefs() - creates it manually. */ - if (tg == THING_FREE) - { - /* FIXME should be unsigned! should accept hex. */ - *number = - InputIntegerValue(x0 + 84, - y0 + BOX_BORDER + (3 + tgno) * FONTH, - -32768, 32767, 0); - if (*number != IIV_CANCEL) - break; - goto again; - } + /* KLUDGE: Special thinggroup THING_FREE means "enter number". + Don't look for this thinggroup in the .ygd file : LoadGameDefs() + creates it manually. */ + if (tg == THING_FREE) + { + /* FIXME should be unsigned! should accept hex. */ + *number = + InputIntegerValue(x0 + 84, + y0 + BOX_BORDER + (3 + tgno) * FONTH, + -32768, 32767, 0); + if (*number != IIV_CANCEL) + break; + goto again; + } - /* Then build a list of pointers on all things that have this - thinggroup and let user select one. */ - list = al_lcreate(sizeof(void *)); - for (al_lrewind(thingdef); !al_leol(thingdef); al_lstep(thingdef)) - if (CUR_THINGDEF->thinggroup == tg) - { - void *ptr = CUR_THINGDEF; - al_lwrite(list, &ptr); - } - r = DisplayMenuList(x0 + 84, y0 + BOX_BORDER + (3 + tgno) * FONTH, - "Select thing", list, PrintThingdef, NULL); - if (r < 0) - goto again; - if (al_lseek(list, r, SEEK_SET)) - fatal_error("%s ITT2 (%s)", msg_unexpected, - al_astrerror(al_aerrno)); - *number = (*((thingdef_t **) al_lptr(list)))->number; - al_ldiscard(list); - break; + /* Then build a list of pointers on all things that have this + thinggroup and let user select one. */ + list = al_lcreate(sizeof(void *)); + for (al_lrewind(thingdef); !al_leol(thingdef); al_lstep(thingdef)) + if (CUR_THINGDEF->thinggroup == tg) + { + void *ptr = CUR_THINGDEF; + al_lwrite(list, &ptr); + } + r = DisplayMenuList(x0 + 84, y0 + BOX_BORDER + (3 + tgno) * FONTH, + "Select thing", list, PrintThingdef, NULL); + if (r < 0) + goto again; + if (al_lseek(list, r, SEEK_SET)) + fatal_error("%s ITT2 (%s)", msg_unexpected, + al_astrerror(al_aerrno)); + *number = (*((thingdef_t **) al_lptr(list)))->number; + al_ldiscard(list); + break; again: - ; - /* DrawMap (OBJ_THINGS, 0, 0); FIXME! */ + ; + /* DrawMap (OBJ_THINGS, 0, 0); FIXME! */ } return 0; } /* - * PrintThinggroup - * Used by DisplayMenuList when called by InputThingType + * PrintThinggroup + * Used by DisplayMenuList when called by InputThingType */ static const char *PrintThinggroup(void *ptr) { if (ptr == NULL) - return "PrintThinggroup: (null)"; + return "PrintThinggroup: (null)"; return ((thinggroup_t *) ptr)->desc; } /* - * PrintThingdef - * Used by DisplayMenuList when called by InputThingType + * PrintThingdef + * Used by DisplayMenuList when called by InputThingType */ static const char *PrintThingdef(void *ptr) { if (ptr == NULL) - return "PrintThingdef: (null)"; + return "PrintThingdef: (null)"; return (*((thingdef_t **) ptr))->desc; } @@ -346,17 +346,17 @@ for (cur = things; cur; cur = cur->next) { - if (!is_obj(cur->objnum)) - continue; + if (!is_obj(cur->objnum)) + continue; - Things[cur->objnum].angle = Things[src_thing].angle; - Things[cur->objnum].type = Things[src_thing].type; - Things[cur->objnum].when = Things[src_thing].when; + Things[cur->objnum].angle = Things[src_thing].angle; + Things[cur->objnum].type = Things[src_thing].type; + Things[cur->objnum].when = Things[src_thing].when; - MadeChanges = 1; + MadeChanges = 1; - things_types++; - things_angles++; + things_types++; + things_angles++; } } diff -r 594dea11ccd9 -r a68786b9c74b src/t_spin.cc --- a/src/t_spin.cc Sat Sep 24 15:01:56 2011 +0300 +++ b/src/t_spin.cc Sat Sep 24 15:59:33 2011 +0300 @@ -1,6 +1,6 @@ /* - * t_spin.cc - * AYM 1998-12-06 + * t_spin.cc + * AYM 1998-12-06 */ @@ -34,21 +34,21 @@ /* - * spin_thing - change the angle of things + * spin_thing - change the angle of things */ void spin_things(SelPtr obj, int degrees) { SelPtr cur; if (!obj) - return; + return; for (cur = obj; cur; cur = cur->next) { - Things[cur->objnum].angle += degrees; - while (Things[cur->objnum].angle >= 360) // No we can't use % - Things[cur->objnum].angle -= 360; - while (Things[cur->objnum].angle < 0) // (negatives...) - Things[cur->objnum].angle += 360; + Things[cur->objnum].angle += degrees; + while (Things[cur->objnum].angle >= 360) // No we can't use % + Things[cur->objnum].angle -= 360; + while (Things[cur->objnum].angle < 0) // (negatives...) + Things[cur->objnum].angle += 360; } things_angles++; MadeChanges = 1; diff -r 594dea11ccd9 -r a68786b9c74b src/t_spin.h --- a/src/t_spin.h Sat Sep 24 15:01:56 2011 +0300 +++ b/src/t_spin.h Sat Sep 24 15:59:33 2011 +0300 @@ -1,6 +1,6 @@ /* - * t_spin.h - * AYM 1998-12-06 + * t_spin.h + * AYM 1998-12-06 */ diff -r 594dea11ccd9 -r a68786b9c74b src/textures.cc --- a/src/textures.cc Sat Sep 24 15:01:56 2011 +0300 +++ b/src/textures.cc Sat Sep 24 15:59:33 2011 +0300 @@ -1,7 +1,7 @@ /* - * textures.cc - * Trevor Phillips, RQ and Christian Johannes Schladetsch - * sometime in 1994. + * textures.cc + * Trevor Phillips, RQ and Christian Johannes Schladetsch + * sometime in 1994. */ @@ -33,7 +33,7 @@ #include <X11/Xlib.h> #endif #include "dialog.h" -#include "game.h" /* yg_picture_format */ +#include "game.h" /* yg_picture_format */ #include "gfx.h" #include "lists.h" #include "patchdir.h" @@ -51,14 +51,14 @@ */ void DisplayWallTexture(hookfunc_comm_t * c) { - MDirPtr dir = 0; // Main directory pointer to the TEXTURE* entries - int n; // General counter - i16 width, height; // Size of the texture - i16 npatches; // Number of patches in the textures - i32 numtex; // number of texture names in TEXTURE* list - i32 texofs; // Offset in the wad file to the texture data - char tname[WAD_TEX_NAME + 1]; /* texture name */ - char picname[WAD_PIC_NAME + 1]; /* wall patch name */ + MDirPtr dir = 0; // Main directory pointer to the TEXTURE* entries + int n; // General counter + i16 width, height; // Size of the texture + i16 npatches; // Number of patches in the textures + i32 numtex; // number of texture names in TEXTURE* list + i32 texofs; // Offset in the wad file to the texture data + char tname[WAD_TEX_NAME + 1]; /* texture name */ + char picname[WAD_PIC_NAME + 1]; /* wall patch name */ bool have_dummy_bytes; int header_size; int item_size; @@ -72,269 +72,269 @@ // Iwad-dependant details if (yg_texture_format == YGTF_NAMELESS) { - have_dummy_bytes = true; - header_size = 14; - item_size = 10; + have_dummy_bytes = true; + header_size = 14; + item_size = 10; } else if (yg_texture_format == YGTF_NORMAL) { - have_dummy_bytes = true; - header_size = 14; - item_size = 10; + have_dummy_bytes = true; + header_size = 14; + item_size = 10; } else if (yg_texture_format == YGTF_STRIFE11) { - have_dummy_bytes = false; - header_size = 10; - item_size = 6; + have_dummy_bytes = false; + header_size = 10; + item_size = 6; } else { - nf_bug("Bad texture format %d.", (int) yg_texture_format); - return; + nf_bug("Bad texture format %d.", (int) yg_texture_format); + return; } #ifndef Y_X11 if (have_key()) - return; // Speedup + return; // Speedup #endif // Offset for texture we want texofs = 0; // Doom alpha 0.4 : "TEXTURES", no names if (yg_texture_lumps == YGTL_TEXTURES - && yg_texture_format == YGTF_NAMELESS) + && yg_texture_format == YGTF_NAMELESS) { - const char *lump_name = "TEXTURES"; - dir = FindMasterDir(MasterDir, lump_name); - if (dir != NULL) - { - const Wad_file *wf = dir->wadfile; - wf->seek(dir->dir.start); - if (wf->error()) - { - warn("%s: can't seek to lump\n", lump_name); - goto alpha04_done; - } - wf->read_i32(&numtex); - if (wf->error()) - { - warn("%s: error reading texture count\n", lump_name); - goto alpha04_done; - } - if (WAD_TEX_NAME < 7) - nf_bug("WAD_TEX_NAME too small"); // Sanity - if (!y_strnicmp(c->name, "TEX", 3) - && isdigit(c->name[3]) - && isdigit(c->name[4]) - && isdigit(c->name[5]) - && isdigit(c->name[6]) && c->name[7] == '\0') - { - long num; - if (sscanf(c->name + 3, "%4ld", &num) == 1 - && num >= 0 && num < numtex) - { - wf->seek(dir->dir.start + 4 + 4 * num); - if (wf->error()) - { - // FIXME print name of offending texture (or #) - warn("%s: can't seek to offsets table entry\n", - lump_name); - goto alpha04_done; - } - wf->read_i32(&texofs); - if (wf->error()) - { - warn("%s: error reading texture offset\n", lump_name); - goto alpha04_done; - } - texofs += dir->dir.start; - } - } - } + const char *lump_name = "TEXTURES"; + dir = FindMasterDir(MasterDir, lump_name); + if (dir != NULL) + { + const Wad_file *wf = dir->wadfile; + wf->seek(dir->dir.start); + if (wf->error()) + { + warn("%s: can't seek to lump\n", lump_name); + goto alpha04_done; + } + wf->read_i32(&numtex); + if (wf->error()) + { + warn("%s: error reading texture count\n", lump_name); + goto alpha04_done; + } + if (WAD_TEX_NAME < 7) + nf_bug("WAD_TEX_NAME too small"); // Sanity + if (!y_strnicmp(c->name, "TEX", 3) + && isdigit(c->name[3]) + && isdigit(c->name[4]) + && isdigit(c->name[5]) + && isdigit(c->name[6]) && c->name[7] == '\0') + { + long num; + if (sscanf(c->name + 3, "%4ld", &num) == 1 + && num >= 0 && num < numtex) + { + wf->seek(dir->dir.start + 4 + 4 * num); + if (wf->error()) + { + // FIXME print name of offending texture (or #) + warn("%s: can't seek to offsets table entry\n", + lump_name); + goto alpha04_done; + } + wf->read_i32(&texofs); + if (wf->error()) + { + warn("%s: error reading texture offset\n", lump_name); + goto alpha04_done; + } + texofs += dir->dir.start; + } + } + } alpha04_done: - ; + ; } // Doom alpha 0.5 : only "TEXTURES" else if (yg_texture_lumps == YGTL_TEXTURES - && (yg_texture_format == YGTF_NORMAL - || yg_texture_format == YGTF_STRIFE11)) + && (yg_texture_format == YGTF_NORMAL + || yg_texture_format == YGTF_STRIFE11)) { - const char *lump_name = "TEXTURES"; - dir = FindMasterDir(MasterDir, lump_name); - if (dir != NULL) // (Theoretically, it should always exist) - { - i32 *offsets = NULL; // Array of offsets to texture names - const Wad_file *wf = dir->wadfile; + const char *lump_name = "TEXTURES"; + dir = FindMasterDir(MasterDir, lump_name); + if (dir != NULL) // (Theoretically, it should always exist) + { + i32 *offsets = NULL; // Array of offsets to texture names + const Wad_file *wf = dir->wadfile; - wf->seek(dir->dir.start); - if (wf->error()) - { - warn("%s: can't seek to lump\n", lump_name); - goto textures_done; - } - wf->read_i32(&numtex); - if (wf->error()) - { - warn("%s: error reading texture count\n", lump_name); - goto textures_done; - } - // Read in the offsets for texture1 names and info - offsets = (i32 *) GetMemory((long) numtex * 4); - wf->read_i32(offsets, numtex); - if (wf->error()) - { - warn("%s: error reading offsets table\n", lump_name); - goto textures_done; - } - for (long n = 0; n < numtex && !texofs; n++) - { - wf->seek(dir->dir.start + offsets[n]); - if (wf->error()) - { - warn("%s: error seeking to definition of texture #%ld\n", - lump_name, n); - break; - } - wf->read_bytes(&tname, WAD_TEX_NAME); - if (wf->error()) - { - warn("%s: error reading name of texture #%ld\n", - lump_name, n); - break; - } - if (!y_strnicmp(tname, c->name, WAD_TEX_NAME)) - texofs = dir->dir.start + offsets[n]; - } - textures_done: - if (offsets != NULL) - FreeMemory(offsets); - } + wf->seek(dir->dir.start); + if (wf->error()) + { + warn("%s: can't seek to lump\n", lump_name); + goto textures_done; + } + wf->read_i32(&numtex); + if (wf->error()) + { + warn("%s: error reading texture count\n", lump_name); + goto textures_done; + } + // Read in the offsets for texture1 names and info + offsets = (i32 *) GetMemory((long) numtex * 4); + wf->read_i32(offsets, numtex); + if (wf->error()) + { + warn("%s: error reading offsets table\n", lump_name); + goto textures_done; + } + for (long n = 0; n < numtex && !texofs; n++) + { + wf->seek(dir->dir.start + offsets[n]); + if (wf->error()) + { + warn("%s: error seeking to definition of texture #%ld\n", + lump_name, n); + break; + } + wf->read_bytes(&tname, WAD_TEX_NAME); + if (wf->error()) + { + warn("%s: error reading name of texture #%ld\n", + lump_name, n); + break; + } + if (!y_strnicmp(tname, c->name, WAD_TEX_NAME)) + texofs = dir->dir.start + offsets[n]; + } + textures_done: + if (offsets != NULL) + FreeMemory(offsets); + } } // Other iwads : "TEXTURE1" and "TEXTURE2" else if (yg_texture_lumps == YGTL_NORMAL - && (yg_texture_format == YGTF_NORMAL - || yg_texture_format == YGTF_STRIFE11)) + && (yg_texture_format == YGTF_NORMAL + || yg_texture_format == YGTF_STRIFE11)) { - // Is it in TEXTURE1 ? - { - const char *lump_name = "TEXTURE1"; - dir = FindMasterDir(MasterDir, lump_name); - if (dir != NULL) // (Theoretically, it should always exist) - { - const Wad_file *wf = dir->wadfile; - i32 *offsets = NULL; // Array of offsets to texture names + // Is it in TEXTURE1 ? + { + const char *lump_name = "TEXTURE1"; + dir = FindMasterDir(MasterDir, lump_name); + if (dir != NULL) // (Theoretically, it should always exist) + { + const Wad_file *wf = dir->wadfile; + i32 *offsets = NULL; // Array of offsets to texture names - wf->seek(dir->dir.start); - if (wf->error()) - { - warn("%s: can't seek to lump\n", lump_name); - goto texture1_done; - } - wf->read_i32(&numtex); - if (wf->error()) - { - warn("%s: error reading texture count\n", lump_name); - goto texture1_done; - } - // Read in the offsets for texture1 names and info - offsets = (i32 *) GetMemory((long) numtex * 4); - wf->read_i32(offsets, numtex); - if (wf->error()) - { - warn("%s: error reading offsets table\n", lump_name); - goto texture1_done; - } - for (long n = 0; n < numtex && !texofs; n++) - { - wf->seek(dir->dir.start + offsets[n]); - if (wf->error()) - { - warn("%s: error seeking to definition of texture #%ld\n", lump_name, n); - break; - } - wf->read_bytes(&tname, WAD_TEX_NAME); - if (wf->error()) - { - warn("%s: error reading name of texture #%ld\n", - lump_name, n); - break; - } - if (!y_strnicmp(tname, c->name, WAD_TEX_NAME)) - texofs = dir->dir.start + offsets[n]; - } - texture1_done: - if (offsets != NULL) - FreeMemory(offsets); - } - } - // Well, then is it in TEXTURE2 ? - if (texofs == 0) - { - const char *lump_name = "TEXTURE2"; - i32 *offsets = NULL; // Array of offsets to texture names + wf->seek(dir->dir.start); + if (wf->error()) + { + warn("%s: can't seek to lump\n", lump_name); + goto texture1_done; + } + wf->read_i32(&numtex); + if (wf->error()) + { + warn("%s: error reading texture count\n", lump_name); + goto texture1_done; + } + // Read in the offsets for texture1 names and info + offsets = (i32 *) GetMemory((long) numtex * 4); + wf->read_i32(offsets, numtex); + if (wf->error()) + { + warn("%s: error reading offsets table\n", lump_name); + goto texture1_done; + } + for (long n = 0; n < numtex && !texofs; n++) + { + wf->seek(dir->dir.start + offsets[n]); + if (wf->error()) + { + warn("%s: error seeking to definition of texture #%ld\n", lump_name, n); + break; + } + wf->read_bytes(&tname, WAD_TEX_NAME); + if (wf->error()) + { + warn("%s: error reading name of texture #%ld\n", + lump_name, n); + break; + } + if (!y_strnicmp(tname, c->name, WAD_TEX_NAME)) + texofs = dir->dir.start + offsets[n]; + } + texture1_done: + if (offsets != NULL) + FreeMemory(offsets); + } + } + // Well, then is it in TEXTURE2 ? + if (texofs == 0) + { + const char *lump_name = "TEXTURE2"; + i32 *offsets = NULL; // Array of offsets to texture names - dir = FindMasterDir(MasterDir, lump_name); - if (dir != NULL) // Doom II has no TEXTURE2 - { - const Wad_file *wf = dir->wadfile; - wf->seek(dir->dir.start); - if (wf->error()) - { - warn("%s: can't seek to lump\n", lump_name); - goto texture2_done; - } - wf->read_i32(&numtex); - if (wf->error()) - { - warn("%s: error reading texture count\n", lump_name); - goto texture2_done; - } - // Read in the offsets for TEXTURE2 names - offsets = (i32 *) GetMemory((long) numtex * 4); - wf->read_i32(offsets, numtex); - if (wf->error()) - { - warn("%s: error reading offsets table\n", lump_name); - goto texture2_done; - } - for (long n = 0; n < numtex && !texofs; n++) - { - wf->seek(dir->dir.start + offsets[n]); - if (wf->error()) - { - warn("%s: error seeking to definition of texture #%ld\n", lump_name, n); - break; - } - wf->read_bytes(&tname, WAD_TEX_NAME); - if (wf->error()) - { - warn("%s: error reading name of texture #%ld\n", - lump_name, n); - break; - } - if (!y_strnicmp(tname, c->name, WAD_TEX_NAME)) - texofs = dir->dir.start + offsets[n]; - } - texture2_done: - if (offsets != NULL) - FreeMemory(offsets); - } - } + dir = FindMasterDir(MasterDir, lump_name); + if (dir != NULL) // Doom II has no TEXTURE2 + { + const Wad_file *wf = dir->wadfile; + wf->seek(dir->dir.start); + if (wf->error()) + { + warn("%s: can't seek to lump\n", lump_name); + goto texture2_done; + } + wf->read_i32(&numtex); + if (wf->error()) + { + warn("%s: error reading texture count\n", lump_name); + goto texture2_done; + } + // Read in the offsets for TEXTURE2 names + offsets = (i32 *) GetMemory((long) numtex * 4); + wf->read_i32(offsets, numtex); + if (wf->error()) + { + warn("%s: error reading offsets table\n", lump_name); + goto texture2_done; + } + for (long n = 0; n < numtex && !texofs; n++) + { + wf->seek(dir->dir.start + offsets[n]); + if (wf->error()) + { + warn("%s: error seeking to definition of texture #%ld\n", lump_name, n); + break; + } + wf->read_bytes(&tname, WAD_TEX_NAME); + if (wf->error()) + { + warn("%s: error reading name of texture #%ld\n", + lump_name, n); + break; + } + if (!y_strnicmp(tname, c->name, WAD_TEX_NAME)) + texofs = dir->dir.start + offsets[n]; + } + texture2_done: + if (offsets != NULL) + FreeMemory(offsets); + } + } } else - nf_bug("Invalid texture_format/texture_lumps combination."); + nf_bug("Invalid texture_format/texture_lumps combination."); // Texture name not found if (texofs == 0) - return; + return; // Read the info for this texture i32 header_ofs; if (yg_texture_format == YGTF_NAMELESS) - header_ofs = texofs; + header_ofs = texofs; else - header_ofs = texofs + WAD_TEX_NAME; + header_ofs = texofs + WAD_TEX_NAME; dir->wadfile->seek(header_ofs + 4); // FIXME dir->wadfile->read_i16(&width); @@ -343,9 +343,9 @@ // FIXME if (have_dummy_bytes) { - i16 dummy; - dir->wadfile->read_i16(&dummy); - dir->wadfile->read_i16(&dummy); + i16 dummy; + dir->wadfile->read_i16(&dummy); + dir->wadfile->read_i16(&dummy); } dir->wadfile->read_i16(&npatches); // FIXME @@ -369,66 +369,66 @@ paste only the first maxpatches ones. */ int maxpatches = npatches; if (c->maxpatches != 0 && c->maxpatches <= npatches) - maxpatches = c->maxpatches; + maxpatches = c->maxpatches; for (n = 0; n < maxpatches; n++) { - hookfunc_comm_t subc; - i16 xofs, yofs; // Offset in texture space for the patch - i16 pnameind; // Index of patch in PNAMES + hookfunc_comm_t subc; + i16 xofs, yofs; // Offset in texture space for the patch + i16 pnameind; // Index of patch in PNAMES - dir->wadfile->seek(header_ofs + header_size + (long) n * item_size); - dir->wadfile->read_i16(&xofs); - dir->wadfile->read_i16(&yofs); - dir->wadfile->read_i16(&pnameind); - if (have_dummy_bytes) - { - i16 stepdir; - i16 colormap; - dir->wadfile->read_i16(&stepdir); // Always 1, unused. - dir->wadfile->read_i16(&colormap); // Always 0, unused. - } + dir->wadfile->seek(header_ofs + header_size + (long) n * item_size); + dir->wadfile->read_i16(&xofs); + dir->wadfile->read_i16(&yofs); + dir->wadfile->read_i16(&pnameind); + if (have_dummy_bytes) + { + i16 stepdir; + i16 colormap; + dir->wadfile->read_i16(&stepdir); // Always 1, unused. + dir->wadfile->read_i16(&colormap); // Always 0, unused. + } - /* AYM 1998-08-08: Yes, that's weird but that's what Doom - does. Without these two lines, the few textures that have - patches with negative y-offsets (BIGDOOR7, SKY1, TEKWALL1, - TEKWALL5 and a few others) would not look in the texture - viewer quite like in Doom. This should be mentioned in - the UDS, by the way. */ - if (yofs < 0) - yofs = 0; + /* AYM 1998-08-08: Yes, that's weird but that's what Doom + does. Without these two lines, the few textures that have + patches with negative y-offsets (BIGDOOR7, SKY1, TEKWALL1, + TEKWALL5 and a few others) would not look in the texture + viewer quite like in Doom. This should be mentioned in + the UDS, by the way. */ + if (yofs < 0) + yofs = 0; - Lump_loc loc; - { - wad_pic_name_t *name = patch_dir.name_for_num(pnameind); - if (name == 0) - { - warn("texture \"%.*s\": patch %2d has bad index %d.\n", - WAD_TEX_NAME, tname, (int) n, (int) pnameind); - continue; - } - patch_dir.loc_by_name((const char *) *name, loc); - *picname = '\0'; - strncat(picname, (const char *) *name, sizeof picname - 1); + Lump_loc loc; + { + wad_pic_name_t *name = patch_dir.name_for_num(pnameind); + if (name == 0) + { + warn("texture \"%.*s\": patch %2d has bad index %d.\n", + WAD_TEX_NAME, tname, (int) n, (int) pnameind); + continue; + } + patch_dir.loc_by_name((const char *) *name, loc); + *picname = '\0'; + strncat(picname, (const char *) *name, sizeof picname - 1); #ifdef DEBUG - printf("Texture \"%.*s\": Patch %2d: #%3d %-8.8s (%d, %d)\n", - c->name, (int) n, (int) pnameind, picname, (int) xofs, - (int) yofs); + printf("Texture \"%.*s\": Patch %2d: #%3d %-8.8s (%d, %d)\n", + c->name, (int) n, (int) pnameind, picname, (int) xofs, + (int) yofs); #endif - } + } - subc.x0 = y_max(c->x0, c->x0 + xofs); - subc.y0 = y_min(c->y0, c->y0 + yofs); - subc.x1 = c->x1; - subc.x1 = c->y1; - subc.name = picname; + subc.x0 = y_max(c->x0, c->x0 + xofs); + subc.y0 = y_min(c->y0, c->y0 + yofs); + subc.x1 = c->x1; + subc.x1 = c->y1; + subc.name = picname; - if (LoadPicture(c->img, picname, loc, xofs, yofs, 0, 0)) - warn("texture \"%.*s\": patch \"%.*s\" not found.\n", - WAD_TEX_NAME, tname, WAD_PIC_NAME, picname); + if (LoadPicture(c->img, picname, loc, xofs, yofs, 0, 0)) + warn("texture \"%.*s\": patch \"%.*s\" not found.\n", + WAD_TEX_NAME, tname, WAD_PIC_NAME, picname); } // Display the texture - Sticker sticker(c->img, true); // Use opaque because it's faster + Sticker sticker(c->img, true); // Use opaque because it's faster sticker.draw(drw, 't', c->x0, c->y0); c->flags |= HOOK_DRAWN; c->disp_x0 = c->x0 + c->xofs; @@ -443,110 +443,110 @@ */ void GetWallTextureSize(i16 * width, i16 * height, const char *texname) { - MDirPtr dir = 0; // Pointer in main directory to texname - i32 *offsets; // Array of offsets to texture names - int n; // General counter - i32 numtex; // Number of texture names in TEXTURE* - i32 texofs; // Offset in wad for the texture data - char tname[WAD_TEX_NAME + 1]; // Texture name + MDirPtr dir = 0; // Pointer in main directory to texname + i32 *offsets; // Array of offsets to texture names + int n; // General counter + i32 numtex; // Number of texture names in TEXTURE* + i32 texofs; // Offset in wad for the texture data + char tname[WAD_TEX_NAME + 1]; // Texture name // Offset for texture we want texofs = 0; // Search for texname in TEXTURE1 (or TEXTURES) if (yg_texture_lumps == YGTL_TEXTURES - && yg_texture_format == YGTF_NAMELESS) + && yg_texture_format == YGTF_NAMELESS) { - dir = FindMasterDir(MasterDir, "TEXTURES"); - if (dir != NULL) - { - dir->wadfile->seek(dir->dir.start); - dir->wadfile->read_i32(&numtex); - if (WAD_TEX_NAME < 7) - nf_bug("WAD_TEX_NAME too small"); // Sanity - if (!y_strnicmp(texname, "TEX", 3) - && isdigit(texname[3]) - && isdigit(texname[4]) - && isdigit(texname[5]) - && isdigit(texname[6]) && texname[7] == '\0') - { - long num; - if (sscanf(texname + 3, "%4ld", &num) == 1 - && num >= 0 && num < numtex) - { - dir->wadfile->seek(dir->dir.start + 4 + 4 * num); - dir->wadfile->read_i32(&texofs); - } - } - } + dir = FindMasterDir(MasterDir, "TEXTURES"); + if (dir != NULL) + { + dir->wadfile->seek(dir->dir.start); + dir->wadfile->read_i32(&numtex); + if (WAD_TEX_NAME < 7) + nf_bug("WAD_TEX_NAME too small"); // Sanity + if (!y_strnicmp(texname, "TEX", 3) + && isdigit(texname[3]) + && isdigit(texname[4]) + && isdigit(texname[5]) + && isdigit(texname[6]) && texname[7] == '\0') + { + long num; + if (sscanf(texname + 3, "%4ld", &num) == 1 + && num >= 0 && num < numtex) + { + dir->wadfile->seek(dir->dir.start + 4 + 4 * num); + dir->wadfile->read_i32(&texofs); + } + } + } } else if (yg_texture_format == YGTF_NORMAL - || yg_texture_format == YGTF_STRIFE11) + || yg_texture_format == YGTF_STRIFE11) { - if (yg_texture_lumps == YGTL_TEXTURES) - dir = FindMasterDir(MasterDir, "TEXTURES"); // Doom alpha 0.5 - else if (yg_texture_lumps == YGTL_NORMAL) - dir = FindMasterDir(MasterDir, "TEXTURE1"); - else - { - dir = 0; - nf_bug("Invalid texture_format/texture_lumps combination."); - } - if (dir != NULL) - { - dir->wadfile->seek(dir->dir.start); - dir->wadfile->read_i32(&numtex); - // Read in the offsets for texture1 names and info - offsets = (i32 *) GetMemory((long) numtex * 4); - dir->wadfile->read_i32(offsets, numtex); - for (n = 0; n < numtex && !texofs; n++) - { - dir->wadfile->seek(dir->dir.start + offsets[n]); - dir->wadfile->read_bytes(&tname, WAD_TEX_NAME); - if (!y_strnicmp(tname, texname, WAD_TEX_NAME)) - texofs = dir->dir.start + offsets[n]; - } - FreeMemory(offsets); - } - if (texofs == 0 && yg_texture_lumps == YGTL_NORMAL) - { - // Search for texname in TEXTURE2 - dir = FindMasterDir(MasterDir, "TEXTURE2"); - if (dir != NULL) // Doom II has no TEXTURE2 - { - dir->wadfile->seek(dir->dir.start); - dir->wadfile->read_i32(&numtex); - // Read in the offsets for texture2 names - offsets = (i32 *) GetMemory((long) numtex * 4); - dir->wadfile->read_i32(offsets); - for (n = 0; n < numtex && !texofs; n++) - { - dir->wadfile->seek(dir->dir.start + offsets[n]); - dir->wadfile->read_bytes(&tname, WAD_TEX_NAME); - if (!y_strnicmp(tname, texname, WAD_TEX_NAME)) - texofs = dir->dir.start + offsets[n]; - } - FreeMemory(offsets); - } - } + if (yg_texture_lumps == YGTL_TEXTURES) + dir = FindMasterDir(MasterDir, "TEXTURES"); // Doom alpha 0.5 + else if (yg_texture_lumps == YGTL_NORMAL) + dir = FindMasterDir(MasterDir, "TEXTURE1"); + else + { + dir = 0; + nf_bug("Invalid texture_format/texture_lumps combination."); + } + if (dir != NULL) + { + dir->wadfile->seek(dir->dir.start); + dir->wadfile->read_i32(&numtex); + // Read in the offsets for texture1 names and info + offsets = (i32 *) GetMemory((long) numtex * 4); + dir->wadfile->read_i32(offsets, numtex); + for (n = 0; n < numtex && !texofs; n++) + { + dir->wadfile->seek(dir->dir.start + offsets[n]); + dir->wadfile->read_bytes(&tname, WAD_TEX_NAME); + if (!y_strnicmp(tname, texname, WAD_TEX_NAME)) + texofs = dir->dir.start + offsets[n]; + } + FreeMemory(offsets); + } + if (texofs == 0 && yg_texture_lumps == YGTL_NORMAL) + { + // Search for texname in TEXTURE2 + dir = FindMasterDir(MasterDir, "TEXTURE2"); + if (dir != NULL) // Doom II has no TEXTURE2 + { + dir->wadfile->seek(dir->dir.start); + dir->wadfile->read_i32(&numtex); + // Read in the offsets for texture2 names + offsets = (i32 *) GetMemory((long) numtex * 4); + dir->wadfile->read_i32(offsets); + for (n = 0; n < numtex && !texofs; n++) + { + dir->wadfile->seek(dir->dir.start + offsets[n]); + dir->wadfile->read_bytes(&tname, WAD_TEX_NAME); + if (!y_strnicmp(tname, texname, WAD_TEX_NAME)) + texofs = dir->dir.start + offsets[n]; + } + FreeMemory(offsets); + } + } } else - nf_bug("Invalid texture_format/texture_lumps combination."); + nf_bug("Invalid texture_format/texture_lumps combination."); if (texofs != 0) { - // Read the info for this texture - if (yg_texture_format == YGTF_NAMELESS) - dir->wadfile->seek(texofs + 4L); - else - dir->wadfile->seek(texofs + 12L); - dir->wadfile->read_i16(width); - dir->wadfile->read_i16(height); + // Read the info for this texture + if (yg_texture_format == YGTF_NAMELESS) + dir->wadfile->seek(texofs + 4L); + else + dir->wadfile->seek(texofs + 12L); + dir->wadfile->read_i16(width); + dir->wadfile->read_i16(height); } else { - // Texture data not found - *width = -1; - *height = -1; + // Texture data not found + *width = -1; + *height = -1; } } @@ -555,9 +555,9 @@ choose a wall texture */ void ChooseWallTexture(int x0, int y0, const char *prompt, int listsize, - char **list, char *name) + char **list, char *name) { InputNameFromListWithFunc(x0, y0, prompt, listsize, list, 9, name, - 512, 256, DisplayWallTexture); + 512, 256, DisplayWallTexture); } diff -r 594dea11ccd9 -r a68786b9c74b src/textures.h --- a/src/textures.h Sat Sep 24 15:01:56 2011 +0300 +++ b/src/textures.h Sat Sep 24 15:59:33 2011 +0300 @@ -1,10 +1,10 @@ /* - * textures.h - * AYM 2000-04-29 + * textures.h + * AYM 2000-04-29 */ -#ifndef YH_TEXTURES /* DO NOT ADD ANYTHING BEFORE THIS LINE */ +#ifndef YH_TEXTURES /* DO NOT ADD ANYTHING BEFORE THIS LINE */ #define YH_TEXTURES diff -r 594dea11ccd9 -r a68786b9c74b src/things.cc --- a/src/things.cc Sat Sep 24 15:01:56 2011 +0300 +++ b/src/things.cc Sat Sep 24 15:59:33 2011 +0300 @@ -1,7 +1,7 @@ /* - * things.cc - * Misc things routines. - * BW & RQ sometime in 1993 or 1994. + * things.cc + * Misc things routines. + * BW & RQ sometime in 1993 or 1994. */ @@ -63,10 +63,10 @@ /* - * create_things_table - * Build things_table, a table of things attributes - * that's used by get_thing_*() to speed things up. - * Call delete_things_table to delete that table. + * create_things_table + * Build things_table, a table of things attributes + * that's used by get_thing_*() to speed things up. + * Call delete_things_table to delete that table. */ void create_things_table() { @@ -76,34 +76,34 @@ nthings = al_lcount(thingdef); if (nthings == 0) { - things_table = NULL; - return; + things_table = NULL; + return; } things_table = - (thing_attributes_t *) malloc(nthings * sizeof *things_table); + (thing_attributes_t *) malloc(nthings * sizeof *things_table); if (!things_table) - fatal_error("Not enough memory"); + fatal_error("Not enough memory"); for (al_lrewind(thingdef), n = 0; n < nthings; al_lstep(thingdef), n++) { - things_table[n].type = CUR_THINGDEF->number; - things_table[n].flags = CUR_THINGDEF->flags; - things_table[n].radius = CUR_THINGDEF->radius; - _max_radius = y_max(_max_radius, CUR_THINGDEF->radius); + things_table[n].type = CUR_THINGDEF->number; + things_table[n].flags = CUR_THINGDEF->flags; + things_table[n].radius = CUR_THINGDEF->radius; + _max_radius = y_max(_max_radius, CUR_THINGDEF->radius); - // Fetch the app colour no. for the thinggroup - for (al_lrewind(thinggroup); !al_leol(thinggroup); - al_lstep(thinggroup)) - { - if (CUR_THINGGROUP /* don't segfault if zero thinggroup ! */ - && CUR_THINGGROUP->thinggroup == CUR_THINGDEF->thinggroup) - { - things_table[n].colour = CUR_THINGGROUP->acn; - break; - } - } + // Fetch the app colour no. for the thinggroup + for (al_lrewind(thinggroup); !al_leol(thinggroup); + al_lstep(thinggroup)) + { + if (CUR_THINGGROUP /* don't segfault if zero thinggroup ! */ + && CUR_THINGGROUP->thinggroup == CUR_THINGDEF->thinggroup) + { + things_table[n].colour = CUR_THINGGROUP->acn; + break; + } + } - things_table[n].desc = CUR_THINGDEF->desc; - things_table[n].sprite = CUR_THINGDEF->sprite; + things_table[n].desc = CUR_THINGDEF->desc; + things_table[n].sprite = CUR_THINGDEF->sprite; } // Sort the table by increasing thing type @@ -112,88 +112,88 @@ #if 0 printf("Type Colour Radius Desc\n"); for (n = 0; n < nthings; n++) - printf("%5d %-6d %3d %s\n", - things_table[n].type, - things_table[n].colour, - things_table[n].radius, things_table[n].desc); + printf("%5d %-6d %3d %s\n", + things_table[n].type, + things_table[n].colour, + things_table[n].radius, things_table[n].desc); #endif } /* - * delete_things_table - * Free what create_things_table() allocated. + * delete_things_table + * Free what create_things_table() allocated. */ void delete_things_table(void) { if (things_table) { - free(things_table); - nthings = 0; + free(things_table); + nthings = 0; } } /* - * things_table_cmp - * Used by create_things_table() to sort the table - * by increasing THING type. + * things_table_cmp + * Used by create_things_table() to sort the table + * by increasing THING type. */ static int things_table_cmp(const void *a, const void *b) { return ((const thing_attributes_t *) a)->type - - ((const thing_attributes_t *) b)->type; + - ((const thing_attributes_t *) b)->type; } /* - * lookup_thing - * Does a binary search in things_table for the thing of type <type>. - * If succeeds, returns the index of the thing. - * If fails, returns ((size_t) -1). - * To further speed things up, the last index found is kept - * between invocations in a static variable. Thus, if several - * attributes of the same thing type are queried in a row, - * the table search is done only once. + * lookup_thing + * Does a binary search in things_table for the thing of type <type>. + * If succeeds, returns the index of the thing. + * If fails, returns ((size_t) -1). + * To further speed things up, the last index found is kept + * between invocations in a static variable. Thus, if several + * attributes of the same thing type are queried in a row, + * the table search is done only once. */ inline int lookup_thing(wad_ttype_t type) { if (last_table_idx < nthings && things_table[last_table_idx].type == type) - return last_table_idx; + return last_table_idx; if (things_table == NULL) - return (size_t) - 1; + return (size_t) - 1; size_t nmin = 0; size_t nmax = nthings - 1; for (;;) { - last_table_idx = (nmin + nmax) / 2; - if (type > things_table[last_table_idx].type) - { - if (nmin >= nmax) - break; - nmin = last_table_idx + 1; - } - else if (type < things_table[last_table_idx].type) - { - if (nmin >= nmax) - break; - if (last_table_idx < 1) - break; - nmax = last_table_idx - 1; - } - else - return last_table_idx; + last_table_idx = (nmin + nmax) / 2; + if (type > things_table[last_table_idx].type) + { + if (nmin >= nmax) + break; + nmin = last_table_idx + 1; + } + else if (type < things_table[last_table_idx].type) + { + if (nmin >= nmax) + break; + if (last_table_idx < 1) + break; + nmax = last_table_idx - 1; + } + else + return last_table_idx; } return (size_t) - 1; } /* - * is_thing_type - is given type valid (i.e. defined in the ygd) + * is_thing_type - is given type valid (i.e. defined in the ygd) * - * Return true if the thing is defined, false otherwise. + * Return true if the thing is defined, false otherwise. */ bool is_thing_type(wad_ttype_t type) { @@ -203,85 +203,85 @@ /* - * get_thing_colour - return the colour of the thing of given type. + * get_thing_colour - return the colour of the thing of given type. * - * Return the colour. If the + * Return the colour. If the */ acolour_t get_thing_colour(wad_ttype_t type) { size_t table_idx = lookup_thing(type); if (table_idx == (size_t) - 1) - return LIGHTCYAN; // Not found. + return LIGHTCYAN; // Not found. else - return things_table[table_idx].colour; + return things_table[table_idx].colour; } /* - * get_thing_name - return the description of the thing of given type. + * get_thing_name - return the description of the thing of given type. */ const char *get_thing_name(wad_ttype_t type) { size_t table_idx = lookup_thing(type); if (table_idx == (size_t) - 1) { - static char buf[20]; - sprintf(buf, "UNKNOWN (%d)", type); // Not found. - return buf; + static char buf[20]; + sprintf(buf, "UNKNOWN (%d)", type); // Not found. + return buf; } else - return things_table[table_idx].desc; + return things_table[table_idx].desc; } /* - * get_thing_sprite - * Return the root of the sprite name for the thing of given type. + * get_thing_sprite + * Return the root of the sprite name for the thing of given type. */ const char *get_thing_sprite(wad_ttype_t type) { size_t table_idx = lookup_thing(type); if (table_idx == (size_t) - 1) - return NULL; // Not found + return NULL; // Not found else - return things_table[table_idx].sprite; + return things_table[table_idx].sprite; } /* - * get_thing_flags - * Return the flags for the thing of given type. + * get_thing_flags + * Return the flags for the thing of given type. */ char get_thing_flags(wad_ttype_t type) { size_t table_idx = lookup_thing(type); if (table_idx == (size_t) - 1) - return 0; // Not found + return 0; // Not found else - return things_table[table_idx].flags; + return things_table[table_idx].flags; } /* - * get_thing_radius - * Return the radius of the thing of given type. + * get_thing_radius + * Return the radius of the thing of given type. */ int get_thing_radius(wad_ttype_t type) { size_t table_idx = lookup_thing(type); if (table_idx == (size_t) - 1) - return default_radius; // Not found. + return default_radius; // Not found. else - return things_table[table_idx].radius; + return things_table[table_idx].radius; } /* - * get_max_thing_radius - * Return the radius of the largest thing that exists. - * This is a speedup function, used by GetCurObject() - * to avoid calculating the distance for the things - * that are obviously too far away. + * get_max_thing_radius + * Return the radius of the largest thing that exists. + * This is a speedup function, used by GetCurObject() + * to avoid calculating the distance for the things + * that are obviously too far away. */ /* It's now inlined in things.h @@ -293,8 +293,8 @@ /* - * GetAngleName - * Get the name of the angle + * GetAngleName + * Get the name of the angle */ const char *GetAngleName(int angle) { @@ -303,21 +303,21 @@ switch (angle) { case 0: - return "East"; + return "East"; case 45: - return "North-east"; + return "North-east"; case 90: - return "North"; + return "North"; case 135: - return "North-west"; + return "North-west"; case 180: - return "West"; + return "West"; case 225: - return "South-west"; + return "South-west"; case 270: - return "South"; + return "South"; case 315: - return "South-east"; + return "South-east"; } sprintf(buf, "ILLEGAL (%d)", angle); return buf; @@ -325,8 +325,8 @@ /* - * GetWhenName - * get string of when something will appear + * GetWhenName + * get string of when something will appear */ const char *GetWhenName(int when) { @@ -340,12 +340,12 @@ char *b = buf; for (n = 0; n < 16; n++) { - if (n != 0 && n % 4 == 0) - *b++ = ' '; - if (when & (0x8000u >> n)) - *b++ = flag_chars[n]; - else - *b++ = '-'; + if (n != 0 && n % 4 == 0) + *b++ = ' '; + if (when & (0x8000u >> n)) + *b++ = flag_chars[n]; + else + *b++ = '-'; } *b = '\0'; return buf; @@ -356,36 +356,36 @@ *ptr = '\0'; if (when & 0x01) { - strcpy(ptr, "D12"); - ptr += 3; + strcpy(ptr, "D12"); + ptr += 3; } if (when & 0x02) { - if (ptr != buf) - *ptr++ = ' '; - strcpy(ptr, "D3"); - ptr += 2; + if (ptr != buf) + *ptr++ = ' '; + strcpy(ptr, "D3"); + ptr += 2; } if (when & 0x04) { - if (ptr != buf) - *ptr++ = ' '; - strcpy(ptr, "D45"); - ptr += 3; + if (ptr != buf) + *ptr++ = ' '; + strcpy(ptr, "D45"); + ptr += 3; } if (when & 0x08) { - if (ptr != buf) - *ptr++ = ' '; - strcpy(ptr, "Deaf"); - ptr += 4; + if (ptr != buf) + *ptr++ = ' '; + strcpy(ptr, "Deaf"); + ptr += 4; } if (when & 0x10) { - if (ptr != buf) - *ptr++ = ' '; - strcpy(ptr, "Multi"); - ptr += 5; + if (ptr != buf) + *ptr++ = ' '; + strcpy(ptr, "Multi"); + ptr += 5; } return buf; #endif diff -r 594dea11ccd9 -r a68786b9c74b src/things.h --- a/src/things.h Sat Sep 24 15:01:56 2011 +0300 +++ b/src/things.h Sat Sep 24 15:59:33 2011 +0300 @@ -1,12 +1,12 @@ /* - * things.h - * Header for things.cc - * BW & RQ sometime in 1993 or 1994. + * things.h + * Header for things.cc + * BW & RQ sometime in 1993 or 1994. */ -#ifndef YH_THINGS /* Prevent multiple inclusion */ -#define YH_THINGS /* Prevent multiple inclusion */ +#ifndef YH_THINGS /* Prevent multiple inclusion */ +#define YH_THINGS /* Prevent multiple inclusion */ #include "wstructs.h" @@ -45,9 +45,9 @@ /* - * angle_to_direction - convert angle to direction (0-7) + * angle_to_direction - convert angle to direction (0-7) * - * Return a value that is guaranteed to be within [0-7]. + * Return a value that is guaranteed to be within [0-7]. */ inline int angle_to_direction(wad_tangle_t angle) { diff -r 594dea11ccd9 -r a68786b9c74b src/trace.cc --- a/src/trace.cc Sat Sep 24 15:01:56 2011 +0300 +++ b/src/trace.cc Sat Sep 24 15:59:33 2011 +0300 @@ -1,7 +1,7 @@ /* - * trace.cc - * Selective tracing system - * AYM 1999-11-30 + * trace.cc + * Selective tracing system + * AYM 1999-11-30 */ @@ -37,12 +37,12 @@ { if (verbose) { - va_list args; + va_list args; - fprintf(stdout, "%s: ", domain); - va_start(args, fmt); - vprintf(fmt, args); - va_end(args); - putchar('\n'); + fprintf(stdout, "%s: ", domain); + va_start(args, fmt); + vprintf(fmt, args); + va_end(args); + putchar('\n'); } } diff -r 594dea11ccd9 -r a68786b9c74b src/trace.h --- a/src/trace.h Sat Sep 24 15:01:56 2011 +0300 +++ b/src/trace.h Sat Sep 24 15:59:33 2011 +0300 @@ -1,7 +1,7 @@ /* - * trace.h - * Selective tracing system - * AYM 1999-11-30 + * trace.h + * Selective tracing system + * AYM 1999-11-30 */ diff -r 594dea11ccd9 -r a68786b9c74b src/v_centre.cc --- a/src/v_centre.cc Sat Sep 24 15:01:56 2011 +0300 +++ b/src/v_centre.cc Sat Sep 24 15:59:33 2011 +0300 @@ -1,6 +1,6 @@ /* - * v_centre.cc - * AYM 1998-11-22 + * v_centre.cc + * AYM 1998-11-22 */ @@ -35,8 +35,8 @@ /* - * centre_of_vertices - * Return the coordinates of the centre of a group of vertices. + * centre_of_vertices + * Return the coordinates of the centre of a group of vertices. */ void centre_of_vertices(SelPtr list, int *x, int *y) { @@ -49,25 +49,25 @@ y_sum = 0; for (nitems = 0, cur = list; cur; cur = cur->next, nitems++) { - x_sum += Vertices[cur->objnum].x; - y_sum += Vertices[cur->objnum].y; + x_sum += Vertices[cur->objnum].x; + y_sum += Vertices[cur->objnum].y; } if (nitems == 0) { - *x = 0; - *y = 0; + *x = 0; + *y = 0; } else { - *x = (int) (x_sum / nitems); - *y = (int) (y_sum / nitems); + *x = (int) (x_sum / nitems); + *y = (int) (y_sum / nitems); } } /* - * centre_of_vertices - * Return the coordinates of the centre of a group of vertices. + * centre_of_vertices + * Return the coordinates of the centre of a group of vertices. */ void centre_of_vertices(const bitvec_c & bv, int &x, int &y) { @@ -77,21 +77,21 @@ int nvertices = 0; for (int n = 0; n < nmax; n++) { - if (bv.get(n)) - { - x_sum += Vertices[n].x; - y_sum += Vertices[n].y; - nvertices++; - } + if (bv.get(n)) + { + x_sum += Vertices[n].x; + y_sum += Vertices[n].y; + nvertices++; + } } if (nvertices == 0) { - x = 0; - y = 0; + x = 0; + y = 0; } else { - x = (int) (x_sum / nvertices); - y = (int) (y_sum / nvertices); + x = (int) (x_sum / nvertices); + y = (int) (y_sum / nvertices); } } diff -r 594dea11ccd9 -r a68786b9c74b src/v_centre.h --- a/src/v_centre.h Sat Sep 24 15:01:56 2011 +0300 +++ b/src/v_centre.h Sat Sep 24 15:59:33 2011 +0300 @@ -1,6 +1,6 @@ /* - * v_centre.h - * AYM 1998-11-22 + * v_centre.h + * AYM 1998-11-22 */ diff -r 594dea11ccd9 -r a68786b9c74b src/v_merge.cc --- a/src/v_merge.cc Sat Sep 24 15:01:56 2011 +0300 +++ b/src/v_merge.cc Sat Sep 24 15:59:33 2011 +0300 @@ -1,7 +1,7 @@ /* - * v_merge.cc - * Merging vertices - * AYM 1998-02-04 + * v_merge.cc + * Merging vertices + * AYM 1998-02-04 */ @@ -36,7 +36,7 @@ #include "selectn.h" -typedef struct /* Used only by AutoMergeVertices() and SortLinedefs() */ +typedef struct /* Used only by AutoMergeVertices() and SortLinedefs() */ { int vertexl; int vertexh; @@ -59,41 +59,41 @@ while (obj != NULL) { - cur = obj; - obj = obj->next; - lstart = -1; - lend = -1; - for (l = 0; l < NumLineDefs; l++) - { - if (LineDefs[l].start == cur->objnum) - { - if (lstart == -1) - lstart = l; - else - lstart = -2; - } - if (LineDefs[l].end == cur->objnum) - { - if (lend == -1) - lend = l; - else - lend = -2; - } - } - if (lstart < 0 || lend < 0) - { - Beep(); - sprintf(msg, "Cannot delete vertex #%d and join the linedefs", - cur->objnum); - Notify(-1, -1, msg, "The vertex must be the start of one linedef" - " and the end of another one"); - continue; - } - LineDefs[lend].end = LineDefs[lstart].end; - DeleteObject(Objid(OBJ_LINEDEFS, lstart)); - DeleteObject(Objid(OBJ_VERTICES, cur->objnum)); - MadeChanges = 1; - MadeMapChanges = 1; + cur = obj; + obj = obj->next; + lstart = -1; + lend = -1; + for (l = 0; l < NumLineDefs; l++) + { + if (LineDefs[l].start == cur->objnum) + { + if (lstart == -1) + lstart = l; + else + lstart = -2; + } + if (LineDefs[l].end == cur->objnum) + { + if (lend == -1) + lend = l; + else + lend = -2; + } + } + if (lstart < 0 || lend < 0) + { + Beep(); + sprintf(msg, "Cannot delete vertex #%d and join the linedefs", + cur->objnum); + Notify(-1, -1, msg, "The vertex must be the start of one linedef" + " and the end of another one"); + continue; + } + LineDefs[lend].end = LineDefs[lstart].end; + DeleteObject(Objid(OBJ_LINEDEFS, lstart)); + DeleteObject(Objid(OBJ_VERTICES, cur->objnum)); + MadeChanges = 1; + MadeMapChanges = 1; } } @@ -111,25 +111,25 @@ UnSelectObject(list, v); if (*list == NULL) { - Beep(); - Notify(-1, -1, "You must select at least two vertices", NULL); - return; + Beep(); + Notify(-1, -1, "You must select at least two vertices", NULL); + return; } /* change the linedefs starts & ends */ for (l = 0; l < NumLineDefs; l++) { - if (IsSelected(*list, LineDefs[l].start)) - { - /* don't change a linedef that has both ends on the same spot */ - if (!IsSelected(*list, LineDefs[l].end) && LineDefs[l].end != v) - LineDefs[l].start = v; - } - else if (IsSelected(*list, LineDefs[l].end)) - { - /* idem */ - if (LineDefs[l].start != v) - LineDefs[l].end = v; - } + if (IsSelected(*list, LineDefs[l].start)) + { + /* don't change a linedef that has both ends on the same spot */ + if (!IsSelected(*list, LineDefs[l].end) && LineDefs[l].end != v) + LineDefs[l].start = v; + } + else if (IsSelected(*list, LineDefs[l].end)) + { + /* idem */ + if (LineDefs[l].start != v) + LineDefs[l].end = v; + } } /* delete the vertices (and some linedefs too) */ DeleteObjects(OBJ_VERTICES, list); @@ -166,59 +166,59 @@ all the vertices used by those sectors/linedefs and proceed as usually. */ if (obj_type != OBJ_VERTICES) - return false; + return false; redraw = false; mergedone = false; isldend = false; if (operation == 'i') - confirm_flag = insert_vertex_merge_vertices; + confirm_flag = insert_vertex_merge_vertices; else - confirm_flag = YC_ASK_ONCE; + confirm_flag = YC_ASK_ONCE; /* first, check if two (or more) vertices should be merged */ ref = *list; while (ref) { - refv = ref->objnum; - ref = ref->next; - /* check if there is a vertex at the same position (same X and Y) */ - for (v = 0; v < NumVertices; v++) - if (v != refv - && Vertices[refv].x == Vertices[v].x - && Vertices[refv].y == Vertices[v].y) - { - char buf[81]; - redraw = true; - sprintf(buf, "Vertices %d and %d occupy the same position", - refv, v); - if (Confirm2 - (-1, -1, &confirm_flag, buf, - "Do you want to merge them into one?")) - { - /* merge the two vertices */ - mergedone = true; - cur = NULL; - SelectObject(&cur, refv); - SelectObject(&cur, v); - MergeVertices(&cur); - /* update the references in the selection list */ - for (cur = *list; cur; cur = cur->next) - if (cur->objnum > refv) - cur->objnum = cur->objnum - 1; - if (v > refv) - v--; - /* the old vertex has been deleted */ - UnSelectObject(list, refv); - /* select the new vertex instead */ - if (!IsSelected(*list, v)) - SelectObject(list, v); - break; - } - else - return redraw; - } + refv = ref->objnum; + ref = ref->next; + /* check if there is a vertex at the same position (same X and Y) */ + for (v = 0; v < NumVertices; v++) + if (v != refv + && Vertices[refv].x == Vertices[v].x + && Vertices[refv].y == Vertices[v].y) + { + char buf[81]; + redraw = true; + sprintf(buf, "Vertices %d and %d occupy the same position", + refv, v); + if (Confirm2 + (-1, -1, &confirm_flag, buf, + "Do you want to merge them into one?")) + { + /* merge the two vertices */ + mergedone = true; + cur = NULL; + SelectObject(&cur, refv); + SelectObject(&cur, v); + MergeVertices(&cur); + /* update the references in the selection list */ + for (cur = *list; cur; cur = cur->next) + if (cur->objnum > refv) + cur->objnum = cur->objnum - 1; + if (v > refv) + v--; + /* the old vertex has been deleted */ + UnSelectObject(list, refv); + /* select the new vertex instead */ + if (!IsSelected(*list, v)) + SelectObject(list, v); + break; + } + else + return redraw; + } } /* Now, check if one or more vertices are on a linedef */ @@ -228,64 +228,64 @@ int tolerance = (int) (4 / Scale); if (operation == 'i') - confirm_flag = insert_vertex_split_linedef; + confirm_flag = insert_vertex_split_linedef; else - confirm_flag = YC_ASK_ONCE; + confirm_flag = YC_ASK_ONCE; ref = *list; while (ref) { - refv = ref->objnum; - ref = ref->next; - oldnumld = NumLineDefs; - //printf ("V%d %d\n", refv, NumLineDefs); // DEBUG; - /* check if this vertex is on a linedef */ - for (ld = 0; ld < oldnumld; ld++) - { - if (LineDefs[ld].start == refv || LineDefs[ld].end == refv) - { - /* one vertex had a linedef bound to it -- check it later */ - isldend = true; - } - else if (IsLineDefInside(ld, Vertices[refv].x - tolerance, - Vertices[refv].y - tolerance, - Vertices[refv].x + tolerance, - Vertices[refv].y + tolerance)) - { - char buf[81]; - redraw = true; - sprintf(buf, "Vertex %d is on top of linedef %d", refv, ld); - if (Confirm2(-1, -1, &confirm_flag, - buf, "Do you want to split the linedef there?")) - { - /* split the linedef */ - mergedone = true; - InsertObject(OBJ_LINEDEFS, ld, 0, 0); - LineDefs[ld].end = refv; - LineDefs[NumLineDefs - 1].start = refv; - sd = LineDefs[ld].sidedef1; - if (sd >= 0) - { - InsertObject(OBJ_SIDEDEFS, sd, 0, 0); - LineDefs[NumLineDefs - 1].sidedef1 = NumSideDefs - 1; - } - sd = LineDefs[ld].sidedef2; - if (sd >= 0) - { - InsertObject(OBJ_SIDEDEFS, sd, 0, 0); - LineDefs[NumLineDefs - 1].sidedef2 = NumSideDefs - 1; - } - MadeChanges = 1; - MadeMapChanges = 1; - } - else - return redraw; - } - } + refv = ref->objnum; + ref = ref->next; + oldnumld = NumLineDefs; + //printf ("V%d %d\n", refv, NumLineDefs); // DEBUG; + /* check if this vertex is on a linedef */ + for (ld = 0; ld < oldnumld; ld++) + { + if (LineDefs[ld].start == refv || LineDefs[ld].end == refv) + { + /* one vertex had a linedef bound to it -- check it later */ + isldend = true; + } + else if (IsLineDefInside(ld, Vertices[refv].x - tolerance, + Vertices[refv].y - tolerance, + Vertices[refv].x + tolerance, + Vertices[refv].y + tolerance)) + { + char buf[81]; + redraw = true; + sprintf(buf, "Vertex %d is on top of linedef %d", refv, ld); + if (Confirm2(-1, -1, &confirm_flag, + buf, "Do you want to split the linedef there?")) + { + /* split the linedef */ + mergedone = true; + InsertObject(OBJ_LINEDEFS, ld, 0, 0); + LineDefs[ld].end = refv; + LineDefs[NumLineDefs - 1].start = refv; + sd = LineDefs[ld].sidedef1; + if (sd >= 0) + { + InsertObject(OBJ_SIDEDEFS, sd, 0, 0); + LineDefs[NumLineDefs - 1].sidedef1 = NumSideDefs - 1; + } + sd = LineDefs[ld].sidedef2; + if (sd >= 0) + { + InsertObject(OBJ_SIDEDEFS, sd, 0, 0); + LineDefs[NumLineDefs - 1].sidedef2 = NumSideDefs - 1; + } + MadeChanges = 1; + MadeMapChanges = 1; + } + else + return redraw; + } + } } /* Don't continue if this isn't necessary */ if (!isldend || !mergedone) - return redraw; + return redraw; /* finally, test if two linedefs are between the same pair of vertices */ /* AYM 1997-07-17 @@ -308,85 +308,85 @@ //DisplayMessage (-1, -1, "Checking superimposed linedefs"); confirm_flag = YC_ASK_ONCE; { - linedef_t *linedefs; + linedef_t *linedefs; /* Copy the linedefs into array 'linedefs' and sort it */ - linedefs = (linedef_t *) GetMemory(NumLineDefs * sizeof(linedef_t)); - for (ld = 0; ld < NumLineDefs; ld++) - { - linedefs[ld].vertexl = - y_min(LineDefs[ld].start, LineDefs[ld].end); - linedefs[ld].vertexh = - y_max(LineDefs[ld].start, LineDefs[ld].end); - linedefs[ld].linedefno = ld; - } - qsort(linedefs, NumLineDefs, sizeof(linedef_t), SortLinedefs); + linedefs = (linedef_t *) GetMemory(NumLineDefs * sizeof(linedef_t)); + for (ld = 0; ld < NumLineDefs; ld++) + { + linedefs[ld].vertexl = + y_min(LineDefs[ld].start, LineDefs[ld].end); + linedefs[ld].vertexh = + y_max(LineDefs[ld].start, LineDefs[ld].end); + linedefs[ld].linedefno = ld; + } + qsort(linedefs, NumLineDefs, sizeof(linedef_t), SortLinedefs); /* Search for superimposed linedefs in the array */ - for (ld = 0; ld + 1 < NumLineDefs; ld++) - { - if (linedefs[ld + 1].vertexl != linedefs[ld].vertexl - || linedefs[ld + 1].vertexh != linedefs[ld].vertexh) - continue; - int ld1 = linedefs[ld].linedefno; - int ld2 = linedefs[ld + 1].linedefno; - char prompt[81]; - y_snprintf(prompt, sizeof prompt, - "Linedefs %d and %d are superimposed", ld1, ld2); - redraw = true; - if (Expert || Confirm2(-1, -1, &confirm_flag, - prompt, - "(and perhaps others too). Merge them ?")) - { - LDPtr ldo = LineDefs + ld1; - LDPtr ldn = LineDefs + ld2; - /* Test if the linedefs have the same orientation */ - if (ldn->start == ldo->end) - flipped = true; - else - flipped = false; - /* Merge linedef ldo (ld) into linedef ldn (ld+1) */ - /* FIXME When is this done ? Most of the time when adding a - door/corridor/window between two rooms, right ? So we should - handle this in a smarter way by copying middle texture into - lower and upper texture if the sectors don't have the same - heights and maybe setting the LTU and UTU flags. - This also applies when a linedef becomes two-sided as a - result of creating a new sector. */ - if (ldn->sidedef1 < 0) - { - if (flipped) - { - ldn->sidedef1 = ldo->sidedef2; - ldo->sidedef2 = OBJ_NO_NONE; - } - else - { - ldn->sidedef1 = ldo->sidedef1; - ldo->sidedef1 = OBJ_NO_NONE; - } - } - if (ldn->sidedef2 < 0) - { - if (flipped) - { - ldn->sidedef2 = ldo->sidedef1; - ldo->sidedef1 = OBJ_NO_NONE; - } - else - { - ldn->sidedef2 = ldo->sidedef2; - ldo->sidedef2 = OBJ_NO_NONE; - } - } - if (ldn->sidedef1 >= 0 && ldn->sidedef2 >= 0 - && (ldn->flags & 0x04) == 0) - ldn->flags = 0x04; - DeleteObject(Objid(OBJ_LINEDEFS, ld1)); - } - } + for (ld = 0; ld + 1 < NumLineDefs; ld++) + { + if (linedefs[ld + 1].vertexl != linedefs[ld].vertexl + || linedefs[ld + 1].vertexh != linedefs[ld].vertexh) + continue; + int ld1 = linedefs[ld].linedefno; + int ld2 = linedefs[ld + 1].linedefno; + char prompt[81]; + y_snprintf(prompt, sizeof prompt, + "Linedefs %d and %d are superimposed", ld1, ld2); + redraw = true; + if (Expert || Confirm2(-1, -1, &confirm_flag, + prompt, + "(and perhaps others too). Merge them ?")) + { + LDPtr ldo = LineDefs + ld1; + LDPtr ldn = LineDefs + ld2; + /* Test if the linedefs have the same orientation */ + if (ldn->start == ldo->end) + flipped = true; + else + flipped = false; + /* Merge linedef ldo (ld) into linedef ldn (ld+1) */ + /* FIXME When is this done ? Most of the time when adding a + door/corridor/window between two rooms, right ? So we should + handle this in a smarter way by copying middle texture into + lower and upper texture if the sectors don't have the same + heights and maybe setting the LTU and UTU flags. + This also applies when a linedef becomes two-sided as a + result of creating a new sector. */ + if (ldn->sidedef1 < 0) + { + if (flipped) + { + ldn->sidedef1 = ldo->sidedef2; + ldo->sidedef2 = OBJ_NO_NONE; + } + else + { + ldn->sidedef1 = ldo->sidedef1; + ldo->sidedef1 = OBJ_NO_NONE; + } + } + if (ldn->sidedef2 < 0) + { + if (flipped) + { + ldn->sidedef2 = ldo->sidedef1; + ldo->sidedef1 = OBJ_NO_NONE; + } + else + { + ldn->sidedef2 = ldo->sidedef2; + ldo->sidedef2 = OBJ_NO_NONE; + } + } + if (ldn->sidedef1 >= 0 && ldn->sidedef2 >= 0 + && (ldn->flags & 0x04) == 0) + ldn->flags = 0x04; + DeleteObject(Objid(OBJ_LINEDEFS, ld1)); + } + } - FreeMemory(linedefs); + FreeMemory(linedefs); } return redraw; @@ -401,8 +401,8 @@ #define ld1 ((const linedef_t *) item1) #define ld2 ((const linedef_t *) item2) if (ld1->vertexl != ld2->vertexl) - return ld1->vertexl - ld2->vertexl; + return ld1->vertexl - ld2->vertexl; if (ld1->vertexh != ld2->vertexh) - return ld1->vertexh - ld2->vertexh; + return ld1->vertexh - ld2->vertexh; return 0; } diff -r 594dea11ccd9 -r a68786b9c74b src/v_polyg.cc --- a/src/v_polyg.cc Sat Sep 24 15:01:56 2011 +0300 +++ b/src/v_polyg.cc Sat Sep 24 15:59:33 2011 +0300 @@ -1,6 +1,6 @@ /* - * v_polyg.cc - * AYM 1998-08-15 + * v_polyg.cc + * AYM 1998-08-15 */ @@ -42,12 +42,12 @@ int n; for (n = 0; n < sides; n++) - InsertObject(OBJ_VERTICES, -1, - centerx - + - (int) ((double) radius * - cos(TWOPI * (double) n / (double) sides)), - centery + - (int) ((double) radius * - sin(TWOPI * (double) n / (double) sides))); + InsertObject(OBJ_VERTICES, -1, + centerx + + + (int) ((double) radius * + cos(TWOPI * (double) n / (double) sides)), + centery + + (int) ((double) radius * + sin(TWOPI * (double) n / (double) sides))); } diff -r 594dea11ccd9 -r a68786b9c74b src/vectext.cc --- a/src/vectext.cc Sat Sep 24 15:01:56 2011 +0300 +++ b/src/vectext.cc Sat Sep 24 15:59:33 2011 +0300 @@ -1,6 +1,6 @@ /* - * vectext.cc - crude scalable text - * AYM 2000-07-11 + * vectext.cc - crude scalable text + * AYM 2000-07-11 */ @@ -170,53 +170,53 @@ switch (c) { case '-': - p = vmin; - s = sizeof vmin; - break; + p = vmin; + s = sizeof vmin; + break; case '0': - p = v0; - s = sizeof v0; - break; + p = v0; + s = sizeof v0; + break; case '1': - p = v1; - s = sizeof v1; - break; + p = v1; + s = sizeof v1; + break; case '2': - p = v2; - s = sizeof v2; - break; + p = v2; + s = sizeof v2; + break; case '3': - p = v3; - s = sizeof v3; - break; + p = v3; + s = sizeof v3; + break; case '4': - p = v4; - s = sizeof v4; - break; + p = v4; + s = sizeof v4; + break; case '5': - p = v5; - s = sizeof v5; - break; + p = v5; + s = sizeof v5; + break; case '6': - p = v6; - s = sizeof v6; - break; + p = v6; + s = sizeof v6; + break; case '7': - p = v7; - s = sizeof v7; - break; + p = v7; + s = sizeof v7; + break; case '8': - p = v8; - s = sizeof v8; - break; + p = v8; + s = sizeof v8; + break; case '9': - p = v9; - s = sizeof v9; - break; + p = v9; + s = sizeof v9; + break; default: - p = 0; - s = 0; - break; + p = 0; + s = 0; + break; } } @@ -227,7 +227,7 @@ size_t s; vdata(c, d, s); if (d == 0) - return 0; + return 0; return *d; } @@ -242,64 +242,64 @@ void draw_vstring(const char *string, int x, int y, double scale) { - const int height = 48; // Height in units FIXME hard-coded - const double ppu = scale / 4; // Pixels per unit + const int height = 48; // Height in units FIXME hard-coded + const double ppu = scale / 4; // Pixels per unit // Calculate in advance the whole width of the text - int width = 0; // Width in units + int width = 0; // Width in units for (const char *s = string; *s; s++) - width += vwidth(*s); + width += vwidth(*s); int xref = (int) (x - width * ppu / 2); int yref = (int) (y - height * ppu / 2); for (const char *s = string; *s; s++) { - int xcur = xref; - int ycur = yref; - const signed char *d, *dend; - size_t size; - vdata(*s, d, size); - if (d == 0 || size < 1) - continue; - dend = d + size; + int xcur = xref; + int ycur = yref; + const signed char *d, *dend; + size_t size; + vdata(*s, d, size); + if (d == 0 || size < 1) + continue; + dend = d + size; - // Extract the width; - int w = *d++; + // Extract the width; + int w = *d++; - // Process the statements - while ((d + 2) < dend) - { - if (*d == 'd') // d - draw to relative position - { - d++; - int xofs = *d++; - int yofs = *d++; - DrawScreenLine((int) (xref + xcur * ppu + 0.5), - (int) (yref + ycur * ppu + 0.5), - (int) (xref + (xcur + xofs) * ppu + 0.5), - (int) (yref + (ycur + yofs) * ppu + 0.5)); - xcur += xofs; - ycur += yofs; - } - else if (*d == 'm') // m - move the cursor to relative position - { - d++; - xcur += *d++; - ycur += *d++; - } - else if (*d == 'M') // M - move the cursor to absolute position - { - d++; - xcur = *d++; - ycur = *d++; - } - else - { - nf_bug("bad statement \"%c\"", *d); - d += 3; - continue; - } - } - xref += (int) ((w + 8) * ppu + 0.5); + // Process the statements + while ((d + 2) < dend) + { + if (*d == 'd') // d - draw to relative position + { + d++; + int xofs = *d++; + int yofs = *d++; + DrawScreenLine((int) (xref + xcur * ppu + 0.5), + (int) (yref + ycur * ppu + 0.5), + (int) (xref + (xcur + xofs) * ppu + 0.5), + (int) (yref + (ycur + yofs) * ppu + 0.5)); + xcur += xofs; + ycur += yofs; + } + else if (*d == 'm') // m - move the cursor to relative position + { + d++; + xcur += *d++; + ycur += *d++; + } + else if (*d == 'M') // M - move the cursor to absolute position + { + d++; + xcur = *d++; + ycur = *d++; + } + else + { + nf_bug("bad statement \"%c\"", *d); + d += 3; + continue; + } + } + xref += (int) ((w + 8) * ppu + 0.5); } } diff -r 594dea11ccd9 -r a68786b9c74b src/vectext.h --- a/src/vectext.h Sat Sep 24 15:01:56 2011 +0300 +++ b/src/vectext.h Sat Sep 24 15:59:33 2011 +0300 @@ -1,6 +1,6 @@ /* - * vectext.h - crude scalable text - * AYM 2000-07-11 + * vectext.h - crude scalable text + * AYM 2000-07-11 */ diff -r 594dea11ccd9 -r a68786b9c74b src/verbmsg.cc --- a/src/verbmsg.cc Sat Sep 24 15:01:56 2011 +0300 +++ b/src/verbmsg.cc Sat Sep 24 15:59:33 2011 +0300 @@ -1,6 +1,6 @@ /* - * verbmsg.cc - * AYM 1998-11-11 + * verbmsg.cc + * AYM 1998-11-11 */ @@ -31,15 +31,15 @@ /* - * verbmsg - * Like printf() but does nothing unlike <verbose> is set. + * verbmsg + * Like printf() but does nothing unlike <verbose> is set. */ void verbmsg(const char *fmt, ...) { va_list args; if (!verbose) - return; + return; va_start(args, fmt); vprintf(fmt, args); } diff -r 594dea11ccd9 -r a68786b9c74b src/wadfile.cc --- a/src/wadfile.cc Sat Sep 24 15:01:56 2011 +0300 +++ b/src/wadfile.cc Sat Sep 24 15:59:33 2011 +0300 @@ -1,6 +1,6 @@ /* - * wadfile.cc - Wad_file class - * AYM 2001-09-18 + * wadfile.cc - Wad_file class + * AYM 2001-09-18 */ @@ -32,32 +32,32 @@ /* - * Wad_file::~Wad_file - dtor + * Wad_file::~Wad_file - dtor */ Wad_file::~Wad_file() { if (directory != 0) { - FreeMemory(directory); - directory = 0; // Catch bugs + FreeMemory(directory); + directory = 0; // Catch bugs } if (fp != 0) { - fclose(fp); - fp = 0; // Catch bugs + fclose(fp); + fp = 0; // Catch bugs } if (filename != 0) { - FreeMemory(filename); - filename = 0; // Catch bugs + FreeMemory(filename); + filename = 0; // Catch bugs } } /* - * Wad_file::where - return file(offset) string + * Wad_file::where - return file(offset) string * - * Return pointer to a per-Wad_file buffer. + * Return pointer to a per-Wad_file buffer. */ const char *Wad_file::where() const { @@ -66,15 +66,15 @@ const size_t name_len_max = sizeof where_ - 1 - offset_len; if (name_len_max >= strlen(filename)) - sprintf(where_, "%s(%lXh)", filename, offset); + sprintf(where_, "%s(%lXh)", filename, offset); else { - const char *ellipsis = "..."; - const size_t total = name_len_max - strlen(ellipsis); - const size_t left = total / 2; - const size_t right = total - left; - sprintf(where_, "%*s%s%*s(%lXh)", - left, filename, ellipsis, right, filename + total, offset); + const char *ellipsis = "..."; + const size_t total = name_len_max - strlen(ellipsis); + const size_t left = total / 2; + const size_t right = total - left; + sprintf(where_, "%*s%s%*s(%lXh)", + left, filename, ellipsis, right, filename + total, offset); } return where_; @@ -82,14 +82,14 @@ /* - * Wad_file::read_vbytes - read bytes from a wad file + * Wad_file::read_vbytes - read bytes from a wad file * - * Read up to <count> bytes and store them into buffer - * <buf>. <count> is _not_ limited to size_t. If an I/O - * error occurs, set the error flag. EOF is not considered - * an error. + * Read up to <count> bytes and store them into buffer + * <buf>. <count> is _not_ limited to size_t. If an I/O + * error occurs, set the error flag. EOF is not considered + * an error. * - * Return the number of bytes read. + * Return the number of bytes read. */ long Wad_file::read_vbytes(void *buf, long count) const { @@ -101,20 +101,20 @@ bytes_to_read = 0x8000; while (count > 0) { - if (count <= 0x8000) - bytes_to_read = (size_t) count; - bytes_read = fread(buf, 1, bytes_to_read, fp); - bytes_read_total += bytes_read; - if (bytes_read != bytes_to_read) - break; - buf = (char *) buf + bytes_read; - count -= bytes_read; + if (count <= 0x8000) + bytes_to_read = (size_t) count; + bytes_read = fread(buf, 1, bytes_to_read, fp); + bytes_read_total += bytes_read; + if (bytes_read != bytes_to_read) + break; + buf = (char *) buf + bytes_read; + count -= bytes_read; } if (ferror(fp)) { - if (!error_) - err("%s: read error", where()); - error_ = true; + if (!error_) + err("%s: read error", where()); + error_ = true; } return bytes_read_total; } diff -r 594dea11ccd9 -r a68786b9c74b src/wadfile.h --- a/src/wadfile.h Sat Sep 24 15:01:56 2011 +0300 +++ b/src/wadfile.h Sat Sep 24 15:59:33 2011 +0300 @@ -1,6 +1,6 @@ /* - * wadfile.h - Wad_file class - * AYM 2001-09-18 + * wadfile.h - Wad_file class + * AYM 2001-09-18 */ @@ -27,62 +27,62 @@ */ -#ifndef YH_WADFILE /* DO NOT INSERT ANYTHING BEFORE THIS LINE */ +#ifndef YH_WADFILE /* DO NOT INSERT ANYTHING BEFORE THIS LINE */ #define YH_WADFILE /* - * Wad_file - wad file open for reading + * Wad_file - wad file open for reading * - * The Wad_file class is a simple wad file object. It - * provides functions to read the usual data formats (byte, - * 16-bit signed integer, 32-bit signed integer) portably. + * The Wad_file class is a simple wad file object. It + * provides functions to read the usual data formats (byte, + * 16-bit signed integer, 32-bit signed integer) portably. * - * Errors are reported not by overloading the return - * value but by setting an internal flag that can be read - * with the error() function, a bit like stdio's feof() and - * ferror(). Calling error() has the side effect of - * clearing the error flag and calling clearerr() on the - * underlying FILE. This is the only way to reset the error - * flag. Thus, you don't have to check the error status - * after every operation. You can call seek() and read_*() - * any number of times before calling error() : the class - * guarantees that if any one of the operations failed, - * error() returns true. + * Errors are reported not by overloading the return + * value but by setting an internal flag that can be read + * with the error() function, a bit like stdio's feof() and + * ferror(). Calling error() has the side effect of + * clearing the error flag and calling clearerr() on the + * underlying FILE. This is the only way to reset the error + * flag. Thus, you don't have to check the error status + * after every operation. You can call seek() and read_*() + * any number of times before calling error() : the class + * guarantees that if any one of the operations failed, + * error() returns true. * - * Yadex has a policy of reporting I/O errors, mentioning - * the name of the file and the offset at which the error - * occurred. This policy is enforced by the Wad_file class. - * To avoid flooding, no message is printed if the error - * flag was already set before the error occurred. This - * gives you some control on how verbose the error - * reporting is ; if you want a message for every error, - * all you have to do is to check error() after every - * operation. It's probably best to report only the first - * error, though. + * Yadex has a policy of reporting I/O errors, mentioning + * the name of the file and the offset at which the error + * occurred. This policy is enforced by the Wad_file class. + * To avoid flooding, no message is printed if the error + * flag was already set before the error occurred. This + * gives you some control on how verbose the error + * reporting is ; if you want a message for every error, + * all you have to do is to check error() after every + * operation. It's probably best to report only the first + * error, though. * - * If for some reason you need to disable the error - * messages, add a bool quiet parameter with a default - * value of false to the functions that can fail. + * If for some reason you need to disable the error + * messages, add a bool quiet parameter with a default + * value of false to the functions that can fail. * - * It's probably a good idea to call error() after every - * seek(), before attempting to read. Although seek() - * rarely fails under Unix, MS-DOS refuses to seek() past - * EOF, if I recall correctly. + * It's probably a good idea to call error() after every + * seek(), before attempting to read. Although seek() + * rarely fails under Unix, MS-DOS refuses to seek() past + * EOF, if I recall correctly. * - * The interface is somewhat crufty. Some functions take a - * pointer, others take a reference. Some take an optional - * count parameter, some take a mandatory count parameter, - * and some have no count parameter at all. Needs cleanup. + * The interface is somewhat crufty. Some functions take a + * pointer, others take a reference. Some take an optional + * count parameter, some take a mandatory count parameter, + * and some have no count parameter at all. Needs cleanup. * - * This class has many public data members, and no proper - * constructor. That's because it evolved from a C struct. + * This class has many public data members, and no proper + * constructor. That's because it evolved from a C struct. * - * Another problem is the lack of errno detail. That is - * partly stdio's fault. + * Another problem is the lack of errno detail. That is + * partly stdio's fault. * - * const: for the moment, const means that you can read - * from but not change the attributes, close, reopen, etc. + * const: for the moment, const means that you can read + * from but not change the attributes, close, reopen, etc. */ class Wad_file { @@ -103,8 +103,8 @@ fp(0), dirsize(0), dirstart(0), directory(0), error_(false) { - strcpy(type, "BUG"); - strcpy(where_, "DEADBEEF"); + strcpy(type, "BUG"); + strcpy(where_, "DEADBEEF"); } ~Wad_file(); @@ -123,23 +123,23 @@ const char *what() const; private: - char *filename; // Name of the wad file - ygpf_t pic_format_; // Picture format (usually PF_NORMAL) - FILE *fp; // C file stream information - char type[4]; // Type of wad file ("IWAD" or "PWAD") - i32 dirsize; // Entries in directory - i32 dirstart; // Offset to start of directory - DirPtr directory; // Array of directory information - mutable bool error_; // I/O error occur since last error() - mutable char where_[101]; // Static workspace for where() + char *filename; // Name of the wad file + ygpf_t pic_format_; // Picture format (usually PF_NORMAL) + FILE *fp; // C file stream information + char type[4]; // Type of wad file ("IWAD" or "PWAD") + i32 dirsize; // Entries in directory + i32 dirstart; // Offset to start of directory + DirPtr directory; // Array of directory information + mutable bool error_; // I/O error occur since last error() + mutable char where_[101]; // Static workspace for where() - Wad_file(const Wad_file & rhs); // Deliberately not implemented - Wad_file & operator=(const Wad_file & rhs); // Deliberately not implemented + Wad_file(const Wad_file & rhs); // Deliberately not implemented + Wad_file & operator=(const Wad_file & rhs); // Deliberately not implemented }; /* - * Wad_file::pathname - return the pathname of the file + * Wad_file::pathname - return the pathname of the file */ inline const char *Wad_file::pathname() const { @@ -148,7 +148,7 @@ /* - * Wad_file::pic_format - return the pic_format of the wad + * Wad_file::pic_format - return the pic_format of the wad */ inline ygpf_t Wad_file::pic_format() const { @@ -157,22 +157,22 @@ /* - * Wad_file::error - tell whether any errors occurred + * Wad_file::error - tell whether any errors occurred * - * Reset the error indicator and call clearerr() on the - * underlying stdio stream. Thus calling Wad_file::error() - * again immediately after always returns false. Calling - * this function is the only way to clear the error flag of - * a Wad_file. + * Reset the error indicator and call clearerr() on the + * underlying stdio stream. Thus calling Wad_file::error() + * again immediately after always returns false. Calling + * this function is the only way to clear the error flag of + * a Wad_file. * - * So short that it's a good candidate for inlining. + * So short that it's a good candidate for inlining. * - * Return true if an error occurred, false otherwise. + * Return true if an error occurred, false otherwise. */ inline bool Wad_file::error() const { if (!error_) - return false; + return false; clearerr(fp); error_ = false; @@ -181,26 +181,26 @@ /* - * Wad_file::seek - move the file pointer + * Wad_file::seek - move the file pointer * - * If an error occurs, set the error flag. + * If an error occurs, set the error flag. */ inline void Wad_file::seek(long offset) const { if (fseek(fp, offset, 0) != 0) { - if (!error_) - err("%s: can't seek to %lXh", filename, offset); - error_ = true; + if (!error_) + err("%s: can't seek to %lXh", filename, offset); + error_ = true; } } /* - * Wad_file::read_u8 - read a byte + * Wad_file::read_u8 - read a byte * - * If an error occurs, set the error flag and the return - * value is undefined. + * If an error occurs, set the error flag and the return + * value is undefined. */ inline u8 Wad_file::read_u8() const { @@ -208,19 +208,19 @@ if (feof(fp) || ferror(fp)) { - if (!error_) - err("%s: read error", where()); - error_ = true; + if (!error_) + err("%s: read error", where()); + error_ = true; } return v; } /* - * Wad_file::read_u8 - read a byte + * Wad_file::read_u8 - read a byte * - * If an error occurs, set the error flag and the contents - * of buf is undefined. + * If an error occurs, set the error flag and the contents + * of buf is undefined. */ inline void Wad_file::read_u8(u8 & buf) const { @@ -228,18 +228,18 @@ if (feof(fp) || ferror(fp)) { - if (!error_) - err("%s: read error", where()); - error_ = true; + if (!error_) + err("%s: read error", where()); + error_ = true; } } /* - * Wad_file::read_i16 - read a little-endian 16-bit signed integer + * Wad_file::read_i16 - read a little-endian 16-bit signed integer * - * If an error occurs, set the error flag and the return - * value is undefined. + * If an error occurs, set the error flag and the return + * value is undefined. */ inline i16 Wad_file::read_i16() const { @@ -248,20 +248,20 @@ if (fread(buf, 1, nbytes, fp) != nbytes) { - if (!error_) - err("%s: read error", where()); - error_ = true; - return EOF; // Whatever + if (!error_) + err("%s: read error", where()); + error_ = true; + return EOF; // Whatever } return buf[0] | buf[1] << 8; } /* - * Wad_file::read_i16 - read a little-endian 16-bit signed integer + * Wad_file::read_i16 - read a little-endian 16-bit signed integer * - * The value read is stored in *buf. If an error occurs, - * set the error flag and the contents of *buf is undefined. + * The value read is stored in *buf. If an error occurs, + * set the error flag and the contents of *buf is undefined. */ inline void Wad_file::read_i16(i16 * buf) const { @@ -269,45 +269,45 @@ if (feof(fp) || ferror(fp)) { - if (!error_) - err("%s: read error", where()); - error_ = true; + if (!error_) + err("%s: read error", where()); + error_ = true; } } /* - * Wad_file::read_i32 - read little-endian 32-bit signed integers + * Wad_file::read_i32 - read little-endian 32-bit signed integers * - * Read <count> little-endian 32-bit signed integers from - * wad file <wadfile> into *buf. If an error occurs, set - * error_ and the contents of *buf is undefined. + * Read <count> little-endian 32-bit signed integers from + * wad file <wadfile> into *buf. If an error occurs, set + * error_ and the contents of *buf is undefined. */ inline void Wad_file::read_i32(i32 * buf, long count) const { while (count-- > 0) { - *buf++ = getc(fp) - | (getc(fp) << 8) - | ((i32) getc(fp) << 16) | ((i32) getc(fp) << 24); + *buf++ = getc(fp) + | (getc(fp) << 8) + | ((i32) getc(fp) << 16) | ((i32) getc(fp) << 24); } if (feof(fp) || ferror(fp)) { - if (!error_) - err("%s: read error", where()); - error_ = true; + if (!error_) + err("%s: read error", where()); + error_ = true; } } /* - * Wad_file::read_bytes - read bytes from a wad file + * Wad_file::read_bytes - read bytes from a wad file * - * Read <count> bytes and store them into buffer <buf>. - * <count> is _not_ limited to size_t. If an I/O error - * occurs or EOF is reached before the requested number of - * bytes is read, set the error flag. + * Read <count> bytes and store them into buffer <buf>. + * <count> is _not_ limited to size_t. If an I/O error + * occurs or EOF is reached before the requested number of + * bytes is read, set the error flag. */ inline void Wad_file::read_bytes(void *buf, long count) const { @@ -316,26 +316,26 @@ bytes_read = read_vbytes(buf, count); if (bytes_read != count) { - if (!error_) - err("%s: read error", where()); - error_ = true; + if (!error_) + err("%s: read error", where()); + error_ = true; } } /* - * Wad_file::what - what a wad contains + * Wad_file::what - what a wad contains * - * Written for the sake of the "w" command. Return the - * name of the first lump in the wad, which gives an idea - * of what it contains. The string is *not* NUL-terminated. + * Written for the sake of the "w" command. Return the + * name of the first lump in the wad, which gives an idea + * of what it contains. The string is *not* NUL-terminated. */ inline const char *Wad_file::what() const { if (directory == 0) - return "(nodir)"; + return "(nodir)"; if (dirsize < 1) - return "(empty)"; + return "(empty)"; return directory[0].name; } diff -r 594dea11ccd9 -r a68786b9c74b src/wadlist.cc --- a/src/wadlist.cc Sat Sep 24 15:01:56 2011 +0300 +++ b/src/wadlist.cc Sat Sep 24 15:59:33 2011 +0300 @@ -1,6 +1,6 @@ /* - * wadlist.cc - Wad_list class - * AYM 2001-09-23 + * wadlist.cc - Wad_list class + * AYM 2001-09-23 */ @@ -34,7 +34,7 @@ #include <boost/smart_ptr.hpp> -Wad_list wad_list; // One global instance +Wad_list wad_list; // One global instance typedef std::list < boost::shared_ptr < Wad_file > >list_t; @@ -44,8 +44,8 @@ { public: Wad_list_priv(); list_t list; - mutable list_t::iterator iter; // Current element - mutable bool rewound; // If true, next get() will return head + mutable list_t::iterator iter; // Current element + mutable bool rewound; // If true, next get() will return head }; @@ -56,7 +56,7 @@ /* - * Wad_list::Wad_list - default ctor + * Wad_list::Wad_list - default ctor */ Wad_list::Wad_list() { @@ -65,17 +65,17 @@ /* - * Wad_list::~Wad_list - dtor + * Wad_list::~Wad_list - dtor */ Wad_list::~Wad_list() { delete priv; - priv = 0; // Catch bugs + priv = 0; // Catch bugs } /* - * Wad_list::rewind - arrange so that the next get() will return head + * Wad_list::rewind - arrange so that the next get() will return head */ void Wad_list::rewind() const { @@ -84,30 +84,30 @@ /* - * Wad_list::get - retrieve the next wad from the list + * Wad_list::get - retrieve the next wad from the list * - * If get() was not called since the last call to rewind(), - * the first wad is returned. Otherwise, the wad returned - * is the one that follows the one returned by the previous - * call to get(). + * If get() was not called since the last call to rewind(), + * the first wad is returned. Otherwise, the wad returned + * is the one that follows the one returned by the previous + * call to get(). * - * Return false if already at the end of the list, true - * otherwise. + * Return false if already at the end of the list, true + * otherwise. */ bool Wad_list::get(Wad_file * &wf) { if (priv->rewound) { - priv->iter = priv->list.begin(); - priv->rewound = false; + priv->iter = priv->list.begin(); + priv->rewound = false; } else - ++priv->iter; + ++priv->iter; if (priv->iter == priv->list.end()) { - wf = 0; - return false; + wf = 0; + return false; } wf = priv->iter->get(); @@ -119,14 +119,14 @@ { if (priv->rewound) { - priv->iter = priv->list.begin(); - priv->rewound = false; + priv->iter = priv->list.begin(); + priv->rewound = false; } else - ++priv->iter; + ++priv->iter; if (priv->iter == priv->list.end()) - return false; + return false; wf = priv->iter->get(); return true; @@ -134,7 +134,7 @@ /* - * Wad_list::insert - insert a new wad at the pointer + * Wad_list::insert - insert a new wad at the pointer */ void Wad_list::insert(Wad_file * wf) { @@ -143,16 +143,16 @@ /* - * Wad_list::del - delete from the list the wad under the pointer + * Wad_list::del - delete from the list the wad under the pointer * - * If get() was not called since the last call to rewind(), - * the first wad is deleted. Otherwise, the wad deleted is - * the one returned by the last call to get(). + * If get() was not called since the last call to rewind(), + * the first wad is deleted. Otherwise, the wad deleted is + * the one returned by the last call to get(). * - * After a call to del(), a call to get will return the wad - * the followed the one that was deleted. + * After a call to del(), a call to get will return the wad + * the followed the one that was deleted. * - * If already at the end of the list, nf_bug() is called. + * If already at the end of the list, nf_bug() is called. */ void Wad_list::del() { @@ -160,21 +160,21 @@ if (priv->rewound) { - i = priv->list.begin(); + i = priv->list.begin(); } else { - i = priv->iter; + i = priv->iter; } if (i == priv->list.end()) { - nf_bug("Wad_list::del: attempt to delete last item"); - return; + nf_bug("Wad_list::del: attempt to delete last item"); + return; } priv->iter = priv->list.erase(i); if (priv->iter == priv->list.begin()) { // priv->iter = 0; // Catch bugs - priv->rewound = true; + priv->rewound = true; } } diff -r 594dea11ccd9 -r a68786b9c74b src/wadlist.h --- a/src/wadlist.h Sat Sep 24 15:01:56 2011 +0300 +++ b/src/wadlist.h Sat Sep 24 15:59:33 2011 +0300 @@ -1,6 +1,6 @@ /* - * wadlist.h - Wad_list class - * AYM 2001-09-23 + * wadlist.h - Wad_list class + * AYM 2001-09-23 */ @@ -27,32 +27,32 @@ */ -#ifndef YH_WADLIST /* DO NOT INSERT ANYTHING BEFORE THIS LINE */ +#ifndef YH_WADLIST /* DO NOT INSERT ANYTHING BEFORE THIS LINE */ #define YH_WADLIST /* - * Wad_list - list of open wads + * Wad_list - list of open wads * - * The Wad_list class is designed to hold the list of open - * wads. It will probably have only one (global) instance. - * Here is how it's supposed to be used : + * The Wad_list class is designed to hold the list of open + * wads. It will probably have only one (global) instance. + * Here is how it's supposed to be used : * - * extern Wad_list wl; - * Wad_file *wf; + * extern Wad_list wl; + * Wad_file *wf; * - * // Is foo.wad in our list ? - * for (wl.rewind (); wl.get (wf);) - * if (strcmp (wf->filename, "foo.wad") == 0) - * { - * puts ("Got it !"); - * break; - * } + * // Is foo.wad in our list ? + * for (wl.rewind (); wl.get (wf);) + * if (strcmp (wf->filename, "foo.wad") == 0) + * { + * puts ("Got it !"); + * break; + * } * - * // Remove from the list all wads beginning with a "z" - * for (wl.rewind (); wl.get (wf);) - * if (*wf->filename == 'z') - * wl.del (); + * // Remove from the list all wads beginning with a "z" + * for (wl.rewind (); wl.get (wf);) + * if (*wf->filename == 'z') + * wl.del (); */ @@ -69,13 +69,13 @@ void insert(Wad_file *); void del(); - private: Wad_list(const Wad_list &); // Too lazy to implement it - Wad_list & operator=(const Wad_list &); // Too lazy to implement it + private: Wad_list(const Wad_list &); // Too lazy to implement it + Wad_list & operator=(const Wad_list &); // Too lazy to implement it Wad_list_priv *priv; }; -extern Wad_list wad_list; // One global instance +extern Wad_list wad_list; // One global instance #endif /* DO NOT ADD ANYTHING AFTER THIS LINE */ diff -r 594dea11ccd9 -r a68786b9c74b src/wadname.h --- a/src/wadname.h Sat Sep 24 15:01:56 2011 +0300 +++ b/src/wadname.h Sat Sep 24 15:59:33 2011 +0300 @@ -1,6 +1,6 @@ /* - * wadname.h - * AYM 2000-04-13 + * wadname.h + * AYM 2000-04-13 */ @@ -38,18 +38,18 @@ /* - * Wad_name - the name of a wad directory entry + * Wad_name - the name of a wad directory entry * - * This class is used to store a wad directory entry name. - * It provides the following guarantees : + * This class is used to store a wad directory entry name. + * It provides the following guarantees : * - * - there is minimal memory overhead, + * - there is minimal memory overhead, * - * - the name is stored in CAPITALS and padded to the - * maximum length with NULs so that the comparison of two - * names can be done with memcmp() instead of - * y_strnicmp(). This is very important for performance - * reasons. + * - the name is stored in CAPITALS and padded to the + * maximum length with NULs so that the comparison of two + * names can be done with memcmp() instead of + * y_strnicmp(). This is very important for performance + * reasons. */ struct Wad_name { @@ -66,7 +66,7 @@ /* - * default ctor + * default ctor */ inline Wad_name::Wad_name () { @@ -75,10 +75,10 @@ /* - * initialize from a trusted source + * initialize from a trusted source * - * The source *must* be already upper-cased and padded with - * NULs. + * The source *must* be already upper-cased and padded with + * NULs. */ inline Wad_name::Wad_name (const Wad_name& source) { @@ -87,7 +87,7 @@ /* - * initialize from an untrusted source + * initialize from an untrusted source */ inline Wad_name::Wad_name (const char *source) { @@ -104,7 +104,7 @@ /* - * initialize from an untrusted source + * initialize from an untrusted source */ inline Wad_name& Wad_name::operator= (const char *source) { @@ -122,7 +122,7 @@ /* - * compare two Wad_name objects for equality + * compare two Wad_name objects for equality */ inline bool Wad_name::operator== (const Wad_name& ref) const { @@ -131,7 +131,7 @@ /* - * compare for equality with an untrusted char[8] + * compare for equality with an untrusted char[8] */ inline bool Wad_name::operator== (const char *ref) const { @@ -140,13 +140,13 @@ /* - * less - less operator for map + * less - less operator for map * - * This is the operator suitable for use in a map. See - * Lump_dir for an example. + * This is the operator suitable for use in a map. See + * Lump_dir for an example. * - * Return true iff <this> is "smaller" (lexicographically - * speaking) than <other>, false otherwise. + * Return true iff <this> is "smaller" (lexicographically + * speaking) than <other>, false otherwise. */ inline bool Wad_name::less(const Wad_name& other) const { diff -r 594dea11ccd9 -r a68786b9c74b src/wadnamec.cc --- a/src/wadnamec.cc Sat Sep 24 15:01:56 2011 +0300 +++ b/src/wadnamec.cc Sat Sep 24 15:59:33 2011 +0300 @@ -1,6 +1,6 @@ /* - * wadnamec.cc - * AYM 2000-04-11 + * wadnamec.cc + * AYM 2000-04-11 */ @@ -36,7 +36,7 @@ char *p = name; char *pmax = name + 8; while (*string && p < pmax) - *p++ = toupper(*string++); + *p++ = toupper(*string++); *p = '\0'; } diff -r 594dea11ccd9 -r a68786b9c74b src/wadnamec.h --- a/src/wadnamec.h Sat Sep 24 15:01:56 2011 +0300 +++ b/src/wadnamec.h Sat Sep 24 15:59:33 2011 +0300 @@ -1,6 +1,6 @@ /* - * wadnamec.h - * AYM 2000-04-11 + * wadnamec.h + * AYM 2000-04-11 */ @@ -9,7 +9,7 @@ /* - * Wad_name_c - a lump name + * Wad_name_c - a lump name */ struct Wad_name_c { diff -r 594dea11ccd9 -r a68786b9c74b src/wadres.cc --- a/src/wadres.cc Sat Sep 24 15:01:56 2011 +0300 +++ b/src/wadres.cc Sat Sep 24 15:59:33 2011 +0300 @@ -1,7 +1,7 @@ /* - * wadres.cc - * Wadres class - * AYM 2000-04-07 + * wadres.cc + * Wadres class + * AYM 2000-04-07 */ diff -r 594dea11ccd9 -r a68786b9c74b src/wadres.h --- a/src/wadres.h Sat Sep 24 15:01:56 2011 +0300 +++ b/src/wadres.h Sat Sep 24 15:59:33 2011 +0300 @@ -1,7 +1,7 @@ /* - * wadres.h - * Wadres class - * AYM 2000-04-06 + * wadres.h + * Wadres class + * AYM 2000-04-06 */ @@ -28,7 +28,7 @@ */ -#ifndef YH_WADRES /* DO NOT INSERT ANYTHING BEFORE THIS LINE */ +#ifndef YH_WADRES /* DO NOT INSERT ANYTHING BEFORE THIS LINE */ #define YH_WADRES diff -r 594dea11ccd9 -r a68786b9c74b src/wads.cc --- a/src/wads.cc Sat Sep 24 15:01:56 2011 +0300 +++ b/src/wads.cc Sat Sep 24 15:59:33 2011 +0300 @@ -1,7 +1,7 @@ /* - * wads.cc - * Wad file routines - * BW & RQ sometime in 1993 or 1994. + * wads.cc + * Wad file routines + * BW & RQ sometime in 1993 or 1994. */ @@ -33,44 +33,44 @@ #include "wads.h" -MDirPtr MasterDir = NULL; // The master directory -Serial_num master_dir_serial; // The revision# thereof +MDirPtr MasterDir = NULL; // The master directory +Serial_num master_dir_serial; // The revision# thereof /* - * file_read_i16 - read little-endian 16-bit signed integers from a file + * file_read_i16 - read little-endian 16-bit signed integers from a file * - * Return 0 on success, non-zero on failure. + * Return 0 on success, non-zero on failure. */ int file_read_i16(FILE * fp, i16 * buf, long count) { while (count-- > 0) - *buf = getc(fp) | (getc(fp) << 8); + *buf = getc(fp) | (getc(fp) << 8); return feof(fp) || ferror(fp); } /* - * file_read_i32 - read little-endian 32-bit signed integers from a file + * file_read_i32 - read little-endian 32-bit signed integers from a file * - * Return 0 on success, non-zero on failure. + * Return 0 on success, non-zero on failure. */ int file_read_i32(FILE * fp, i32 * buf, long count) { while (count-- > 0) { - *buf++ = getc(fp) - | (getc(fp) << 8) - | ((i32) getc(fp) << 16) | ((i32) getc(fp) << 24); + *buf++ = getc(fp) + | (getc(fp) << 8) + | ((i32) getc(fp) << 16) | ((i32) getc(fp) << 24); } return feof(fp) || ferror(fp); } /* - * file_read_vbytes - read bytes from file + * file_read_vbytes - read bytes from file * - * Return the number of bytes read. + * Return the number of bytes read. */ long file_read_vbytes(FILE * fp, void *buf, long count) { @@ -82,23 +82,23 @@ bytes_to_read = 0x8000; while (count > 0) { - if (count <= 0x8000) - bytes_to_read = (size_t) count; - bytes_read = fread(buf, 1, bytes_to_read, fp); - bytes_read_total += bytes_read; - if (bytes_read != bytes_to_read) - break; - buf = (char *) buf + bytes_read; - count -= bytes_read; + if (count <= 0x8000) + bytes_to_read = (size_t) count; + bytes_read = fread(buf, 1, bytes_to_read, fp); + bytes_read_total += bytes_read; + if (bytes_read != bytes_to_read) + break; + buf = (char *) buf + bytes_read; + count -= bytes_read; } return bytes_read_total; } /* - * file_read_bytes - read bytes from a file + * file_read_bytes - read bytes from a file * - * Return 0 on success, non-zero on failure. + * Return 0 on success, non-zero on failure. */ int file_read_bytes(FILE * fp, void *buf, long count) { @@ -107,9 +107,9 @@ /* - * file_write_i16 - write a little-endian 16-bit signed integer to a file + * file_write_i16 - write a little-endian 16-bit signed integer to a file * - * Does no error checking. + * Does no error checking. */ void file_write_i16(FILE * fd, i16 buf) { @@ -119,9 +119,9 @@ /* - * file_write_i32 - write little-endian 32-bit signed integers to a file + * file_write_i32 - write little-endian 32-bit signed integers to a file * - * Does no error checking. + * Does no error checking. */ void file_write_i32(FILE * fd, i32 buf, long count) { @@ -129,40 +129,40 @@ and write the whole i32 at once. */ while (count-- > 0) { - putc(buf & 0xff, fd); - putc((buf >> 8) & 0xff, fd); - putc((buf >> 16) & 0xff, fd); - putc((buf >> 24) & 0xff, fd); + putc(buf & 0xff, fd); + putc((buf >> 8) & 0xff, fd); + putc((buf >> 16) & 0xff, fd); + putc((buf >> 24) & 0xff, fd); } } /* - * file_write_name - write directory entry name to file + * file_write_name - write directory entry name to file * - * Write to file <fd> the directory entry name contained in - * <name>. The string written in the file is exactly the - * same as the string contained in <name> except that : + * Write to file <fd> the directory entry name contained in + * <name>. The string written in the file is exactly the + * same as the string contained in <name> except that : * - * - only the first WAD_NAME characters of <name> are - * used, or up to the first occurrence of a NUL, - * - * - all letters are forced to upper case, + * - only the first WAD_NAME characters of <name> are + * used, or up to the first occurrence of a NUL, + * + * - all letters are forced to upper case, * - * - if necessary, the string is padded to WAD_NAME - * characters with NULs. + * - if necessary, the string is padded to WAD_NAME + * characters with NULs. * - * Does no error checking. + * Does no error checking. */ void file_write_name(FILE * fd, const char *name) { const unsigned char *const p0 = (const unsigned char *) name; - const unsigned char *p = p0; // "unsigned" for toupper()'s sake + const unsigned char *p = p0; // "unsigned" for toupper()'s sake for (; p - p0 < (ptrdiff_t) WAD_NAME && *p; p++) - putc(toupper(*p), fd); + putc(toupper(*p), fd); for (; p - p0 < (ptrdiff_t) WAD_NAME; p++) - putc('\0', fd); + putc('\0', fd); } @@ -174,25 +174,25 @@ { while (from) { - if (!y_strnicmp(from->dir.name, name, WAD_NAME)) - break; - from = from->next; + if (!y_strnicmp(from->dir.name, name, WAD_NAME)) + break; + from = from->next; } return from; } /* - * Find an entry in the master directory + * Find an entry in the master directory */ MDirPtr FindMasterDir(MDirPtr from, const char *name1, const char *name2) { while (from) { - if (!y_strnicmp(from->dir.name, name1, WAD_NAME) - || !y_strnicmp(from->dir.name, name2, WAD_NAME)) - break; - from = from->next; + if (!y_strnicmp(from->dir.name, name1, WAD_NAME) + || !y_strnicmp(from->dir.name, name2, WAD_NAME)) + break; + from = from->next; } return from; } @@ -205,29 +205,29 @@ void WriteBytes(FILE * file, const void *buf, long size) { if (!Registered) - return; + return; while (size > 0x8000) { - if (fwrite(buf, 1, 0x8000, file) != 0x8000) - fatal_error("error writing to file"); - buf = (const char *) buf + 0x8000; - size -= 0x8000; + if (fwrite(buf, 1, 0x8000, file) != 0x8000) + fatal_error("error writing to file"); + buf = (const char *) buf + 0x8000; + size -= 0x8000; } if (fwrite(buf, 1, size, file) != (size_t) size) - fatal_error("error writing to file"); + fatal_error("error writing to file"); } /* - * copy_bytes - copy bytes from a binary file to another + * copy_bytes - copy bytes from a binary file to another * - * FIXME it's silly to allocate such a large buffer on - * memory constrained systems. The function should be able - * to fall back on a smaller buffer. + * FIXME it's silly to allocate such a large buffer on + * memory constrained systems. The function should be able + * to fall back on a smaller buffer. * - * Return 0 on success, 1 if there was a read error on - * source file, 2 if there was a write error on destination - * file. + * Return 0 on success, 1 if there was a read error on + * source file, 2 if there was a write error on destination + * file. */ int copy_bytes(FILE * dest, FILE * source, long size) { @@ -238,31 +238,31 @@ data = GetMemory(chunksz + 2); while (size > chunksz) { - if (fread(data, 1, chunksz, source) != chunksz) - { - rc = 1; - goto byebye; - } - if (fwrite(data, 1, chunksz, dest) != chunksz) - { - rc = 2; - goto byebye; - } - size -= chunksz; + if (fread(data, 1, chunksz, source) != chunksz) + { + rc = 1; + goto byebye; + } + if (fwrite(data, 1, chunksz, dest) != chunksz) + { + rc = 2; + goto byebye; + } + size -= chunksz; } if (fread(data, 1, size, source) != (size_t) size) { - rc = 1; - goto byebye; + rc = 1; + goto byebye; } if (fwrite(data, 1, size, dest) != (size_t) size) { - rc = 2; - goto byebye; + rc = 2; + goto byebye; } byebye: if (data != 0) - FreeMemory(data); + FreeMemory(data); return rc; } diff -r 594dea11ccd9 -r a68786b9c74b src/wads.h --- a/src/wads.h Sat Sep 24 15:01:56 2011 +0300 +++ b/src/wads.h Sat Sep 24 15:59:33 2011 +0300 @@ -1,10 +1,10 @@ /* - * wads.h - * AYM 1998-11-25 + * wads.h + * AYM 1998-11-25 */ -#ifndef YH_WADS /* DO NOT INSERT ANYTHING BEFORE THIS LINE */ +#ifndef YH_WADS /* DO NOT INSERT ANYTHING BEFORE THIS LINE */ #define YH_WADS @@ -30,8 +30,8 @@ #if 0 /* - * flat_name_cmp - * Compare two flat names like strcmp() compares two strings. + * flat_name_cmp + * Compare two flat names like strcmp() compares two strings. */ inline int flat_name_cmp(const char *name1, const char *name2) { @@ -39,9 +39,9 @@ /* - * tex_name_cmp - * Compare two texture names like strcmp() compares two strings. - * T + * tex_name_cmp + * Compare two texture names like strcmp() compares two strings. + * T */ inline int tex_name_cmp(const char *name1, const char *name2) { @@ -49,8 +49,8 @@ /* - * sprite_name_cmp - * Compare two sprite names like strcmp() compares two strings. + * sprite_name_cmp + * Compare two sprite names like strcmp() compares two strings. */ inline int sprite_name_cmp(const char *name1, const char *name2) { diff -r 594dea11ccd9 -r a68786b9c74b src/wads2.cc --- a/src/wads2.cc Sat Sep 24 15:01:56 2011 +0300 +++ b/src/wads2.cc Sat Sep 24 15:59:33 2011 +0300 @@ -1,7 +1,7 @@ /* - * wads2.cc - * Wads functions that are not needed during editing. - * AYM 1998-08-09 + * wads2.cc + * Wads functions that are not needed during editing. + * AYM 1998-08-09 */ @@ -29,7 +29,7 @@ #include "yadex.h" -#include "game.h" /* yg_picture_format */ +#include "game.h" /* yg_picture_format */ #include "serialnum.h" #include "wadfile.h" #include "wadlist.h" @@ -42,12 +42,12 @@ /* - * OpenMainWad - open the iwad + * OpenMainWad - open the iwad * - * Open the main wad file, read in its directory and create - * the master directory. + * Open the main wad file, read in its directory and create + * the master directory. * - * Return 0 on success, non-zero on failure. + * Return 0 on success, non-zero on failure. */ int OpenMainWad(const char *filename) { @@ -59,60 +59,60 @@ printf("Loading iwad: %s...\n", filename); wf = BasicWadOpen(filename, yg_picture_format); if (wf == 0) - return 1; + return 1; if (strncmp(wf->type, "IWAD", 4)) - warn("%.128s: is a pwad, not an iwad. Will use it anyway.\n", - filename); + warn("%.128s: is a pwad, not an iwad. Will use it anyway.\n", + filename); /* create the master directory */ lastp = NULL; for (n = 0; n < wf->dirsize; n++) { - newp = (MDirPtr) GetMemory(sizeof(struct MasterDirectory)); - newp->next = NULL; - newp->wadfile = wf; - memcpy(&(newp->dir), &(wf->directory[n]), sizeof(struct Directory)); - if (MasterDir) - lastp->next = newp; - else - MasterDir = newp; - lastp = newp; + newp = (MDirPtr) GetMemory(sizeof(struct MasterDirectory)); + newp->next = NULL; + newp->wadfile = wf; + memcpy(&(newp->dir), &(wf->directory[n]), sizeof(struct Directory)); + if (MasterDir) + lastp->next = newp; + else + MasterDir = newp; + lastp = newp; } master_dir_serial.bump(); /* check if registered version */ if (FindMasterDir(MasterDir, "E2M1") == NULL - && FindMasterDir(MasterDir, "MAP01") == NULL - && FindMasterDir(MasterDir, "MAP33") == NULL - && strcmp(Game, "doom02") - && strcmp(Game, "doom04") - && strcmp(Game, "doom05") && strcmp(Game, "doompr")) + && FindMasterDir(MasterDir, "MAP01") == NULL + && FindMasterDir(MasterDir, "MAP33") == NULL + && strcmp(Game, "doom02") + && strcmp(Game, "doom04") + && strcmp(Game, "doom05") && strcmp(Game, "doompr")) { - printf - (" *-----------------------------------------------------*\n"); - printf - (" | Warning: this is the shareware version of the game. |\n"); - printf - (" | You won't be allowed to save your changes. |\n"); - printf - (" | PLEASE REGISTER YOUR COPY OF THE GAME. |\n"); - printf - (" *-----------------------------------------------------*\n"); - Registered = false; // If you remove this, bad things will happen to you... + printf + (" *-----------------------------------------------------*\n"); + printf + (" | Warning: this is the shareware version of the game. |\n"); + printf + (" | You won't be allowed to save your changes. |\n"); + printf + (" | PLEASE REGISTER YOUR COPY OF THE GAME. |\n"); + printf + (" *-----------------------------------------------------*\n"); + Registered = false; // If you remove this, bad things will happen to you... } else - Registered = true; + Registered = true; return 0; } /* - * OpenPatchWad - add a pwad + * OpenPatchWad - add a pwad * - * Open a patch wad file, read in its directory and alter - * the master directory. + * Open a patch wad file, read in its directory and alter + * the master directory. * - * Return 0 on success, non-zero on failure. + * Return 0 on success, non-zero on failure. */ int OpenPatchWad(const char *filename) { @@ -122,14 +122,14 @@ char entryname[WAD_NAME + 1]; const char *entry_type = 0; char *real_name; - int nitems = 0; // Number of items in group of flats/patches/sprites + int nitems = 0; // Number of items in group of flats/patches/sprites // Look for the file and ignore it if it doesn't exist real_name = locate_pwad(filename); if (real_name == NULL) { - warn("%.128s: not found.\n", filename); - return 1; + warn("%.128s: not found.\n", filename); + return 1; } /* open the wad file */ @@ -138,10 +138,10 @@ wad = BasicWadOpen(real_name, YGPF_NORMAL); FreeMemory(real_name); if (!wad) - return 1; + return 1; if (strncmp(wad->type, "PWAD", 4)) - warn("%.128s: is an iwad, not a pwad. Will use it anyway.\n", - filename); + warn("%.128s: is an iwad, not a pwad. Will use it anyway.\n", + filename); /* alter the master directory */ @@ -157,175 +157,175 @@ int replaces = 0; int state_prev; int replaces_prev; - int names = 0; // Number of names already printed on current line + int names = 0; // Number of names already printed on current line const char *entry_type_prev; typedef char level_list_item_t[WAD_NAME]; level_list_item_t *level_list = 0; size_t nlevels = 0; for (n = 0; n < wad->dirsize; n++) { - strncpy(entryname, wad->directory[n].name, WAD_NAME); - entryname[WAD_NAME] = '\0'; - state_prev = state; - replaces_prev = replaces; - entry_type_prev = entry_type; - if (state == 0) - { - if (!strcmp(entryname, "F_START") - || !strcmp(entryname, "P_START") - || !strcmp(entryname, "S_START")) - { - entry_type = "label"; - replaces = 0; - } - // DeuTex puts flats between FF_START and FF_END/F_END. - // All lumps between those markers are assumed - // to be flats. - else if (!strncmp(entryname, "FF_START", WAD_NAME)) - { - state = 'f'; - entry_type = "group of flats"; - replaces = 0; - nitems = 0; - } - // DeuTex puts patches between PP_START and PP_END. - // All lumps between those markers are assumed - // to be patches. - else if (!strncmp(entryname, "PP_START", WAD_NAME)) - { - state = 'p'; - entry_type = "group of patches"; - replaces = 0; - nitems = 0; - } - // DeuTex puts patches between SS_START and SS_END/S_END. - // All lumps between those markers are assumed - // to be sprites. - else if (!strncmp(entryname, "SS_START", WAD_NAME)) - { - state = 's'; - entry_type = "group of sprites"; - replaces = 0; - nitems = 0; - } - else - { - mdir = FindMasterDir(MasterDir, entryname); - replaces = mdir != NULL; - /* if it is a level, do the same thing for the next 10 entries too */ - if (levelname2levelno(entryname)) - { - state = 11; - entry_type = "level"; - // Add to list of level names - { - level_list_item_t *new_list; - new_list = (level_list_item_t *) - realloc(level_list, - (nlevels + 1) * sizeof *level_list); - if (new_list != 0) - { - level_list = new_list; - strncpy(level_list[nlevels], entryname, - sizeof *level_list); - nlevels++; - } - } - } - else - entry_type = "entry"; - } - if (n == 0 - || state_prev != state - || replaces_prev != replaces || entry_type_prev != entry_type) - { - if (n > 0) - verbmsg("\n"); - names = 0; - verbmsg(" %s %s", replaces ? "Updating" : "Adding new", - entry_type); - } - if (names >= 6) - { - verbmsg("\n %-*s %-*s", - strlen(replaces ? "Updating" : "Adding new"), "", - strlen(entry_type), ""); - names = 0; - } - verbmsg(" %-*s", WAD_NAME, entryname); - names++; - if ((*entry_type == 'm' || *entry_type == 'l') - && wad->directory[n].size) - verbmsg(" warning: non-zero length (%ld)", - wad->directory[n].size); - } - // Either F_END or FF_END mark the end of a - // DeuTex-generated group of flats. - else if (state == 'f') - { - if (!strncmp(entryname, "F_END", WAD_NAME) - || !strncmp(entryname, "FF_END", WAD_NAME)) - { - state = 0; - verbmsg("/%.*s (%d flats)", WAD_NAME, entryname, nitems); - } - // Of course, F?_START and F?_END don't count - // toward the number of flats in the group. - else if (!(*entryname == 'F' - && (!strncmp(entryname + 2, "_START", 6) - || !strcmp(entryname + 2, "_END")))) - nitems++; - } - // PP_END marks the end of a DeuTex-generated group of patches. - else if (state == 'p') - { - if (!strncmp(entryname, "PP_END", WAD_NAME)) - { - state = 0; - verbmsg("/PP_END (%d patches)", nitems); - } - // Of course, P?_START and P?_END don't count - // toward the number of flats in the group. - else if (!(*entryname == 'P' - && (!strncmp(entryname + 2, "_START", 6) - || !strcmp(entryname + 2, "_END")))) - nitems++; - } - // Either S_END or SS_END mark the end of a - // DeuTex-generated group of sprites. - else if (state == 's') - { - if (!strncmp(entryname, "S_END", WAD_NAME) - || !strncmp(entryname, "SS_END", WAD_NAME)) - { - state = 0; - verbmsg("/%.*s (%d sprites)", WAD_NAME, entryname, nitems); - } - // Of course, S?_START and S?_END don't count - // toward the number of sprites in the group. - else if (!(*entryname == 'S' - && (!strncmp(entryname + 2, "_START", 6) - || !strcmp(entryname + 2, "_END")))) - nitems++; - } + strncpy(entryname, wad->directory[n].name, WAD_NAME); + entryname[WAD_NAME] = '\0'; + state_prev = state; + replaces_prev = replaces; + entry_type_prev = entry_type; + if (state == 0) + { + if (!strcmp(entryname, "F_START") + || !strcmp(entryname, "P_START") + || !strcmp(entryname, "S_START")) + { + entry_type = "label"; + replaces = 0; + } + // DeuTex puts flats between FF_START and FF_END/F_END. + // All lumps between those markers are assumed + // to be flats. + else if (!strncmp(entryname, "FF_START", WAD_NAME)) + { + state = 'f'; + entry_type = "group of flats"; + replaces = 0; + nitems = 0; + } + // DeuTex puts patches between PP_START and PP_END. + // All lumps between those markers are assumed + // to be patches. + else if (!strncmp(entryname, "PP_START", WAD_NAME)) + { + state = 'p'; + entry_type = "group of patches"; + replaces = 0; + nitems = 0; + } + // DeuTex puts patches between SS_START and SS_END/S_END. + // All lumps between those markers are assumed + // to be sprites. + else if (!strncmp(entryname, "SS_START", WAD_NAME)) + { + state = 's'; + entry_type = "group of sprites"; + replaces = 0; + nitems = 0; + } + else + { + mdir = FindMasterDir(MasterDir, entryname); + replaces = mdir != NULL; + /* if it is a level, do the same thing for the next 10 entries too */ + if (levelname2levelno(entryname)) + { + state = 11; + entry_type = "level"; + // Add to list of level names + { + level_list_item_t *new_list; + new_list = (level_list_item_t *) + realloc(level_list, + (nlevels + 1) * sizeof *level_list); + if (new_list != 0) + { + level_list = new_list; + strncpy(level_list[nlevels], entryname, + sizeof *level_list); + nlevels++; + } + } + } + else + entry_type = "entry"; + } + if (n == 0 + || state_prev != state + || replaces_prev != replaces || entry_type_prev != entry_type) + { + if (n > 0) + verbmsg("\n"); + names = 0; + verbmsg(" %s %s", replaces ? "Updating" : "Adding new", + entry_type); + } + if (names >= 6) + { + verbmsg("\n %-*s %-*s", + strlen(replaces ? "Updating" : "Adding new"), "", + strlen(entry_type), ""); + names = 0; + } + verbmsg(" %-*s", WAD_NAME, entryname); + names++; + if ((*entry_type == 'm' || *entry_type == 'l') + && wad->directory[n].size) + verbmsg(" warning: non-zero length (%ld)", + wad->directory[n].size); + } + // Either F_END or FF_END mark the end of a + // DeuTex-generated group of flats. + else if (state == 'f') + { + if (!strncmp(entryname, "F_END", WAD_NAME) + || !strncmp(entryname, "FF_END", WAD_NAME)) + { + state = 0; + verbmsg("/%.*s (%d flats)", WAD_NAME, entryname, nitems); + } + // Of course, F?_START and F?_END don't count + // toward the number of flats in the group. + else if (!(*entryname == 'F' + && (!strncmp(entryname + 2, "_START", 6) + || !strcmp(entryname + 2, "_END")))) + nitems++; + } + // PP_END marks the end of a DeuTex-generated group of patches. + else if (state == 'p') + { + if (!strncmp(entryname, "PP_END", WAD_NAME)) + { + state = 0; + verbmsg("/PP_END (%d patches)", nitems); + } + // Of course, P?_START and P?_END don't count + // toward the number of flats in the group. + else if (!(*entryname == 'P' + && (!strncmp(entryname + 2, "_START", 6) + || !strcmp(entryname + 2, "_END")))) + nitems++; + } + // Either S_END or SS_END mark the end of a + // DeuTex-generated group of sprites. + else if (state == 's') + { + if (!strncmp(entryname, "S_END", WAD_NAME) + || !strncmp(entryname, "SS_END", WAD_NAME)) + { + state = 0; + verbmsg("/%.*s (%d sprites)", WAD_NAME, entryname, nitems); + } + // Of course, S?_START and S?_END don't count + // toward the number of sprites in the group. + else if (!(*entryname == 'S' + && (!strncmp(entryname + 2, "_START", 6) + || !strcmp(entryname + 2, "_END")))) + nitems++; + } - /* if this entry is not in the master directory, then add it */ - if (!replaces) - { - mdir = MasterDir; - while (mdir->next) - mdir = mdir->next; - mdir->next = (MDirPtr) GetMemory(sizeof(struct MasterDirectory)); - mdir = mdir->next; - mdir->next = NULL; - } - /* else, simply replace it */ - mdir->wadfile = wad; - memcpy(&(mdir->dir), &(wad->directory[n]), sizeof(struct Directory)); - mdir = mdir->next; + /* if this entry is not in the master directory, then add it */ + if (!replaces) + { + mdir = MasterDir; + while (mdir->next) + mdir = mdir->next; + mdir->next = (MDirPtr) GetMemory(sizeof(struct MasterDirectory)); + mdir = mdir->next; + mdir->next = NULL; + } + /* else, simply replace it */ + mdir->wadfile = wad; + memcpy(&(mdir->dir), &(wad->directory[n]), sizeof(struct Directory)); + mdir = mdir->next; - if (state > 0 && state <= 11) - state--; + if (state > 0 && state <= 11) + state--; } verbmsg("\n"); master_dir_serial.bump(); @@ -333,44 +333,44 @@ // Print list of levels found in this pwad if (level_list != 0) { - printf(" Levels: "); - qsort(level_list, nlevels, sizeof *level_list, level_name_order); - for (size_t n = 0; n < nlevels; n++) - { - int prev = n > 0 ? levelname2rank(level_list[n - 1]) : INT_MIN; - int cur = levelname2rank(level_list[n]); - int next = - n + 1 < nlevels ? levelname2rank(level_list[n + 1]) : INT_MAX; - if (cur != prev + 1 || cur != next - 1) - { - if (cur == prev + 1) - putchar('-'); - else if (n > 0) - putchar(' '); - printf("%.*s", (int) sizeof *level_list, level_list[n]); - } - } - putchar('\n'); - free(level_list); + printf(" Levels: "); + qsort(level_list, nlevels, sizeof *level_list, level_name_order); + for (size_t n = 0; n < nlevels; n++) + { + int prev = n > 0 ? levelname2rank(level_list[n - 1]) : INT_MIN; + int cur = levelname2rank(level_list[n]); + int next = + n + 1 < nlevels ? levelname2rank(level_list[n + 1]) : INT_MAX; + if (cur != prev + 1 || cur != next - 1) + { + if (cur == prev + 1) + putchar('-'); + else if (n > 0) + putchar(' '); + printf("%.*s", (int) sizeof *level_list, level_list[n]); + } + } + putchar('\n'); + free(level_list); } return 0; } /* - * level_name_order - -cmp-style comparison of two level names + * level_name_order - -cmp-style comparison of two level names */ static int level_name_order(const void *p1, const void *p2) { return levelname2rank((const char *) p1) - - levelname2rank((const char *) p2); + - levelname2rank((const char *) p2); } /* - * CloseWadFiles - close all wads + * CloseWadFiles - close all wads * - * Close all the wad, deallocating the wad file structures. + * Close all the wad, deallocating the wad file structures. */ void CloseWadFiles() { @@ -380,23 +380,23 @@ Wad_file *wf; wad_list.rewind(); while (wad_list.get(wf)) - wad_list.del(); + wad_list.del(); // Delete the master directory curd = MasterDir; MasterDir = NULL; while (curd) { - nextd = curd->next; - FreeMemory(curd); - curd = nextd; + nextd = curd->next; + FreeMemory(curd); + curd = nextd; } master_dir_serial.bump(); } /* - * CloseUnusedWadFiles - forget unused patch wad files + * CloseUnusedWadFiles - forget unused patch wad files */ void CloseUnusedWadFiles() { @@ -404,23 +404,23 @@ wad_list.rewind(); while (wad_list.get(wf)) { - // Check if the wad file is used by a directory entry - MDirPtr mdir = MasterDir; - while (mdir && mdir->wadfile != wf) - mdir = mdir->next; - if (mdir == 0) - wad_list.del(); + // Check if the wad file is used by a directory entry + MDirPtr mdir = MasterDir; + while (mdir && mdir->wadfile != wf) + mdir = mdir->next; + if (mdir == 0) + wad_list.del(); } } /* - * BasicWadOpen - open a wad + * BasicWadOpen - open a wad * - * Basic opening of wad file and creation of node in Wad - * linked list. + * Basic opening of wad file and creation of node in Wad + * linked list. * - * Return a null pointer on error. + * Return a null pointer on error. */ Wad_file *BasicWadOpen(const char *filename, ygpf_t pic_format) { @@ -435,14 +435,14 @@ FIXME if reopening fails, we're left in the cold. I'm not sure how to avoid that, though. */ { - Wad_file *dummy; - wad_list.rewind(); - while (wad_list.get(dummy)) - if (fncmp(filename, dummy->filename) == 0) - { - wad_list.del(); - break; - } + Wad_file *dummy; + wad_list.rewind(); + while (wad_list.get(dummy)) + if (fncmp(filename, dummy->filename) == 0) + { + wad_list.del(); + break; + } } // Create a new Wad_file @@ -456,47 +456,47 @@ wf->fp = fopen(filename, "rb"); if (wf->fp == 0) { - printf("%.128s: %s\n", filename, strerror(errno)); - fail = true; - goto byebye; + printf("%.128s: %s\n", filename, strerror(errno)); + fail = true; + goto byebye; } { - bool e = file_read_bytes(wf->fp, wf->type, 4); - e |= file_read_i32(wf->fp, &wf->dirsize); - e |= file_read_i32(wf->fp, &wf->dirstart); - if (e || memcmp(wf->type, "IWAD", 4) != 0 - && memcmp(wf->type, "PWAD", 4) != 0) - { - printf("%.128s: not a wad (bad header)\n", filename); - fail = true; - goto byebye; - } + bool e = file_read_bytes(wf->fp, wf->type, 4); + e |= file_read_i32(wf->fp, &wf->dirsize); + e |= file_read_i32(wf->fp, &wf->dirstart); + if (e || memcmp(wf->type, "IWAD", 4) != 0 + && memcmp(wf->type, "PWAD", 4) != 0) + { + printf("%.128s: not a wad (bad header)\n", filename); + fail = true; + goto byebye; + } } verbmsg(" Type %.4s, directory has %ld entries at offset %08lXh\n", - wf->type, (long) wf->dirsize, (long) wf->dirstart); + wf->type, (long) wf->dirsize, (long) wf->dirstart); // Load the directory of the wad wf->directory = (DirPtr) GetMemory((long) sizeof(struct Directory) - * wf->dirsize); + * wf->dirsize); if (fseek(wf->fp, wf->dirstart, SEEK_SET) != 0) { - printf("%.128s: can't seek to directory at %08lXh\n", - filename, wf->dirstart); - fail = true; - goto byebye; + printf("%.128s: can't seek to directory at %08lXh\n", + filename, wf->dirstart); + fail = true; + goto byebye; } for (i32 n = 0; n < wf->dirsize; n++) { - bool e = file_read_i32(wf->fp, &wf->directory[n].start); - e |= file_read_i32(wf->fp, &wf->directory[n].size); - e |= file_read_bytes(wf->fp, wf->directory[n].name, WAD_NAME); - if (e) - { - printf("%.128s: read error on directory entry %ld\n", filename, - (long) n); - fail = true; - goto byebye; - } + bool e = file_read_i32(wf->fp, &wf->directory[n].start); + e |= file_read_i32(wf->fp, &wf->directory[n].size); + e |= file_read_bytes(wf->fp, wf->directory[n].name, WAD_NAME); + if (e) + { + printf("%.128s: read error on directory entry %ld\n", filename, + (long) n); + fail = true; + goto byebye; + } } // Insert the new wad in the list @@ -505,15 +505,15 @@ byebye: if (fail) { - delete wf; - return 0; + delete wf; + return 0; } return wf; } /* - * ListMasterDirectory - list the master directory + * ListMasterDirectory - list the master directory */ void ListMasterDirectory(FILE * file) { @@ -526,33 +526,33 @@ fprintf(file, "The Master Directory\n"); fprintf(file, "====================\n\n"); fprintf(file, - "NAME____ FILE______________________________________________" - " SIZE__ START____\n"); + "NAME____ FILE______________________________________________" + " SIZE__ START____\n"); for (dir = MasterDir; dir; dir = dir->next) { - strncpy(dataname, dir->dir.name, WAD_NAME); - fprintf(file, "%-*s %-50s %6ld x%08lx\n", - WAD_NAME, dataname, dir->wadfile->pathname(), - dir->dir.size, dir->dir.start); - if (file == stdout && lines++ > screen_lines - 4) - { - lines = 0; - printf - ("['Q' followed by Return to abort, Return only to continue]"); - key = getchar(); - printf("\r%57s\r", ""); - if (key == 'Q' || key == 'q') - { - getchar(); // Read the '\n' - break; - } - } + strncpy(dataname, dir->dir.name, WAD_NAME); + fprintf(file, "%-*s %-50s %6ld x%08lx\n", + WAD_NAME, dataname, dir->wadfile->pathname(), + dir->dir.size, dir->dir.start); + if (file == stdout && lines++ > screen_lines - 4) + { + lines = 0; + printf + ("['Q' followed by Return to abort, Return only to continue]"); + key = getchar(); + printf("\r%57s\r", ""); + if (key == 'Q' || key == 'q') + { + getchar(); // Read the '\n' + break; + } + } } } /* - * ListFileDirectory - list the directory of a wad + * ListFileDirectory - list the directory of a wad */ void ListFileDirectory(FILE * file, const Wad_file * wad) { @@ -568,33 +568,33 @@ fprintf(file, "NAME____ SIZE__ START____ END______\n"); for (n = 0; n < wad->dirsize; n++) { - strncpy(dataname, wad->directory[n].name, WAD_NAME); - fprintf(file, "%-*s %6ld x%08lx x%08lx\n", - WAD_NAME, dataname, - wad->directory[n].size, - wad->directory[n].start, - wad->directory[n].size + wad->directory[n].start - 1); - if (file == stdout && lines++ > screen_lines - 4) - { - lines = 0; - printf - ("['Q' followed by Return to abort, Return only to continue]"); - key = getchar(); - printf("\r%57s\r", ""); - if (key == 'Q' || key == 'q') - { - getchar(); // Read the '\n' - break; - } - } + strncpy(dataname, wad->directory[n].name, WAD_NAME); + fprintf(file, "%-*s %6ld x%08lx x%08lx\n", + WAD_NAME, dataname, + wad->directory[n].size, + wad->directory[n].start, + wad->directory[n].size + wad->directory[n].start - 1); + if (file == stdout && lines++ > screen_lines - 4) + { + lines = 0; + printf + ("['Q' followed by Return to abort, Return only to continue]"); + key = getchar(); + printf("\r%57s\r", ""); + if (key == 'Q' || key == 'q') + { + getchar(); // Read the '\n' + break; + } + } } } /* - * BuildNewMainWad - build a new iwad (or pwad) + * BuildNewMainWad - build a new iwad (or pwad) * - * Build a new wad file from master directory. + * Build a new wad file from master directory. */ void BuildNewMainWad(const char *filename, bool patchonly) { @@ -607,42 +607,42 @@ /* open the file and store signatures */ if (patchonly) - printf("Building a compound Patch Wad file \"%s\".\n", filename); + printf("Building a compound Patch Wad file \"%s\".\n", filename); else - printf("Building a new Main Wad file \"%s\" (size approx 10 MB)\n", - filename); + printf("Building a new Main Wad file \"%s\" (size approx 10 MB)\n", + filename); if (FindMasterDir(MasterDir, "E2M4") == NULL - && FindMasterDir(MasterDir, "MAP01") == NULL - && FindMasterDir(MasterDir, "MAP33") == NULL - && strcmp(Game, "doom02") - && strcmp(Game, "doom04") - && strcmp(Game, "doom05") && strcmp(Game, "doompr")) - fatal_error("You were warned: you are not allowed to do this."); + && FindMasterDir(MasterDir, "MAP01") == NULL + && FindMasterDir(MasterDir, "MAP33") == NULL + && strcmp(Game, "doom02") + && strcmp(Game, "doom04") + && strcmp(Game, "doom05") && strcmp(Game, "doompr")) + fatal_error("You were warned: you are not allowed to do this."); if ((file = fopen(filename, "wb")) == NULL) - fatal_error("unable to open file \"%s\"", filename); + fatal_error("unable to open file \"%s\"", filename); if (patchonly) - WriteBytes(file, "PWAD", 4); + WriteBytes(file, "PWAD", 4); else - WriteBytes(file, "IWAD", 4); - file_write_i32(file, 0xdeadbeef); /* put true value in later */ - file_write_i32(file, 0xdeadbeef); /* put true value in later */ + WriteBytes(file, "IWAD", 4); + file_write_i32(file, 0xdeadbeef); /* put true value in later */ + file_write_i32(file, 0xdeadbeef); /* put true value in later */ /* output the directory data chunks */ - const Wad_file *iwad = 0; // FIXME unreliable way of knowing the iwad - wad_list.rewind(); // got to look into this + const Wad_file *iwad = 0; // FIXME unreliable way of knowing the iwad + wad_list.rewind(); // got to look into this wad_list.get(iwad); for (cur = MasterDir; cur; cur = cur->next) { - if (patchonly && cur->wadfile == iwad) - continue; - size = cur->dir.size; - counter += size; - cur->wadfile->seek(cur->dir.start); - if (cur->wadfile->error()) - ; // FIXME - if (copy_bytes(file, cur->wadfile->fp, size) != 0) - ; // FIXME - printf("Size: %luK\r", counter / 1024); + if (patchonly && cur->wadfile == iwad) + continue; + size = cur->dir.size; + counter += size; + cur->wadfile->seek(cur->dir.start); + if (cur->wadfile->error()) + ; // FIXME + if (copy_bytes(file, cur->wadfile->fp, size) != 0) + ; // FIXME + printf("Size: %luK\r", counter / 1024); } /* output the directory */ @@ -651,23 +651,23 @@ dirnum = 0; for (cur = MasterDir; cur; cur = cur->next) { - if (patchonly && cur->wadfile == iwad) - continue; - if (dirnum % 100 == 0) - printf("Outputting directory %04ld...\r", dirnum); - if (cur->dir.start) - file_write_i32(file, counter); - else - file_write_i32(file, 0); - file_write_i32(file, cur->dir.size); - file_write_name(file, cur->dir.name); - counter += cur->dir.size; - dirnum++; + if (patchonly && cur->wadfile == iwad) + continue; + if (dirnum % 100 == 0) + printf("Outputting directory %04ld...\r", dirnum); + if (cur->dir.start) + file_write_i32(file, counter); + else + file_write_i32(file, 0); + file_write_i32(file, cur->dir.size); + file_write_name(file, cur->dir.name); + counter += cur->dir.size; + dirnum++; } /* fix up the number of entries and directory start information */ if (fseek(file, 4L, 0)) - fatal_error("error writing to file"); + fatal_error("error writing to file"); file_write_i32(file, dirnum); file_write_i32(file, dirstart); @@ -678,9 +678,9 @@ /* - * DumpDirectoryEntry - hexadecimal dump of a lump + * DumpDirectoryEntry - hexadecimal dump of a lump * - * Dump a directory entry in hex + * Dump a directory entry in hex */ void DumpDirectoryEntry(FILE * file, const char *entryname) { @@ -693,175 +693,175 @@ for (MDirPtr entry = MasterDir; entry != 0; entry = entry->next) { - if (y_strnicmp(entry->dir.name, entryname, WAD_NAME) != 0) - continue; - strncpy(dataname, entry->dir.name, WAD_NAME); - dataname[WAD_NAME] = '\0'; - fprintf(file, "Contents of entry %s (size = %ld bytes):\n", - dataname, entry->dir.size); - const Wad_file *wf = entry->wadfile; - wf->seek(entry->dir.start); - for (n = 0; n < entry->dir.size;) - { - int i; - fprintf(file, "%04lX: ", n); + if (y_strnicmp(entry->dir.name, entryname, WAD_NAME) != 0) + continue; + strncpy(dataname, entry->dir.name, WAD_NAME); + dataname[WAD_NAME] = '\0'; + fprintf(file, "Contents of entry %s (size = %ld bytes):\n", + dataname, entry->dir.size); + const Wad_file *wf = entry->wadfile; + wf->seek(entry->dir.start); + for (n = 0; n < entry->dir.size;) + { + int i; + fprintf(file, "%04lX: ", n); - // Nb of bytes to read for this line - long bytes_to_read = entry->dir.size - n; - if (bytes_to_read > bytes_per_line) - bytes_to_read = bytes_per_line; - long nbytes = wf->read_vbytes(buf, bytes_to_read); - if (wf->error()) - break; - n += nbytes; + // Nb of bytes to read for this line + long bytes_to_read = entry->dir.size - n; + if (bytes_to_read > bytes_per_line) + bytes_to_read = bytes_per_line; + long nbytes = wf->read_vbytes(buf, bytes_to_read); + if (wf->error()) + break; + n += nbytes; - for (i = 0; i < nbytes; i++) - fprintf(file, " %02X", buf[i]); - for (; i < bytes_per_line; i++) - fputs(" ", file); - fprintf(file, " "); + for (i = 0; i < nbytes; i++) + fprintf(file, " %02X", buf[i]); + for (; i < bytes_per_line; i++) + fputs(" ", file); + fprintf(file, " "); - for (i = 0; i < nbytes; i++) - { - if (buf[i] >= 0x20 && buf[i] != 0x7f + for (i = 0; i < nbytes; i++) + { + if (buf[i] >= 0x20 && buf[i] != 0x7f #ifdef Y_UNIX - && !(buf[i] >= 0x80 && buf[i] <= 0xa0) // ISO 8859-1 + && !(buf[i] >= 0x80 && buf[i] <= 0xa0) // ISO 8859-1 #endif - ) - putc(buf[i], file); - else - putc('.', file); - } - putc('\n', file); + ) + putc(buf[i], file); + else + putc('.', file); + } + putc('\n', file); - if (file == stdout && lines++ > screen_lines - 4) - { - lines = 0; - printf("[%d%% - Q + Return to abort," - " S + Return to skip this entry," - " Return to continue]", - (int) (n * 100 / entry->dir.size)); - key = getchar(); - printf("\r%68s\r", ""); - if (key == 'S' || key == 's') - { - getchar(); // Read the '\n' - break; - } - if (key == 'Q' || key == 'q') - { - getchar(); // Read the '\n' - return; - } - } - } + if (file == stdout && lines++ > screen_lines - 4) + { + lines = 0; + printf("[%d%% - Q + Return to abort," + " S + Return to skip this entry," + " Return to continue]", + (int) (n * 100 / entry->dir.size)); + key = getchar(); + printf("\r%68s\r", ""); + if (key == 'S' || key == 's') + { + getchar(); // Read the '\n' + break; + } + if (key == 'Q' || key == 'q') + { + getchar(); // Read the '\n' + return; + } + } + } } if (!n) { - printf("Entry not in master directory.\n"); - return; + printf("Entry not in master directory.\n"); + return; } } /* - * SaveDirectoryEntry - write the contents of a lump to a new pwad + * SaveDirectoryEntry - write the contents of a lump to a new pwad * - * Save a directory entry to disk + * Save a directory entry to disk */ void SaveDirectoryEntry(FILE * file, const char *entryname) { MDirPtr entry; for (entry = MasterDir; entry; entry = entry->next) - if (!y_strnicmp(entry->dir.name, entryname, WAD_NAME)) - break; + if (!y_strnicmp(entry->dir.name, entryname, WAD_NAME)) + break; if (entry) { - // Write the header - WriteBytes(file, "PWAD", 4); // Type = PWAD - file_write_i32(file, 1); // 1 entry in the directory - file_write_i32(file, 12); // The directory starts at offset 12 + // Write the header + WriteBytes(file, "PWAD", 4); // Type = PWAD + file_write_i32(file, 1); // 1 entry in the directory + file_write_i32(file, 12); // The directory starts at offset 12 - // Write the directory - file_write_i32(file, 28); // First entry starts at offset 28 - file_write_i32(file, entry->dir.size); // Size of first entry - file_write_name(file, entry->dir.name); // Name of first entry + // Write the directory + file_write_i32(file, 28); // First entry starts at offset 28 + file_write_i32(file, entry->dir.size); // Size of first entry + file_write_name(file, entry->dir.name); // Name of first entry - // Write the lump data - entry->wadfile->seek(entry->dir.start); - if (entry->wadfile->error()) - { - err("%s: seek error", entryname); - return; - } - int r = copy_bytes(file, entry->wadfile->fp, entry->dir.size); - if (r != 0) - { - if (r == 1) - err("%s: error reading from source wad", entryname); - else if (r == 2) - err("%s: error writing to destination wad", entryname); - else - nf_bug("%s: copy_bytes() returned %d", entryname, r); - return; - } + // Write the lump data + entry->wadfile->seek(entry->dir.start); + if (entry->wadfile->error()) + { + err("%s: seek error", entryname); + return; + } + int r = copy_bytes(file, entry->wadfile->fp, entry->dir.size); + if (r != 0) + { + if (r == 1) + err("%s: error reading from source wad", entryname); + else if (r == 2) + err("%s: error writing to destination wad", entryname); + else + nf_bug("%s: copy_bytes() returned %d", entryname, r); + return; + } } else { - printf("Entry not in master directory.\n"); - return; + printf("Entry not in master directory.\n"); + return; } } /* - * SaveEntryToRawFile - write the contents of a lump to a new file + * SaveEntryToRawFile - write the contents of a lump to a new file * - * Save a directory entry to disk, without a pwad header + * Save a directory entry to disk, without a pwad header */ void SaveEntryToRawFile(FILE * file, const char *entryname) { MDirPtr entry; for (entry = MasterDir; entry; entry = entry->next) - if (!y_strnicmp(entry->dir.name, entryname, WAD_NAME)) - break; + if (!y_strnicmp(entry->dir.name, entryname, WAD_NAME)) + break; if (entry) { - verbmsg("Writing %ld bytes starting from offset %lX...\n", - (long) entry->dir.size, (unsigned long) entry->dir.start); - entry->wadfile->seek(entry->dir.start); - if (entry->wadfile->error()) - { - err("%s: seek error", entryname); - return; - } - int r = copy_bytes(file, entry->wadfile->fp, entry->dir.size); - if (r != 0) - { - if (r == 1) - err("%s: error reading from source wad", entryname); - else if (r == 2) - err("%s: error writing to destination file", entryname); - else - nf_bug("%s: copy_bytes() returned %d", entryname, r); - return; - } + verbmsg("Writing %ld bytes starting from offset %lX...\n", + (long) entry->dir.size, (unsigned long) entry->dir.start); + entry->wadfile->seek(entry->dir.start); + if (entry->wadfile->error()) + { + err("%s: seek error", entryname); + return; + } + int r = copy_bytes(file, entry->wadfile->fp, entry->dir.size); + if (r != 0) + { + if (r == 1) + err("%s: error reading from source wad", entryname); + else if (r == 2) + err("%s: error writing to destination file", entryname); + else + nf_bug("%s: copy_bytes() returned %d", entryname, r); + return; + } } else { - printf("[Entry not in master directory]\n"); - return; + printf("[Entry not in master directory]\n"); + return; } } /* - * SaveEntryFromRawFile - encapsulate a raw file in a pwad + * SaveEntryFromRawFile - encapsulate a raw file in a pwad * - * Encapsulate a raw file in a pwad file + * Encapsulate a raw file in a pwad file */ void SaveEntryFromRawFile(FILE * file, FILE * raw, const char *entryname) { @@ -869,56 +869,56 @@ char name8[WAD_NAME]; // Write the header - WriteBytes(file, "PWAD", 4); // Type = PWAD - file_write_i32(file, 1); // 1 entry in the directory - file_write_i32(file, 12); // The directory starts at offset 12 + WriteBytes(file, "PWAD", 4); // Type = PWAD + file_write_i32(file, 1); // 1 entry in the directory + file_write_i32(file, 12); // The directory starts at offset 12 // Write the directory - file_write_i32(file, 28); // First entry starts at offset 28 + file_write_i32(file, 28); // First entry starts at offset 28 if (fseek(raw, 0L, SEEK_END) != 0) - fatal_error("error reading from raw file"); + fatal_error("error reading from raw file"); size = ftell(raw); if (size < 0) - fatal_error("error reading from raw file"); + fatal_error("error reading from raw file"); if (fseek(raw, 0L, SEEK_SET) != 0) - fatal_error("error reading from raw file"); - file_write_i32(file, size); // Size of first entry + fatal_error("error reading from raw file"); + file_write_i32(file, size); // Size of first entry memset(name8, '\0', WAD_NAME); strncpy(name8, entryname, WAD_NAME); - file_write_name(file, name8); // Name of first entry + file_write_name(file, name8); // Name of first entry // Write the lump data int r = copy_bytes(file, raw, size); if (r != 0) { - if (r == 1) - err("%s: error reading from source file", entryname); - else if (r == 2) - err("%s: error writing to destination wad", entryname); - else - nf_bug("%s: copy_bytes() returned %d", entryname, r); - return; + if (r == 1) + err("%s: error reading from source file", entryname); + else if (r == 2) + err("%s: error writing to destination wad", entryname); + else + nf_bug("%s: copy_bytes() returned %d", entryname, r); + return; } } /* - * locate_pwad - * Look for a PWAD in the standard directories - * and returns its name in a GetMemory'd buffer - * (or NULL if not found). It's up to the caller - * to free the buffer after use. + * locate_pwad + * Look for a PWAD in the standard directories + * and returns its name in a GetMemory'd buffer + * (or NULL if not found). It's up to the caller + * to free the buffer after use. */ /* Directories that are searched for PWADs */ static const char *standard_directories[] = { "", - "~/", // "~" means "the user's home directory" - "/usr/local/share/games/%s/", // %s is replaced by <Game> - "/usr/share/games/%s/", // %s is replaced by <Game> + "~/", // "~" means "the user's home directory" + "/usr/local/share/games/%s/", // %s is replaced by <Game> + "/usr/share/games/%s/", // %s is replaced by <Game> "/usr/local/share/games/wads/", "/usr/share/games/wads/", 0 @@ -938,49 +938,49 @@ // If it's an absolute name, stop there. if (is_absolute(filename)) { - real_name = (char *) GetMemory(strlen(filename) + 1 + (*ext ? 0 : 4)); - strcpy(real_name, filename); - if (!*ext) - strcat(real_name, ".wad"); - bool r = file_exists(real_name); - if (!r) - { - FreeMemory(real_name); - return 0; - } - return real_name; + real_name = (char *) GetMemory(strlen(filename) + 1 + (*ext ? 0 : 4)); + strcpy(real_name, filename); + if (!*ext) + strcat(real_name, ".wad"); + bool r = file_exists(real_name); + if (!r) + { + FreeMemory(real_name); + return 0; + } + return real_name; } // It's a relative name. If no extension given, append ".wad" real_basename = (char *) GetMemory(strlen(filename) + 1 + (*ext ? 0 : 4)); strcpy(real_basename, filename); if (!*ext) - strcat(real_basename, ".wad"); + strcat(real_basename, ".wad"); // Then search for a file of that name in the standard directories. real_name = (char *) GetMemory(Y_FILE_NAME + 1); for (dirname = standard_directories; *dirname; dirname++) { - if (!strcmp(*dirname, "~/")) - if (getenv("HOME")) - { - al_scps(real_name, getenv("HOME"), Y_FILE_NAME); - al_sapc(real_name, '/', Y_FILE_NAME); - } - else - continue; - else - y_snprintf(real_name, Y_FILE_NAME + 1, *dirname, - Game ? Game : ""); - al_saps(real_name, real_basename, Y_FILE_NAME); - verbmsg(" Trying \"%s\"... ", real_name); - if (file_exists(real_name)) - { - verbmsg("right on !\n"); - FreeMemory(real_basename); - return real_name; - } - verbmsg("nuts\n"); + if (!strcmp(*dirname, "~/")) + if (getenv("HOME")) + { + al_scps(real_name, getenv("HOME"), Y_FILE_NAME); + al_sapc(real_name, '/', Y_FILE_NAME); + } + else + continue; + else + y_snprintf(real_name, Y_FILE_NAME + 1, *dirname, + Game ? Game : ""); + al_saps(real_name, real_basename, Y_FILE_NAME); + verbmsg(" Trying \"%s\"... ", real_name); + if (file_exists(real_name)) + { + verbmsg("right on !\n"); + FreeMemory(real_basename); + return real_name; + } + verbmsg("nuts\n"); } FreeMemory(real_name); FreeMemory(real_basename); diff -r 594dea11ccd9 -r a68786b9c74b src/wads2.h --- a/src/wads2.h Sat Sep 24 15:01:56 2011 +0300 +++ b/src/wads2.h Sat Sep 24 15:59:33 2011 +0300 @@ -1,11 +1,11 @@ -/* - * wads2.h - * Wads functions that are not needed during editing. - * AYM 2000-05-06 +/* + * wads2.h + * Wads functions that are not needed during editing. + * AYM 2000-05-06 */ -#ifndef YH_WADS2 /* DO NOT INSERT ANYTHING BEFORE THIS LINE */ +#ifndef YH_WADS2 /* DO NOT INSERT ANYTHING BEFORE THIS LINE */ #define YH_WADS2 diff -r 594dea11ccd9 -r a68786b9c74b src/warn.cc --- a/src/warn.cc Sat Sep 24 15:01:56 2011 +0300 +++ b/src/warn.cc Sat Sep 24 15:59:33 2011 +0300 @@ -1,6 +1,6 @@ /* - * warn.cc - * AYM 1999-08-15 + * warn.cc + * AYM 1999-08-15 */ @@ -31,10 +31,10 @@ /* - * warn - * printf a warning message to stdout. - * If the format string of the previous invocation did not - * end with a '\n', do not prepend the "Warning: " string. + * warn + * printf a warning message to stdout. + * If the format string of the previous invocation did not + * end with a '\n', do not prepend the "Warning: " string. * */ void warn(const char *fmt, ...) @@ -43,7 +43,7 @@ va_list args; if (start_of_line) - fputs("Warning: ", stdout); + fputs("Warning: ", stdout); va_start(args, fmt); vprintf(fmt, args); size_t len = strlen(fmt); diff -r 594dea11ccd9 -r a68786b9c74b src/windim.cc --- a/src/windim.cc Sat Sep 24 15:01:56 2011 +0300 +++ b/src/windim.cc Sat Sep 24 15:59:33 2011 +0300 @@ -1,7 +1,7 @@ /* - * windim.cc - * Win_dim class - store the width or height of a window - * AYM 2000-05-29 + * windim.cc + * Win_dim class - store the width or height of a window + * AYM 2000-05-29 */ @@ -72,19 +72,19 @@ bool relative = false; if (!isdigit(*string)) - return 1; // Error + return 1; // Error while (isdigit(*string)) { - value = 10 * value + dectoi(*string); - string++; + value = 10 * value + dectoi(*string); + string++; } if (*string == '%') { - relative = true; - string++; + relative = true; + string++; } if (*string != '\0') - return 1; // Error + return 1; // Error p->value = value; p->relative = relative; return 0; @@ -95,9 +95,9 @@ int Win_dim::pixels(int ref_pixels) { if (p->relative) - return ref_pixels * p->value / 100; + return ref_pixels * p->value / 100; else - return p->value; + return p->value; } @@ -105,7 +105,7 @@ void Win_dim::string(char *buf, size_t buf_size) { if (p->relative) - y_snprintf(buf, buf_size, "%d%%", p->value); + y_snprintf(buf, buf_size, "%d%%", p->value); else - y_snprintf(buf, buf_size, "%d", p->value); + y_snprintf(buf, buf_size, "%d", p->value); } diff -r 594dea11ccd9 -r a68786b9c74b src/windim.h --- a/src/windim.h Sat Sep 24 15:01:56 2011 +0300 +++ b/src/windim.h Sat Sep 24 15:59:33 2011 +0300 @@ -1,11 +1,11 @@ /* - * windim.h - * Win_dim class - store the width or height of a window - * AYM 2000-05-29 + * windim.h + * Win_dim class - store the width or height of a window + * AYM 2000-05-29 */ -#ifndef YH_WINDIM /* DO NOT INSERT ANYTHING BEFORE THIS LINE */ +#ifndef YH_WINDIM /* DO NOT INSERT ANYTHING BEFORE THIS LINE */ #define YH_WINDIM @@ -22,8 +22,8 @@ void string(char *buf, size_t buf_size); private: - Win_dim(const Win_dim &); // Too lazy to implement it - Win_dim & operator=(const Win_dim &); // Too lazy to implement it + Win_dim(const Win_dim &); // Too lazy to implement it + Win_dim & operator=(const Win_dim &); // Too lazy to implement it struct Win_dim_priv *p; }; diff -r 594dea11ccd9 -r a68786b9c74b src/wstructs.h --- a/src/wstructs.h Sat Sep 24 15:01:56 2011 +0300 +++ b/src/wstructs.h Sat Sep 24 15:59:33 2011 +0300 @@ -1,10 +1,10 @@ /* - * wstructs.h - * Wad files data structures. - * BW & RQ sometime in 1993 or 1994. - * FIXME this file should also contain the definitions for - * the wad header and directory entry which are currently - * in yadex.h. + * wstructs.h + * Wad files data structures. + * BW & RQ sometime in 1993 or 1994. + * FIXME this file should also contain the definitions for + * the wad header and directory entry which are currently + * in yadex.h. */ @@ -31,22 +31,22 @@ */ -#ifndef YH_WSTRUCTS // To prevent multiple inclusion -#define YH_WSTRUCTS // To prevent multiple inclusion +#ifndef YH_WSTRUCTS // To prevent multiple inclusion +#define YH_WSTRUCTS // To prevent multiple inclusion // FIXME: all identifiers should start with wad_ or WAD_... // Directory -const size_t WAD_NAME = 8; // Length of a directory entry name +const size_t WAD_NAME = 8; // Length of a directory entry name typedef char wad_name_t[WAD_NAME]; typedef struct Directory *DirPtr; struct Directory { - i32 start; // Offset to start of data - i32 size; // Byte size of data - wad_name_t name; // Name of data block + i32 start; // Offset to start of data + i32 size; // Byte size of data + wad_name_t name; // Name of data block }; @@ -66,29 +66,29 @@ // Level objects properties -typedef i16 wad_coord_t; // Map (X,Y) coordinates -typedef i16 wad_ldn_t; // Linedef# -typedef i16 wad_sdn_t; // Sidedef# -typedef i16 wad_sn_t; // Sector# -typedef i16 wad_tag_t; // Tag -typedef i16 wad_tn_t; // Thing# (theor. there might be more) -typedef i16 wad_vn_t; // Vertex# -typedef i16 wad_z_t; // Map Z coordinate +typedef i16 wad_coord_t; // Map (X,Y) coordinates +typedef i16 wad_ldn_t; // Linedef# +typedef i16 wad_sdn_t; // Sidedef# +typedef i16 wad_sn_t; // Sector# +typedef i16 wad_tag_t; // Tag +typedef i16 wad_tn_t; // Thing# (theor. there might be more) +typedef i16 wad_vn_t; // Vertex# +typedef i16 wad_z_t; // Map Z coordinate // Things -const size_t WAD_THING_BYTES = 10; // Size in the wad file -const size_t WAD_HEXEN_THING_BYTES = 20; // Size in the wad file +const size_t WAD_THING_BYTES = 10; // Size in the wad file +const size_t WAD_HEXEN_THING_BYTES = 20; // Size in the wad file typedef i16 wad_ttype_t; typedef i16 wad_tangle_t; typedef i16 wad_tflags_t; struct Thing { - wad_coord_t xpos; // FIXME rename to "x" - wad_coord_t ypos; // FIXME rename to "y" + wad_coord_t xpos; // FIXME rename to "x" + wad_coord_t ypos; // FIXME rename to "y" wad_tangle_t angle; wad_ttype_t type; - wad_tflags_t when; // FIXME rename to "flags" + wad_tflags_t when; // FIXME rename to "flags" }; typedef struct { @@ -110,19 +110,19 @@ // Linedefs -const size_t WAD_LINEDEF_BYTES = 14; // Size in the wad file -const size_t WAD_HEXEN_LINEDEF_BYTES = 16; // Size in the wad file +const size_t WAD_LINEDEF_BYTES = 14; // Size in the wad file +const size_t WAD_HEXEN_LINEDEF_BYTES = 16; // Size in the wad file typedef i16 wad_ldflags_t; typedef i16 wad_ldtype_t; struct LineDef { - wad_vn_t start; // # of start vertex - wad_vn_t end; // # of end vertex + wad_vn_t start; // # of start vertex + wad_vn_t end; // # of end vertex wad_ldflags_t flags; wad_ldtype_t type; wad_tag_t tag; - wad_sdn_t sidedef1; // # of first (right) sidedef - wad_sdn_t sidedef2; // # of second (left) sidedef or 0xffff + wad_sdn_t sidedef1; // # of first (right) sidedef + wad_sdn_t sidedef2; // # of second (left) sidedef or 0xffff }; typedef struct { @@ -142,22 +142,22 @@ // Sidedefs -const size_t WAD_SIDEDEF_BYTES = 30; // Size in the wad file +const size_t WAD_SIDEDEF_BYTES = 30; // Size in the wad file struct SideDef { - wad_coord_t xoff; // FIXME rename to "xofs" - wad_coord_t yoff; // FIXME rename to "yofs" - wad_tex_name_t tex1; // Name of upper texture - wad_tex_name_t tex2; // Name of lower texture - wad_tex_name_t tex3; // Name of middle texture - wad_sn_t sector; // # of adjacent sector + wad_coord_t xoff; // FIXME rename to "xofs" + wad_coord_t yoff; // FIXME rename to "yofs" + wad_tex_name_t tex1; // Name of upper texture + wad_tex_name_t tex2; // Name of lower texture + wad_tex_name_t tex3; // Name of middle texture + wad_sn_t sector; // # of adjacent sector }; // (it's the same for Hexen) typedef struct SideDef *SDPtr; // Vertices -const size_t WAD_VERTEX_BYTES = 4; // Size in the wad file +const size_t WAD_VERTEX_BYTES = 4; // Size in the wad file struct Vertex { wad_coord_t x; @@ -168,16 +168,16 @@ // Sectors -const size_t WAD_SECTOR_BYTES = 26; // Size in the wad file +const size_t WAD_SECTOR_BYTES = 26; // Size in the wad file typedef i16 wad_stype_t; struct Sector { - wad_z_t floorh; // Floor height - wad_z_t ceilh; // Ceiling height - wad_flat_name_t floort; // Name of floor texture - wad_flat_name_t ceilt; // Name of ceiling texture - i16 light; // Light level (0-255) - wad_stype_t special; // FIXME rename to "type" + wad_z_t floorh; // Floor height + wad_z_t ceilh; // Ceiling height + wad_flat_name_t floort; // Name of floor texture + wad_flat_name_t ceilt; // Name of ceiling texture + i16 light; // Light level (0-255) + wad_stype_t special; // FIXME rename to "type" wad_tag_t tag; }; typedef struct Sector *SPtr; diff -r 594dea11ccd9 -r a68786b9c74b src/x11.cc --- a/src/x11.cc Sat Sep 24 15:01:56 2011 +0300 +++ b/src/x11.cc Sat Sep 24 15:59:33 2011 +0300 @@ -1,7 +1,7 @@ /* - * x11.c - * X11-specific stuff - * AYM 1999-08-03 + * x11.c + * X11-specific stuff + * AYM 1999-08-03 */ @@ -41,24 +41,24 @@ /* - * x_bell - * Ring the bell + * x_bell + * Ring the bell */ void x_bell() { if (dpy) - XBell(dpy, 0); + XBell(dpy, 0); else - nf_bug("x_bell: not connected"); + nf_bug("x_bell: not connected"); } /* - * x_catch_on - * Setup things so that from now on, any X protocol errors - * will be handled by x_error_handler instead of the - * default handler (that has the annoying property of - * calling exit()). + * x_catch_on + * Setup things so that from now on, any X protocol errors + * will be handled by x_error_handler instead of the + * default handler (that has the annoying property of + * calling exit()). */ void x_catch_on() { @@ -69,8 +69,8 @@ /* - * x_catch_off - * Restore the default error handler. + * x_catch_off + * Restore the default error handler. */ void x_catch_off() { @@ -80,21 +80,21 @@ /* - * x_error_handler - * An error handler that does not exit. + * x_error_handler + * An error handler that does not exit. */ int x_error_handler(Display * dpy, XErrorEvent * e) { _have_error = true; - _error_code = e->error_code; // We're only interested in the error code + _error_code = e->error_code; // We're only interested in the error code return 0; } /* - * x_clear_error - * Call this before attempting an operation that might - * cause an error that you want to catch. + * x_clear_error + * Call this before attempting an operation that might + * cause an error that you want to catch. */ void x_clear_error() { @@ -103,15 +103,15 @@ /* - * x_error - * Return a string corresponding to the last error caught - * or a NULL pointer if no error has occured since last - * call to x_clear_error(). + * x_error + * Return a string corresponding to the last error caught + * or a NULL pointer if no error has occured since last + * call to x_clear_error(). */ const char *x_error() { if (!_have_error) - return 0; + return 0; static char buf[100]; XGetErrorText(dpy, _error_code, buf, sizeof buf); return buf; diff -r 594dea11ccd9 -r a68786b9c74b src/x11.h --- a/src/x11.h Sat Sep 24 15:01:56 2011 +0300 +++ b/src/x11.h Sat Sep 24 15:59:33 2011 +0300 @@ -1,7 +1,7 @@ /* - * x11.h - * X11-specific functions - * AYM 1999-08-03 + * x11.h + * X11-specific functions + * AYM 1999-08-03 */ diff -r 594dea11ccd9 -r a68786b9c74b src/x_centre.cc --- a/src/x_centre.cc Sat Sep 24 15:01:56 2011 +0300 +++ b/src/x_centre.cc Sat Sep 24 15:59:33 2011 +0300 @@ -1,6 +1,6 @@ /* - * x_centre.cc - * AYM 1998-11-22 + * x_centre.cc + * AYM 1998-11-22 */ @@ -38,27 +38,27 @@ /* - * centre_of_objects - * Return the coordinates of the centre of a group of objects - * of type <obj_type>. + * centre_of_objects + * Return the coordinates of the centre of a group of objects + * of type <obj_type>. */ void centre_of_objects(int obj_type, SelPtr list, int *x, int *y) { switch (obj_type) { case OBJ_LINEDEFS: - centre_of_linedefs(list, x, y); - break; + centre_of_linedefs(list, x, y); + break; case OBJ_SECTORS: - centre_of_sectors(list, x, y); - break; + centre_of_sectors(list, x, y); + break; case OBJ_THINGS: - centre_of_things(list, x, y); - break; + centre_of_things(list, x, y); + break; case OBJ_VERTICES: - centre_of_vertices(list, x, y); - break; + centre_of_vertices(list, x, y); + break; default: - fatal_error("coo: bad obj_type %d", obj_type); + fatal_error("coo: bad obj_type %d", obj_type); } } diff -r 594dea11ccd9 -r a68786b9c74b src/x_centre.h --- a/src/x_centre.h Sat Sep 24 15:01:56 2011 +0300 +++ b/src/x_centre.h Sat Sep 24 15:59:33 2011 +0300 @@ -1,6 +1,6 @@ /* - * x_centre.h - * AYM 1998-11-22 + * x_centre.h + * AYM 1998-11-22 */ diff -r 594dea11ccd9 -r a68786b9c74b src/x_exchng.cc --- a/src/x_exchng.cc Sat Sep 24 15:01:56 2011 +0300 +++ b/src/x_exchng.cc Sat Sep 24 15:59:33 2011 +0300 @@ -1,7 +1,7 @@ /* - * x_exchng.cc - * Exchange objects numbers. - * AYM 1999-06-11 + * x_exchng.cc + * Exchange objects numbers. + * AYM 1999-06-11 */ @@ -36,10 +36,10 @@ /* - * exchange_objects_numbers - * Exchange the numbers of two objects + * exchange_objects_numbers + * Exchange the numbers of two objects * - * Return 0 on success, non-zero on failure. + * Return 0 on success, non-zero on failure. */ int exchange_objects_numbers(int obj_type, SelPtr list, bool adjust) { @@ -48,63 +48,63 @@ // Must have exactly two objects in the selection if (list == 0 || list->next == 0 || (list->next)->next != 0) { - nf_bug("exchange_object_numbers: wrong objects count."); - return 1; + nf_bug("exchange_object_numbers: wrong objects count."); + return 1; } n1 = list->objnum; n2 = (list->next)->objnum; if (obj_type == OBJ_LINEDEFS) { - struct LineDef swap_buf; - swap_buf = LineDefs[n1]; - LineDefs[n1] = LineDefs[n2]; - LineDefs[n2] = swap_buf; + struct LineDef swap_buf; + swap_buf = LineDefs[n1]; + LineDefs[n1] = LineDefs[n2]; + LineDefs[n2] = swap_buf; } else if (obj_type == OBJ_SECTORS) { - struct Sector swap_buf; - swap_buf = Sectors[n1]; - Sectors[n1] = Sectors[n2]; - Sectors[n2] = swap_buf; - if (adjust) - { - for (int n = 0; n < NumSideDefs; n++) - { - if (SideDefs[n].sector == n1) - SideDefs[n].sector = n2; - else if (SideDefs[n].sector == n2) - SideDefs[n].sector = n1; - } - } + struct Sector swap_buf; + swap_buf = Sectors[n1]; + Sectors[n1] = Sectors[n2]; + Sectors[n2] = swap_buf; + if (adjust) + { + for (int n = 0; n < NumSideDefs; n++) + { + if (SideDefs[n].sector == n1) + SideDefs[n].sector = n2; + else if (SideDefs[n].sector == n2) + SideDefs[n].sector = n1; + } + } } else if (obj_type == OBJ_THINGS) { - struct Thing swap_buf; - swap_buf = Things[n1]; - Things[n1] = Things[n2]; - Things[n2] = swap_buf; + struct Thing swap_buf; + swap_buf = Things[n1]; + Things[n1] = Things[n2]; + Things[n2] = swap_buf; } else if (obj_type == OBJ_VERTICES) { - struct Vertex swap_buf; - swap_buf = Vertices[n1]; - Vertices[n1] = Vertices[n2]; - Vertices[n2] = swap_buf; - if (adjust) - { - for (int n = 0; n < NumLineDefs; n++) - { - if (LineDefs[n].start == n1) - LineDefs[n].start = n2; - else if (LineDefs[n].start == n2) - LineDefs[n].start = n1; - if (LineDefs[n].end == n1) - LineDefs[n].end = n2; - else if (LineDefs[n].end == n2) - LineDefs[n].end = n1; - } - } + struct Vertex swap_buf; + swap_buf = Vertices[n1]; + Vertices[n1] = Vertices[n2]; + Vertices[n2] = swap_buf; + if (adjust) + { + for (int n = 0; n < NumLineDefs; n++) + { + if (LineDefs[n].start == n1) + LineDefs[n].start = n2; + else if (LineDefs[n].start == n2) + LineDefs[n].start = n1; + if (LineDefs[n].end == n1) + LineDefs[n].end = n2; + else if (LineDefs[n].end == n2) + LineDefs[n].end = n1; + } + } } return 0; } diff -r 594dea11ccd9 -r a68786b9c74b src/x_exchng.h --- a/src/x_exchng.h Sat Sep 24 15:01:56 2011 +0300 +++ b/src/x_exchng.h Sat Sep 24 15:59:33 2011 +0300 @@ -1,6 +1,6 @@ /* - * x_exchng.h - * AYM 1999-06-11 + * x_exchng.h + * AYM 1999-06-11 */ diff -r 594dea11ccd9 -r a68786b9c74b src/x_hover.cc --- a/src/x_hover.cc Sat Sep 24 15:01:56 2011 +0300 +++ b/src/x_hover.cc Sat Sep 24 15:59:33 2011 +0300 @@ -1,6 +1,6 @@ /* - * x_hover.cc - * AYM 2000-11-08 + * x_hover.cc + * AYM 2000-11-08 */ @@ -41,45 +41,45 @@ { public:Close_obj() { - nil(); + nil(); } void nil() { - obj.nil(); - distance = ULONG_MAX; - radius = INT_MAX; - inside = false; + obj.nil(); + distance = ULONG_MAX; + radius = INT_MAX; + inside = false; } bool operator==(const Close_obj & other) const { - if (inside == other.inside - && radius == other.radius && distance == other.distance) - return true; - return false; + if (inside == other.inside + && radius == other.radius && distance == other.distance) + return true; + return false; } bool operator<(const Close_obj & other) const { - if (inside && !other.inside) - return true; - if (!inside && other.inside) - return false; + if (inside && !other.inside) + return true; + if (!inside && other.inside) + return false; - // Small objects should "mask" large objects - if (radius < other.radius) - return true; - if (radius > other.radius) - return false; + // Small objects should "mask" large objects + if (radius < other.radius) + return true; + if (radius > other.radius) + return false; - if (distance < other.distance) - return true; - if (distance > other.distance) - return false; + if (distance < other.distance) + return true; + if (distance > other.distance) + return false; - return radius < other.radius; + return radius < other.radius; } bool operator<=(const Close_obj & other) const { - return *this == other || *this < other; + return *this == other || *this < other; } Objid obj; double distance; @@ -95,72 +95,72 @@ /* - * GetCurObject - determine which object is under the pointer + * GetCurObject - determine which object is under the pointer * - * Set <o> to point to the object under the pointer (map - * coordinates (<x>, <y>). If several objects are close - * enough to the pointer, the smallest object is chosen. + * Set <o> to point to the object under the pointer (map + * coordinates (<x>, <y>). If several objects are close + * enough to the pointer, the smallest object is chosen. */ void GetCurObject(Objid & o, int objtype, int x, int y) { switch (objtype) { case OBJ_THINGS: - { - o = get_cur_thing(x, y).obj; - return; - } + { + o = get_cur_thing(x, y).obj; + return; + } case OBJ_VERTICES: - { - o = get_cur_vertex(x, y).obj; - return; - } + { + o = get_cur_vertex(x, y).obj; + return; + } case OBJ_LINEDEFS: - { - o = get_cur_linedef(x, y).obj; - return; - } + { + o = get_cur_linedef(x, y).obj; + return; + } case OBJ_SECTORS: - { - o = get_cur_sector(x, y).obj; - return; - } + { + o = get_cur_sector(x, y).obj; + return; + } case OBJ_ANY: - { - std::vector < Close_obj > v; - v.push_back(get_cur_linedef(x, y)); - v.push_back(get_cur_thing(x, y)); - v.push_back(get_cur_vertex(x, y)); - sort(v.begin(), v.end()); - if (v[0].obj()) - { - o = v[0].obj; - return; - } - o = get_cur_sector(x, y).obj; - return; - } + { + std::vector < Close_obj > v; + v.push_back(get_cur_linedef(x, y)); + v.push_back(get_cur_thing(x, y)); + v.push_back(get_cur_vertex(x, y)); + sort(v.begin(), v.end()); + if (v[0].obj()) + { + o = v[0].obj; + return; + } + o = get_cur_sector(x, y).obj; + return; + } default: - nf_bug("GetCurObject: objtype %d", (int) objtype); - o.nil(); - return; + nf_bug("GetCurObject: objtype %d", (int) objtype); + o.nil(); + return; } } /* - * get_cur_linedef - determine which linedef is under the pointer + * get_cur_linedef - determine which linedef is under the pointer */ static const Close_obj & get_cur_linedef(int x, int y) { static Close_obj object; - const int screenslack = 15; // Slack in pixels - double mapslack = fabs(screenslack / Scale); // Slack in map units + const int screenslack = 15; // Slack in pixels + double mapslack = fabs(screenslack / Scale); // Slack in map units int xmin = (int) (x - mapslack + 0.5); int xmax = (int) (x + mapslack + 0.5); int ymin = (int) (y - mapslack + 0.5); @@ -168,81 +168,81 @@ object.nil(); for (int n = 0; n < NumLineDefs; n++) { - int x0 = Vertices[LineDefs[n].start].x; - int y0 = Vertices[LineDefs[n].start].y; - int x1 = Vertices[LineDefs[n].end].x; - int y1 = Vertices[LineDefs[n].end].y; - int dx; - int dy; + int x0 = Vertices[LineDefs[n].start].x; + int y0 = Vertices[LineDefs[n].start].y; + int x1 = Vertices[LineDefs[n].end].x; + int y1 = Vertices[LineDefs[n].end].y; + int dx; + int dy; - /* Skip all lines of which all points are more than <mapslack> - units away from (x,y). In a typical level, this test will - filter out all the linedefs but a handful. */ - if (x0 < xmin && x1 < xmin - || x0 > xmax && x1 > xmax - || y0 < ymin && y1 < ymin || y0 > ymax && y1 > ymax) - continue; + /* Skip all lines of which all points are more than <mapslack> + units away from (x,y). In a typical level, this test will + filter out all the linedefs but a handful. */ + if (x0 < xmin && x1 < xmin + || x0 > xmax && x1 > xmax + || y0 < ymin && y1 < ymin || y0 > ymax && y1 > ymax) + continue; - /* This is where it gets ugly. We're trying to calculate the - distance between the pointer (x,y) and the linedef. Doing that - rigorously involves doing an orthogonal projection. I use - something simpler (for me). + /* This is where it gets ugly. We're trying to calculate the + distance between the pointer (x,y) and the linedef. Doing that + rigorously involves doing an orthogonal projection. I use + something simpler (for me). - If the pointer is not within the ends of the linedef, I calculate - the distance between the pointer and the closest end. + If the pointer is not within the ends of the linedef, I calculate + the distance between the pointer and the closest end. - If the pointer is within the ends of the linedef, I calculate - what the ordinate would be for a point of the linedef that had - the same abscissa as the pointer. Then I calculate the difference - between that and the actual ordinate of the pointer and I call - that the distance. It's a gross approximation but, in practice, - it gives quite satisfactory results. Of course, for lines where - dy > dx, the abscissa is y and the ordinate is x. - -- AYM 1998-06-29 */ - dx = x1 - x0; - dy = y1 - y0; - double dist = ULONG_MAX; - // The linedef is rather horizontal - if (abs(dx) > abs(dy)) - { - /* Are we to the left of the leftmost end or to the right of the - rightmost end or between the two ? */ - if (x < (dx > 0 ? x0 : x1)) - dist = hypot(x - (dx > 0 ? x0 : x1), y - (dx > 0 ? y0 : y1)); - else if (x > (dx > 0 ? x1 : x0)) - dist = hypot(x - (dx > 0 ? x1 : x0), y - (dx > 0 ? y1 : y0)); - else - dist = fabs(y0 + ((double) dy) / dx * (x - x0) - y); - } - // The linedef is rather vertical - else - { - /* Are we above the high end or below the low end or in between ? */ - if (y < (dy > 0 ? y0 : y1)) - dist = hypot(x - (dy > 0 ? x0 : x1), y - (dy > 0 ? y0 : y1)); - else if (y > (dy > 0 ? y1 : y0)) - dist = hypot(x - (dy > 0 ? x1 : x0), y - (dy > 0 ? y1 : y0)); - else - dist = fabs(x0 + ((double) dx) / dy * (y - y0) - x); - } - if (dist <= object.distance /* "<=" because if there are superimposed - linedefs, we want to return the - highest-numbered one. */ - && dist <= mapslack) - { - object.obj.type = OBJ_LINEDEFS; - object.obj.num = n; - object.distance = dist; - object.radius = (int) (hypot(dx, dy) / 2); - object.inside = dist < 2 * Scale; - } + If the pointer is within the ends of the linedef, I calculate + what the ordinate would be for a point of the linedef that had + the same abscissa as the pointer. Then I calculate the difference + between that and the actual ordinate of the pointer and I call + that the distance. It's a gross approximation but, in practice, + it gives quite satisfactory results. Of course, for lines where + dy > dx, the abscissa is y and the ordinate is x. + -- AYM 1998-06-29 */ + dx = x1 - x0; + dy = y1 - y0; + double dist = ULONG_MAX; + // The linedef is rather horizontal + if (abs(dx) > abs(dy)) + { + /* Are we to the left of the leftmost end or to the right of the + rightmost end or between the two ? */ + if (x < (dx > 0 ? x0 : x1)) + dist = hypot(x - (dx > 0 ? x0 : x1), y - (dx > 0 ? y0 : y1)); + else if (x > (dx > 0 ? x1 : x0)) + dist = hypot(x - (dx > 0 ? x1 : x0), y - (dx > 0 ? y1 : y0)); + else + dist = fabs(y0 + ((double) dy) / dx * (x - x0) - y); + } + // The linedef is rather vertical + else + { + /* Are we above the high end or below the low end or in between ? */ + if (y < (dy > 0 ? y0 : y1)) + dist = hypot(x - (dy > 0 ? x0 : x1), y - (dy > 0 ? y0 : y1)); + else if (y > (dy > 0 ? y1 : y0)) + dist = hypot(x - (dy > 0 ? x1 : x0), y - (dy > 0 ? y1 : y0)); + else + dist = fabs(x0 + ((double) dx) / dy * (y - y0) - x); + } + if (dist <= object.distance /* "<=" because if there are superimposed + linedefs, we want to return the + highest-numbered one. */ + && dist <= mapslack) + { + object.obj.type = OBJ_LINEDEFS; + object.obj.num = n; + object.distance = dist; + object.radius = (int) (hypot(dx, dy) / 2); + object.inside = dist < 2 * Scale; + } } return object; } /* - * get_cur_sector - determine which sector is under the pointer + * get_cur_sector - determine which sector is under the pointer */ static const Close_obj & get_cur_sector(int x, int y) { @@ -262,42 +262,42 @@ and SaveLevelData() refreshed it.) -- AYM 1999-03-18 */ static Close_obj object; int best_match = -1; - int curx = 32767; // Oh yes, one more hard-coded constant! + int curx = 32767; // Oh yes, one more hard-coded constant! for (int n = 0; n < NumLineDefs; n++) - if ((Vertices[LineDefs[n].start].y > y) - != (Vertices[LineDefs[n].end].y > y)) - { - int lx0 = Vertices[LineDefs[n].start].x; - int ly0 = Vertices[LineDefs[n].start].y; - int lx1 = Vertices[LineDefs[n].end].x; - int ly1 = Vertices[LineDefs[n].end].y; - int m = lx0 + (int) ((long) (y - ly0) * (long) (lx1 - lx0) - / (long) (ly1 - ly0)); - if (m >= x && m < curx) - { - curx = m; - best_match = n; - } - } + if ((Vertices[LineDefs[n].start].y > y) + != (Vertices[LineDefs[n].end].y > y)) + { + int lx0 = Vertices[LineDefs[n].start].x; + int ly0 = Vertices[LineDefs[n].start].y; + int lx1 = Vertices[LineDefs[n].end].x; + int ly1 = Vertices[LineDefs[n].end].y; + int m = lx0 + (int) ((long) (y - ly0) * (long) (lx1 - lx0) + / (long) (ly1 - ly0)); + if (m >= x && m < curx) + { + curx = m; + best_match = n; + } + } // Now look if this linedef has a sidedef bound to one sector object.nil(); if (best_match >= 0) { - if (Vertices[LineDefs[best_match].start].y - > Vertices[LineDefs[best_match].end].y) - best_match = LineDefs[best_match].sidedef1; - else - best_match = LineDefs[best_match].sidedef2; - if (best_match >= 0) - { - object.obj.type = OBJ_SECTORS; - object.obj.num = SideDefs[best_match].sector; - object.distance = 0; // Not meaningful for sectors - object.radius = 1; // Not meaningful for sectors - object.inside = true; // Not meaningful for sectors - } - else; + if (Vertices[LineDefs[best_match].start].y + > Vertices[LineDefs[best_match].end].y) + best_match = LineDefs[best_match].sidedef1; + else + best_match = LineDefs[best_match].sidedef2; + if (best_match >= 0) + { + object.obj.type = OBJ_SECTORS; + object.obj.num = SideDefs[best_match].sector; + object.distance = 0; // Not meaningful for sectors + object.radius = 1; // Not meaningful for sectors + object.inside = true; // Not meaningful for sectors + } + else; } else; return object; @@ -305,13 +305,13 @@ /* - * get_cur_thing - determine which thing is under the pointer + * get_cur_thing - determine which thing is under the pointer */ static const Close_obj & get_cur_thing(int x, int y) { static Close_obj closest; - const int screenslack = 15; // Slack in pixels - double mapslack = fabs(screenslack / Scale); // Slack in map units + const int screenslack = 15; // Slack in pixels + double mapslack = fabs(screenslack / Scale); // Slack in map units int max_radius = (int) (get_max_thing_radius() + mapslack); int xmin = x - max_radius; int xmax = x + max_radius; @@ -321,49 +321,49 @@ closest.nil(); for (int n = 0; n < NumThings; n++) { - // Filter out things that are farther than <max_radius> units away. - if (Things[n].xpos < xmin - || Things[n].xpos > xmax - || Things[n].ypos < ymin || Things[n].ypos > ymax) - continue; + // Filter out things that are farther than <max_radius> units away. + if (Things[n].xpos < xmin + || Things[n].xpos > xmax + || Things[n].ypos < ymin || Things[n].ypos > ymax) + continue; - // So how far is that thing exactly ? + // So how far is that thing exactly ? #ifdef ROUND_THINGS - double dist = hypot(x - Things[n].xpos, y - Things[n].ypos); - if (dist < closest.distance - && dist <= get_thing_radius(Things[n].type) + mapslack) - { - closest.obj.type = OBJ_THINGS; - closest.obj.num = n; - closest.distance = dist; - closest.radius = get_thing_radius(Things[n].type); - closest.inside = dist < closest.radius; - } + double dist = hypot(x - Things[n].xpos, y - Things[n].ypos); + if (dist < closest.distance + && dist <= get_thing_radius(Things[n].type) + mapslack) + { + closest.obj.type = OBJ_THINGS; + closest.obj.num = n; + closest.distance = dist; + closest.radius = get_thing_radius(Things[n].type); + closest.inside = dist < closest.radius; + } #else - { - int thing_radius = - (int) (get_thing_radius(Things[n].type) + mapslack); - if (x > Things[n].xpos - thing_radius - && x < Things[n].xpos + thing_radius - && y > Things[n].ypos - thing_radius - && y < Things[n].ypos + thing_radius) - { - Close_obj current; - current.obj.type = OBJ_THINGS; - current.obj.num = n; - current.distance = - hypot(x - Things[n].xpos, y - Things[n].ypos); - current.radius = get_thing_radius(Things[n].type); - current.inside = x > Things[n].xpos - current.radius - && x < Things[n].xpos + current.radius - && y > Things[n].ypos - current.radius - && y < Things[n].ypos + current.radius; - if (current <= closest) /* "<=" because if there are superimposed - things, we want to return the - highest-numbered one. */ - closest = current; - } - } + { + int thing_radius = + (int) (get_thing_radius(Things[n].type) + mapslack); + if (x > Things[n].xpos - thing_radius + && x < Things[n].xpos + thing_radius + && y > Things[n].ypos - thing_radius + && y < Things[n].ypos + thing_radius) + { + Close_obj current; + current.obj.type = OBJ_THINGS; + current.obj.num = n; + current.distance = + hypot(x - Things[n].xpos, y - Things[n].ypos); + current.radius = get_thing_radius(Things[n].type); + current.inside = x > Things[n].xpos - current.radius + && x < Things[n].xpos + current.radius + && y > Things[n].ypos - current.radius + && y < Things[n].ypos + current.radius; + if (current <= closest) /* "<=" because if there are superimposed + things, we want to return the + highest-numbered one. */ + closest = current; + } + } #endif } return closest; @@ -371,15 +371,15 @@ /* - * get_cur_vertex - determine which vertex is under the pointer + * get_cur_vertex - determine which vertex is under the pointer */ static const Close_obj & get_cur_vertex(int x, int y) { static Close_obj object; - const int screenradius = vertex_radius(Scale); // Radius in pixels - const int screenslack = screenradius + 15; // Slack in pixels - double mapslack = fabs(screenslack / Scale); // Slack in map units - const int mapradius = (int) (screenradius / Scale); // Radius in map units + const int screenradius = vertex_radius(Scale); // Radius in pixels + const int screenslack = screenradius + 15; // Slack in pixels + double mapslack = fabs(screenslack / Scale); // Slack in map units + const int mapradius = (int) (screenradius / Scale); // Radius in map units int xmin = (int) (x - mapslack + 0.5); int xmax = (int) (x + mapslack + 0.5); int ymin = (int) (y - mapslack + 0.5); @@ -388,26 +388,26 @@ object.nil(); for (int n = 0; n < NumVertices; n++) { - /* Filter out objects that are farther than <radius> units away. */ - if (Vertices[n].x < xmin - || Vertices[n].x > xmax - || Vertices[n].y < ymin || Vertices[n].y > ymax) - continue; - double dist = hypot(x - Vertices[n].x, y - Vertices[n].y); - if (dist <= object.distance /* "<=" because if there are superimposed - vertices, we want to return the - highest-numbered one. */ - && dist <= mapslack) - { - object.obj.type = OBJ_VERTICES; - object.obj.num = n; - object.distance = dist; - object.radius = mapradius; - object.inside = x > Vertices[n].x - mapradius - && x < Vertices[n].x + mapradius - && y > Vertices[n].y - mapradius - && y < Vertices[n].y + mapradius; - } + /* Filter out objects that are farther than <radius> units away. */ + if (Vertices[n].x < xmin + || Vertices[n].x > xmax + || Vertices[n].y < ymin || Vertices[n].y > ymax) + continue; + double dist = hypot(x - Vertices[n].x, y - Vertices[n].y); + if (dist <= object.distance /* "<=" because if there are superimposed + vertices, we want to return the + highest-numbered one. */ + && dist <= mapslack) + { + object.obj.type = OBJ_VERTICES; + object.obj.num = n; + object.distance = dist; + object.radius = mapradius; + object.inside = x > Vertices[n].x - mapradius + && x < Vertices[n].x + mapradius + && y > Vertices[n].y - mapradius + && y < Vertices[n].y + mapradius; + } } return object; } diff -r 594dea11ccd9 -r a68786b9c74b src/x_hover.h --- a/src/x_hover.h Sat Sep 24 15:01:56 2011 +0300 +++ b/src/x_hover.h Sat Sep 24 15:59:33 2011 +0300 @@ -1,10 +1,10 @@ /* - * x_hover.h - * AYM 2000-11-08 + * x_hover.h + * AYM 2000-11-08 */ -#ifndef YH_X_HOVER /* DO NOT INSERT ANYTHING BEFORE THIS LINE */ +#ifndef YH_X_HOVER /* DO NOT INSERT ANYTHING BEFORE THIS LINE */ #define YH_X_HOVER diff -r 594dea11ccd9 -r a68786b9c74b src/x_mirror.cc --- a/src/x_mirror.cc Sat Sep 24 15:01:56 2011 +0300 +++ b/src/x_mirror.cc Sat Sep 24 15:59:33 2011 +0300 @@ -1,7 +1,7 @@ /* - * x_mirror.cc - * Flip or mirror objects - * AYM 1999-05-01 + * x_mirror.cc + * Flip or mirror objects + * AYM 1999-05-01 */ @@ -41,15 +41,15 @@ /* - * flip_mirror - * All objects of type <obj_type> in list <list> are - * flipped (if <flags> is equal to 'f') or mirrored (if - * <flags> is equal to 'm') around their geometric centre. + * flip_mirror + * All objects of type <obj_type> in list <list> are + * flipped (if <flags> is equal to 'f') or mirrored (if + * <flags> is equal to 'm') around their geometric centre. * - * In addition of being moved, things have their angle - * changed so as to remain consistent with their - * environment (E.G. when mirroring or flipping the level - * too). + * In addition of being moved, things have their angle + * changed so as to remain consistent with their + * environment (E.G. when mirroring or flipping the level + * too). */ void flip_mirror(SelPtr list, int obj_type, char op) { @@ -57,120 +57,120 @@ { flip, mirror } operation; if (op == 'f') - operation = flip; + operation = flip; else if (op == 'm') - operation = mirror; + operation = mirror; else { - nf_bug("flip_mirror: Bad operation %02Xh", op); - return; + nf_bug("flip_mirror: Bad operation %02Xh", op); + return; } if (!list) - return; + return; /* Vertices, linedefs and sectors: flip/mirror the vertices. */ if (obj_type == OBJ_VERTICES - || obj_type == OBJ_LINEDEFS || obj_type == OBJ_SECTORS) + || obj_type == OBJ_LINEDEFS || obj_type == OBJ_SECTORS) { - // Get the list of vertices to flip/mirror. - bitvec_c *vert; - if (obj_type == OBJ_LINEDEFS) - vert = bv_vertices_of_linedefs(list); - else if (obj_type == OBJ_SECTORS) - vert = bv_vertices_of_sectors(list); - else - vert = list_to_bitvec(list, NumVertices); + // Get the list of vertices to flip/mirror. + bitvec_c *vert; + if (obj_type == OBJ_LINEDEFS) + vert = bv_vertices_of_linedefs(list); + else if (obj_type == OBJ_SECTORS) + vert = bv_vertices_of_sectors(list); + else + vert = list_to_bitvec(list, NumVertices); - /* Determine the geometric centre - of that set of vertices. */ - int xref, yref; - centre_of_vertices(*vert, xref, yref); - xref *= 2; - yref *= 2; + /* Determine the geometric centre + of that set of vertices. */ + int xref, yref; + centre_of_vertices(*vert, xref, yref); + xref *= 2; + yref *= 2; - /* Change the coordinates of the - vertices. */ - if (operation == flip) - { - int n; - VPtr v; - for (n = 0, v = Vertices; n < NumVertices; n++, v++) - if (vert->get(n)) - v->y = yref - v->y; - } - else if (operation == mirror) - { - int n; - VPtr v; - for (n = 0, v = Vertices; n < NumVertices; n++, v++) - if (vert->get(n)) - v->x = xref - v->x; - } + /* Change the coordinates of the + vertices. */ + if (operation == flip) + { + int n; + VPtr v; + for (n = 0, v = Vertices; n < NumVertices; n++, v++) + if (vert->get(n)) + v->y = yref - v->y; + } + else if (operation == mirror) + { + int n; + VPtr v; + for (n = 0, v = Vertices; n < NumVertices; n++, v++) + if (vert->get(n)) + v->x = xref - v->x; + } - /* Flip all the linedefs between the - flipped/mirrored vertices by swapping - their start and end vertices. */ - { - int n; - LDPtr l; - for (n = 0, l = LineDefs; n < NumLineDefs; n++, l++) - if (vert->get(l->start) && vert->get(l->end)) - { - int w = l->start; - l->start = l->end; - l->end = w; - MadeMapChanges = 1; - } - } + /* Flip all the linedefs between the + flipped/mirrored vertices by swapping + their start and end vertices. */ + { + int n; + LDPtr l; + for (n = 0, l = LineDefs; n < NumLineDefs; n++, l++) + if (vert->get(l->start) && vert->get(l->end)) + { + int w = l->start; + l->start = l->end; + l->end = w; + MadeMapChanges = 1; + } + } - delete vert; + delete vert; } /* Things: flip/mirror the things. */ else if (obj_type == OBJ_THINGS) { - /* Determine the geometric centre - of that set of things. */ - int xref, yref; - centre_of_things(list, &xref, &yref); - xref *= 2; - yref *= 2; + /* Determine the geometric centre + of that set of things. */ + int xref, yref; + centre_of_things(list, &xref, &yref); + xref *= 2; + yref *= 2; - /* Change the coordinates of the - things and adjust the angles. */ - if (operation == flip) - { - if (list) - { - things_angles++; - MadeChanges = 1; - } - for (SelPtr cur = list; cur; cur = cur->next) - { - TPtr t = Things + cur->objnum; - t->ypos = yref - t->ypos; - if (t->angle != 0) - t->angle = 360 - t->angle; - } - } - else if (operation == mirror) - { - if (list) - { - things_angles++; - MadeChanges = 1; - } - for (SelPtr cur = list; cur; cur = cur->next) - { - TPtr t = Things + cur->objnum; - t->xpos = xref - t->xpos; - if (t->angle > 180) - t->angle = 540 - t->angle; - else - t->angle = 180 - t->angle; - } - } + /* Change the coordinates of the + things and adjust the angles. */ + if (operation == flip) + { + if (list) + { + things_angles++; + MadeChanges = 1; + } + for (SelPtr cur = list; cur; cur = cur->next) + { + TPtr t = Things + cur->objnum; + t->ypos = yref - t->ypos; + if (t->angle != 0) + t->angle = 360 - t->angle; + } + } + else if (operation == mirror) + { + if (list) + { + things_angles++; + MadeChanges = 1; + } + for (SelPtr cur = list; cur; cur = cur->next) + { + TPtr t = Things + cur->objnum; + t->xpos = xref - t->xpos; + if (t->angle > 180) + t->angle = 540 - t->angle; + else + t->angle = 180 - t->angle; + } + } } } diff -r 594dea11ccd9 -r a68786b9c74b src/x_mirror.h --- a/src/x_mirror.h Sat Sep 24 15:01:56 2011 +0300 +++ b/src/x_mirror.h Sat Sep 24 15:59:33 2011 +0300 @@ -1,7 +1,7 @@ /* - * x_mirror.h - * Flip or mirror objects - * AYM 1999-05-01 + * x_mirror.h + * Flip or mirror objects + * AYM 1999-05-01 */ diff -r 594dea11ccd9 -r a68786b9c74b src/x_rotate.cc --- a/src/x_rotate.cc Sat Sep 24 15:01:56 2011 +0300 +++ b/src/x_rotate.cc Sat Sep 24 15:59:33 2011 +0300 @@ -1,7 +1,7 @@ /* - * x_rotate.cc - * Rotate and scale a group of objects - * AYM 1998-02-07 + * x_rotate.cc + * Rotate and scale a group of objects + * AYM 1998-02-07 */ @@ -61,54 +61,54 @@ rotate and scale a group of objects around the centre of gravity */ -void RotateAndScaleObjects(int objtype, SelPtr obj, double angle, double scale) /* SWAP! */ +void RotateAndScaleObjects(int objtype, SelPtr obj, double angle, double scale) /* SWAP! */ { int dx, dy; int centerx, centery; SelPtr cur, vertices; if (obj == NULL) - return; + return; switch (objtype) { case OBJ_THINGS: - centre_of_things(obj, ¢erx, ¢ery); - for (cur = obj; cur; cur = cur->next) - { - dx = Things[cur->objnum].xpos - centerx; - dy = Things[cur->objnum].ypos - centery; - RotateAndScaleCoords(&dx, &dy, angle, scale); - Things[cur->objnum].xpos = centerx + dx; - Things[cur->objnum].ypos = centery + dy; - } - MadeChanges = 1; - break; + centre_of_things(obj, ¢erx, ¢ery); + for (cur = obj; cur; cur = cur->next) + { + dx = Things[cur->objnum].xpos - centerx; + dy = Things[cur->objnum].ypos - centery; + RotateAndScaleCoords(&dx, &dy, angle, scale); + Things[cur->objnum].xpos = centerx + dx; + Things[cur->objnum].ypos = centery + dy; + } + MadeChanges = 1; + break; case OBJ_VERTICES: - centre_of_vertices(obj, ¢erx, ¢ery); - for (cur = obj; cur; cur = cur->next) - { - dx = Vertices[cur->objnum].x - centerx; - dy = Vertices[cur->objnum].y - centery; - RotateAndScaleCoords(&dx, &dy, angle, scale); - Vertices[cur->objnum].x = (centerx + dx + /*4 */ 2) & ~ /*7 */ 3; - Vertices[cur->objnum].y = (centery + dy + /*4 */ 2) & ~ /*7 */ 3; - } - MadeChanges = 1; - MadeMapChanges = 1; - break; + centre_of_vertices(obj, ¢erx, ¢ery); + for (cur = obj; cur; cur = cur->next) + { + dx = Vertices[cur->objnum].x - centerx; + dy = Vertices[cur->objnum].y - centery; + RotateAndScaleCoords(&dx, &dy, angle, scale); + Vertices[cur->objnum].x = (centerx + dx + /*4 */ 2) & ~ /*7 */ 3; + Vertices[cur->objnum].y = (centery + dy + /*4 */ 2) & ~ /*7 */ 3; + } + MadeChanges = 1; + MadeMapChanges = 1; + break; case OBJ_LINEDEFS: - vertices = list_vertices_of_linedefs(obj); - RotateAndScaleObjects(OBJ_VERTICES, vertices, angle, scale); - ForgetSelection(&vertices); - break; + vertices = list_vertices_of_linedefs(obj); + RotateAndScaleObjects(OBJ_VERTICES, vertices, angle, scale); + ForgetSelection(&vertices); + break; case OBJ_SECTORS: - vertices = list_vertices_of_sectors(obj); - RotateAndScaleObjects(OBJ_VERTICES, vertices, angle, scale); - ForgetSelection(&vertices); - break; + vertices = list_vertices_of_sectors(obj); + RotateAndScaleObjects(OBJ_VERTICES, vertices, angle, scale); + ForgetSelection(&vertices); + break; } } diff -r 594dea11ccd9 -r a68786b9c74b src/x_rotate.h --- a/src/x_rotate.h Sat Sep 24 15:01:56 2011 +0300 +++ b/src/x_rotate.h Sat Sep 24 15:59:33 2011 +0300 @@ -1,6 +1,6 @@ /* - * x_rotate.h - * AYM 1998-11-22 + * x_rotate.h + * AYM 1998-11-22 */ diff -r 594dea11ccd9 -r a68786b9c74b src/xref.cc --- a/src/xref.cc Sat Sep 24 15:01:56 2011 +0300 +++ b/src/xref.cc Sat Sep 24 15:59:33 2011 +0300 @@ -1,8 +1,8 @@ /* - * xref.cc - * Cross reference stuff (who references who ?) - * and miscellaneous test/debug/exploration funcs. - * AYM 1999-03-31 + * xref.cc + * Cross reference stuff (who references who ?) + * and miscellaneous test/debug/exploration funcs. + * AYM 1999-03-31 */ @@ -43,16 +43,16 @@ int count = 0; for (int n = 0; n < NumLineDefs; n++) { - if (LineDefs[n].sidedef1 == sidedef_no) - { - printf(" %dR", n); - count++; - } - if (LineDefs[n].sidedef2 == sidedef_no) - { - printf(" %dL", n); - count++; - } + if (LineDefs[n].sidedef1 == sidedef_no) + { + printf(" %dR", n); + count++; + } + if (LineDefs[n].sidedef2 == sidedef_no) + { + printf(" %dL", n); + count++; + } } printf(" (total %d linedefs)\n", count); } @@ -63,11 +63,11 @@ printf("Secret sectors:"); int count = 0; for (int n = 0; n < NumSectors; n++) - if (Sectors[n].special == 9) // FIXME hard-coded - { - printf(" %d", n); - count++; - } + if (Sectors[n].special == 9) // FIXME hard-coded + { + printf(" %d", n); + count++; + } printf(" (total %d)\n", count); } @@ -76,8 +76,8 @@ void unknown_linedef_type(SelPtr * list) { for (int n = 0; n < NumLineDefs; n++) - if (*GetLineDefTypeName(LineDefs[n].type) == '?') - SelectObject(list, n); + if (*GetLineDefTypeName(LineDefs[n].type) == '?') + SelectObject(list, n); } @@ -85,19 +85,19 @@ { for (int n = 0; n < NumLineDefs; n++) { - int s1 = LineDefs[n].sidedef1; - int s2 = LineDefs[n].sidedef2; - if (s1 >= 0 && s1 < NumSideDefs - && SideDefs[s1].sector < 0 || SideDefs[s1].sector >= NumSectors - || s2 >= 0 && s2 < NumSideDefs - && SideDefs[s2].sector < 0 || SideDefs[s2].sector >= NumSectors) - SelectObject(list, n); + int s1 = LineDefs[n].sidedef1; + int s2 = LineDefs[n].sidedef2; + if (s1 >= 0 && s1 < NumSideDefs + && SideDefs[s1].sector < 0 || SideDefs[s1].sector >= NumSectors + || s2 >= 0 && s2 < NumSideDefs + && SideDefs[s2].sector < 0 || SideDefs[s2].sector >= NumSectors) + SelectObject(list, n); } } /* - * A stopgap to please IvL + * A stopgap to please IvL */ void list_tagged_sectors(int tag) { @@ -105,17 +105,17 @@ int count = 0; for (int n = 0; n < NumSectors; n++) - if (Sectors[n].tag == tag) - { - printf(" %d", n); - count++; - } + if (Sectors[n].tag == tag) + { + printf(" %d", n); + count++; + } printf(" (total %d)\n", count); } /* - * A stopgap to please IvL + * A stopgap to please IvL */ void list_tagged_linedefs(int tag) { @@ -123,10 +123,10 @@ int count = 0; for (int n = 0; n < NumLineDefs; n++) - if (LineDefs[n].tag == tag) - { - printf(" %d", n); - count++; - } + if (LineDefs[n].tag == tag) + { + printf(" %d", n); + count++; + } printf(" (total %d)\n", count); } diff -r 594dea11ccd9 -r a68786b9c74b src/xref.h --- a/src/xref.h Sat Sep 24 15:01:56 2011 +0300 +++ b/src/xref.h Sat Sep 24 15:59:33 2011 +0300 @@ -1,8 +1,8 @@ /* - * xref.cc - * Cross reference stuff (who references who ?) - * and miscellaneous test/debug/exploration funcs. - * AYM 1999-03-31 + * xref.cc + * Cross reference stuff (who references who ?) + * and miscellaneous test/debug/exploration funcs. + * AYM 1999-03-31 */ diff -r 594dea11ccd9 -r a68786b9c74b src/yadex.cc --- a/src/yadex.cc Sat Sep 24 15:01:56 2011 +0300 +++ b/src/yadex.cc Sat Sep 24 15:59:33 2011 +0300 @@ -1,7 +1,7 @@ /* - * yadex.cc - * The main module. - * BW & RQ sometime in 1993 or 1994. + * yadex.cc + * The main module. + * BW & RQ sometime in 1993 or 1994. */ @@ -33,18 +33,18 @@ #include "acolours.h" #include "bench.h" #include "cfgfile.h" -#include "disppic.h" /* Because of "p" */ +#include "disppic.h" /* Because of "p" */ #include "editlev.h" #include "endian.h" #include "flats.h" #include "game.h" #include "gfx.h" #include "help1.h" -#include "levels.h" /* Because of "viewtex" */ +#include "levels.h" /* Because of "viewtex" */ #include "lists.h" #include "mkpalette.h" #include "palview.h" -#include "patchdir.h" /* Because of "p" */ +#include "patchdir.h" /* Because of "p" */ #include "rgb.h" #include "sanity.h" #include "textures.h" @@ -57,7 +57,7 @@ /* - * Constants (declared in yadex.h) + * Constants (declared in yadex.h) */ const char *const log_file = "yadex.log"; const char *const msg_unexpected = "unexpected error"; @@ -65,22 +65,22 @@ /* - * Not real variables -- just unique pointer values - * used by functions that return pointers to + * Not real variables -- just unique pointer values + * used by functions that return pointers to */ -char error_non_unique[1]; // Found more than one -char error_none[1]; // Found none -char error_invalid[1]; // Invalid parameter +char error_non_unique[1]; // Found more than one +char error_none[1]; // Found none +char error_invalid[1]; // Invalid parameter /* - * Global variables + * Global variables */ -const char *install_dir = 0; // Where Yadex is installed -FILE *logfile = NULL; // Filepointer to the error log -bool Registered = false; // Registered or shareware game? -int screen_lines = 24; // Lines that our TTY can display -int remind_to_build_nodes = 0; // Remind user to build nodes +const char *install_dir = 0; // Where Yadex is installed +FILE *logfile = NULL; // Filepointer to the error log +bool Registered = false; // Registered or shareware game? +int screen_lines = 24; // Lines that our TTY can display +int remind_to_build_nodes = 0; // Remind user to build nodes Wad_res wad_res(&MasterDir); // Set from command line and/or config file @@ -108,10 +108,10 @@ int GridMax = 128; int idle_sleep_ms = 50; bool InfoShown = true; -int zoom_default = 0; // 0 means fit -int zoom_step = 0; // 0 means sqrt(2) +int zoom_default = 0; // 0 means fit +int zoom_step = 0; // 0 means sqrt(2) int digit_zoom_base = 100; -int digit_zoom_step = 0; // 0 means sqrt(2) +int digit_zoom_step = 0; // 0 means sqrt(2) confirm_t insert_vertex_split_linedef = YC_ASK_ONCE; confirm_t insert_vertex_merge_vertices = YC_ASK_ONCE; bool blindly_swap_sidedefs = false; @@ -158,7 +158,7 @@ /* - * Prototypes of private functions + * Prototypes of private functions */ static int parse_environment_vars(); static void MainLoop(); @@ -190,8 +190,8 @@ /* - * main - * Guess what. + * main + * Guess what. */ int main(int argc, char *argv[]) { @@ -199,41 +199,41 @@ // Set <screen_lines> if (getenv("LINES") != NULL) - screen_lines = atoi(getenv("LINES")); + screen_lines = atoi(getenv("LINES")); else - screen_lines = 0; + screen_lines = 0; if (screen_lines == 0) - screen_lines = 24; + screen_lines = 24; // First detect manually --help and --version // because parse_command_line_options() cannot. if (argc == 2 && strcmp(argv[1], "--help") == 0) { - print_usage(stdout); - if (fflush(stdout) != 0) - fatal_error("stdout: %s", strerror(errno)); - exit(0); + print_usage(stdout); + if (fflush(stdout) != 0) + fatal_error("stdout: %s", strerror(errno)); + exit(0); } if (argc == 2 && strcmp(argv[1], "--version") == 0) { - puts(what()); - puts(config_file_magic); - puts(ygd_file_magic); - if (fflush(stdout) != 0) - fatal_error("stdout: %s", strerror(errno)); - exit(0); + puts(what()); + puts(config_file_magic); + puts(ygd_file_magic); + if (fflush(stdout) != 0) + fatal_error("stdout: %s", strerror(errno)); + exit(0); } // Second a quick pass through the command line // arguments to detect -?, -f and -help. r = parse_command_line_options(argc - 1, argv + 1, 1); if (r) - goto syntax_error; + goto syntax_error; if (show_help) { - print_usage(stdout); - exit(1); + print_usage(stdout); + exit(1); } printf("%s\n", what()); @@ -245,74 +245,74 @@ // The config file provides some values. if (config_file != NULL) - r = parse_config_file_user(config_file); + r = parse_config_file_user(config_file); else - r = parse_config_file_default(); + r = parse_config_file_default(); if (r == 0) { - // Environment variables can override them. - r = parse_environment_vars(); - if (r == 0) - { - // And the command line argument can override both. - r = parse_command_line_options(argc - 1, argv + 1, 2); - } + // Environment variables can override them. + r = parse_environment_vars(); + if (r == 0) + { + // And the command line argument can override both. + r = parse_command_line_options(argc - 1, argv + 1, 2); + } } if (r != 0) { syntax_error: - fprintf(stderr, "Try \"yadex --help\" or \"man yadex\".\n"); - exit(1); + fprintf(stderr, "Try \"yadex --help\" or \"man yadex\".\n"); + exit(1); } if (Game != NULL) { - int n; - for (n = 0; n < ngameList; n++) - { - GameInfo *info = &gameList[n]; - if (strcmp(Game, info->game) == 0) - { - if (*(info->pwadloc) == NULL) - { - err("You have to tell me where %s is.", info->wadname); - fprintf(stderr, - "Use \"-i%d <file>\" or put \"iwad%d=<file>\" in yadex.cfg\n", - n + 1, n + 1); - exit(1); - } - MainWad = *(info->pwadloc); - } - } + int n; + for (n = 0; n < ngameList; n++) + { + GameInfo *info = &gameList[n]; + if (strcmp(Game, info->game) == 0) + { + if (*(info->pwadloc) == NULL) + { + err("You have to tell me where %s is.", info->wadname); + fprintf(stderr, + "Use \"-i%d <file>\" or put \"iwad%d=<file>\" in yadex.cfg\n", + n + 1, n + 1); + exit(1); + } + MainWad = *(info->pwadloc); + } + } } if (MainWad == NULL) { - int n; - if (Game == NULL) - err("You didn't say for which game you want to edit."); - else - err("Unknown game \"%s\"", Game); - fprintf(stderr, - "Use \"-g <game>\" on the command line or put \"game=<game>\" in yadex.cfg\n" - "where <game> is one of: "); - for (n = 0; n < ngameList; n++) - { - fprintf(stderr, "%s\"%s\"", n > 0 ? ", " : "", gameList[n].game); - } - fprintf(stderr, ".\n"); - exit(1); + int n; + if (Game == NULL) + err("You didn't say for which game you want to edit."); + else + err("Unknown game \"%s\"", Game); + fprintf(stderr, + "Use \"-g <game>\" on the command line or put \"game=<game>\" in yadex.cfg\n" + "where <game> is one of: "); + for (n = 0; n < ngameList; n++) + { + fprintf(stderr, "%s\"%s\"", n > 0 ? ", " : "", gameList[n].game); + } + fprintf(stderr, ".\n"); + exit(1); } if (Debug) { - logfile = fopen(log_file, "a"); - if (logfile == NULL) - warn("can't open log file \"%s\" (%s)", log_file, - strerror(errno)); - LogMessage(": Welcome to Yadex!\n"); + logfile = fopen(log_file, "a"); + if (logfile == NULL) + warn("can't open log file \"%s\" (%s)", log_file, + strerror(errno)); + LogMessage(": Welcome to Yadex!\n"); } if (Quieter) - Quiet = true; + Quiet = true; // Sanity checks (useful when porting). check_types(); @@ -328,12 +328,12 @@ // Load the iwad and the pwads. if (OpenMainWad(MainWad)) - fatal_error("If you don't give me an iwad, I'll quit. I'm serious."); + fatal_error("If you don't give me an iwad, I'll quit. I'm serious."); if (PatchWads) { - const char *const *pwad_name; - for (pwad_name = PatchWads; *pwad_name; pwad_name++) - OpenPatchWad(*pwad_name); + const char *const *pwad_name; + for (pwad_name = PatchWads; *pwad_name; pwad_name++) + OpenPatchWad(*pwad_name); } /* sanity check */ CloseUnusedWadFiles(); @@ -341,29 +341,29 @@ // BRANCH 1 : benchmarking (-b) if (bench != 0) { - benchmark(bench); - return 0; // Exit successfully + benchmark(bench); + return 0; // Exit successfully } // BRANCH 2 : normal use ("yadex:" prompt) else { - if (welcome_message) - print_welcome(stdout); + if (welcome_message) + print_welcome(stdout); - if (strcmp(Game, "hexen") == 0) - printf - ("WARNING: Hexen mode is experimental. Don't expect to be able to do any\n" - "real Hexen editing with it. You can edit levels but you can't save them.\n" - "And there might be other bugs... BE CAREFUL !\n\n"); + if (strcmp(Game, "hexen") == 0) + printf + ("WARNING: Hexen mode is experimental. Don't expect to be able to do any\n" + "real Hexen editing with it. You can edit levels but you can't save them.\n" + "And there might be other bugs... BE CAREFUL !\n\n"); - if (strcmp(Game, "strife") == 0) - printf - ("WARNING: Strife mode is experimental. Many thing types, linedef types,\n" - "etc. are missing or wrong. And be careful, there might be bugs.\n\n"); + if (strcmp(Game, "strife") == 0) + printf + ("WARNING: Strife mode is experimental. Many thing types, linedef types,\n" + "etc. are missing or wrong. And be careful, there might be bugs.\n\n"); - /* all systems go! */ - MainLoop(); + /* all systems go! */ + MainLoop(); } /* that's all, folks! */ @@ -371,20 +371,20 @@ FreeGameDefs(); LogMessage(": The end!\n\n\n"); if (logfile != NULL) - fclose(logfile); + fclose(logfile); if (remind_to_build_nodes) - printf("\n" - "** You have made changes to one or more wads. Don't forget to pass\n" - "** them through a nodes builder (E.G. BSP) before running them.\n" - "** Like this: \"ybsp foo.wad -o tmp.wad; doom -file tmp.wad\"\n\n"); + printf("\n" + "** You have made changes to one or more wads. Don't forget to pass\n" + "** them through a nodes builder (E.G. BSP) before running them.\n" + "** Like this: \"ybsp foo.wad -o tmp.wad; doom -file tmp.wad\"\n\n"); return 0; } /* - * parse_environment_vars - * Check certain environment variables. - * Returns 0 on success, <>0 on error. + * parse_environment_vars + * Check certain environment variables. + * Returns 0 on success, <>0 on error. */ static int parse_environment_vars() { @@ -392,7 +392,7 @@ value = getenv("YADEX_GAME"); if (value != NULL) - Game = value; + Game = value; return 0; } @@ -416,12 +416,12 @@ #if defined Y_DOS if (!Quiet) { - sound(freq); - delay(msec); - nosound(); + sound(freq); + delay(msec); + nosound(); } #elif defined Y_UNIX - freq = msec; // To prevent a warning about unused variables + freq = msec; // To prevent a warning about unused variables return; #endif } @@ -429,8 +429,8 @@ /* - * fatal_error - * Print an error message and terminate the program with code 2. + * fatal_error + * Print an error message and terminate the program with code 2. */ void fatal_error(const char *fmt, ...) { @@ -442,7 +442,7 @@ // call TermGfx() before printing so we do it last so // that a segfault occuring in TermGfx() does not // prevent us from seeing the stderr message. - TermGfx(); // Don't need to sleep (1) either. + TermGfx(); // Don't need to sleep (1) either. // Clean up things and free swap space ForgetLevelData(); @@ -454,8 +454,8 @@ /* - * err - * Print an error message but do not terminate the program. + * err + * Print an error message but do not terminate the program. */ void err(const char *fmt, ...) { @@ -467,8 +467,8 @@ /* - * print_error_message - * Print an error message to stderr. + * print_error_message + * Print an error message to stderr. */ static void print_error_message(const char *fmt, va_list args) { @@ -479,18 +479,18 @@ fflush(stderr); if (Debug && logfile != NULL) { - fputs("Error: ", logfile); - vfprintf(logfile, fmt, args); - fputc('\n', logfile); - fflush(logfile); + fputs("Error: ", logfile); + vfprintf(logfile, fmt, args); + fputc('\n', logfile); + fflush(logfile); } } /* - * nf_bug - * Report about a non-fatal bug to stderr. The message - * should not expand to more than 80 characters. + * nf_bug + * Report about a non-fatal bug to stderr. The message + * should not expand to more than 80 characters. */ void nf_bug(const char *fmt, ...) { @@ -504,35 +504,35 @@ y_vsnprintf(msg, sizeof msg, fmt, args); if (first_time || strncmp(msg, msg_prev, sizeof msg)) { - fflush(stdout); - if (repeats) - { - fprintf(stderr, "Bug: Previous message repeated %d times\n", - repeats); - repeats = 0; - } + fflush(stdout); + if (repeats) + { + fprintf(stderr, "Bug: Previous message repeated %d times\n", + repeats); + repeats = 0; + } - fprintf(stderr, "Bug: %s\n", msg); - fflush(stderr); - if (first_time) - { - fputs("REPORT ALL \"Bug:\" MESSAGES TO THE MAINTAINER !\n", - stderr); - first_time = 0; - } - strncpy(msg_prev, msg, sizeof msg_prev); + fprintf(stderr, "Bug: %s\n", msg); + fflush(stderr); + if (first_time) + { + fputs("REPORT ALL \"Bug:\" MESSAGES TO THE MAINTAINER !\n", + stderr); + first_time = 0; + } + strncpy(msg_prev, msg, sizeof msg_prev); } else { - repeats++; // Same message as above - if (repeats == 10) - { - fflush(stdout); - fprintf(stderr, "Bug: Previous message repeated %d times\n", - repeats); - fflush(stderr); - repeats = 0; - } + repeats++; // Same message as above + if (repeats == 10) + { + fflush(stdout); + fprintf(stderr, "Bug: Previous message repeated %d times\n", + repeats); + fflush(stderr); + repeats = 0; + } } } @@ -549,17 +549,17 @@ if (Debug && logfile != NULL) { - va_start(args, logstr); - /* if the message begins with ":", output the current date & time first */ - if (logstr[0] == ':') - { - time(&tval); - tstr = ctime(&tval); - tstr[strlen(tstr) - 1] = '\0'; - fprintf(logfile, "%s", tstr); - } - vfprintf(logfile, logstr, args); - fflush(logfile); /* AYM 19971031 */ + va_start(args, logstr); + /* if the message begins with ":", output the current date & time first */ + if (logstr[0] == ':') + { + time(&tval); + tstr = ctime(&tval); + tstr[strlen(tstr) - 1] = '\0'; + fprintf(logfile, "%s", tstr); + } + vfprintf(logfile, logstr, args); + fflush(logfile); /* AYM 19971031 */ } } @@ -577,744 +577,744 @@ for (;;) { - /* get the input */ - printf("yadex: "); - if (!fgets(input, sizeof input, stdin)) - { - puts("q"); - break; - } + /* get the input */ + printf("yadex: "); + if (!fgets(input, sizeof input, stdin)) + { + puts("q"); + break; + } - /* Strip the trailing '\n' */ - if (strlen(input) > 0 && input[strlen(input) - 1] == '\n') - input[strlen(input) - 1] = '\0'; + /* Strip the trailing '\n' */ + if (strlen(input) > 0 && input[strlen(input) - 1] == '\n') + input[strlen(input) - 1] = '\0'; - /* eat the white space and get the first command word */ - com = strtok(input, " "); + /* eat the white space and get the first command word */ + com = strtok(input, " "); - /* user just hit return */ - if (com == NULL) - printf("Please enter a command or ? for help.\n"); + /* user just hit return */ + if (com == NULL) + printf("Please enter a command or ? for help.\n"); - /* user inputting for help */ - else if (strcmp(com, "?") == 0 - || strcmp(com, "h") == 0 || strcmp(com, "help") == 0) - { - printf("? | h | help --" - " display this text\n"); - printf("b[uild] <WadFile> --" - " build a new iwad\n"); - printf("c[reate] <levelname> --" - " create and edit a new (empty) level\n"); - printf("d[ump] <DirEntry> [outfile] --" - " dump a directory entry in hex\n"); - printf("e[dit] <levelname> --" - " edit a game level saving results to\n"); - printf - (" a patch wad file\n"); - printf("g[roup] <WadFile> --" - " group all patch wads in a file\n"); - printf("i[nsert] <RawFile> <DirEntry> --" - " insert a raw file in a patch wad file\n"); - printf("l[ist] <WadFile> [outfile] --" - " list the directory of a wadfile\n"); - printf("m[aster] [outfile] --" - " list the master directory\n"); - printf("make_gimp_palette <outfile> --" - " generate a gimp palette file from\n" - " " - " entry 0 of lump PLAYPAL.\n"); - printf("make_palette_ppm <outfile> --" - " generate a palette image from\n" - " " - " entry 0 of lump PLAYPAL.\n"); - printf("q[uit] --" " quit\n"); - printf("r[ead] <WadFile> --" - " read a new wad patch file\n"); - printf("s[ave] <DirEntry> <WadFile> --" - " save one object to a separate file\n"); - printf("set --" - " list all options and their values\n"); - printf("v[iew] [<spritename>] --" - " display the sprites\n"); - printf("viewflat [<flatname>] --" " flat viewer\n"); - printf("viewpal --" - " palette viewer\n"); - printf("viewpat [<patchname>] --" " patch viewer\n"); - printf("viewtex [<texname>] --" - " texture viewer\n"); - printf("w[ads] --" - " display the open wads\n"); - printf("x[tract] <DirEntry> <RawFile> --" - " save (extract) one object to a raw file\n"); - } + /* user inputting for help */ + else if (strcmp(com, "?") == 0 + || strcmp(com, "h") == 0 || strcmp(com, "help") == 0) + { + printf("? | h | help --" + " display this text\n"); + printf("b[uild] <WadFile> --" + " build a new iwad\n"); + printf("c[reate] <levelname> --" + " create and edit a new (empty) level\n"); + printf("d[ump] <DirEntry> [outfile] --" + " dump a directory entry in hex\n"); + printf("e[dit] <levelname> --" + " edit a game level saving results to\n"); + printf + (" a patch wad file\n"); + printf("g[roup] <WadFile> --" + " group all patch wads in a file\n"); + printf("i[nsert] <RawFile> <DirEntry> --" + " insert a raw file in a patch wad file\n"); + printf("l[ist] <WadFile> [outfile] --" + " list the directory of a wadfile\n"); + printf("m[aster] [outfile] --" + " list the master directory\n"); + printf("make_gimp_palette <outfile> --" + " generate a gimp palette file from\n" + " " + " entry 0 of lump PLAYPAL.\n"); + printf("make_palette_ppm <outfile> --" + " generate a palette image from\n" + " " + " entry 0 of lump PLAYPAL.\n"); + printf("q[uit] --" " quit\n"); + printf("r[ead] <WadFile> --" + " read a new wad patch file\n"); + printf("s[ave] <DirEntry> <WadFile> --" + " save one object to a separate file\n"); + printf("set --" + " list all options and their values\n"); + printf("v[iew] [<spritename>] --" + " display the sprites\n"); + printf("viewflat [<flatname>] --" " flat viewer\n"); + printf("viewpal --" + " palette viewer\n"); + printf("viewpat [<patchname>] --" " patch viewer\n"); + printf("viewtex [<texname>] --" + " texture viewer\n"); + printf("w[ads] --" + " display the open wads\n"); + printf("x[tract] <DirEntry> <RawFile> --" + " save (extract) one object to a raw file\n"); + } - /* user asked for list of open wad files */ - else if (strcmp(com, "wads") == 0 || strcmp(com, "w") == 0) - { - const Wad_file *wf; - wad_list.rewind(); - if (wad_list.get(wf)) - printf("%-40s Iwad\n", wf->pathname()); - while (wad_list.get(wf)) - printf("%-40s Pwad (%.*s)\n", - wf->pathname(), (int) WAD_NAME, wf->what()); - } + /* user asked for list of open wad files */ + else if (strcmp(com, "wads") == 0 || strcmp(com, "w") == 0) + { + const Wad_file *wf; + wad_list.rewind(); + if (wad_list.get(wf)) + printf("%-40s Iwad\n", wf->pathname()); + while (wad_list.get(wf)) + printf("%-40s Pwad (%.*s)\n", + wf->pathname(), (int) WAD_NAME, wf->what()); + } - /* user asked to quit */ - else if (strcmp(com, "quit") == 0 || strcmp(com, "q") == 0) - { - if (!Registered) - printf("Remember to register your copy of the game !\n"); - break; - } + /* user asked to quit */ + else if (strcmp(com, "quit") == 0 || strcmp(com, "q") == 0) + { + if (!Registered) + printf("Remember to register your copy of the game !\n"); + break; + } - /* user asked to edit a level */ - else if (strcmp(com, "edit") == 0 || strcmp(com, "e") == 0 - || strcmp(com, "create") == 0 || strcmp(com, "c") == 0) - { - const int newlevel = strcmp(com, "create") == 0 - || strcmp(com, "c") == 0; - char *level_name = 0; - com = strtok(NULL, " "); - if (com == 0) - if (!newlevel) - { - printf("Which level ?\n"); - continue; - } - else - level_name = 0; - else - { - level_name = find_level(com); - if (level_name == error_invalid) - { - printf("\"%s\" is not a valid level name.\n", com); - continue; - } - else if (level_name == error_none) - { - printf("Neither E%dM%d nor MAP%02d exist.\n", - atoi(com) / 10, atoi(com) % 10, atoi(com)); - continue; - } - else if (level_name == error_non_unique) - { - printf - ("Both E%dM%d and MAP%02d exist. Use an unambiguous name.\n", - atoi(com) / 10, atoi(com) % 10, atoi(com)); - continue; - } - else if (level_name == NULL) - { - printf("Level %s not found.", com); - // Hint absent-minded users - if (tolower(*com) == 'e' && yg_level_name == YGLN_MAP01 - || tolower(*com) == 'm' && yg_level_name == YGLN_E1M1) - printf(" You are in %s mode.", Game); - else if (tolower(*com) == 'e' && com[1] > '1' - && !Registered) - printf(" You have the shareware iwad."); - putchar('\n'); - continue; - } - } - EditLevel(level_name, newlevel); - if (level_name) - free(level_name); - } + /* user asked to edit a level */ + else if (strcmp(com, "edit") == 0 || strcmp(com, "e") == 0 + || strcmp(com, "create") == 0 || strcmp(com, "c") == 0) + { + const int newlevel = strcmp(com, "create") == 0 + || strcmp(com, "c") == 0; + char *level_name = 0; + com = strtok(NULL, " "); + if (com == 0) + if (!newlevel) + { + printf("Which level ?\n"); + continue; + } + else + level_name = 0; + else + { + level_name = find_level(com); + if (level_name == error_invalid) + { + printf("\"%s\" is not a valid level name.\n", com); + continue; + } + else if (level_name == error_none) + { + printf("Neither E%dM%d nor MAP%02d exist.\n", + atoi(com) / 10, atoi(com) % 10, atoi(com)); + continue; + } + else if (level_name == error_non_unique) + { + printf + ("Both E%dM%d and MAP%02d exist. Use an unambiguous name.\n", + atoi(com) / 10, atoi(com) % 10, atoi(com)); + continue; + } + else if (level_name == NULL) + { + printf("Level %s not found.", com); + // Hint absent-minded users + if (tolower(*com) == 'e' && yg_level_name == YGLN_MAP01 + || tolower(*com) == 'm' && yg_level_name == YGLN_E1M1) + printf(" You are in %s mode.", Game); + else if (tolower(*com) == 'e' && com[1] > '1' + && !Registered) + printf(" You have the shareware iwad."); + putchar('\n'); + continue; + } + } + EditLevel(level_name, newlevel); + if (level_name) + free(level_name); + } - /* user asked to build a new main wad file */ - else if (strcmp(com, "build") == 0 || strcmp(com, "b") == 0) - { - com = strtok(NULL, " "); - if (com == NULL) - { - printf("Wad file name argument missing.\n"); - continue; - } - if (wad_already_loaded(com)) - { - printf("%s: in use, close it first\n", com); - continue; - } - BuildNewMainWad(com, 0); - } + /* user asked to build a new main wad file */ + else if (strcmp(com, "build") == 0 || strcmp(com, "b") == 0) + { + com = strtok(NULL, " "); + if (com == NULL) + { + printf("Wad file name argument missing.\n"); + continue; + } + if (wad_already_loaded(com)) + { + printf("%s: in use, close it first\n", com); + continue; + } + BuildNewMainWad(com, 0); + } - /* user asked to build a compound patch wad file */ - else if (strcmp(com, "group") == 0 || strcmp(com, "g") == 0) - { - wad_list.rewind(); - const Wad_file *wf; - if (!wad_list.get(wf) || !wad_list.get(wf)) - { - printf("You need at least two open wad files " - "if you want to group them.\n"); - continue; - } - com = strtok(NULL, " "); - if (com == NULL) - { - printf("Wad file name argument missing.\n"); - continue; - } - if (wad_already_loaded(com)) - { - printf("%s: in use, close it first\n", com); - continue; - } - BuildNewMainWad(com, 1); - } + /* user asked to build a compound patch wad file */ + else if (strcmp(com, "group") == 0 || strcmp(com, "g") == 0) + { + wad_list.rewind(); + const Wad_file *wf; + if (!wad_list.get(wf) || !wad_list.get(wf)) + { + printf("You need at least two open wad files " + "if you want to group them.\n"); + continue; + } + com = strtok(NULL, " "); + if (com == NULL) + { + printf("Wad file name argument missing.\n"); + continue; + } + if (wad_already_loaded(com)) + { + printf("%s: in use, close it first\n", com); + continue; + } + BuildNewMainWad(com, 1); + } - /* user ask for a listing of a wad file */ - else if (strcmp(com, "list") == 0 || strcmp(com, "l") == 0) - { - com = strtok(NULL, " "); - if (com == NULL) - { - printf("Wad file name argument missing.\n"); - continue; - } - const Wad_file *wf = wad_by_name(com); - if (wf == 0) - { - printf("%s: not open\n", com); - continue; - } - out = strtok(NULL, " "); - if (out) - { - printf("Outputting directory of \"%s\" to \"%s\".\n", - wf->pathname(), out); - if ((file = fopen(out, "w")) == NULL) - fatal_error("error opening output file \"%s\"", com); - fprintf(file, "%s\n", what()); - ListFileDirectory(file, wf); - fprintf(file, "\nEnd of file.\n"); - fclose(file); - } - else - ListFileDirectory(stdout, wf); - } + /* user ask for a listing of a wad file */ + else if (strcmp(com, "list") == 0 || strcmp(com, "l") == 0) + { + com = strtok(NULL, " "); + if (com == NULL) + { + printf("Wad file name argument missing.\n"); + continue; + } + const Wad_file *wf = wad_by_name(com); + if (wf == 0) + { + printf("%s: not open\n", com); + continue; + } + out = strtok(NULL, " "); + if (out) + { + printf("Outputting directory of \"%s\" to \"%s\".\n", + wf->pathname(), out); + if ((file = fopen(out, "w")) == NULL) + fatal_error("error opening output file \"%s\"", com); + fprintf(file, "%s\n", what()); + ListFileDirectory(file, wf); + fprintf(file, "\nEnd of file.\n"); + fclose(file); + } + else + ListFileDirectory(stdout, wf); + } - /* user asked for the list of the master directory */ - else if (strcmp(com, "master") == 0 || strcmp(com, "m") == 0) - { - out = strtok(NULL, " "); - if (out) - { - printf("Outputting master directory to \"%s\".\n", out); - if ((file = fopen(out, "w")) == NULL) - fatal_error("error opening output file \"%s\"", com); - fprintf(file, "%s\n", what()); - ListMasterDirectory(file); - fprintf(file, "\nEnd of file.\n"); - fclose(file); - } - else - ListMasterDirectory(stdout); - } + /* user asked for the list of the master directory */ + else if (strcmp(com, "master") == 0 || strcmp(com, "m") == 0) + { + out = strtok(NULL, " "); + if (out) + { + printf("Outputting master directory to \"%s\".\n", out); + if ((file = fopen(out, "w")) == NULL) + fatal_error("error opening output file \"%s\"", com); + fprintf(file, "%s\n", what()); + ListMasterDirectory(file); + fprintf(file, "\nEnd of file.\n"); + fclose(file); + } + else + ListMasterDirectory(stdout); + } - // make_gimp_palette - else if (strcmp(com, "make_gimp_palette") == 0) - { - out = strtok(NULL, " "); - if (out == NULL) - { - printf("Output file name argument missing.\n"); - continue; - } - make_gimp_palette(0, out); - } + // make_gimp_palette + else if (strcmp(com, "make_gimp_palette") == 0) + { + out = strtok(NULL, " "); + if (out == NULL) + { + printf("Output file name argument missing.\n"); + continue; + } + make_gimp_palette(0, out); + } - // make_palette_ppm - else if (strcmp(com, "make_palette_ppm") == 0) - { - out = strtok(NULL, ""); - if (out == NULL) - { - printf("Output file name argument missing.\n"); - continue; - } - make_palette_ppm(0, out); - } + // make_palette_ppm + else if (strcmp(com, "make_palette_ppm") == 0) + { + out = strtok(NULL, ""); + if (out == NULL) + { + printf("Output file name argument missing.\n"); + continue; + } + make_palette_ppm(0, out); + } - // make_palette_ppm - else if (strcmp(com, "mp2") == 0) - { - out = strtok(NULL, ""); - if (out == NULL) - { - printf("Output file name argument missing.\n"); - continue; - } - make_palette_ppm_2(0, out); - } + // make_palette_ppm + else if (strcmp(com, "mp2") == 0) + { + out = strtok(NULL, ""); + if (out == NULL) + { + printf("Output file name argument missing.\n"); + continue; + } + make_palette_ppm_2(0, out); + } - /* user asked to list all options and their values */ - else if (strcmp(com, "set") == 0) - { - dump_parameters(stdout); - } + /* user asked to list all options and their values */ + else if (strcmp(com, "set") == 0) + { + dump_parameters(stdout); + } - /* user asked to read a new patch wad file */ - else if (strcmp(com, "read") == 0 || strcmp(com, "r") == 0) - { - com = strtok(NULL, " "); - if (com == NULL) - { - printf("Wad file name argument missing.\n"); - continue; - } - out = strtok(NULL, " "); - if (out) - *out = '\0'; - out = (char *) GetMemory(strlen(com) + 1); - strcpy(out, com); - OpenPatchWad(out); - CloseUnusedWadFiles(); - } + /* user asked to read a new patch wad file */ + else if (strcmp(com, "read") == 0 || strcmp(com, "r") == 0) + { + com = strtok(NULL, " "); + if (com == NULL) + { + printf("Wad file name argument missing.\n"); + continue; + } + out = strtok(NULL, " "); + if (out) + *out = '\0'; + out = (char *) GetMemory(strlen(com) + 1); + strcpy(out, com); + OpenPatchWad(out); + CloseUnusedWadFiles(); + } - /* user asked to dump the contents of a wad file */ - else if (strcmp(com, "dump") == 0 || strcmp(com, "d") == 0) - { - com = strtok(NULL, " "); - if (com == NULL) - { - printf("Object name argument missing.\n"); - continue; - } - out = strtok(NULL, " "); - if (out) - { - printf("Outputting directory entry data to \"%s\".\n", out); - if ((file = fopen(out, "w")) == NULL) - fatal_error("error opening output file \"%s\"", com); - fprintf(file, "%s\n", what()); - DumpDirectoryEntry(file, com); - fprintf(file, "\nEnd of file.\n"); - fclose(file); - } - else - DumpDirectoryEntry(stdout, com); - } + /* user asked to dump the contents of a wad file */ + else if (strcmp(com, "dump") == 0 || strcmp(com, "d") == 0) + { + com = strtok(NULL, " "); + if (com == NULL) + { + printf("Object name argument missing.\n"); + continue; + } + out = strtok(NULL, " "); + if (out) + { + printf("Outputting directory entry data to \"%s\".\n", out); + if ((file = fopen(out, "w")) == NULL) + fatal_error("error opening output file \"%s\"", com); + fprintf(file, "%s\n", what()); + DumpDirectoryEntry(file, com); + fprintf(file, "\nEnd of file.\n"); + fclose(file); + } + else + DumpDirectoryEntry(stdout, com); + } - // "v"/"view" - view the sprites - else if (strcmp(com, "view") == 0 || strcmp(com, "v") == 0) - { - if (InitGfx()) - goto v_end; - init_input_status(); - do - get_input_status(); - while (is.key != YE_EXPOSE); - force_window_not_pixmap(); // FIXME quick hack - { - Lump_list list; - wad_res.sprites.list(list); - char buf[WAD_PIC_NAME + 1]; - const char *sprite = strtok(NULL, " "); - *buf = '\0'; - if (sprite != 0) - { - strncat(buf, sprite, sizeof buf - 1); - for (char *p = buf; *p != '\0'; p++) - *p = toupper(*p); - } - InputNameFromListWithFunc(-1, -1, "Sprite viewer", - list.size(), list.data(), 10, buf, - 320, 200, display_pic, - HOOK_DISP_SIZE | HOOK_SPRITE); - } - TermGfx(); - v_end:; - } + // "v"/"view" - view the sprites + else if (strcmp(com, "view") == 0 || strcmp(com, "v") == 0) + { + if (InitGfx()) + goto v_end; + init_input_status(); + do + get_input_status(); + while (is.key != YE_EXPOSE); + force_window_not_pixmap(); // FIXME quick hack + { + Lump_list list; + wad_res.sprites.list(list); + char buf[WAD_PIC_NAME + 1]; + const char *sprite = strtok(NULL, " "); + *buf = '\0'; + if (sprite != 0) + { + strncat(buf, sprite, sizeof buf - 1); + for (char *p = buf; *p != '\0'; p++) + *p = toupper(*p); + } + InputNameFromListWithFunc(-1, -1, "Sprite viewer", + list.size(), list.data(), 10, buf, + 320, 200, display_pic, + HOOK_DISP_SIZE | HOOK_SPRITE); + } + TermGfx(); + v_end:; + } - // "viewflat" - view the flats - else if (strcmp(com, "viewflat") == 0) - { - if (InitGfx()) - goto viewflat_end; - init_input_status(); - do - get_input_status(); - while (is.key != YE_EXPOSE); - com = strtok(NULL, " "); - force_window_not_pixmap(); // FIXME quick hack - char buf[WAD_FLAT_NAME + 1]; - *buf = '\0'; - if (com != 0) - strncat(buf, com, sizeof buf - 1); - ReadFTextureNames(); - { - char **flat_names = - (char **) GetMemory(NumFTexture * sizeof *flat_names); - for (size_t n = 0; n < NumFTexture; n++) - flat_names[n] = flat_list[n].name; - ChooseFloorTexture(-1, -1, "Flat viewer", - NumFTexture, flat_names, buf); - FreeMemory(flat_names); - } - ForgetFTextureNames(); - TermGfx(); - viewflat_end:; - } + // "viewflat" - view the flats + else if (strcmp(com, "viewflat") == 0) + { + if (InitGfx()) + goto viewflat_end; + init_input_status(); + do + get_input_status(); + while (is.key != YE_EXPOSE); + com = strtok(NULL, " "); + force_window_not_pixmap(); // FIXME quick hack + char buf[WAD_FLAT_NAME + 1]; + *buf = '\0'; + if (com != 0) + strncat(buf, com, sizeof buf - 1); + ReadFTextureNames(); + { + char **flat_names = + (char **) GetMemory(NumFTexture * sizeof *flat_names); + for (size_t n = 0; n < NumFTexture; n++) + flat_names[n] = flat_list[n].name; + ChooseFloorTexture(-1, -1, "Flat viewer", + NumFTexture, flat_names, buf); + FreeMemory(flat_names); + } + ForgetFTextureNames(); + TermGfx(); + viewflat_end:; + } - // "viewpal" - view the palette (PLAYPAL and COLORMAP) - else if (strcmp(com, "viewpal") == 0) - { - if (InitGfx()) - goto viewpal_end; - init_input_status(); - do - get_input_status(); - while (is.key != YE_EXPOSE); - force_window_not_pixmap(); // FIXME quick hack - { - Palette_viewer pv; - pv.run(); - } - TermGfx(); - viewpal_end:; - } + // "viewpal" - view the palette (PLAYPAL and COLORMAP) + else if (strcmp(com, "viewpal") == 0) + { + if (InitGfx()) + goto viewpal_end; + init_input_status(); + do + get_input_status(); + while (is.key != YE_EXPOSE); + force_window_not_pixmap(); // FIXME quick hack + { + Palette_viewer pv; + pv.run(); + } + TermGfx(); + viewpal_end:; + } - // "viewpat" - view the patches - else if (strcmp(com, "viewpat") == 0) - { - if (InitGfx()) - goto viewpat_end; - init_input_status(); - do - get_input_status(); - while (is.key != YE_EXPOSE); - com = strtok(NULL, " "); - force_window_not_pixmap(); // FIXME quick hack - patch_dir.refresh(MasterDir); - { - char buf[WAD_NAME + 1]; - *buf = '\0'; - if (com != 0) - strncat(buf, com, sizeof buf - 1); - Patch_list pl; - patch_dir.list(pl); - InputNameFromListWithFunc(-1, -1, "Patch viewer", pl.size(), - pl.data(), 10, buf, 256, 256, - display_pic, - HOOK_DISP_SIZE | HOOK_PATCH); - } - TermGfx(); - viewpat_end:; - } + // "viewpat" - view the patches + else if (strcmp(com, "viewpat") == 0) + { + if (InitGfx()) + goto viewpat_end; + init_input_status(); + do + get_input_status(); + while (is.key != YE_EXPOSE); + com = strtok(NULL, " "); + force_window_not_pixmap(); // FIXME quick hack + patch_dir.refresh(MasterDir); + { + char buf[WAD_NAME + 1]; + *buf = '\0'; + if (com != 0) + strncat(buf, com, sizeof buf - 1); + Patch_list pl; + patch_dir.list(pl); + InputNameFromListWithFunc(-1, -1, "Patch viewer", pl.size(), + pl.data(), 10, buf, 256, 256, + display_pic, + HOOK_DISP_SIZE | HOOK_PATCH); + } + TermGfx(); + viewpat_end:; + } - // "viewtex" - view the textures - else if (strcmp(com, "viewtex") == 0) - { - if (InitGfx()) - goto viewtex_end; - init_input_status(); - do - get_input_status(); - while (is.key != YE_EXPOSE); - com = strtok(NULL, " "); - force_window_not_pixmap(); // FIXME quick hack - patch_dir.refresh(MasterDir); - { - char buf[WAD_TEX_NAME + 1]; - *buf = '\0'; - if (com != 0) - strncat(buf, com, sizeof buf - 1); - ReadWTextureNames(); - ChooseWallTexture(-1, -1, "Texture viewer", NumWTexture, - WTexture, buf); - ForgetWTextureNames(); - } - TermGfx(); - viewtex_end:; - } + // "viewtex" - view the textures + else if (strcmp(com, "viewtex") == 0) + { + if (InitGfx()) + goto viewtex_end; + init_input_status(); + do + get_input_status(); + while (is.key != YE_EXPOSE); + com = strtok(NULL, " "); + force_window_not_pixmap(); // FIXME quick hack + patch_dir.refresh(MasterDir); + { + char buf[WAD_TEX_NAME + 1]; + *buf = '\0'; + if (com != 0) + strncat(buf, com, sizeof buf - 1); + ReadWTextureNames(); + ChooseWallTexture(-1, -1, "Texture viewer", NumWTexture, + WTexture, buf); + ForgetWTextureNames(); + } + TermGfx(); + viewtex_end:; + } - /* user asked to save an object to a separate pwad file */ - else if (strcmp(com, "save") == 0 || strcmp(com, "s") == 0) - { - com = strtok(NULL, " "); - if (com == NULL) - { - printf("Object name argument missing.\n"); - continue; - } - if (strlen(com) > WAD_NAME || strchr(com, '.') != NULL) - { - printf("Invalid object name.\n"); - continue; - } - out = strtok(NULL, " "); - if (out == NULL) - { - printf("Wad file name argument missing.\n"); - continue; - } - if (wad_already_loaded(com)) - { - printf("%s: in use, close it first\n", com); - continue; - } - printf("Saving directory entry data to \"%s\".\n", out); - if ((file = fopen(out, "wb")) == NULL) - fatal_error("error opening output file \"%s\"", out); - SaveDirectoryEntry(file, com); - fclose(file); - } + /* user asked to save an object to a separate pwad file */ + else if (strcmp(com, "save") == 0 || strcmp(com, "s") == 0) + { + com = strtok(NULL, " "); + if (com == NULL) + { + printf("Object name argument missing.\n"); + continue; + } + if (strlen(com) > WAD_NAME || strchr(com, '.') != NULL) + { + printf("Invalid object name.\n"); + continue; + } + out = strtok(NULL, " "); + if (out == NULL) + { + printf("Wad file name argument missing.\n"); + continue; + } + if (wad_already_loaded(com)) + { + printf("%s: in use, close it first\n", com); + continue; + } + printf("Saving directory entry data to \"%s\".\n", out); + if ((file = fopen(out, "wb")) == NULL) + fatal_error("error opening output file \"%s\"", out); + SaveDirectoryEntry(file, com); + fclose(file); + } - /* user asked to encapsulate a raw file in a pwad file */ - else if (strcmp(com, "insert") == 0 || strcmp(com, "i") == 0) - { - com = strtok(NULL, " "); - if (com == NULL) - { - printf("Raw file name argument missing.\n"); - continue; - } - out = strtok(NULL, " "); - if (out == NULL) - { - printf("Object name argument missing.\n"); - continue; - } - if (strlen(out) > WAD_NAME || strchr(out, '.') != NULL) - { - printf("Invalid object name.\n"); - continue; - } - if ((raw = fopen(com, "rb")) == NULL) - fatal_error("error opening input file \"%s\"", com); - /* kluge */ - strcpy(input, out); - strcat(input, ".wad"); - if (wad_already_loaded(input)) - { - printf("%s: in use, close it first\n", input); - continue; - } - printf("Including new object %s in \"%s\".\n", out, input); - if ((file = fopen(input, "wb")) == NULL) - fatal_error("error opening output file \"%s\"", input); - SaveEntryFromRawFile(file, raw, out); - fclose(raw); - fclose(file); - } + /* user asked to encapsulate a raw file in a pwad file */ + else if (strcmp(com, "insert") == 0 || strcmp(com, "i") == 0) + { + com = strtok(NULL, " "); + if (com == NULL) + { + printf("Raw file name argument missing.\n"); + continue; + } + out = strtok(NULL, " "); + if (out == NULL) + { + printf("Object name argument missing.\n"); + continue; + } + if (strlen(out) > WAD_NAME || strchr(out, '.') != NULL) + { + printf("Invalid object name.\n"); + continue; + } + if ((raw = fopen(com, "rb")) == NULL) + fatal_error("error opening input file \"%s\"", com); + /* kluge */ + strcpy(input, out); + strcat(input, ".wad"); + if (wad_already_loaded(input)) + { + printf("%s: in use, close it first\n", input); + continue; + } + printf("Including new object %s in \"%s\".\n", out, input); + if ((file = fopen(input, "wb")) == NULL) + fatal_error("error opening output file \"%s\"", input); + SaveEntryFromRawFile(file, raw, out); + fclose(raw); + fclose(file); + } - /* user asked to extract an object to a raw binary file */ - else if (strcmp(com, "xtract") == 0 - || strcmp(com, "extract") == 0 || strcmp(com, "x") == 0) - { - com = strtok(NULL, " "); - if (com == NULL) - { - printf("Object name argument missing.\n"); - continue; - } - if (strlen(com) > WAD_NAME || strchr(com, '.') != NULL) - { - printf("Invalid object name.\n"); - continue; - } - out = strtok(NULL, " "); - if (out == NULL) - { - printf("Raw file name argument missing.\n"); - continue; - } - if (wad_already_loaded(com)) - { - printf("%s: in use, close it first\n", com); - printf - ("Besides do you really want to overwrite a wad file with" - " raw data ?\n"); - continue; - } - printf("Saving directory entry data to \"%s\".\n", out); - if ((file = fopen(out, "wb")) == NULL) - fatal_error("error opening output file \"%s\"", out); - SaveEntryToRawFile(file, com); - fclose(file); - } + /* user asked to extract an object to a raw binary file */ + else if (strcmp(com, "xtract") == 0 + || strcmp(com, "extract") == 0 || strcmp(com, "x") == 0) + { + com = strtok(NULL, " "); + if (com == NULL) + { + printf("Object name argument missing.\n"); + continue; + } + if (strlen(com) > WAD_NAME || strchr(com, '.') != NULL) + { + printf("Invalid object name.\n"); + continue; + } + out = strtok(NULL, " "); + if (out == NULL) + { + printf("Raw file name argument missing.\n"); + continue; + } + if (wad_already_loaded(com)) + { + printf("%s: in use, close it first\n", com); + printf + ("Besides do you really want to overwrite a wad file with" + " raw data ?\n"); + continue; + } + printf("Saving directory entry data to \"%s\".\n", out); + if ((file = fopen(out, "wb")) == NULL) + fatal_error("error opening output file \"%s\"", out); + SaveEntryToRawFile(file, com); + fclose(file); + } - /* unknown command */ - else - printf("Unknown command \"%s\"!\n", com); + /* unknown command */ + else + printf("Unknown command \"%s\"!\n", com); } } /* - * add_base_colours - * Add the NCOLOURS base colours to the list of - * application colours. + * add_base_colours + * Add the NCOLOURS base colours to the list of + * application colours. */ static void add_base_colours() { for (size_t n = 0; n < NCOLOURS; n++) { - rgb_c c; + rgb_c c; - // The first 16 are the standard IRGB VGA colours. - // FIXME they're to be removed and replaced by - // "logical" colours. + // The first 16 are the standard IRGB VGA colours. + // FIXME they're to be removed and replaced by + // "logical" colours. #ifdef WHITE_BACKGROUND - if (n == 0) - irgb2rgb(15, &c); - else if (n == 15) - irgb2rgb(0, &c); - else + if (n == 0) + irgb2rgb(15, &c); + else if (n == 15) + irgb2rgb(0, &c); + else #endif - if (n < 16) - irgb2rgb(n, &c); + if (n < 16) + irgb2rgb(n, &c); - // Then there are the colours used to draw the - // windows and the map. The colours used to draw - // the things are parametrized in the .ygd ; they - // are added by load_game(). - // FIXME they should not be hard-coded, of course ! + // Then there are the colours used to draw the + // windows and the map. The colours used to draw + // the things are parametrized in the .ygd ; they + // are added by load_game(). + // FIXME they should not be hard-coded, of course ! - /* WINBG* is for window backgrounds. Use the _HL variant is - for highlighted parts of windows (E.G. the current line in - a menu). _LIGHT and _DARK are for window borders and - grooves. There is no _HL flavour of these because I didn't - feel the need. */ + /* WINBG* is for window backgrounds. Use the _HL variant is + for highlighted parts of windows (E.G. the current line in + a menu). _LIGHT and _DARK are for window borders and + grooves. There is no _HL flavour of these because I didn't + feel the need. */ #ifdef WHITE_BACKGROUND - else if (n == WINBG) - c.set(0xe2, 0xdc, 0xd6); - else if (n == WINBG_LIGHT) - c.set(0xee, 0xe8, 0xe2); - else if (n == WINBG_DARK) - c.set(0xc3, 0xbe, 0xb9); - else if (n == WINBG_HL) - c.set(0xf4, 0xee, 0xe7); + else if (n == WINBG) + c.set(0xe2, 0xdc, 0xd6); + else if (n == WINBG_LIGHT) + c.set(0xee, 0xe8, 0xe2); + else if (n == WINBG_DARK) + c.set(0xc3, 0xbe, 0xb9); + else if (n == WINBG_HL) + c.set(0xf4, 0xee, 0xe7); #else - else if (n == WINBG) - c.set(0x2a, 0x24, 0x18); - else if (n == WINBG_LIGHT) - c.set(0x48, 0x42, 0x3c); - else if (n == WINBG_DARK) - c.set(0x20, 0x1b, 0x12); - else if (n == WINBG_HL) - c.set(0x58, 0x50, 0x48); + else if (n == WINBG) + c.set(0x2a, 0x24, 0x18); + else if (n == WINBG_LIGHT) + c.set(0x48, 0x42, 0x3c); + else if (n == WINBG_DARK) + c.set(0x20, 0x1b, 0x12); + else if (n == WINBG_HL) + c.set(0x58, 0x50, 0x48); #endif - /* WINFG* is for regular text. _DIM is for greyed out text - (for disabled options or text that is not applicable). */ + /* WINFG* is for regular text. _DIM is for greyed out text + (for disabled options or text that is not applicable). */ #ifdef WHITE_BACKGROUND - else if (n == WINFG) - c.set(0x60, 0x60, 0x60); - else if (n == WINFG_HL) - c.set(0x30, 0x30, 0x30); - else if (n == WINFG_DIM) - c.set(0xB8, 0xB8, 0xB8); - else if (n == WINFG_DIM_HL) - c.set(0x90, 0x90, 0x90); + else if (n == WINFG) + c.set(0x60, 0x60, 0x60); + else if (n == WINFG_HL) + c.set(0x30, 0x30, 0x30); + else if (n == WINFG_DIM) + c.set(0xB8, 0xB8, 0xB8); + else if (n == WINFG_DIM_HL) + c.set(0x90, 0x90, 0x90); #else - else if (n == WINFG) - c.set(0xa0, 0xa0, 0xa0); - else if (n == WINFG_HL) - c.set(0xd0, 0xd0, 0xd0); - else if (n == WINFG_DIM) - c.set(0x48, 0x48, 0x48); - else if (n == WINFG_DIM_HL) - c.set(0x70, 0x70, 0x70); + else if (n == WINFG) + c.set(0xa0, 0xa0, 0xa0); + else if (n == WINFG_HL) + c.set(0xd0, 0xd0, 0xd0); + else if (n == WINFG_DIM) + c.set(0x48, 0x48, 0x48); + else if (n == WINFG_DIM_HL) + c.set(0x70, 0x70, 0x70); #endif - /* WINLABEL is for text of lesser importance. For example, - the brackets around key binding are displayed in WINLABEL, - while what's between them is displayed in WINFG. The - difference with WINFG is not very noticeable but it does - improve readability. The static text in the object info - windows should be displayed in WINLABEL. */ + /* WINLABEL is for text of lesser importance. For example, + the brackets around key binding are displayed in WINLABEL, + while what's between them is displayed in WINFG. The + difference with WINFG is not very noticeable but it does + improve readability. The static text in the object info + windows should be displayed in WINLABEL. */ #ifdef WHITE_BACKGROUND - else if (n == WINLABEL) - c.set(0x88, 0x88, 0x88); - else if (n == WINLABEL_HL) - c.set(0x60, 0x60, 0x60); - else if (n == WINLABEL_DIM) - c.set(0xc8, 0xc8, 0xc8); - else if (n == WINLABEL_DIM_HL) - c.set(0xb0, 0xb0, 0xb0); + else if (n == WINLABEL) + c.set(0x88, 0x88, 0x88); + else if (n == WINLABEL_HL) + c.set(0x60, 0x60, 0x60); + else if (n == WINLABEL_DIM) + c.set(0xc8, 0xc8, 0xc8); + else if (n == WINLABEL_DIM_HL) + c.set(0xb0, 0xb0, 0xb0); #else - else if (n == WINLABEL) - c.set(0x78, 0x78, 0x78); - else if (n == WINLABEL_HL) - c.set(0xa0, 0xa0, 0xa0); - else if (n == WINLABEL_DIM) - c.set(0x38, 0x38, 0x38); - else if (n == WINLABEL_DIM_HL) - c.set(0x50, 0x50, 0x50); + else if (n == WINLABEL) + c.set(0x78, 0x78, 0x78); + else if (n == WINLABEL_HL) + c.set(0xa0, 0xa0, 0xa0); + else if (n == WINLABEL_DIM) + c.set(0x38, 0x38, 0x38); + else if (n == WINLABEL_DIM_HL) + c.set(0x50, 0x50, 0x50); #endif #ifdef WHITE_BACKGROUND - else if (n == GRID1) - c.set(0x80, 0x80, 0xff); - else if (n == GRID2H) - c.set(0xf0, 0xf0, 0xff); - else if (n == GRID2V) - c.set(0xf0, 0xf0, 0xff); - else if (n == GRID3H) - c.set(0xd0, 0xd0, 0xff); - else if (n == GRID3V) - c.set(0xd0, 0xd0, 0xff); - else if (n == GRID4H) - c.set(0xb0, 0xb0, 0xff); - else if (n == GRID4V) - c.set(0xb0, 0xb0, 0xff); + else if (n == GRID1) + c.set(0x80, 0x80, 0xff); + else if (n == GRID2H) + c.set(0xf0, 0xf0, 0xff); + else if (n == GRID2V) + c.set(0xf0, 0xf0, 0xff); + else if (n == GRID3H) + c.set(0xd0, 0xd0, 0xff); + else if (n == GRID3V) + c.set(0xd0, 0xd0, 0xff); + else if (n == GRID4H) + c.set(0xb0, 0xb0, 0xff); + else if (n == GRID4V) + c.set(0xb0, 0xb0, 0xff); #else - else if (n == GRID1) - c.set(0, 0, 0xc0); - else if (n == GRID2H) - c.set(0, 0, 0x30); - else if (n == GRID2V) - c.set(0, 0, 0x40); - else if (n == GRID3H) - c.set(0, 0, 0x50); - else if (n == GRID3V) - c.set(0, 0, 0x70); - else if (n == GRID4H) - c.set(0, 0, 0x80); - else if (n == GRID4V) - c.set(0, 0, 0xc0); + else if (n == GRID1) + c.set(0, 0, 0xc0); + else if (n == GRID2H) + c.set(0, 0, 0x30); + else if (n == GRID2V) + c.set(0, 0, 0x40); + else if (n == GRID3H) + c.set(0, 0, 0x50); + else if (n == GRID3V) + c.set(0, 0, 0x70); + else if (n == GRID4H) + c.set(0, 0, 0x80); + else if (n == GRID4V) + c.set(0, 0, 0xc0); #endif - else if (n == LINEDEF_NO) - c.set(0x40, 0xd0, 0xf0); - else if (n == SECTOR_NO) - c.set(0x40, 0xd0, 0xf0); - else if (n == THING_NO) - c.set(0x40, 0xd0, 0xf0); - else if (n == VERTEX_NO) - c.set(0x40, 0xd0, 0xf0); - else if (n == CLR_ERROR) - c.set(0xff, 0, 0); - else if (n == THING_REM) - c.set(0x40, 0x40, 0x40); + else if (n == LINEDEF_NO) + c.set(0x40, 0xd0, 0xf0); + else if (n == SECTOR_NO) + c.set(0x40, 0xd0, 0xf0); + else if (n == THING_NO) + c.set(0x40, 0xd0, 0xf0); + else if (n == VERTEX_NO) + c.set(0x40, 0xd0, 0xf0); + else if (n == CLR_ERROR) + c.set(0xff, 0, 0); + else if (n == THING_REM) + c.set(0x40, 0x40, 0x40); - else if (n == SECTOR_TAG) - c.set(0x00, 0xff, 0x00); - else if (n == SECTOR_TAGTYPE) - c.set(0x00, 0xe0, 0xe0); - else if (n == SECTOR_TYPE) - c.set(0x00, 0x80, 0xff); + else if (n == SECTOR_TAG) + c.set(0x00, 0xff, 0x00); + else if (n == SECTOR_TAGTYPE) + c.set(0x00, 0xe0, 0xe0); + else if (n == SECTOR_TYPE) + c.set(0x00, 0x80, 0xff); #ifdef WHITE_BACKGROUND - else if (n == WINTITLE) - c.set(0xb0, 0x80, 0x00); + else if (n == WINTITLE) + c.set(0xb0, 0x80, 0x00); #else - else if (n == WINTITLE) - c.set(0xff, 0xff, 0x00); + else if (n == WINTITLE) + c.set(0xff, 0xff, 0x00); #endif - else - fatal_error("Wrong acn %d", n); + else + fatal_error("Wrong acn %d", n); - acolour_t acn = add_app_colour(c); - if (acn != n) - fatal_error("add_base_colours: got %d for %d\n", acn, n); + acolour_t acn = add_app_colour(c); + if (acn != n) + fatal_error("add_base_colours: got %d for %d\n", acn, n); } } @@ -1324,8 +1324,8 @@ const Wad_file *wf; for (wad_list.rewind(); wad_list.get(wf);) - if (fncmp(pathname, wf->pathname()) == 0) - return wf; + if (fncmp(pathname, wf->pathname()) == 0) + return wf; return 0; } diff -r 594dea11ccd9 -r a68786b9c74b src/yadex.h --- a/src/yadex.h Sat Sep 24 15:01:56 2011 +0300 +++ b/src/yadex.h Sat Sep 24 15:59:33 2011 +0300 @@ -1,7 +1,7 @@ /* - * yadex.h - * The header that all modules include. - * BW & RQ sometime in 1993 or 1994. + * yadex.h + * The header that all modules include. + * BW & RQ sometime in 1993 or 1994. */ @@ -28,7 +28,7 @@ */ -#ifndef YH_YADEX /* DO NOT INSERT ANYTHING BEFORE THIS LINE */ +#ifndef YH_YADEX /* DO NOT INSERT ANYTHING BEFORE THIS LINE */ #define YH_YADEX @@ -40,7 +40,7 @@ /* - * Standard headers + * Standard headers */ #include <stddef.h> #include <stdio.h> @@ -55,18 +55,18 @@ #endif /* - * Additional libraries + * Additional libraries */ #include <atclib.h> -#include "bitvec.h" /* bv_set, bv_clear, bv_toggle */ +#include "bitvec.h" /* bv_set, bv_clear, bv_toggle */ #include "yerror.h" -#include "aym.h" /* Needs yerror.h */ +#include "aym.h" /* Needs yerror.h */ #include "windim.h" #include "ymemory.h" /* - * Platform-independant types and formats. + * Platform-independant types and formats. */ typedef unsigned char u8; typedef signed char i8; @@ -89,11 +89,11 @@ /* - * Platform definitions + * Platform definitions */ #if defined Y_DOS -const int Y_PATH = 64; // Maximum length of a path -const int Y_FILE_NAME = 255; // Maximum length of file name, including path +const int Y_PATH = 64; // Maximum length of a path +const int Y_FILE_NAME = 255; // Maximum length of file name, including path #elif defined Y_UNIX const int Y_PATH = 255; const int Y_FILE_NAME = 255; @@ -102,7 +102,7 @@ /* - * Constants of the universe. + * Constants of the universe. */ const double HALFPI = 1.5707963; const double ONEPI = 3.1415926; @@ -111,15 +111,15 @@ /* - * Syntactic sugar + * Syntactic sugar */ #define y_min(a,b) ((a) < (b) ? (a) : (b)) #define y_max(a,b) ((a) > (b) ? (a) : (b)) -const char *const Y_NULL = 0; // NULL (const char *) +const char *const Y_NULL = 0; // NULL (const char *) /* - * To avoid including certain headers. + * To avoid including certain headers. */ class rgb_c; @@ -128,10 +128,10 @@ /* - * Doom definitions - * Things about the Doom engine - * FIXME should move as much of this as possible to the ygd file... - * FIXME Hexen has a different value for MIN_DEATHMATH_STARTS + * Doom definitions + * Things about the Doom engine + * FIXME should move as much of this as possible to the ygd file... + * FIXME Hexen has a different value for MIN_DEATHMATH_STARTS */ const int DOOM_PLAYER_HEIGHT = 56; const int DOOM_FLAT_WIDTH = 64; @@ -148,7 +148,7 @@ /* - * Directory + * Directory */ /* The wad file pointer structure is used for holding the information on the wad files in a linked list. @@ -160,9 +160,9 @@ typedef struct MasterDirectory *MDirPtr; struct MasterDirectory { - MDirPtr next; // Next in list - const Wad_file *wadfile; // File of origin - struct Directory dir; // Directory data + MDirPtr next; // Next in list + const Wad_file *wadfile; // File of origin + struct Directory dir; // Directory data }; /* Lump location : enough information to load a lump without @@ -171,17 +171,17 @@ { Lump_loc() { - wad = 0; + wad = 0; } Lump_loc(const Wad_file * w, i32 o, i32 l) { - wad = w; - ofs = o; - len = l; + wad = w; + ofs = o; + len = l; } bool operator ==(const Lump_loc & other) const { - return wad == other.wad && ofs == other.ofs && len == other.len; + return wad == other.wad && ofs == other.ofs && len == other.len; } const Wad_file *wad; i32 ofs; @@ -192,17 +192,17 @@ /* - * The colour system. - * FIXME: only the logical side of the colour system - * should be declared here. The physical side should - * be moved to a less used header as very few modules - * need to know about it. + * The colour system. + * FIXME: only the logical side of the colour system + * should be declared here. The physical side should + * be moved to a less used header as very few modules + * need to know about it. */ /* acolour_t -- an application colour number. Several different application colours may refer to the same physical colour. */ typedef u8 acolour_t; -#define ACOLOUR_NONE 0xff // The out-of-band value +#define ACOLOUR_NONE 0xff // The out-of-band value /* The 16 VGA colours that DEU used to use. FIXME: all references to these in the code should be removed. */ @@ -252,7 +252,7 @@ const acolour_t THING_NO = 37; const acolour_t VERTEX_NO = 38; const acolour_t CLR_ERROR = 39; -const acolour_t THING_REM = 40; // Things when not in things mode +const acolour_t THING_REM = 40; // Things when not in things mode const acolour_t SECTOR_TAG = 41; const acolour_t SECTOR_TAGTYPE = 42; @@ -264,16 +264,16 @@ /* - * More stuff + * More stuff */ // The actual definition is in selectn.h typedef struct SelectionList *SelPtr; // Operations on the selection : typedef enum { - YS_ADD = BV_SET, // Add to selection - YS_REMOVE = BV_CLEAR, // Remove from selection - YS_TOGGLE = BV_TOGGLE // If not in selection, add; else, remove + YS_ADD = BV_SET, // Add to selection + YS_REMOVE = BV_CLEAR, // Remove from selection + YS_TOGGLE = BV_TOGGLE // If not in selection, add; else, remove } sel_op_t; // Confirmation options are stored internally this way : @@ -286,142 +286,142 @@ } confirm_t; // Bit bashing operations -const int YO_AND = 'a'; // Argument = mask -const int YO_CLEAR = 'c'; // Argument = bit# -const int YO_COPY = 'd'; // Argument = source_bit# dest_bit# -const int YO_OR = 'o'; // Argument = mask -const int YO_SET = 's'; // Argument = bit# -const int YO_TOGGLE = 't'; // Argument = bit# -const int YO_XOR = 'x'; // Argument = mask +const int YO_AND = 'a'; // Argument = mask +const int YO_CLEAR = 'c'; // Argument = bit# +const int YO_COPY = 'd'; // Argument = source_bit# dest_bit# +const int YO_OR = 'o'; // Argument = mask +const int YO_SET = 's'; // Argument = bit# +const int YO_TOGGLE = 't'; // Argument = bit# +const int YO_XOR = 'x'; // Argument = mask /* - * Even more stuff ("the macros and constants") + * Even more stuff ("the macros and constants") */ -extern const char *const log_file; // "yadex.log" -extern const char *const msg_unexpected; // "unexpected error" -extern const char *const msg_nomem; // "Not enough memory" +extern const char *const log_file; // "yadex.log" +extern const char *const msg_unexpected; // "unexpected error" +extern const char *const msg_nomem; // "Not enough memory" // Convert screen/window coordinates to map coordinates -#define MAPX(x) (OrigX + (int) (((int) (x) - ScrCenterX) / Scale)) -#define MAPY(y) (OrigY + (int) ((ScrCenterY - (int) (y)) / Scale)) +#define MAPX(x) (OrigX + (int) (((int) (x) - ScrCenterX) / Scale)) +#define MAPY(y) (OrigY + (int) ((ScrCenterY - (int) (y)) / Scale)) // Convert map coordinates to screen/window coordinates -#define SCREENX(x) (ScrCenterX + (int) (((x) - OrigX) * Scale)) -#define SCREENY(y) (ScrCenterY + (int) ((OrigY - (y)) * Scale)) +#define SCREENX(x) (ScrCenterX + (int) (((x) - OrigX) * Scale)) +#define SCREENY(y) (ScrCenterY + (int) ((OrigY - (y)) * Scale)) // AYM 19980213: InputIntegerValue() uses this to mean that Esc was pressed #define IIV_CANCEL INT_MIN /* - * Not real variables -- just a way for functions - * that return pointers to report errors in a better - * fashion than by just returning NULL and setting - * a global variable. + * Not real variables -- just a way for functions + * that return pointers to report errors in a better + * fashion than by just returning NULL and setting + * a global variable. */ -extern char error_non_unique[1]; // Found more than one -extern char error_none[1]; // Found none -extern char error_invalid[1]; // Invalid parameter +extern char error_non_unique[1]; // Found more than one +extern char error_none[1]; // Found none +extern char error_invalid[1]; // Invalid parameter /* - * Interfile global variables + * Interfile global variables */ // Defined in yadex.cc -extern const char *install_dir; // Where yadex is installed -extern FILE *logfile; // Filepointer to the error log -extern bool Registered; // Registered or shareware iwad ? -extern int screen_lines; // Lines that our TTY can display -extern int remind_to_build_nodes; // Remind the user to build nodes +extern const char *install_dir; // Where yadex is installed +extern FILE *logfile; // Filepointer to the error log +extern bool Registered; // Registered or shareware iwad ? +extern int screen_lines; // Lines that our TTY can display +extern int remind_to_build_nodes; // Remind the user to build nodes // Defined in yadex.c and set from // command line and/or config file -extern bool autoscroll; // Autoscrolling enabled. -extern unsigned long autoscroll_amp; // Amplitude in percents of screen/window size. -extern unsigned long autoscroll_edge; // Max. dist. in pixels to edge. -extern const char *config_file; // Name of the configuration file +extern bool autoscroll; // Autoscrolling enabled. +extern unsigned long autoscroll_amp; // Amplitude in percents of screen/window size. +extern unsigned long autoscroll_edge; // Max. dist. in pixels to edge. +extern const char *config_file; // Name of the configuration file extern int copy_linedef_reuse_sidedefs; -extern int cpu_big_endian; // Am I running on a big-endian CPU ? -extern bool Debug; // Are we debugging? -extern int default_ceiling_height; // For new sectors -extern char default_ceiling_texture[WAD_FLAT_NAME + 1]; // For new sectors -extern int default_floor_height; // For new sectors -extern char default_floor_texture[WAD_FLAT_NAME + 1]; // For new sectors -extern int default_light_level; // For new sectors -extern char default_lower_texture[WAD_TEX_NAME + 1]; // For new linedefs -extern char default_middle_texture[WAD_TEX_NAME + 1]; // For new linedefs -extern int default_thing; // For new THINGS -extern char default_upper_texture[WAD_TEX_NAME + 1]; // For new linedefs -extern int double_click_timeout; // Max ms between clicks of double click. -extern bool Expert; // Don't ask for confirmation for some ops. -extern const char *Game; // Name of game "doom", "doom2", "heretic", ... -extern int grid_pixels_min; // Minimum grid step in pixels when not locked -extern int GridMin; // Minimum grid step in map units -extern int GridMax; // Maximum grid step in map units -extern int idle_sleep_ms; // Time to sleep after empty XPending() -extern int zoom_default; // Initial zoom factor for map -extern int zoom_step; // Step between zoom factors in percent -extern int digit_zoom_base; // Zoom factor of `1' key, in percent -extern int digit_zoom_step; // Step between digit keys, in percent +extern int cpu_big_endian; // Am I running on a big-endian CPU ? +extern bool Debug; // Are we debugging? +extern int default_ceiling_height; // For new sectors +extern char default_ceiling_texture[WAD_FLAT_NAME + 1]; // For new sectors +extern int default_floor_height; // For new sectors +extern char default_floor_texture[WAD_FLAT_NAME + 1]; // For new sectors +extern int default_light_level; // For new sectors +extern char default_lower_texture[WAD_TEX_NAME + 1]; // For new linedefs +extern char default_middle_texture[WAD_TEX_NAME + 1]; // For new linedefs +extern int default_thing; // For new THINGS +extern char default_upper_texture[WAD_TEX_NAME + 1]; // For new linedefs +extern int double_click_timeout; // Max ms between clicks of double click. +extern bool Expert; // Don't ask for confirmation for some ops. +extern const char *Game; // Name of game "doom", "doom2", "heretic", ... +extern int grid_pixels_min; // Minimum grid step in pixels when not locked +extern int GridMin; // Minimum grid step in map units +extern int GridMax; // Maximum grid step in map units +extern int idle_sleep_ms; // Time to sleep after empty XPending() +extern int zoom_default; // Initial zoom factor for map +extern int zoom_step; // Step between zoom factors in percent +extern int digit_zoom_base; // Zoom factor of `1' key, in percent +extern int digit_zoom_step; // Step between digit keys, in percent extern confirm_t insert_vertex_merge_vertices; extern confirm_t insert_vertex_split_linedef; extern bool blindly_swap_sidedefs; -extern const char *Iwad1; // Name of the Doom iwad -extern const char *Iwad2; // Name of the Doom II iwad -extern const char *Iwad3; // Name of the Heretic iwad -extern const char *Iwad4; // Name of the Hexen iwad -extern const char *Iwad5; // Name of the Strife iwad -extern const char *Iwad6; // Name of the Doom alpha 0.2 iwad -extern const char *Iwad7; // Name of the Doom alpha 0.4 iwad -extern const char *Iwad8; // Name of the Doom alpha 0.5 iwad -extern const char *Iwad9; // Name of the Doom press release iwad -extern const char *Iwad10; // Name of the Strife 1.0 iwad -extern const char *MainWad; // Name of the main wad file +extern const char *Iwad1; // Name of the Doom iwad +extern const char *Iwad2; // Name of the Doom II iwad +extern const char *Iwad3; // Name of the Heretic iwad +extern const char *Iwad4; // Name of the Hexen iwad +extern const char *Iwad5; // Name of the Strife iwad +extern const char *Iwad6; // Name of the Doom alpha 0.2 iwad +extern const char *Iwad7; // Name of the Doom alpha 0.4 iwad +extern const char *Iwad8; // Name of the Doom alpha 0.5 iwad +extern const char *Iwad9; // Name of the Doom press release iwad +extern const char *Iwad10; // Name of the Strife 1.0 iwad +extern const char *MainWad; // Name of the main wad file #ifdef AYM_MOUSE_HACKS extern int MouseMickeysH; extern int MouseMickeysV; #endif -extern char **PatchWads; // List of pwad files -extern bool Quiet; // Don't beep when an object is selected -extern bool Quieter; // Don't beep, even on error -extern unsigned long scroll_less; // %s of screenful to scroll by -extern unsigned long scroll_more; // %s of screenful to scroll by -extern bool Select0; // Autom. select obj. 0 when switching modes -extern int show_help; // Print usage message and exit. -extern int sprite_scale; // Relative scale used to display sprites -extern bool SwapButtons; // Swap right and middle mouse buttons -extern int verbose; // Verbose mode -extern int welcome_message; // Print the welcome message on startup. -extern const char *bench; // Benchmark to run +extern char **PatchWads; // List of pwad files +extern bool Quiet; // Don't beep when an object is selected +extern bool Quieter; // Don't beep, even on error +extern unsigned long scroll_less; // %s of screenful to scroll by +extern unsigned long scroll_more; // %s of screenful to scroll by +extern bool Select0; // Autom. select obj. 0 when switching modes +extern int show_help; // Print usage message and exit. +extern int sprite_scale; // Relative scale used to display sprites +extern bool SwapButtons; // Swap right and middle mouse buttons +extern int verbose; // Verbose mode +extern int welcome_message; // Print the welcome message on startup. +extern const char *bench; // Benchmark to run // Defined in gfx.cc -extern int ScrMaxX; // Maximum display X-coord of screen/window -extern int ScrMaxY; // Maximum display Y-coord of screen/window -extern float Scale; // Scale to draw map 20 to 1 +extern int ScrMaxX; // Maximum display X-coord of screen/window +extern int ScrMaxY; // Maximum display Y-coord of screen/window +extern float Scale; // Scale to draw map 20 to 1 // Defined in wads.cc -extern MDirPtr MasterDir; // The master directory +extern MDirPtr MasterDir; // The master directory class Serial_num; -extern Serial_num master_dir_serial; // The revision# thereof +extern Serial_num master_dir_serial; // The revision# thereof // Defined in edit.cc -extern bool InfoShown; // Is the bottom line displayed? +extern bool InfoShown; // Is the bottom line displayed? /* - * Prototypes - * AYM 1998-10-16: DEU used to have _all_ prototypes here. Thus - * I had to recompile _all_ the modules every time I changed - * a single prototype. To avoid this, my theory is to put all - * the prototypes I can in individual headers. There is still - * room for improvement on that matter... + * Prototypes + * AYM 1998-10-16: DEU used to have _all_ prototypes here. Thus + * I had to recompile _all_ the modules every time I changed + * a single prototype. To avoid this, my theory is to put all + * the prototypes I can in individual headers. There is still + * room for improvement on that matter... */ // checks.cc (previously in editobj.cc) -void CheckLevel(int, int, int pulldown); /* SWAP! */ -bool CheckStartingPos(void); /* SWAP! */ +void CheckLevel(int, int, int pulldown); /* SWAP! */ +bool CheckStartingPos(void); /* SWAP! */ // colour1.cc int getcolour(const char *s, rgb_c * rgb); @@ -437,8 +437,8 @@ int InputObjectXRef(int, int, int, bool, int); bool Input2VertexNumbers(int, int, const char *, int *, int *); void EditObjectsInfo(int, int, int, SelPtr); -void InsertStandardObject(int, int, int choice); /* SWAP! */ -void MiscOperations(int, SelPtr *, int choice); /* SWAP! */ +void InsertStandardObject(int, int, int choice); /* SWAP! */ +void MiscOperations(int, SelPtr *, int choice); /* SWAP! */ // game.cc void InitGameDefs(void); @@ -453,13 +453,13 @@ #include "input.h" // l_align.cc (previously in objects.cc) -void AlignTexturesY(SelPtr *); /* SWAP! */ -void AlignTexturesX(SelPtr *); /* SWAP! */ +void AlignTexturesY(SelPtr *); /* SWAP! */ +void AlignTexturesX(SelPtr *); /* SWAP! */ // l_misc.cc (previously in objects.cc) -void FlipLineDefs(SelPtr, bool); /* SWAP! */ -void SplitLineDefs(SelPtr); /* SWAP! */ -void MakeRectangularNook(SelPtr obj, int width, int depth, int convex); /* SWAP! */ +void FlipLineDefs(SelPtr, bool); /* SWAP! */ +void SplitLineDefs(SelPtr); /* SWAP! */ +void MakeRectangularNook(SelPtr obj, int width, int depth, int convex); /* SWAP! */ void SetLinedefLength(SelPtr obj, int length, int move_2nd_vertex); // l_prop.cc (previously in editobj.cc) @@ -470,9 +470,9 @@ void unlink_sidedef(SelPtr linedefs, int side1, int side2); // levels.cc -int ReadLevelData(const char *); /* SWAP! */ -void ForgetLevelData(void); /* SWAP! */ -int SaveLevelData(const char *, const char *level_name); /* SWAP! */ +int ReadLevelData(const char *); /* SWAP! */ +void ForgetLevelData(void); /* SWAP! */ +int SaveLevelData(const char *, const char *level_name); /* SWAP! */ void ReadWTextureNames(void); void ForgetFTextureNames(void); int is_flat_name_in_list(const char *name); @@ -493,18 +493,18 @@ void nop(...); // s_door.cc (previously in objects.cc) -void MakeDoorFromSector(int); /* SWAP! */ +void MakeDoorFromSector(int); /* SWAP! */ // s_lift.cc (previously in objects.cc) -void MakeLiftFromSector(int); /* SWAP! */ +void MakeLiftFromSector(int); /* SWAP! */ // s_merge.cc (previously in objects.cc) -void MergeSectors(SelPtr *); /* SWAP! */ -void DeleteLineDefsJoinSectors(SelPtr *); /* SWAP! */ +void MergeSectors(SelPtr *); /* SWAP! */ +void DeleteLineDefsJoinSectors(SelPtr *); /* SWAP! */ // s_misc.cc (previously in objects.cc) -void DistributeSectorFloors(SelPtr); /* SWAP! */ -void DistributeSectorCeilings(SelPtr); /* SWAP! */ +void DistributeSectorFloors(SelPtr); /* SWAP! */ +void DistributeSectorCeilings(SelPtr); /* SWAP! */ void RaiseOrLowerSectors(SelPtr obj); void BrightenOrDarkenSectors(SelPtr obj); void SuperSectorSelector(int map_x, int map_y, int new_sec); @@ -514,9 +514,9 @@ void TransferSectorProperties(int src_sector, SelPtr sectors); // s_split.cc (previously in objects.cc) -void SplitSector(int, int); /* SWAP! */ -void SplitLineDefsAndSector(int, int); /* SWAP! */ -void MultiSplitLineDefsAndSector(int, int); /* SWAP! */ +void SplitSector(int, int); /* SWAP! */ +void SplitLineDefsAndSector(int, int); /* SWAP! */ +void MultiSplitLineDefsAndSector(int, int); /* SWAP! */ // scrnshot.cc void ScreenShot(void); @@ -527,9 +527,9 @@ void TransferThingProperties(int src_thing, SelPtr things); // v_merge.cc -void DeleteVerticesJoinLineDefs(SelPtr); /* SWAP! */ -void MergeVertices(SelPtr *); /* SWAP! */ -bool AutoMergeVertices(SelPtr *, int obj_type, char operation); /* SWAP! */ +void DeleteVerticesJoinLineDefs(SelPtr); /* SWAP! */ +void MergeVertices(SelPtr *); /* SWAP! */ +bool AutoMergeVertices(SelPtr *, int obj_type, char operation); /* SWAP! */ // v_polyg.cc void InsertPolygonVertices(int, int, int, int); diff -r 594dea11ccd9 -r a68786b9c74b src/yerror.h --- a/src/yerror.h Sat Sep 24 15:01:56 2011 +0300 +++ b/src/yerror.h Sat Sep 24 15:59:33 2011 +0300 @@ -1,6 +1,6 @@ /* - * yerror.h - * AYM 1999-03-24 + * yerror.h + * AYM 1999-03-24 */ diff -r 594dea11ccd9 -r a68786b9c74b src/ymemory.h --- a/src/ymemory.h Sat Sep 24 15:01:56 2011 +0300 +++ b/src/ymemory.h Sat Sep 24 15:59:33 2011 +0300 @@ -1,7 +1,7 @@ /* - * ymemory.h - * Memory allocation functions. - * AYM 1999-03-24 + * ymemory.h + * Memory allocation functions. + * AYM 1999-03-24 */ diff -r 594dea11ccd9 -r a68786b9c74b src/ytime.cc --- a/src/ytime.cc Sat Sep 24 15:01:56 2011 +0300 +++ b/src/ytime.cc Sat Sep 24 15:59:33 2011 +0300 @@ -1,6 +1,6 @@ /* - * ytime.cc - * AYM 1999-11-11 + * ytime.cc + * AYM 1999-11-11 */ @@ -36,7 +36,7 @@ /* - * Return the current time in ms + * Return the current time in ms */ unsigned long y_milliseconds() { @@ -45,8 +45,8 @@ struct timezone tz; if (gettimeofday(&tv, &tz)) { - nf_bug("gettimeofday() error (%s)", strerror(errno)); - return 0; + nf_bug("gettimeofday() error (%s)", strerror(errno)); + return 0; } return tv.tv_sec * 1000 + tv.tv_usec / 1000; #else /* Sucks ! */ diff -r 594dea11ccd9 -r a68786b9c74b src/ytime.h --- a/src/ytime.h Sat Sep 24 15:01:56 2011 +0300 +++ b/src/ytime.h Sat Sep 24 15:59:33 2011 +0300 @@ -1,10 +1,10 @@ /* - * ytime.h - * AYM 1999-11-11 + * ytime.h + * AYM 1999-11-11 */ -#ifndef YH_YTIME /* DO NOT INSERT ANYTHING BEFORE THIS LINE */ +#ifndef YH_YTIME /* DO NOT INSERT ANYTHING BEFORE THIS LINE */ #define YH_YTIME