diff --git a/CHANGELOG.txt b/CHANGELOG.txt index d3e770a57..cb83fdbd1 100644 --- a/CHANGELOG.txt +++ b/CHANGELOG.txt @@ -1,5 +1,9 @@ D1X-Rebirth Changelog +20100310 +-------- +main/titles.c: Put most local variables in show_briefing in 'briefing' struct, to make briefing a window in future + 20100309 -------- main/titles.c: Put briefing globals in 'briefing' struct, pass this by parameter diff --git a/main/titles.c b/main/titles.c index 6eb6886fe..71c0fe211 100644 --- a/main/titles.c +++ b/main/titles.c @@ -331,16 +331,26 @@ typedef struct briefing { short level_num; short cur_screen; + briefing_screen *screen; grs_bitmap background; char background_name[16]; char *text; char *message; int text_x, text_y; msgstream messagestream[2048]; + int streamcount; + short tab_stop; + ubyte flashing_cursor; + ubyte new_page; + int delay_count; + int robot_num; grs_canvas *robot_canv; vms_angvec robot_angles; char bitmap_name[32]; + grs_bitmap guy_bitmap; + sbyte guy_bitmap_show; sbyte door_dir, door_div_count, animating_bitmap_type; + sbyte prev_ch; } briefing; void briefing_init(briefing *br, short level_num) @@ -734,33 +744,30 @@ void redraw_messagestream(msgstream *stream, int count) // Draws text, images and bitmaps actually int show_briefing(briefing *br) { - int prev_ch=-1; int ch, done=0; - briefing_screen *bsp; - int delay_count = KEY_DELAY_DEFAULT; int key_check; - int robot_num=-1; int rval=0; - static int tab_stop=0; - int flashing_cursor=0; - int new_page=0; - char fname[15]; - grs_bitmap guy_bitmap; - int streamcount=0, guy_bitmap_show=0; - strncpy(fname, br->background_name, 15);//fname = br->background_name; - br->bitmap_name[0] = 0; Current_color = 0; + br->streamcount = 0; + br->tab_stop = 0; + br->flashing_cursor = 0; + br->new_page = 0; + br->delay_count = KEY_DELAY_DEFAULT; + br->robot_num = -1; + br->bitmap_name[0] = 0; + br->guy_bitmap_show = 0; + br->prev_ch = -1; gr_set_curfont( GAME_FONT ); - MALLOC(bsp, briefing_screen, 1); - memcpy(bsp, &Briefing_screens[br->cur_screen], sizeof(briefing_screen)); - bsp->text_ulx = rescale_x(bsp->text_ulx); - bsp->text_uly = rescale_y(bsp->text_uly); - bsp->text_width = rescale_x(bsp->text_width); - bsp->text_height = rescale_y(bsp->text_height); - init_char_pos(br, bsp->text_ulx, bsp->text_uly); + MALLOC(br->screen, briefing_screen, 1); + memcpy(br->screen, &Briefing_screens[br->cur_screen], sizeof(briefing_screen)); + br->screen->text_ulx = rescale_x(br->screen->text_ulx); + br->screen->text_uly = rescale_y(br->screen->text_uly); + br->screen->text_width = rescale_x(br->screen->text_width); + br->screen->text_height = rescale_y(br->screen->text_height); + init_char_pos(br, br->screen->text_ulx, br->screen->text_uly); while (!done) { ch = *br->message++; @@ -769,16 +776,16 @@ int show_briefing(briefing *br) if (ch == 'C') { Current_color = get_message_num(&br->message)-1; Assert((Current_color >= 0) && (Current_color < MAX_BRIEFING_COLORS)); - prev_ch = 10; + br->prev_ch = 10; } else if (ch == 'F') { // toggle flashing cursor - flashing_cursor = !flashing_cursor; - prev_ch = 10; + br->flashing_cursor = !br->flashing_cursor; + br->prev_ch = 10; while (*br->message++ != 10) ; } else if (ch == 'T') { - tab_stop = get_message_num(&br->message); - tab_stop*=(1+HIRESMODE); - prev_ch = 10; // read to eoln + br->tab_stop = get_message_num(&br->message); + br->tab_stop*=(1+HIRESMODE); + br->prev_ch = 10; // read to eoln } else if (ch == 'R') { if (br->robot_canv != NULL) { @@ -787,10 +794,10 @@ int show_briefing(briefing *br) } init_spinning_robot(br); - robot_num = get_message_num(&br->message); + br->robot_num = get_message_num(&br->message); while (*br->message++ != 10) ; - prev_ch = 10; // read to eoln + br->prev_ch = 10; // read to eoln } else if (ch == 'N') { if (br->robot_canv != NULL) { @@ -801,7 +808,7 @@ int show_briefing(briefing *br) get_message_name(&br->message, br->bitmap_name); strcat(br->bitmap_name, "#0"); br->animating_bitmap_type = 0; - prev_ch = 10; + br->prev_ch = 10; } else if (ch == 'O') { if (br->robot_canv != NULL) { @@ -812,7 +819,7 @@ int show_briefing(briefing *br) get_message_name(&br->message, br->bitmap_name); strcat(br->bitmap_name, "#0"); br->animating_bitmap_type = 1; - prev_ch = 10; + br->prev_ch = 10; } else if (ch == 'B') { char bitmap_name[32]; ubyte temp_palette[768]; @@ -826,14 +833,14 @@ int show_briefing(briefing *br) get_message_name(&br->message, bitmap_name); strcat(bitmap_name, ".bbm"); - gr_init_bitmap_data (&guy_bitmap); - iff_error = iff_read_bitmap(bitmap_name, &guy_bitmap, BM_LINEAR, temp_palette); + gr_init_bitmap_data (&br->guy_bitmap); + iff_error = iff_read_bitmap(bitmap_name, &br->guy_bitmap, BM_LINEAR, temp_palette); Assert(iff_error == IFF_NO_ERROR); - gr_remap_bitmap_good( &guy_bitmap, temp_palette, -1, -1 ); + gr_remap_bitmap_good( &br->guy_bitmap, temp_palette, -1, -1 ); - show_briefing_bitmap(&guy_bitmap); - guy_bitmap_show=1; - prev_ch = 10; + show_briefing_bitmap(&br->guy_bitmap); + br->guy_bitmap_show=1; + br->prev_ch = 10; } else if (ch == 'S') { int keypress; fix start_time; @@ -846,12 +853,12 @@ int show_briefing(briefing *br) timer_delay2(50); gr_flip(); show_fullscr(&br->background); - redraw_messagestream(br->messagestream, streamcount); - if (guy_bitmap_show) - show_briefing_bitmap(&guy_bitmap); - flash_cursor(br, flashing_cursor); - if (robot_num != -1) - show_spinning_robot_frame(br, robot_num); + redraw_messagestream(br->messagestream, br->streamcount); + if (br->guy_bitmap_show) + show_briefing_bitmap(&br->guy_bitmap); + flash_cursor(br, br->flashing_cursor); + if (br->robot_num != -1) + show_spinning_robot_frame(br, br->robot_num); if (br->bitmap_name[0] != 0) show_animated_bitmap(br); @@ -865,68 +872,68 @@ int show_briefing(briefing *br) if (keypress == KEY_ESC) rval = 1; - flashing_cursor = 0; + br->flashing_cursor = 0; done = 1; } else if (ch == 'P') { // New page. - new_page = 1; + br->new_page = 1; while (*br->message != 10) { br->message++; // drop carriage return after special escape sequence } br->message++; - prev_ch = 10; + br->prev_ch = 10; } else if (ch == '$' || ch == ';') { // Print a $/; - prev_ch = ch; - br->text_x += show_char_delay(br, ch, delay_count, robot_num, flashing_cursor); + br->prev_ch = ch; + br->text_x += show_char_delay(br, ch, br->delay_count, br->robot_num, br->flashing_cursor); } } else if (ch == '\t') { // Tab - if (br->text_x - bsp->text_ulx < tab_stop) - br->text_x = bsp->text_ulx + tab_stop; - } else if ((ch == ';') && (prev_ch == 10)) { + if (br->text_x - br->screen->text_ulx < br->tab_stop) + br->text_x = br->screen->text_ulx + br->tab_stop; + } else if ((ch == ';') && (br->prev_ch == 10)) { while (*br->message++ != 10) ; - prev_ch = 10; + br->prev_ch = 10; } else if (ch == '\\') { - prev_ch = ch; + br->prev_ch = ch; } else if (ch == 10) { - if (prev_ch != '\\') { - prev_ch = ch; + if (br->prev_ch != '\\') { + br->prev_ch = ch; br->text_y += FSPACY(5)+FSPACY(5)*3/5; - br->text_x = bsp->text_ulx; - if (br->text_y > bsp->text_uly + bsp->text_height) { + br->text_x = br->screen->text_ulx; + if (br->text_y > br->screen->text_uly + br->screen->text_height) { load_briefing_screen(br, Briefing_screens[br->cur_screen].bs_name); - br->text_x = bsp->text_ulx; - br->text_y = bsp->text_uly; + br->text_x = br->screen->text_ulx; + br->text_y = br->screen->text_uly; } } else { if (ch == 13) //Can this happen? Above says ch==10 Int3(); - prev_ch = ch; + br->prev_ch = ch; } } else { - br->messagestream[streamcount].x = br->text_x; - br->messagestream[streamcount].y = br->text_y; - br->messagestream[streamcount].color = Briefing_text_colors[Current_color]; - br->messagestream[streamcount].ch = ch; - if (delay_count) { + br->messagestream[br->streamcount].x = br->text_x; + br->messagestream[br->streamcount].y = br->text_y; + br->messagestream[br->streamcount].color = Briefing_text_colors[Current_color]; + br->messagestream[br->streamcount].ch = ch; + if (br->delay_count) { gr_flip(); show_fullscr(&br->background); - redraw_messagestream(br->messagestream, streamcount); - if (flashing_cursor) + redraw_messagestream(br->messagestream, br->streamcount); + if (br->flashing_cursor) gr_printf(br->text_x + FSPACX(7),br->text_y,"_"); } - if (guy_bitmap_show) - show_briefing_bitmap(&guy_bitmap); - streamcount++; + if (br->guy_bitmap_show) + show_briefing_bitmap(&br->guy_bitmap); + br->streamcount++; - prev_ch = ch; - br->text_x += show_char_delay(br, ch, delay_count, robot_num, flashing_cursor); + br->prev_ch = ch; + br->text_x += show_char_delay(br, ch, br->delay_count, br->robot_num, br->flashing_cursor); } // Check for Esc -> abort. - if(delay_count) + if(br->delay_count) key_check=local_key_inkey(); else key_check=0; @@ -940,18 +947,18 @@ int show_briefing(briefing *br) title_save_game(); if ((key_check == KEY_SPACEBAR) || (key_check == KEY_ENTER)) - delay_count = 0; + br->delay_count = 0; - if (br->text_x > bsp->text_ulx + bsp->text_width) { - br->text_x = bsp->text_ulx; - br->text_y += bsp->text_uly; + if (br->text_x > br->screen->text_ulx + br->screen->text_width) { + br->text_x = br->screen->text_ulx; + br->text_y += br->screen->text_uly; } - if ((new_page) || (br->text_y > bsp->text_uly + bsp->text_height)) { + if ((br->new_page) || (br->text_y > br->screen->text_uly + br->screen->text_height)) { fix start_time = 0; int keypress; - new_page = 0; + br->new_page = 0; start_time = timer_get_fixed_seconds(); while ( (keypress = local_key_inkey()) == 0 ) { // Wait for a key while (timer_get_fixed_seconds() < start_time + KEY_DELAY_DEFAULT/2) @@ -959,18 +966,18 @@ int show_briefing(briefing *br) timer_delay2(50); gr_flip(); show_fullscr(&br->background); - redraw_messagestream(br->messagestream, streamcount); - if (guy_bitmap_show) - show_briefing_bitmap(&guy_bitmap); - flash_cursor(br, flashing_cursor); - if (robot_num != -1) - show_spinning_robot_frame(br, robot_num); + redraw_messagestream(br->messagestream, br->streamcount); + if (br->guy_bitmap_show) + show_briefing_bitmap(&br->guy_bitmap); + flash_cursor(br, br->flashing_cursor); + if (br->robot_num != -1) + show_spinning_robot_frame(br, br->robot_num); if (br->bitmap_name[0] != 0) show_animated_bitmap(br); start_time += KEY_DELAY_DEFAULT/2; } - robot_num = -1; + br->robot_num = -1; #ifndef NDEBUG if (keypress == KEY_BACKSP) @@ -980,24 +987,24 @@ int show_briefing(briefing *br) rval = 1; done = 1; } - load_briefing_screen(br, fname); - br->text_x = bsp->text_ulx; - br->text_y = bsp->text_uly; + load_briefing_screen(br, br->background_name); + br->text_x = br->screen->text_ulx; + br->text_y = br->screen->text_uly; - streamcount=0; - if (guy_bitmap_show) { - gr_free_bitmap_data (&guy_bitmap); - guy_bitmap_show=0; + br->streamcount=0; + if (br->guy_bitmap_show) { + gr_free_bitmap_data (&br->guy_bitmap); + br->guy_bitmap_show=0; } - delay_count = KEY_DELAY_DEFAULT; + br->delay_count = KEY_DELAY_DEFAULT; } } if (br->robot_canv != NULL) {d_free(br->robot_canv); br->robot_canv=NULL;} - d_free(bsp); + d_free(br->screen); if (br->background.bm_data != NULL) gr_free_bitmap_data (&br->background);