/* * Initialise SDL and open the mixer */ static bool open_audio(void) { int audio_rate; Uint16 audio_format; int audio_channels; /* Initialize variables */ audio_rate = 22050; audio_format = AUDIO_S16; audio_channels = 2; /* Initialize the SDL library */ if (SDL_Init(SDL_INIT_AUDIO) < 0) { plog_fmt("Couldn't initialize SDL: %s", SDL_GetError()); return FALSE; } /* Try to open the audio */ if (Mix_OpenAudio(audio_rate, audio_format, audio_channels, 4096) < 0) { plog_fmt("Couldn't open mixer: %s", SDL_GetError()); return FALSE; } /* Success */ return TRUE; }
/* * Request a Pixell by name. Note: uses 'Metadpy'. * * Inputs: * name: The name of the color to try to load (see below) * * Output: * The Pixell value that metched the given name * 'Metadpy->fg' if the name was unparseable * * Valid forms for 'name': * 'fg', 'bg', 'zg', '<name>' and '#<code>' */ static Pixell Infoclr_Pixell(cptr name) { XColor scrn; /* Attempt to Parse the name */ if (name && name[0]) { /* The 'bg' color is available */ if (streq(name, "bg")) return (Metadpy->bg); /* The 'fg' color is available */ if (streq(name, "fg")) return (Metadpy->fg); /* The 'zg' color is available */ if (streq(name, "zg")) return (Metadpy->zg); /* The 'white' color is available */ if (streq(name, "white")) return (Metadpy->white); /* The 'black' color is available */ if (streq(name, "black")) return (Metadpy->black); /* Attempt to parse 'name' into 'scrn' */ if (!(XParseColor(Metadpy->dpy, Metadpy->cmap, name, &scrn))) { plog_fmt("Warning: Couldn't parse color '%s'\n", name); } /* Attempt to Allocate the Parsed color */ if (!(XAllocColor(Metadpy->dpy, Metadpy->cmap, &scrn))) { plog_fmt("Warning: Couldn't allocate color '%s'\n", name); } /* The Pixel was Allocated correctly */ else return (scrn.pixel); } /* Warn about the Default being Used */ plog_fmt("Warning: Using 'fg' for unknown color '%s'\n", name); /* Default to the 'Foreground' color */ return (Metadpy->fg); }
/** * Iterate through all the sound types supporting by the platform's sound * module. Call the platform's sound modules 'load sound' function for each * supported file type until the platform's sound module tell us that it * could load the sound. * NOTE: The platform's sound module does not have to load the sound into * memory, it merely has to let us know that it can play the sound when * asked to. */ static void load_sound(struct sound_data *sound_data) { if ((hooks.load_sound_hook) && (hooks.supported_files_hook)) { char path[2048]; char *filename_buf; size_t filename_buf_size; int i = 0; bool load_success = false; const struct sound_file_type *supported_sound_files = hooks.supported_files_hook(); /* Build the path to the sound file (minus extension) */ path_build(path, sizeof(path), ANGBAND_DIR_SOUNDS, sound_data->name); /* * Loop through all the extensions supported by the * platform's sound module. */ while ((0 != supported_sound_files[i].type) && (!load_success)) { /* * Create a buffer to store the filename plus extension */ filename_buf_size = strlen(path) + strlen(supported_sound_files[i].extension) + 1; filename_buf = mem_zalloc(filename_buf_size); my_strcpy(filename_buf, path, filename_buf_size); filename_buf = string_append(filename_buf, supported_sound_files[i].extension); if (file_exists(filename_buf)) load_success = hooks.load_sound_hook(filename_buf, supported_sound_files[i].type, sound_data); mem_free(filename_buf); i++; } if (!load_success) plog_fmt("Failed to load sound '%s'", sound_data->name); } }
/* * Prepare "curses" for use by the file "z-term.c" * * Installs the "hook" functions defined above, and then activates * the main screen "term", which clears the screen and such things. * * Someone should really check the semantics of "initscr()" */ errr init_gcu(int argc, char **argv) { int i; int num_term = MAX_TERM_DATA, next_win = 0; bool use_big_screen = FALSE; /* Parse args */ for (i = 1; i < argc; i++) { if (prefix(argv[i], "-b")) { use_big_screen = TRUE; continue; } plog_fmt("Ignoring option: %s", argv[i]); } /* Extract the normal keymap */ keymap_norm_prepare(); /* Initialize */ if (initscr() == NULL) return (-1); /* Activate hooks */ quit_aux = hook_quit; core_aux = hook_quit; /* Require standard size screen */ if ((LINES < 24) || (COLS < 80)) { quit(GAME_NAME " needs at least an 80x24 'curses' screen"); } #ifdef USE_GRAPHICS /* Set graphics flag */ use_graphics = arg_graphics; #endif #ifdef A_COLOR /*** Init the Color-pairs and set up a translation table ***/ /* Do we have color, and enough color, available? */ can_use_color = ((start_color() != ERR) && has_colors() && (COLORS >= 8) && (COLOR_PAIRS >= 8)); #ifdef REDEFINE_COLORS /* Can we change colors? */ can_fix_color = (can_use_color && can_change_color() && (COLORS >= 16) && (COLOR_PAIRS > 8)); #endif /* Attempt to use customized colors */ if (can_fix_color) { /* Prepare the color pairs */ for (i = 1; i <= 8; i++) { /* Reset the color */ if (init_pair(i, i - 1, 0) == ERR) { quit("Color pair init failed"); } /* Set up the colormap */ colortable[i - 1] = (COLOR_PAIR(i) | A_NORMAL); colortable[i + 7] = (COLOR_PAIR(i) | A_BRIGHT); } /* Take account of "gamma correction" XXX XXX XXX */ /* Prepare the "Angband Colors" */ Term_xtra_gcu_react(); } /* Attempt to use colors */ else if (can_use_color) { /* Color-pair 0 is *always* WHITE on BLACK */ /* Prepare the color pairs */ init_pair(1, COLOR_RED, COLOR_BLACK); init_pair(2, COLOR_GREEN, COLOR_BLACK); init_pair(3, COLOR_YELLOW, COLOR_BLACK); init_pair(4, COLOR_BLUE, COLOR_BLACK); init_pair(5, COLOR_MAGENTA, COLOR_BLACK); init_pair(6, COLOR_CYAN, COLOR_BLACK); init_pair(7, COLOR_BLACK, COLOR_BLACK); /* Prepare the "Angband Colors" -- Bright white is too bright */ colortable[0] = (COLOR_PAIR(7) | A_NORMAL); /* Black */ colortable[1] = (COLOR_PAIR(0) | A_NORMAL); /* White */ colortable[2] = (COLOR_PAIR(6) | A_NORMAL); /* Grey XXX */ colortable[3] = (COLOR_PAIR(1) | A_BRIGHT); /* Orange XXX */ colortable[4] = (COLOR_PAIR(1) | A_NORMAL); /* Red */ colortable[5] = (COLOR_PAIR(2) | A_NORMAL); /* Green */ colortable[6] = (COLOR_PAIR(4) | A_NORMAL); /* Blue */ colortable[7] = (COLOR_PAIR(3) | A_NORMAL); /* Umber */ colortable[8] = (COLOR_PAIR(7) | A_BRIGHT); /* Dark-grey XXX */ colortable[9] = (COLOR_PAIR(6) | A_BRIGHT); /* Light-grey XXX */ colortable[10] = (COLOR_PAIR(5) | A_NORMAL); /* Purple */ colortable[11] = (COLOR_PAIR(3) | A_BRIGHT); /* Yellow */ colortable[12] = (COLOR_PAIR(5) | A_BRIGHT); /* Light Red XXX */ colortable[13] = (COLOR_PAIR(2) | A_BRIGHT); /* Light Green */ colortable[14] = (COLOR_PAIR(4) | A_BRIGHT); /* Light Blue */ colortable[15] = (COLOR_PAIR(3) | A_NORMAL); /* Light Umber XXX */ } #endif /*** Low level preparation ***/ #ifdef USE_GETCH /* Paranoia -- Assume no waiting */ nodelay(stdscr, FALSE); #endif /* Prepare */ cbreak(); noecho(); nonl(); /* Extract the game keymap */ keymap_game_prepare(); /*** Now prepare the term(s) ***/ /* Big screen -- one big term */ if (use_big_screen) { /* Create a term */ term_data_init_gcu(&data[0], LINES, COLS, 0, 0); /* Remember the term */ windows[0].term = &data[0].t; } /* No big screen -- create as many term windows as possible */ else { /* Create several terms */ for (i = 0; i < num_term; i++) { int rows, cols, y, x; /* Decide on size and position */ switch (i) { /* Upper left */ case 0: { rows = 24; cols = 80; y = x = 0; break; } /* Lower left */ case 1: { rows = LINES - 25; cols = 80; y = 25; x = 0; break; } /* Upper right */ case 2: { rows = 24; cols = COLS - 81; y = 0; x = 81; break; } /* Lower right */ case 3: { rows = LINES - 25; cols = COLS - 81; y = 25; x = 81; break; } /* XXX */ default: { rows = cols = y = x = 0; break; } } /* Skip non-existant windows */ if (rows <= 0 || cols <= 0) continue; /* Create a term */ term_data_init_gcu(&data[next_win], rows, cols, y, x); /* Remember the term */ windows[next_win].term = &data[next_win].t; /* One more window */ next_win++; } } /* Activate the "Angband" window screen */ Term_activate(&data[0].t); /* Remember the active screen */ term_screen = &data[0].t; /* Success */ return (0); }
/* * Initialization function for an X Athena Widget module to Angband * * We should accept "-d<dpy>" requests in the "argv" array. XXX XXX XXX */ errr init_xaw(int argc, char *argv[]) { int i; Widget topLevel; Display *dpy; cptr dpy_name = ""; #ifdef USE_GRAPHICS char filename[1024]; int pict_wid = 0; int pict_hgt = 0; #ifdef USE_TRANSPARENCY char *TmpData; #endif /* USE_TRANSPARENCY */ #endif /* USE_GRAPHICS */ /* Parse args */ for (i = 1; i < argc; i++) { if (prefix(argv[i], "-d")) { dpy_name = &argv[i][2]; continue; } #ifdef USE_GRAPHICS if (prefix(argv[i], "-s")) { smoothRescaling = FALSE; continue; } #endif /* USE_GRAPHICS */ if (prefix(argv[i], "-n")) { num_term = atoi(&argv[i][2]); if (num_term > MAX_TERM_DATA) num_term = MAX_TERM_DATA; else if (num_term < 1) num_term = 1; continue; } plog_fmt("Ignoring option: %s", argv[i]); } /* Attempt to open the local display */ dpy = XOpenDisplay(dpy_name); /* Failure -- assume no X11 available */ if (!dpy) return (-1); /* Close the local display */ XCloseDisplay(dpy); #ifdef USE_XAW_LANG /* Support locale processing */ XtSetLanguageProc(NULL, NULL, NULL); #endif /* USE_XAW_LANG */ /* Initialize the toolkit */ topLevel = XtAppInitialize(&appcon, "Angband", NULL, 0, &argc, argv, fallback, NULL, 0); /* Initialize the windows */ for (i = 0; i < num_term; i++) { term_data *td = &data[i]; term_data_init(td, topLevel, 1024, termNames[i], (i == 0) ? specialArgs : defaultArgs, TERM_FALLBACKS, i); angband_term[i] = Term; } /* Activate the "Angband" window screen */ Term_activate(&data[0].t); /* Raise the "Angband" window */ term_raise(&data[0]); #ifdef USE_GRAPHICS /* Try graphics */ if (arg_graphics) { /* Try the "16x16.bmp" file */ path_build(filename, 1024, ANGBAND_DIR_XTRA, "graf/16x16.bmp"); /* Use the "16x16.bmp" file if it exists */ if (0 == fd_close(fd_open(filename, O_RDONLY))) { /* Use graphics */ use_graphics = TRUE; use_transparency = TRUE; pict_wid = pict_hgt = 16; ANGBAND_GRAF = "new"; } else { /* Try the "8x8.bmp" file */ path_build(filename, 1024, ANGBAND_DIR_XTRA, "graf/8x8.bmp"); /* Use the "8x8.bmp" file if it exists */ if (0 == fd_close(fd_open(filename, O_RDONLY))) { /* Use graphics */ use_graphics = TRUE; pict_wid = pict_hgt = 8; ANGBAND_GRAF = "old"; } } } /* Load graphics */ if (use_graphics) { /* Hack -- Get the Display */ term_data *td = &data[0]; Widget widget = (Widget)(td->widget); Display *dpy = XtDisplay(widget); XImage *tiles_raw; /* Load the graphical tiles */ tiles_raw = ReadBMP(dpy, filename); /* Initialize the windows */ for (i = 0; i < num_term; i++) { term_data *td = &data[i]; term *t = &td->t; t->pict_hook = Term_pict_xaw; t->higher_pict = TRUE; /* Resize tiles */ td->widget->angband.tiles = ResizeImage(dpy, tiles_raw, pict_wid, pict_hgt, td->widget->angband.fontwidth, td->widget->angband.fontheight); } #ifdef USE_TRANSPARENCY /* Initialize the transparency temp storage*/ for (i = 0; i < num_term; i++) { term_data *td = &data[i]; int ii, jj; int depth = DefaultDepth(dpy, DefaultScreen(dpy)); Visual *visual = DefaultVisual(dpy, DefaultScreen(dpy)); int total; /* Determine total bytes needed for image */ ii = 1; jj = (depth - 1) >> 2; while (jj >>= 1) ii <<= 1; total = td->widget->angband.fontwidth * td->widget->angband.fontheight * ii; TmpData = (char *)malloc(total); td->widget->angband.TmpImage = XCreateImage(dpy, visual,depth, ZPixmap, 0, TmpData, td->widget->angband.fontwidth, td->widget->angband.fontheight, 8, 0); } #endif /* USE_TRANSPARENCY */ /* Free tiles_raw? XXX XXX */ } #endif /* USE_GRAPHICS */ /* Success */ return (0); }
/** * Prepare "curses" for use by the file "ui-term.c" * * Installs the "hook" functions defined above, and then activates * the main screen "term", which clears the screen and such things. * * Someone should really check the semantics of "initscr()" */ errr init_gcu(int argc, char **argv) { int i; int rows, cols, y, x; int next_win = 0; /* Initialize info about terminal capabilities */ termtype = getenv("TERM"); loaded_terminfo = termtype && tgetent(0, termtype) == 1; /* Parse args */ for (i = 1; i < argc; i++) { if (prefix(argv[i], "-b")) { term_count = 1; } else if (prefix(argv[i], "-B")) { bold_extended = TRUE; } else if (prefix(argv[i], "-a")) { ascii_walls = TRUE; } else if (prefix(argv[i], "-n")) { term_count = atoi(&argv[i][2]); if (term_count > MAX_TERM_DATA) term_count = MAX_TERM_DATA; else if (term_count < 1) term_count = 1; } else { plog_fmt("Ignoring option: %s", argv[i]); } } /* Extract the normal keymap */ keymap_norm_prepare(); /* We do it like this to prevent a link error with curseses that * lack ESCDELAY. */ if (!getenv("ESCDELAY")) putenv("ESCDELAY=20"); /* Initialize */ if (initscr() == NULL) return (-1); /* Activate hooks */ quit_aux = hook_quit; /* Require standard size screen */ if (LINES < MIN_TERM0_LINES || COLS < MIN_TERM0_COLS) quit("Angband needs at least an 80x24 'curses' screen"); #ifdef A_COLOR /* Do we have color, and enough color, available? */ can_use_color = ((start_color() != ERR) && has_colors() && (COLORS >= 8) && (COLOR_PAIRS >= 8)); #ifdef HAVE_USE_DEFAULT_COLORS /* Should we use curses' "default color" */ if (use_default_colors() == OK) bg_color = -1; #endif /* Attempt to use colors */ if (can_use_color) { /* Prepare the color pairs */ /* PAIR_WHITE (pair 0) is *always* WHITE on BLACK */ init_pair(PAIR_RED, COLOR_RED, bg_color); init_pair(PAIR_GREEN, COLOR_GREEN, bg_color); init_pair(PAIR_YELLOW, COLOR_YELLOW, bg_color); init_pair(PAIR_BLUE, COLOR_BLUE, bg_color); init_pair(PAIR_MAGENTA, COLOR_MAGENTA, bg_color); init_pair(PAIR_CYAN, COLOR_CYAN, bg_color); init_pair(PAIR_BLACK, COLOR_BLACK, bg_color); /* Prepare the colors */ colortable[COLOUR_DARK] = (COLOR_PAIR(PAIR_BLACK)); colortable[COLOUR_WHITE] = (COLOR_PAIR(PAIR_WHITE) | A_BRIGHT); colortable[COLOUR_SLATE] = (COLOR_PAIR(PAIR_WHITE)); colortable[COLOUR_ORANGE] = (COLOR_PAIR(PAIR_YELLOW) | A_BRIGHT); colortable[COLOUR_RED] = (COLOR_PAIR(PAIR_RED)); colortable[COLOUR_GREEN] = (COLOR_PAIR(PAIR_GREEN)); colortable[COLOUR_BLUE] = (COLOR_PAIR(PAIR_BLUE)); colortable[COLOUR_UMBER] = (COLOR_PAIR(PAIR_YELLOW)); colortable[COLOUR_L_DARK] = (COLOR_PAIR(PAIR_BLACK) | A_BRIGHT); colortable[COLOUR_L_WHITE] = (COLOR_PAIR(PAIR_WHITE)); colortable[COLOUR_L_PURPLE] = (COLOR_PAIR(PAIR_MAGENTA)); colortable[COLOUR_YELLOW] = (COLOR_PAIR(PAIR_YELLOW) | A_BRIGHT); colortable[COLOUR_L_RED] = (COLOR_PAIR(PAIR_MAGENTA) | A_BRIGHT); colortable[COLOUR_L_GREEN] = (COLOR_PAIR(PAIR_GREEN) | A_BRIGHT); colortable[COLOUR_L_BLUE] = (COLOR_PAIR(PAIR_BLUE) | A_BRIGHT); colortable[COLOUR_L_UMBER] = (COLOR_PAIR(PAIR_YELLOW)); colortable[COLOUR_PURPLE] = (COLOR_PAIR(PAIR_MAGENTA)); colortable[COLOUR_VIOLET] = (COLOR_PAIR(PAIR_MAGENTA)); colortable[COLOUR_TEAL] = (COLOR_PAIR(PAIR_CYAN)); colortable[COLOUR_MUD] = (COLOR_PAIR(PAIR_YELLOW)); colortable[COLOUR_L_YELLOW] = (COLOR_PAIR(PAIR_YELLOW | A_BRIGHT)); colortable[COLOUR_MAGENTA] = (COLOR_PAIR(PAIR_MAGENTA | A_BRIGHT)); colortable[COLOUR_L_TEAL] = (COLOR_PAIR(PAIR_CYAN) | A_BRIGHT); colortable[COLOUR_L_VIOLET] = (COLOR_PAIR(PAIR_MAGENTA) | A_BRIGHT); colortable[COLOUR_L_PINK] = (COLOR_PAIR(PAIR_MAGENTA) | A_BRIGHT); colortable[COLOUR_MUSTARD] = (COLOR_PAIR(PAIR_YELLOW)); colortable[COLOUR_BLUE_SLATE] = (COLOR_PAIR(PAIR_BLUE)); colortable[COLOUR_DEEP_L_BLUE] = (COLOR_PAIR(PAIR_BLUE)); } #endif /* Paranoia -- Assume no waiting */ nodelay(stdscr, FALSE); /* Prepare */ cbreak(); noecho(); nonl(); /* Tell curses to rewrite escape sequences to KEY_UP and friends */ keypad(stdscr, TRUE); /* Extract the game keymap */ keymap_game_prepare(); /* Now prepare the term(s) */ for (i = 0; i < term_count; i++) { /* Get the terminal dimensions; if the user asked for a big screen * then we'll put the whole screen in term 0; otherwise we'll divide * it amongst the available terms */ get_gcu_term_size(i, &rows, &cols, &y, &x); /* Skip non-existant windows */ if (rows <= 0 || cols <= 0) continue; /* Create a term */ term_data_init_gcu(&data[next_win], rows, cols, y, x); /* Remember the term */ angband_term[next_win] = &data[next_win].t; /* One more window */ next_win++; } /* Activate the "Angband" window screen */ Term_activate(&data[0].t); /* Remember the active screen */ term_screen = &data[0].t; /* Success */ return (0); }
/** * Take an html screenshot */ void html_screenshot(const char *path, int mode) { int y, x; int wid, hgt; int a = COLOUR_WHITE; int oa = COLOUR_WHITE; int fg_colour = COLOUR_WHITE; int bg_colour = COLOUR_DARK; wchar_t c = L' '; const char *new_color_fmt = (mode == 0) ? "<font color=\"#%02X%02X%02X\" style=\"background-color: #%02X%02X%02X\">" : "[COLOR=\"#%02X%02X%02X\"]"; const char *change_color_fmt = (mode == 0) ? "</font><font color=\"#%02X%02X%02X\" style=\"background-color: #%02X%02X%02X\">" : "[/COLOR][COLOR=\"#%02X%02X%02X\"]"; const char *close_color_fmt = mode == 0 ? "</font>" : "[/COLOR]"; ang_file *fp; fp = file_open(path, MODE_WRITE, FTYPE_TEXT); /* Oops */ if (!fp) { plog_fmt("Cannot write the '%s' file!", path); return; } /* Retrieve current screen size */ Term_get_size(&wid, &hgt); if (mode == 0) { file_putf(fp, "<!DOCTYPE html><html><head>\n"); file_putf(fp, " <meta='generator' content='%s'>\n", buildid); file_putf(fp, " <title>%s</title>\n", path); file_putf(fp, "</head>\n\n"); file_putf(fp, "<body style='color: #fff; background: #000;'>\n"); file_putf(fp, "<pre>\n"); } else { file_putf(fp, "[CODE][TT][BC=black][COLOR=white]\n"); } /* Dump the screen */ for (y = 0; y < hgt; y++) { for (x = 0; x < wid; x++) { /* Get the attr/char */ (void)(Term_what(x, y, &a, &c)); /* Set the foreground and background */ fg_colour = a % MAX_COLORS; switch (a / MAX_COLORS) { case BG_BLACK: bg_colour = COLOUR_DARK; break; case BG_SAME: bg_colour = fg_colour; break; case BG_DARK: bg_colour = COLOUR_SHADE; break; default: assert((a >= BG_BLACK) && (a < BG_MAX * MAX_COLORS)); } /* Color change */ if (oa != a) { if (oa == COLOUR_WHITE) { /* From the default white to another color */ file_putf(fp, new_color_fmt, angband_color_table[fg_colour][1], angband_color_table[fg_colour][2], angband_color_table[fg_colour][3], angband_color_table[bg_colour][1], angband_color_table[bg_colour][2], angband_color_table[bg_colour][3]); } else if (fg_colour == COLOUR_WHITE && bg_colour == COLOUR_DARK) { /* From another color to the default white */ file_putf(fp, close_color_fmt); } else { /* Change colors */ file_putf(fp, change_color_fmt, angband_color_table[fg_colour][1], angband_color_table[fg_colour][2], angband_color_table[fg_colour][3], angband_color_table[bg_colour][1], angband_color_table[bg_colour][2], angband_color_table[bg_colour][3]); } /* Remember the last color */ oa = a; } /* Write the character and escape special HTML characters */ if (mode == 0) write_html_escape_char(fp, c); else { char mbseq[MB_LEN_MAX+1] = {0}; wctomb(mbseq, c); file_putf(fp, "%s", mbseq); } } /* End the row */ file_putf(fp, "\n"); } /* Close the last font-color tag if necessary */ if (oa != COLOUR_WHITE) file_putf(fp, close_color_fmt); if (mode == 0) { file_putf(fp, "</pre>\n"); file_putf(fp, "</body>\n"); file_putf(fp, "</html>\n"); } else { file_putf(fp, "[/COLOR][/BC][/TT][/CODE]\n"); } /* Close it */ file_close(fp); }
/* * Prepare "curses" for use by the file "z-term.c" * * Installs the "hook" functions defined above, and then activates * the main screen "term", which clears the screen and such things. * * Someone should really check the semantics of "initscr()" */ errr init_gcu(int argc, char **argv) { int i; int rows, cols, y, x; int next_win = 0; /* Initialize info about terminal capabilities */ termtype = getenv("TERM"); loaded_terminfo = termtype && tgetent(0, termtype) == 1; /* Let's learn about our terminal */ use_alt_charset = loaded_terminfo && tgetstr("acs_chars", NULL); /* Parse args */ for (i = 1; i < argc; i++) { if (prefix(argv[i], "-b")) use_big_screen = TRUE; #ifdef A_ALTCHARSET else if (prefix(argv[i], "-a")) use_alt_charset = 0; else if (prefix(argv[i], "-g")) use_alt_charset = 1; #endif else plog_fmt("Ignoring option: %s", argv[i]); } /* Extract the normal keymap */ keymap_norm_prepare(); /* We do it like this to prevent a link error with curseses that * lack ESCDELAY. */ if (!getenv("ESCDELAY")) putenv("ESCDELAY=20"); /* Initialize */ if (initscr() == NULL) return (-1); /* Activate hooks */ quit_aux = hook_quit; /* Require standard size screen */ if ((LINES < 24) || (COLS < 80)) { quit("Angband needs at least an 80x24 'curses' screen"); } #ifdef A_COLOR /*** Init the Color-pairs and set up a translation table ***/ /* Do we have color, and enough color, available? */ can_use_color = ((start_color() != ERR) && has_colors() && (COLORS >= 8) && (COLOR_PAIRS >= 8)); #ifdef HAVE_USE_DEFAULT_COLORS /* Should we use curses' "default color" */ if (use_default_colors() == OK) bg_color = -1; #endif #ifdef HAVE_CAN_CHANGE_COLOR /* Can we change colors? */ can_fix_color = (can_use_color && can_change_color() && orig_colors && (COLORS >= 16) && (COLOR_PAIRS > 8)); #endif /* Attempt to use customized colors */ if (can_fix_color) { /* Prepare the color pairs */ for (i = 0; i < (BASIC_COLORS / 2); i++) { /* Reset the color */ if (init_pair(i + 1, i, bg_color) == ERR) { quit("Color pair init failed"); } /* Set up the colormap */ colortable[i] = (COLOR_PAIR(i + 1) | A_NORMAL); colortable[i + (BASIC_COLORS / 2)] = (COLOR_PAIR(i + 1) | A_BRIGHT); } /* Take account of "gamma correction" XXX XXX XXX */ /* Prepare the "Angband Colors" */ Term_xtra_gcu_react(); } /* Attempt to use colors */ else if (can_use_color) { /* Prepare the color pairs */ /* PAIR_WHITE (pair 0) is *always* WHITE on BLACK */ init_pair(PAIR_RED, COLOR_RED, bg_color); init_pair(PAIR_GREEN, COLOR_GREEN, bg_color); init_pair(PAIR_YELLOW, COLOR_YELLOW, bg_color); init_pair(PAIR_BLUE, COLOR_BLUE, bg_color); init_pair(PAIR_MAGENTA, COLOR_MAGENTA, bg_color); init_pair(PAIR_CYAN, COLOR_CYAN, bg_color); init_pair(PAIR_BLACK, COLOR_BLACK, bg_color); /* Prepare the colors */ colortable[TERM_DARK] = (COLOR_PAIR(PAIR_BLACK)); colortable[TERM_WHITE] = (COLOR_PAIR(PAIR_WHITE) | A_BRIGHT); colortable[TERM_SLATE] = (COLOR_PAIR(PAIR_WHITE)); colortable[TERM_ORANGE] = (COLOR_PAIR(PAIR_RED) | A_BRIGHT); colortable[TERM_RED] = (COLOR_PAIR(PAIR_RED)); colortable[TERM_GREEN] = (COLOR_PAIR(PAIR_GREEN)); colortable[TERM_BLUE] = (COLOR_PAIR(PAIR_BLUE)); colortable[TERM_UMBER] = (COLOR_PAIR(PAIR_YELLOW)); colortable[TERM_L_DARK] = (COLOR_PAIR(PAIR_BLACK) | A_BRIGHT); colortable[TERM_L_WHITE] = (COLOR_PAIR(PAIR_WHITE)); colortable[TERM_L_PURPLE] = (COLOR_PAIR(PAIR_MAGENTA)); colortable[TERM_YELLOW] = (COLOR_PAIR(PAIR_YELLOW) | A_BRIGHT); colortable[TERM_L_RED] = (COLOR_PAIR(PAIR_MAGENTA) | A_BRIGHT); colortable[TERM_L_GREEN] = (COLOR_PAIR(PAIR_GREEN) | A_BRIGHT); colortable[TERM_L_BLUE] = (COLOR_PAIR(PAIR_BLUE) | A_BRIGHT); colortable[TERM_L_UMBER] = (COLOR_PAIR(PAIR_YELLOW)); colortable[TERM_PURPLE] = (COLOR_PAIR(PAIR_MAGENTA)); colortable[TERM_VIOLET] = (COLOR_PAIR(PAIR_MAGENTA)); colortable[TERM_TEAL] = (COLOR_PAIR(PAIR_CYAN)); colortable[TERM_MUD] = (COLOR_PAIR(PAIR_YELLOW)); colortable[TERM_L_YELLOW] = (COLOR_PAIR(PAIR_YELLOW | A_BRIGHT)); colortable[TERM_MAGENTA] = (COLOR_PAIR(PAIR_MAGENTA | A_BRIGHT)); colortable[TERM_L_TEAL] = (COLOR_PAIR(PAIR_CYAN | A_BRIGHT)); colortable[TERM_L_VIOLET] = (COLOR_PAIR(PAIR_MAGENTA | A_BRIGHT)); colortable[TERM_L_PINK] = (COLOR_PAIR(PAIR_MAGENTA | A_BRIGHT)); colortable[TERM_MUSTARD] = (COLOR_PAIR(PAIR_YELLOW)); colortable[TERM_BLUE_SLATE] = (COLOR_PAIR(PAIR_BLUE)); colortable[TERM_DEEP_L_BLUE] = (COLOR_PAIR(PAIR_BLUE)); } #endif #ifdef A_ALTCHARSET /* Build a quick access table for the "alternate character set". */ if (use_alt_charset) { acs_table[1] = ACS_DIAMOND; acs_table[16] = ACS_S1; acs_table[2] = ACS_CKBOARD; acs_table[18] = ACS_HLINE; acs_table[7] = ACS_DEGREE; acs_table[20] = ACS_S9; acs_table[8] = ACS_PLMINUS; acs_table[21] = ACS_LTEE; acs_table[11] = ACS_LRCORNER; acs_table[22] = ACS_RTEE; acs_table[12] = ACS_URCORNER; acs_table[23] = ACS_BTEE; acs_table[13] = ACS_ULCORNER; acs_table[24] = ACS_TTEE; acs_table[14] = ACS_LLCORNER; acs_table[25] = ACS_VLINE; acs_table[15] = ACS_PLUS; acs_table[31] = ACS_BULLET; } #endif /*** Low level preparation ***/ /* Paranoia -- Assume no waiting */ nodelay(stdscr, FALSE); /* Prepare */ cbreak(); noecho(); nonl(); /* Tell curses to rewrite escape sequences to KEY_UP and friends */ keypad(stdscr, TRUE); /* Extract the game keymap */ keymap_game_prepare(); /*** Now prepare the term(s) ***/ for (i = 0; i < MAX_TERM_DATA; i++) { if (use_big_screen && i > 0) break; /* Get the terminal dimensions; if the user asked for a big screen * then we'll put the whole screen in term 0; otherwise we'll divide * it amongst the available terms */ get_gcu_term_size(i, &rows, &cols, &y, &x); /* Skip non-existant windows */ if (rows <= 0 || cols <= 0) continue; /* Create a term */ term_data_init_gcu(&data[next_win], rows, cols, y, x); /* Remember the term */ angband_term[next_win] = &data[next_win].t; /* One more window */ next_win++; } /* Activate the "Angband" window screen */ Term_activate(&data[0].t); /* Remember the active screen */ term_screen = &data[0].t; /* Success */ return (0); }
/* * Prepare "curses" for use by the file "z-term.c" * * Installs the "hook" functions defined above, and then activates * the main screen "term", which clears the screen and such things. * * Someone should really check the semantics of "initscr()" */ errr init_gcu(int argc, char **argv) { int i; int num_term = MAX_TERM_DATA, next_win = 0; bool use_big_screen = FALSE; /* Parse args */ for (i = 1; i < argc; i++) { if (prefix(argv[i], "-b")) { use_big_screen = TRUE; continue; } plog_fmt("Ignoring option: %s", argv[i]); } /* Extract the normal keymap */ keymap_norm_prepare(); /* Initialize */ if (initscr() == NULL) return (-1); /* Activate hooks */ quit_aux = hook_quit; core_aux = hook_quit; /* Require standard size screen */ if ((LINES < 24) || (COLS < 80)) { quit("Angband needs at least an 80x24 'curses' screen"); } #ifdef USE_GRAPHICS /* Set graphics */ if (arg_graphics) { use_graphics = GRAPHICS_PSEUDO; ANGBAND_GRAF = "pseudo"; } #endif /* USE_GRAPHICS */ #ifdef A_COLOR /*** Init the Color-pairs and set up a translation table ***/ /* Do we have color, and enough color, available? */ can_use_color = ((start_color() != ERR) && has_colors() && (COLORS >= 8) && (COLOR_PAIRS >= 8)); #ifdef REDEFINE_COLORS /* Can we change colors? */ can_fix_color = (can_use_color && can_change_color() && (COLORS >= 16) && (COLOR_PAIRS > 8)); #endif /* Attempt to use customized colors */ if (can_fix_color) { /* Prepare the color pairs */ for (i = 1; i <= 8; i++) { /* Reset the color */ if (init_pair(i, i - 1, 0) == ERR) { quit("Color pair init failed"); } /* Set up the colormap */ colortable[i - 1] = (COLOR_PAIR(i) | A_NORMAL); colortable[i + 7] = (COLOR_PAIR(i) | A_BRIGHT); } /* Take account of "gamma correction" XXX XXX XXX */ /* Prepare the "Angband Colors" */ Term_xtra_gcu_react(); } /* Attempt to use colors */ else if (can_use_color) { /* Color-pair 0 is *always* WHITE on BLACK */ /* Prepare the color pairs */ init_pair(1, COLOR_RED, COLOR_BLACK); init_pair(2, COLOR_GREEN, COLOR_BLACK); init_pair(3, COLOR_YELLOW, COLOR_BLACK); init_pair(4, COLOR_BLUE, COLOR_BLACK); init_pair(5, COLOR_MAGENTA, COLOR_BLACK); init_pair(6, COLOR_CYAN, COLOR_BLACK); init_pair(7, COLOR_BLACK, COLOR_BLACK); /* Prepare the colors */ colortable[0] = (COLOR_PAIR(7) | A_NORMAL); /* Black */ colortable[1] = (COLOR_PAIR(0) | A_BRIGHT); /* White */ colortable[2] = (COLOR_PAIR(0) | A_NORMAL); /* Grey XXX */ colortable[3] = (COLOR_PAIR(1) | A_BRIGHT); /* Orange XXX */ colortable[4] = (COLOR_PAIR(1) | A_NORMAL); /* Red */ colortable[5] = (COLOR_PAIR(2) | A_NORMAL); /* Green */ colortable[6] = (COLOR_PAIR(4) | A_NORMAL); /* Blue */ colortable[7] = (COLOR_PAIR(3) | A_NORMAL); /* Umber */ colortable[8] = (COLOR_PAIR(7) | A_BRIGHT); /* Dark-grey XXX */ colortable[9] = (COLOR_PAIR(0) | A_NORMAL); /* Light-grey XXX */ colortable[10] = (COLOR_PAIR(5) | A_NORMAL); /* Purple */ colortable[11] = (COLOR_PAIR(3) | A_BRIGHT); /* Yellow */ colortable[12] = (COLOR_PAIR(5) | A_BRIGHT); /* Light Red XXX */ colortable[13] = (COLOR_PAIR(2) | A_BRIGHT); /* Light Green */ colortable[14] = (COLOR_PAIR(4) | A_BRIGHT); /* Light Blue */ colortable[15] = (COLOR_PAIR(3) | A_NORMAL); /* Light Umber XXX */ } #endif /*** Low level preparation ***/ #ifdef USE_GETCH /* Paranoia -- Assume no waiting */ nodelay(stdscr, FALSE); #endif /* Prepare */ cbreak(); noecho(); nonl(); /* Extract the game keymap */ keymap_game_prepare(); /*** Now prepare the term(s) ***/ /* Big screen -- one big term */ if (use_big_screen) { /* Create a term */ term_data_init_gcu(&data[0], LINES, COLS, 0, 0); /* Remember the term */ angband_term[0] = &data[0].t; } /* No big screen -- create as many term windows as possible */ else { /* * If we have a REALLY big screen, try to put any * extra real estate into the upper-left window. * Hack -- these constants rely on a-priori knowledge * of the sort of things that go in the windows. * * This patch is by 'bron' from the Angband Forum * under the directions: 'Feel free to use this (or not) as you see fit.' */ /* Minimum size for UpperLeft window */ const int ul_min_rows = 24; const int ul_min_cols = 80; /* Maximum (useful) columns for UpperRight window */ const int ur_max_cols = 80; /* Maximum (useful) rows for LowerLeft window */ const int ll_max_rows = 26; /* Actual size of UpperLeft window */ int ul_rows = MAX(ul_min_rows, LINES - (ll_max_rows + 1)); int ul_cols = MAX(ul_min_cols, COLS - (ur_max_cols + 1)); /* Create several terms */ for (i = 0; i < num_term; i++) { int rows, cols, y, x; /* Decide on size and position */ switch (i) { /* Upper left */ case 0: { rows = ul_rows; cols = ul_cols; y = x = 0; break; } /* Lower left */ case 1: { rows = LINES - (ul_rows + 1); cols = ul_cols; y = ul_rows + 1; x = 0; break; } /* Upper right */ case 2: { rows = ul_rows; cols = COLS - (ul_cols + 1); y = 0; x = ul_cols + 1; break; } /* Lower right */ case 3: { rows = LINES - (ul_rows + 1); cols = COLS - (ul_cols + 1); y = ul_rows + 1; x = ul_cols + 1; break; } /* XXX */ default: { rows = cols = y = x = 0; break; } } /* Skip non-existant windows */ if (rows <= 0 || cols <= 0) continue; /* Create a term */ term_data_init_gcu(&data[next_win], rows, cols, y, x); /* Remember the term */ angband_term[next_win] = &data[next_win].t; /* One more window */ next_win++; } } /* Activate the "Angband" window screen */ Term_activate(&data[0].t); /* Remember the active screen */ term_screen = &data[0].t; /* Success */ return (0); }
/* * Initialization function for an "X11" module to Angband */ errr init_x11(int argc, char **argv) { int i; cptr dpy_name = ""; int num_term = 1; #ifdef USE_GRAPHICS cptr bitmap_file = ""; char filename[1024]; int pict_wid = 0; int pict_hgt = 0; char *TmpData; #endif /* USE_GRAPHICS */ /* Parse args */ for (i = 1; i < argc; i++) { if (prefix(argv[i], "-d")) { dpy_name = &argv[i][2]; continue; } #ifdef USE_GRAPHICS if (prefix(argv[i], "-s")) { smoothRescaling = FALSE; continue; } if (prefix(argv[i], "-o")) { arg_graphics = GRAPHICS_ORIGINAL; continue; } if (prefix(argv[i], "-a")) { arg_graphics = GRAPHICS_ADAM_BOLT; continue; } if (prefix(argv[i], "-g")) { smoothRescaling = FALSE; arg_graphics = GRAPHICS_DAVID_GERVAIS; continue; } if (prefix(argv[i], "-b")) { use_bigtile = TRUE; continue; } #endif /* USE_GRAPHICS */ if (prefix(argv[i], "-n")) { num_term = atoi(&argv[i][2]); if (num_term > MAX_TERM_DATA) num_term = MAX_TERM_DATA; else if (num_term < 1) num_term = 1; continue; } plog_fmt("Ignoring option: %s", argv[i]); } /* Init the Metadpy if possible */ if (Metadpy_init_name(dpy_name)) return (-1); /* Prepare cursor color */ MAKE(xor, infoclr); Infoclr_set(xor); Infoclr_init_ppn(Metadpy->fg, Metadpy->bg, "xor", 0); /* Prepare normal colors */ for (i = 0; i < 256; ++i) { Pixell pixel; MAKE(clr[i], infoclr); Infoclr_set(clr[i]); /* Acquire Angband colors */ color_table[i][0] = angband_color_table[i][0]; color_table[i][1] = angband_color_table[i][1]; color_table[i][2] = angband_color_table[i][2]; color_table[i][3] = angband_color_table[i][3]; /* Default to monochrome */ pixel = ((i == 0) ? Metadpy->bg : Metadpy->fg); /* Handle color */ if (Metadpy->color) { /* Create pixel */ pixel = create_pixel(Metadpy->dpy, color_table[i][1], color_table[i][2], color_table[i][3]); } /* Initialize the color */ Infoclr_init_ppn(pixel, Metadpy->bg, "cpy", 0); } /* Initialize the windows */ for (i = 0; i < num_term; i++) { term_data *td = &data[i]; /* Initialize the term_data */ term_data_init(td, i); /* Save global entry */ angband_term[i] = Term; } /* Raise the "Angband" window */ Infowin_set(data[0].win); Infowin_raise(); /* Activate the "Angband" window screen */ Term_activate(&data[0].t); #ifdef USE_GRAPHICS /* Try graphics */ switch (arg_graphics) { case GRAPHICS_ADAM_BOLT: /* Use tile graphics of Adam Bolt */ bitmap_file = "16x16.bmp"; /* Try the "16x16.bmp" file */ path_build(filename, sizeof(filename), ANGBAND_DIR_XTRA, format("graf/%s", bitmap_file)); /* Use the "16x16.bmp" file if it exists */ if (0 == fd_close(fd_open(filename, O_RDONLY))) { /* Use graphics */ use_graphics = TRUE; use_transparency = TRUE; pict_wid = pict_hgt = 16; ANGBAND_GRAF = "new"; break; } /* Fall through */ case GRAPHICS_ORIGINAL: /* Use original tile graphics */ bitmap_file = "8x8.bmp"; /* Try the "8x8.bmp" file */ path_build(filename, sizeof(filename), ANGBAND_DIR_XTRA, format("graf/%s", bitmap_file)); /* Use the "8x8.bmp" file if it exists */ if (0 == fd_close(fd_open(filename, O_RDONLY))) { /* Use graphics */ use_graphics = TRUE; pict_wid = pict_hgt = 8; ANGBAND_GRAF = "old"; break; } break; case GRAPHICS_DAVID_GERVAIS: /* Use tile graphics of David Gervais */ bitmap_file = "32x32.bmp"; /* Use graphics */ use_graphics = TRUE; use_transparency = TRUE; pict_wid = pict_hgt = 32; ANGBAND_GRAF = "david"; break; } /* Load graphics */ if (use_graphics) { Display *dpy = Metadpy->dpy; XImage *tiles_raw; /* Initialize */ for (i = 0; i < num_term; i++) { term_data *td = &data[i]; td->tiles = NULL; } path_build(filename, sizeof(filename), ANGBAND_DIR_XTRA, format("graf/%s", bitmap_file)); /* Load the graphical tiles */ tiles_raw = ReadBMP(dpy, filename); if (tiles_raw) { /* Initialize the windows */ for (i = 0; i < num_term; i++) { int j; bool same = FALSE; term_data *td = &data[i]; term_data *o_td = NULL; term *t = &td->t; /* Graphics hook */ t->pict_hook = Term_pict_x11; /* Use graphics sometimes */ t->higher_pict = TRUE; /* Look for another term with same font size */ for (j = 0; j < i; j++) { o_td = &data[j]; if ((td->fnt->twid == o_td->fnt->twid) && (td->fnt->hgt == o_td->fnt->hgt)) { same = TRUE; break; } } if (!same) { /* Resize tiles */ td->tiles = ResizeImage(dpy, tiles_raw, pict_wid, pict_hgt, td->fnt->twid, td->fnt->hgt); } else { /* Use same graphics */ td->tiles = o_td->tiles; } } /* Free tiles_raw */ FREE(tiles_raw); } /* Initialize the transparency masks */ for (i = 0; i < num_term; i++) { term_data *td = &data[i]; int ii, jj; int depth = DefaultDepth(dpy, DefaultScreen(dpy)); Visual *visual = DefaultVisual(dpy, DefaultScreen(dpy)); int total; /* Determine total bytes needed for image */ ii = 1; jj = (depth - 1) >> 2; while (jj >>= 1) ii <<= 1; total = td->fnt->twid * td->fnt->hgt * ii; TmpData = (char *)malloc(total); td->TmpImage = XCreateImage(dpy,visual,depth, ZPixmap, 0, TmpData, td->fnt->twid, td->fnt->hgt, 32, 0); } } #endif /* USE_GRAPHICS */ /* Success */ return (0); }
/* * Initialization function for an X Athena Widget module to Angband * * We should accept "-d<dpy>" requests in the "argv" array. XXX XXX XXX */ errr init_xaw(int argc, char **argv) { int i; Widget topLevel; Display *dpy; cptr dpy_name = ""; #ifdef USE_GRAPHICS cptr bitmap_file = ""; char filename[1024]; int pict_wid = 0; int pict_hgt = 0; char *TmpData; #endif /* USE_GRAPHICS */ /* Parse args */ for (i = 1; i < argc; i++) { if (prefix(argv[i], "-d")) { dpy_name = &argv[i][2]; continue; } #ifdef USE_GRAPHICS if (prefix(argv[i], "-s")) { smoothRescaling = FALSE; continue; } if (prefix(argv[i], "-o")) { arg_graphics = GRAPHICS_ORIGINAL; continue; } if (prefix(argv[i], "-a")) { arg_graphics = GRAPHICS_ADAM_BOLT; continue; } if (prefix(argv[i], "-g")) { smoothRescaling = FALSE; arg_graphics = GRAPHICS_DAVID_GERVAIS; continue; } if (prefix(argv[i], "-b")) { use_bigtile = TRUE; continue; } #endif /* USE_GRAPHICS */ if (prefix(argv[i], "-n")) { num_term = atoi(&argv[i][2]); if (num_term > MAX_TERM_DATA) num_term = MAX_TERM_DATA; else if (num_term < 1) num_term = 1; continue; } plog_fmt("Ignoring option: %s", argv[i]); } /* Attempt to open the local display */ dpy = XOpenDisplay(dpy_name); /* Failure -- assume no X11 available */ if (!dpy) return (-1); /* Close the local display */ XCloseDisplay(dpy); #ifdef USE_XAW_LANG /* Support locale processing */ XtSetLanguageProc(NULL, NULL, NULL); #endif /* USE_XAW_LANG */ /* Initialize the toolkit */ topLevel = XtAppInitialize(&appcon, "Angband", NULL, 0, &argc, argv, fallback, NULL, 0); /* Initialize the windows */ for (i = 0; i < num_term; i++) { term_data *td = &data[i]; term_data_init(td, topLevel, 1024, termNames[i], (i == 0) ? specialArgs : defaultArgs, TERM_FALLBACKS, i); angband_term[i] = Term; } /* Activate the "Angband" window screen */ Term_activate(&data[0].t); /* Raise the "Angband" window */ term_raise(&data[0]); #ifdef USE_GRAPHICS /* Try graphics */ switch (arg_graphics) { case GRAPHICS_ADAM_BOLT: /* Use tile graphics of Adam Bolt */ bitmap_file = "16x16.bmp"; /* Try the "16x16.bmp" file */ path_build(filename, sizeof(filename), ANGBAND_DIR_XTRA, format("graf/%s", bitmap_file)); /* Use the "16x16.bmp" file if it exists */ if (0 == fd_close(fd_open(filename, O_RDONLY))) { /* Use graphics */ use_graphics = GRAPHICS_ADAM_BOLT; use_transparency = TRUE; pict_wid = pict_hgt = 16; ANGBAND_GRAF = "new"; break; } /* Fall through */ case GRAPHICS_ORIGINAL: /* Use original tile graphics */ bitmap_file = "8x8.bmp"; /* Try the "8x8.bmp" file */ path_build(filename, sizeof(filename), ANGBAND_DIR_XTRA, format("graf/%s", bitmap_file)); /* Use the "8x8.bmp" file if it exists */ if (0 == fd_close(fd_open(filename, O_RDONLY))) { /* Use graphics */ use_graphics = GRAPHICS_ORIGINAL; pict_wid = pict_hgt = 8; ANGBAND_GRAF = "old"; break; } break; case GRAPHICS_DAVID_GERVAIS: /* Use tile graphics of David Gervais */ bitmap_file = "32x32.bmp"; /* Use graphics */ use_graphics = GRAPHICS_DAVID_GERVAIS; use_transparency = TRUE; pict_wid = pict_hgt = 32; ANGBAND_GRAF = "david"; break; } /* Load graphics */ if (use_graphics) { /* Hack -- Get the Display */ term_data *td = &data[0]; Widget widget = (Widget)(td->widget); Display *dpy = XtDisplay(widget); XImage *tiles_raw; for (i = 0; i < num_term; i++) { term_data *td = &data[i]; td->widget->angband.tiles = NULL; } path_build(filename, sizeof(filename), ANGBAND_DIR_XTRA, format("graf/%s", bitmap_file)); /* Load the graphical tiles */ tiles_raw = ReadBMP(dpy, filename); if (tiles_raw) { /* Initialize the windows */ for (i = 0; i < num_term; i++) { int j; bool same = FALSE; term_data *td = &data[i]; term_data *o_td = NULL; term *t = &td->t; t->pict_hook = Term_pict_xaw; t->higher_pict = TRUE; /* Look for another term with same font size */ for (j = 0; j < i; j++) { o_td = &data[j]; if ((td->widget->angband.tilewidth == o_td->widget->angband.tilewidth) && (td->widget->angband.fontheight == o_td->widget->angband.fontheight)) { same = TRUE; break; } } if (!same) { /* Resize tiles */ td->widget->angband.tiles = ResizeImage(dpy, tiles_raw, pict_wid, pict_hgt, td->widget->angband.tilewidth, td->widget->angband.fontheight); } else { /* Use same graphics */ td->widget->angband.tiles = o_td->widget->angband.tiles; } } /* Free tiles_raw */ FREE(tiles_raw); } /* Initialize the transparency temp storage */ for (i = 0; i < num_term; i++) { term_data *td = &data[i]; int ii, jj; int depth = DefaultDepth(dpy, DefaultScreen(dpy)); Visual *visual = DefaultVisual(dpy, DefaultScreen(dpy)); int total; /* Determine total bytes needed for image */ ii = 1; jj = (depth - 1) >> 2; while (jj >>= 1) ii <<= 1; total = td->widget->angband.tilewidth * td->widget->angband.fontheight * ii; TmpData = (char *)malloc(total); td->widget->angband.TmpImage = XCreateImage(dpy, visual,depth, ZPixmap, 0, TmpData, td->widget->angband.tilewidth, td->widget->angband.fontheight, 8, 0); } } #endif /* USE_GRAPHICS */ /* Success */ return (0); }
/* * Read sound.cfg and map events to sounds; then load all the sounds into * memory to avoid I/O latency later. */ static bool sound_sdl_init(bool no_cache) { char path[2048]; char buffer[2048]; ang_file *fff; /* Initialise the mixer */ if (!open_audio()) return FALSE; /* Build the "sound" path */ path_build(path, sizeof(path), ANGBAND_DIR_XTRA, "sound"); ANGBAND_DIR_XTRA_SOUND = string_make(path); /* Find and open the config file */ path_build(path, sizeof(path), ANGBAND_DIR_XTRA_SOUND, "sound.cfg"); fff = file_open(path, MODE_READ, -1); /* Handle errors */ if (!fff) { plog_fmt("Failed to open sound config (%s):\n %s", path, strerror(errno)); return FALSE; } /* Parse the file */ /* Lines are always of the form "name = sample [sample ...]" */ while (file_getl(fff, buffer, sizeof(buffer))) { char *msg_name; char *sample_list; char *search; char *cur_token; char *next_token; int event; /* Skip anything not beginning with an alphabetic character */ if (!buffer[0] || !isalpha((unsigned char)buffer[0])) continue; /* Split the line into two: message name, and the rest */ search = strchr(buffer, ' '); sample_list = strchr(search + 1, ' '); if (!search) continue; if (!sample_list) continue; /* Set the message name, and terminate at first space */ msg_name = buffer; search[0] = '\0'; /* Make sure this is a valid event name */ for (event = MSG_MAX - 1; event >= 0; event--) { if (strcmp(msg_name, angband_sound_name[event]) == 0) break; } if (event < 0) continue; /* Advance the sample list pointer so it's at the beginning of text */ sample_list++; if (!sample_list[0]) continue; /* Terminate the current token */ cur_token = sample_list; search = strchr(cur_token, ' '); if (search) { search[0] = '\0'; next_token = search + 1; } else { next_token = NULL; } /* * Now we find all the sample names and add them one by one */ while (cur_token) { int num = samples[event].num; /* Don't allow too many samples */ if (num >= MAX_SAMPLES) break; /* Build the path to the sample */ path_build(path, sizeof(path), ANGBAND_DIR_XTRA_SOUND, cur_token); if (!file_exists(path)) goto next_token; /* Don't load now if we're not caching */ if (no_cache) { /* Just save the path for later */ samples[event].paths[num] = (char *)string_make(path); } else { /* Load the file now */ samples[event].wavs[num] = Mix_LoadWAV(path); if (!samples[event].wavs[num]) { plog_fmt("%s: %s", SDL_GetError(), strerror(errno)); goto next_token; } } /* Imcrement the sample count */ samples[event].num++; next_token: /* Figure out next token */ cur_token = next_token; if (next_token) { /* Try to find a space */ search = strchr(cur_token, ' '); /* If we can find one, terminate, and set new "next" */ if (search) { search[0] = '\0'; next_token = search + 1; } else { /* Otherwise prevent infinite looping */ next_token = NULL; } } } } /* Close the file */ file_close(fff); /* Success */ return TRUE; }
/* Take an html screenshot */ void html_screenshot(const char *name, int mode) { int y, x; int wid, hgt; byte a = TERM_WHITE; byte oa = TERM_WHITE; char c = ' '; const char *new_color_fmt = (mode == 0) ? "<font color=\"#%02X%02X%02X\">" : "[COLOR=\"#%02X%02X%02X\"]"; const char *change_color_fmt = (mode == 0) ? "</font><font color=\"#%02X%02X%02X\">" : "[/COLOR][COLOR=\"#%02X%02X%02X\"]"; const char *close_color_fmt = mode == 0 ? "</font>" : "[/COLOR]"; ang_file *fp; char buf[1024]; path_build(buf, sizeof(buf), ANGBAND_DIR_USER, name); fp = file_open(buf, MODE_WRITE, FTYPE_TEXT); /* Oops */ if (!fp) { plog_fmt("Cannot write the '%s' file!", buf); return; } /* Retrieve current screen size */ Term_get_size(&wid, &hgt); if (mode == 0) { file_putf(fp, "<!DOCTYPE html><html><head>\n"); file_putf(fp, " <meta='generator' content='%s'>\n", buildid); file_putf(fp, " <title>%s</title>\n", name); file_putf(fp, "</head>\n\n"); file_putf(fp, "<body style='color: #fff; background: #000;'>\n"); file_putf(fp, "<pre>\n"); } else { file_putf(fp, "[CODE][TT][BC=black][COLOR=white]\n"); } /* Dump the screen */ for (y = 0; y < hgt; y++) { for (x = 0; x < wid; x++) { /* Get the attr/char */ (void)(Term_what(x, y, &a, &c)); /* Color change */ if (oa != a && c != ' ') { /* From the default white to another color */ if (oa == TERM_WHITE) { file_putf(fp, new_color_fmt, angband_color_table[a][1], angband_color_table[a][2], angband_color_table[a][3]); } /* From another color to the default white */ else if (a == TERM_WHITE) { file_putf(fp, close_color_fmt); } /* Change colors */ else { file_putf(fp, change_color_fmt, angband_color_table[a][1], angband_color_table[a][2], angband_color_table[a][3]); } /* Remember the last color */ oa = a; } /* Write the character and escape special HTML characters */ if (mode == 0) write_html_escape_char(fp, c); else file_putf(fp, "%c", c); } /* End the row */ file_putf(fp, "\n"); } /* Close the last font-color tag if necessary */ if (oa != TERM_WHITE) file_putf(fp, close_color_fmt); if (mode == 0) { file_putf(fp, "</pre>\n"); file_putf(fp, "</body>\n"); file_putf(fp, "</html>\n"); } else { file_putf(fp, "[/COLOR][/BC][/TT][/CODE]\n"); } /* Close it */ file_close(fp); }