1 /* $Id: gamerend.c,v 1.20 2005-08-07 09:58:12 chris Exp $ */
3 THE COMPUTER CODE CONTAINED HEREIN IS THE SOLE PROPERTY OF PARALLAX
4 SOFTWARE CORPORATION ("PARALLAX"). PARALLAX, IN DISTRIBUTING THE CODE TO
5 END-USERS, AND SUBJECT TO ALL OF THE TERMS AND CONDITIONS HEREIN, GRANTS A
6 ROYALTY-FREE, PERPETUAL LICENSE TO SUCH END-USERS FOR USE BY SUCH END-USERS
7 IN USING, DISPLAYING, AND CREATING DERIVATIVE WORKS THEREOF, SO LONG AS
8 SUCH USE, DISPLAY OR CREATION IS FOR NON-COMMERCIAL, ROYALTY OR REVENUE
9 FREE PURPOSES. IN NO EVENT SHALL THE END-USER USE THE COMPUTER CODE
10 CONTAINED HEREIN FOR REVENUE-BEARING PURPOSES. THE END-USER UNDERSTANDS
11 AND AGREES TO THE TERMS HEREIN AND ACCEPTS THE SAME BY USE OF THIS FILE.
12 COPYRIGHT 1993-1999 PARALLAX SOFTWARE CORPORATION. ALL RIGHTS RESERVED.
17 * Stuff for rendering the HUD
26 static char rcsid[] = "$Id: gamerend.c,v 1.20 2005-08-07 09:58:12 chris Exp $";
68 extern fix Cruise_speed;
69 extern int LinearSVGABuffer;
70 extern int Current_display_mode;
71 extern cvar_t r_framerate;
75 extern int Debug_pause; //John's debugging pause system
79 extern int Saving_movie_frames;
81 #define Saving_movie_frames 0
84 // Returns the length of the first 'n' characters of a string.
85 int string_width( char * s, int n )
91 gr_get_string_size( s, &w, &h, &aw );
96 // Draw string 's' centered on a canvas... if wider than
97 // canvas, then wrap it.
98 void draw_centered_text( int y, char * s )
105 if ( string_width( s, l ) < grd_curcanv->cv_bitmap.bm_w ) {
106 gr_string( 0x8000, y, s );
110 for (i=0; i<l; i++ ) {
111 if ( string_width(s,i) > (grd_curcanv->cv_bitmap.bm_w - 16) ) {
114 gr_string( 0x8000, y, s );
116 gr_string( 0x8000, y+grd_curcanv->cv_font->ft_h+1, &s[i] );
122 extern ubyte DefiningMarkerMessage;
123 extern char Marker_input[];
125 #define MAX_MARKER_MESSAGE_LEN 120
126 void game_draw_marker_message()
128 char temp_string[MAX_MARKER_MESSAGE_LEN+25];
130 if ( DefiningMarkerMessage)
132 gr_set_curfont( GAME_FONT ); //GAME_FONT
133 gr_set_fontcolor(gr_getcolor(0,63,0), -1 );
134 sprintf( temp_string, "Marker: %s_", Marker_input );
135 draw_centered_text(grd_curcanv->cv_bitmap.bm_h/2-16, temp_string );
141 void game_draw_multi_message()
143 char temp_string[MAX_MULTI_MESSAGE_LEN+25];
145 if ( (Game_mode&GM_MULTI) && (multi_sending_message)) {
146 gr_set_curfont( GAME_FONT ); //GAME_FONT );
147 gr_set_fontcolor(gr_getcolor(0,63,0), -1 );
148 sprintf( temp_string, "%s: %s_", TXT_MESSAGE, Network_message );
149 draw_centered_text(grd_curcanv->cv_bitmap.bm_h/2-16, temp_string );
153 if ( (Game_mode&GM_MULTI) && (multi_defining_message)) {
154 gr_set_curfont( GAME_FONT ); //GAME_FONT );
155 gr_set_fontcolor(gr_getcolor(0,63,0), -1 );
156 sprintf( temp_string, "%s #%d: %s_", TXT_MACRO, multi_defining_message, Network_message );
157 draw_centered_text(grd_curcanv->cv_bitmap.bm_h/2-16, temp_string );
162 //these should be in gr.h
163 #define cv_w cv_bitmap.bm_w
164 #define cv_h cv_bitmap.bm_h
166 fix frame_time_list[8] = {0,0,0,0,0,0,0,0};
167 fix frame_time_total=0;
168 int frame_time_cntr=0;
170 void ftoa(char *string, fix f)
172 int decimal, fractional;
175 fractional = ((f & 0xffff)*100)/65536;
178 if (fractional > 99 ) fractional = 99;
179 sprintf( string, "%d.%02d", decimal, fractional );
182 void show_framerate()
188 int x = 8, y = 5; // position measured from lower right corner
190 frame_time_total += RealFrameTime - frame_time_list[frame_time_cntr];
191 frame_time_list[frame_time_cntr] = RealFrameTime;
192 frame_time_cntr = (frame_time_cntr+1)%8;
194 rate = fixdiv(f1_0*8,frame_time_total);
196 gr_set_curfont( GAME_FONT );
197 gr_set_fontcolor(gr_getcolor(0,31,0),-1 );
199 ftoa( temp, rate ); // Convert fixed to string
200 if (Game_mode & GM_MULTI)
202 gr_printf(grd_curcanv->cv_w-(x*GAME_FONT->ft_w),grd_curcanv->cv_h-y*(GAME_FONT->ft_h+GAME_FONT->ft_h/4),"FPS: %s ", temp );
203 // if ( !( q++ % 30 ) )
204 // mprintf( (0,"fps: %s\n", temp ) );
209 fix Show_view_text_timer = -1;
211 void draw_window_label()
213 if ( Show_view_text_timer > 0 )
215 char *viewer_name,*control_name;
217 Show_view_text_timer -= FrameTime;
218 gr_set_curfont( GAME_FONT );
221 switch( Viewer->type )
223 case OBJ_FIREBALL: viewer_name = "Fireball"; break;
224 case OBJ_ROBOT: viewer_name = "Robot";
226 viewer_id = Robot_names[Viewer->id];
229 case OBJ_HOSTAGE: viewer_name = "Hostage"; break;
230 case OBJ_PLAYER: viewer_name = "Player"; break;
231 case OBJ_WEAPON: viewer_name = "Weapon"; break;
232 case OBJ_CAMERA: viewer_name = "Camera"; break;
233 case OBJ_POWERUP: viewer_name = "Powerup";
235 viewer_id = Powerup_names[Viewer->id];
238 case OBJ_DEBRIS: viewer_name = "Debris"; break;
239 case OBJ_CNTRLCEN: viewer_name = "Reactor"; break;
240 default: viewer_name = "Unknown"; break;
243 switch ( Viewer->control_type) {
244 case CT_NONE: control_name = "Stopped"; break;
245 case CT_AI: control_name = "AI"; break;
246 case CT_FLYING: control_name = "Flying"; break;
247 case CT_SLEW: control_name = "Slew"; break;
248 case CT_FLYTHROUGH: control_name = "Flythrough"; break;
249 case CT_MORPH: control_name = "Morphing"; break;
250 default: control_name = "Unknown"; break;
253 gr_set_fontcolor( gr_getcolor(31, 0, 0), -1 );
254 gr_printf( 0x8000, 45, "%i: %s [%s] View - %s",Viewer-Objects, viewer_name, viewer_id, control_name );
260 extern int Game_window_x;
261 extern int Game_window_y;
262 extern int Game_window_w;
263 extern int Game_window_h;
264 extern int max_window_w;
265 extern int max_window_h;
267 void render_countdown_gauge()
269 if (!Endlevel_sequence && Control_center_destroyed && (Countdown_seconds_left>-1)) { // && (Countdown_seconds_left<127)) {
272 if (!is_D2_OEM && !is_MAC_SHARE && !is_SHAREWARE) // no countdown on registered only
274 // On last level, we don't want a countdown.
275 if (PLAYING_BUILTIN_MISSION && Current_level_num == Last_level)
277 if (!(Game_mode & GM_MULTI))
279 if (Game_mode & GM_MULTI_ROBOTS)
284 gr_set_curfont( SMALL_FONT );
285 gr_set_fontcolor(gr_getcolor(0,63,0), -1 );
286 y = SMALL_FONT->ft_h*4;
287 if (Cockpit_mode == CM_FULL_SCREEN)
288 y += SMALL_FONT->ft_h*2;
291 y += SMALL_FONT->ft_h*2;
293 //if (!((Cockpit_mode == CM_STATUS_BAR) && (Game_window_y >= 19)))
295 gr_printf(0x8000, y, "T-%d s", Countdown_seconds_left );
299 void game_draw_hud_stuff()
301 //mprintf ((0,"Linear is %d!\n",LinearSVGABuffer));
305 gr_set_curfont( MEDIUM1_FONT );
306 gr_set_fontcolor( gr_getcolor(31, 31, 31), -1 ); // gr_getcolor(31,0,0));
307 gr_ustring( 0x8000, 85/2, "Debug Pause - Press P to exit" );
316 game_draw_multi_message();
319 game_draw_marker_message();
321 // if (Game_mode & GM_MULTI)
323 // if (Netgame.PlayTimeAllowed)
324 // game_draw_time_left ();
327 if ((Newdemo_state == ND_STATE_PLAYBACK) || (Newdemo_state == ND_STATE_RECORDING)) {
331 if (Newdemo_state == ND_STATE_PLAYBACK) {
332 if (Newdemo_vcr_state != ND_STATE_PRINTSCREEN) {
333 sprintf(message, "%s (%d%%%% %s)", TXT_DEMO_PLAYBACK, newdemo_get_percent_done(), TXT_DONE);
335 sprintf (message, " ");
338 sprintf (message, TXT_DEMO_RECORDING);
340 gr_set_curfont( GAME_FONT ); //GAME_FONT );
341 gr_set_fontcolor(gr_getcolor(27,0,0), -1 );
343 gr_get_string_size(message, &w, &h, &aw );
344 if (Cockpit_mode == CM_FULL_COCKPIT) {
345 if (grd_curcanv->cv_bitmap.bm_h > 240)
349 } else if ( Cockpit_mode == CM_LETTERBOX )
351 if (Cockpit_mode != CM_REAR_VIEW && !Saving_movie_frames)
352 gr_printf((grd_curcanv->cv_bitmap.bm_w-w)/2, grd_curcanv->cv_bitmap.bm_h - h - 2, message );
355 render_countdown_gauge();
357 if ( Player_num > -1 && Viewer->type==OBJ_PLAYER && Viewer->id==Player_num ) {
359 int y = grd_curcanv->cv_bitmap.bm_h;
361 gr_set_curfont( GAME_FONT );
362 gr_set_fontcolor( gr_getcolor(0, 31, 0), -1 );
363 if (Cruise_speed > 0) {
364 int line_spacing = GAME_FONT->ft_h + GAME_FONT->ft_h/4;
366 mprintf((0,"line_spacing=%d ",line_spacing));
368 if (Cockpit_mode==CM_FULL_SCREEN) {
369 if (Game_mode & GM_MULTI)
370 y -= line_spacing * 11; //64
372 y -= line_spacing * 6; //32
373 } else if (Cockpit_mode == CM_STATUS_BAR) {
374 if (Game_mode & GM_MULTI)
375 y -= line_spacing * 8; //48
377 y -= line_spacing * 4; //24
379 y = line_spacing * 2; //12
383 gr_printf( x, y, "%s %2d%%", TXT_CRUISE, f2i(Cruise_speed) );
387 if (r_framerate.value)
390 if ( (Newdemo_state == ND_STATE_PLAYBACK) )
391 Game_mode = Newdemo_game_mode;
395 if ( (Newdemo_state == ND_STATE_PLAYBACK) )
396 Game_mode = GM_NORMAL;
398 if ( Player_is_dead )
399 player_dead_message();
402 extern int gr_bitblt_dest_step_shift;
403 extern int gr_wait_for_retrace;
404 extern int gr_bitblt_double;
407 void expand_row(ubyte * dest, ubyte * src, int num_src_pixels );
408 #pragma aux expand_row parm [edi] [esi] [ecx] modify exact [ecx esi edi eax ebx] = \
426 void expand_row(ubyte * dest, ubyte * src, int num_src_pixels )
430 for (i = 0; i < num_src_pixels; i++) {
437 // doubles the size in x or y of a bitmap in place.
438 void game_expand_bitmap( grs_bitmap * bmp, uint flags )
441 ubyte * dptr, * sptr;
445 Assert( bmp->bm_rowsize == bmp->bm_w*2 );
446 dptr = &bmp->bm_data[(bmp->bm_h-1)*bmp->bm_rowsize];
447 for (i=bmp->bm_h-1; i>=0; i-- ) {
448 expand_row( dptr, dptr, bmp->bm_w );
449 dptr -= bmp->bm_rowsize;
454 dptr = &bmp->bm_data[(2*(bmp->bm_h-1)+1)*bmp->bm_rowsize];
455 sptr = &bmp->bm_data[(bmp->bm_h-1)*bmp->bm_rowsize];
456 for (i=bmp->bm_h-1; i>=0; i-- ) {
457 memcpy( dptr, sptr, bmp->bm_w );
458 dptr -= bmp->bm_rowsize;
459 memcpy( dptr, sptr, bmp->bm_w );
460 dptr -= bmp->bm_rowsize;
461 sptr -= bmp->bm_rowsize;
465 case 3: // expand x & y
466 Assert( bmp->bm_rowsize == bmp->bm_w*2 );
467 dptr = &bmp->bm_data[(2*(bmp->bm_h-1)+1)*bmp->bm_rowsize];
468 sptr = &bmp->bm_data[(bmp->bm_h-1)*bmp->bm_rowsize];
469 for (i=bmp->bm_h-1; i>=0; i-- ) {
470 expand_row( dptr, sptr, bmp->bm_w );
471 dptr -= bmp->bm_rowsize;
472 expand_row( dptr, sptr, bmp->bm_w );
473 dptr -= bmp->bm_rowsize;
474 sptr -= bmp->bm_rowsize;
482 extern int SW_drawn[2], SW_x[2], SW_y[2], SW_w[2], SW_h[2];
484 extern int Guided_in_big_window;
487 //render a frame for the game in stereo
488 void game_render_frame_stereo()
492 fix actual_eye_width;
493 int actual_eye_offset;
494 grs_canvas RenderCanvas[2];
497 save_aspect = grd_curscreen->sc_aspect;
498 grd_curscreen->sc_aspect *= 2; //Muck with aspect ratio
500 sw = dw = VR_render_buffer[0].cv_bitmap.bm_w;
501 sh = dh = VR_render_buffer[0].cv_bitmap.bm_h;
503 if (VR_low_res & 1) {
505 grd_curscreen->sc_aspect *= 2; //Muck with aspect ratio
507 if (VR_low_res & 2) {
509 grd_curscreen->sc_aspect /= 2; //Muck with aspect ratio
512 gr_init_sub_canvas( &RenderCanvas[0], &VR_render_buffer[0], 0, 0, sw, sh );
513 gr_init_sub_canvas( &RenderCanvas[1], &VR_render_buffer[1], 0, 0, sw, sh );
515 // Draw the left eye's view
517 actual_eye_width = -VR_eye_width;
518 actual_eye_offset = -VR_eye_offset;
520 actual_eye_width = VR_eye_width;
521 actual_eye_offset = VR_eye_offset;
524 if (Guided_missile[Player_num] && Guided_missile[Player_num]->type==OBJ_WEAPON && Guided_missile[Player_num]->id==GUIDEDMISS_ID && Guided_missile[Player_num]->signature==Guided_missile_sig[Player_num] && Guided_in_big_window)
525 actual_eye_offset = 0;
527 gr_set_current_canvas(&RenderCanvas[0]);
529 if (Guided_missile[Player_num] && Guided_missile[Player_num]->type==OBJ_WEAPON && Guided_missile[Player_num]->id==GUIDEDMISS_ID && Guided_missile[Player_num]->signature==Guided_missile_sig[Player_num] && Guided_in_big_window) {
530 char *msg = "Guided Missile View";
531 object *viewer_save = Viewer;
534 Viewer = Guided_missile[Player_num];
537 update_rendered_data(0, Viewer, 0, 0);
540 wake_up_rendered_objects(Viewer, 0);
541 Viewer = viewer_save;
543 gr_set_curfont( GAME_FONT ); //GAME_FONT );
544 gr_set_fontcolor(gr_getcolor(27,0,0), -1 );
545 gr_get_string_size(msg, &w, &h, &aw );
547 gr_printf((grd_curcanv->cv_bitmap.bm_w-w)/2, 3, msg );
549 draw_guided_crosshair();
552 HUD_render_message_frame();
557 render_frame(actual_eye_width, 0); // switch eye positions for rear view
559 render_frame(-actual_eye_width, 0); // Left eye
562 game_expand_bitmap( &RenderCanvas[0].cv_bitmap, VR_low_res );
564 { //render small window into left eye's canvas
565 grs_canvas *save=grd_curcanv;
566 fix save_aspect2 = grd_curscreen->sc_aspect;
567 grd_curscreen->sc_aspect = save_aspect*2;
568 SW_drawn[0] = SW_drawn[1] = 0;
570 gr_set_current_canvas(save);
571 grd_curscreen->sc_aspect = save_aspect2;
575 if (actual_eye_offset > 0 ) {
576 gr_setcolor( gr_getcolor(0,0,0) );
577 gr_rect( grd_curcanv->cv_bitmap.bm_w-labs(actual_eye_offset)*2, 0,
578 grd_curcanv->cv_bitmap.bm_w-1, grd_curcanv->cv_bitmap.bm_h );
579 } else if (actual_eye_offset < 0 ) {
580 gr_setcolor( gr_getcolor(0,0,0) );
581 gr_rect( 0, 0, labs(actual_eye_offset)*2-1, grd_curcanv->cv_bitmap.bm_h );
584 if ( VR_show_hud && !no_draw_hud ) {
586 if (actual_eye_offset < 0 ) {
587 gr_init_sub_canvas( &tmp, grd_curcanv, labs(actual_eye_offset*2), 0, grd_curcanv->cv_bitmap.bm_w-(labs(actual_eye_offset)*2), grd_curcanv->cv_bitmap.bm_h );
589 gr_init_sub_canvas( &tmp, grd_curcanv, 0, 0, grd_curcanv->cv_bitmap.bm_w-(labs(actual_eye_offset)*2), grd_curcanv->cv_bitmap.bm_h );
591 gr_set_current_canvas( &tmp );
592 game_draw_hud_stuff();
596 // Draw the right eye's view
597 gr_set_current_canvas(&RenderCanvas[1]);
599 if (Guided_missile[Player_num] && Guided_missile[Player_num]->type==OBJ_WEAPON && Guided_missile[Player_num]->id==GUIDEDMISS_ID && Guided_missile[Player_num]->signature==Guided_missile_sig[Player_num] && Guided_in_big_window)
600 gr_bitmap(0,0,&RenderCanvas[0].cv_bitmap);
603 render_frame(-actual_eye_width, 0); // switch eye positions for rear view
605 render_frame(actual_eye_width, 0); // Right eye
608 game_expand_bitmap( &RenderCanvas[1].cv_bitmap, VR_low_res );
612 { //copy small window from left eye
617 gr_init_sub_canvas(&temp,&RenderCanvas[0],SW_x[w],SW_y[w],SW_w[w],SW_h[w]);
618 gr_bitmap(SW_x[w]+actual_eye_offset*2,SW_y[w],&temp.cv_bitmap);
624 if (actual_eye_offset>0) {
625 gr_setcolor( gr_getcolor(0,0,0) );
626 gr_rect( 0, 0, labs(actual_eye_offset)*2-1, grd_curcanv->cv_bitmap.bm_h );
627 } else if ( actual_eye_offset < 0 ) {
628 gr_setcolor( gr_getcolor(0,0,0) );
629 gr_rect( grd_curcanv->cv_bitmap.bm_w-labs(actual_eye_offset)*2, 0,
630 grd_curcanv->cv_bitmap.bm_w-1, grd_curcanv->cv_bitmap.bm_h );
633 //NEWVR (Add the next 2 lines)
634 if ( VR_show_hud && !no_draw_hud ) {
636 if (actual_eye_offset > 0 ) {
637 gr_init_sub_canvas( &tmp, grd_curcanv, labs(actual_eye_offset*2), 0, grd_curcanv->cv_bitmap.bm_w-(labs(actual_eye_offset)*2), grd_curcanv->cv_bitmap.bm_h );
639 gr_init_sub_canvas( &tmp, grd_curcanv, 0, 0, grd_curcanv->cv_bitmap.bm_w-(labs(actual_eye_offset)*2), grd_curcanv->cv_bitmap.bm_h );
641 gr_set_current_canvas( &tmp );
642 game_draw_hud_stuff();
646 // Draws white and black registration encoding lines
647 // and Accounts for pixel-shift adjustment in upcoming bitblts
648 if (VR_use_reg_code) {
649 int width, height, quarter;
651 width = RenderCanvas[0].cv_bitmap.bm_w;
652 height = RenderCanvas[0].cv_bitmap.bm_h;
655 // black out left-hand side of left page
657 // draw registration code for left eye
659 gr_set_current_canvas( &RenderCanvas[1] );
661 gr_set_current_canvas( &RenderCanvas[0] );
662 gr_setcolor( VR_WHITE_INDEX );
663 gr_scanline( 0, quarter, height-1 );
664 gr_setcolor( VR_BLACK_INDEX );
665 gr_scanline( quarter, width-1, height-1 );
668 gr_set_current_canvas( &RenderCanvas[0] );
670 gr_set_current_canvas( &RenderCanvas[1] );
671 gr_setcolor( VR_WHITE_INDEX );
672 gr_scanline( 0, quarter*3, height-1 );
673 gr_setcolor( VR_BLACK_INDEX );
674 gr_scanline( quarter*3, width-1, height-1 );
677 // Copy left eye, then right eye
678 if ( VR_screen_flags&VRF_USE_PAGING )
679 VR_current_page = !VR_current_page;
682 gr_set_current_canvas( &VR_screen_pages[VR_current_page] );
686 if ( VR_eye_offset_changed > 0 ) {
687 VR_eye_offset_changed--;
691 sw = dw = VR_render_buffer[0].cv_bitmap.bm_w;
692 sh = dh = VR_render_buffer[0].cv_bitmap.bm_h;
694 // Copy left eye, then right eye
695 gr_bitblt_dest_step_shift = 1; // Skip every other scanline.
697 if (VR_render_mode == VR_INTERLACED ) {
698 if ( actual_eye_offset > 0 ) {
699 int xoff = labs(actual_eye_offset);
700 gr_bm_ubitblt( dw-xoff, dh, xoff, 0, 0, 0, &RenderCanvas[0].cv_bitmap, &VR_screen_pages[VR_current_page].cv_bitmap);
701 gr_bm_ubitblt( dw-xoff, dh, 0, 1, xoff, 0, &RenderCanvas[1].cv_bitmap, &VR_screen_pages[VR_current_page].cv_bitmap);
702 } else if ( actual_eye_offset < 0 ) {
703 int xoff = labs(actual_eye_offset);
704 gr_bm_ubitblt( dw-xoff, dh, 0, 0, xoff, 0, &RenderCanvas[0].cv_bitmap, &VR_screen_pages[VR_current_page].cv_bitmap);
705 gr_bm_ubitblt( dw-xoff, dh, xoff, 1, 0, 0, &RenderCanvas[1].cv_bitmap, &VR_screen_pages[VR_current_page].cv_bitmap);
707 gr_bm_ubitblt( dw, dh, 0, 0, 0, 0, &RenderCanvas[0].cv_bitmap, &VR_screen_pages[VR_current_page].cv_bitmap);
708 gr_bm_ubitblt( dw, dh, 0, 1, 0, 0, &RenderCanvas[1].cv_bitmap, &VR_screen_pages[VR_current_page].cv_bitmap);
710 } else if (VR_render_mode == VR_AREA_DET) {
712 gr_bm_ubitblt( dw, dh, 0, VR_current_page, 0, 0, &RenderCanvas[0].cv_bitmap, &VR_screen_pages[0].cv_bitmap);
713 gr_bm_ubitblt( dw, dh, dw, VR_current_page, 0, 0, &RenderCanvas[1].cv_bitmap, &VR_screen_pages[0].cv_bitmap);
718 gr_bitblt_dest_step_shift = 0;
720 //if ( Game_vfx_flag )
721 // vfx_set_page(VR_current_page); // 0 or 1
723 if ( VR_screen_flags&VRF_USE_PAGING ) {
724 gr_wait_for_retrace = 0;
726 // Added by Samir from John's code
727 if ( (VR_screen_pages[VR_current_page].cv_bitmap.bm_type == BM_MODEX) && (Game_3dmax_flag==3) ) {
728 int old_x, old_y, new_x;
729 old_x = VR_screen_pages[VR_current_page].cv_bitmap.bm_x;
730 old_y = VR_screen_pages[VR_current_page].cv_bitmap.bm_y;
731 new_x = old_y*VR_screen_pages[VR_current_page].cv_bitmap.bm_rowsize;
733 VR_screen_pages[VR_current_page].cv_bitmap.bm_x = new_x;
734 VR_screen_pages[VR_current_page].cv_bitmap.bm_y = 0;
735 VR_screen_pages[VR_current_page].cv_bitmap.bm_type = BM_SVGA;
736 gr_show_canvas( &VR_screen_pages[VR_current_page] );
737 VR_screen_pages[VR_current_page].cv_bitmap.bm_type = BM_MODEX;
738 VR_screen_pages[VR_current_page].cv_bitmap.bm_x = old_x;
739 VR_screen_pages[VR_current_page].cv_bitmap.bm_y = old_y;
741 gr_show_canvas( &VR_screen_pages[VR_current_page] );
743 gr_wait_for_retrace = 1;
745 grd_curscreen->sc_aspect=save_aspect;
748 ubyte RenderingType=0;
749 ubyte DemoDoingRight=0,DemoDoingLeft=0;
750 extern ubyte DemoDoRight,DemoDoLeft;
751 extern object DemoRightExtra,DemoLeftExtra;
753 char DemoWBUType[]={0,WBU_MISSILE,WBU_MISSILE,WBU_REAR,WBU_ESCORT,WBU_MARKER,WBU_MISSILE};
754 char DemoRearCheck[]={0,0,0,1,0,0,0};
755 char *DemoExtraMessage[]={"PLAYER","GUIDED","MISSILE","REAR","GUIDE-BOT","MARKER","SHIP"};
757 extern char guidebot_name[];
759 void show_extra_views()
761 int did_missile_view=0;
762 int save_newdemo_state = Newdemo_state;
765 if (Newdemo_state==ND_STATE_PLAYBACK)
769 DemoDoingLeft=DemoDoLeft;
772 do_cockpit_window_view(0,ConsoleObject,1,WBU_REAR,"REAR");
774 do_cockpit_window_view(0,&DemoLeftExtra,DemoRearCheck[DemoDoLeft],DemoWBUType[DemoDoLeft],DemoExtraMessage[DemoDoLeft]);
777 do_cockpit_window_view(0,NULL,0,WBU_WEAPON,NULL);
781 DemoDoingRight=DemoDoRight;
784 do_cockpit_window_view(1,ConsoleObject,1,WBU_REAR,"REAR");
786 do_cockpit_window_view(1,&DemoRightExtra,DemoRearCheck[DemoDoRight],DemoWBUType[DemoDoRight],DemoExtraMessage[DemoDoRight]);
789 do_cockpit_window_view(1,NULL,0,WBU_WEAPON,NULL);
791 DemoDoLeft=DemoDoRight=0;
792 DemoDoingLeft=DemoDoingRight=0;
797 if (Guided_missile[Player_num] && Guided_missile[Player_num]->type==OBJ_WEAPON && Guided_missile[Player_num]->id==GUIDEDMISS_ID && Guided_missile[Player_num]->signature==Guided_missile_sig[Player_num]) {
798 if (Guided_in_big_window)
800 RenderingType=6+(1<<4);
801 do_cockpit_window_view(1,Viewer,0,WBU_MISSILE,"SHIP");
805 RenderingType=1+(1<<4);
806 do_cockpit_window_view(1,Guided_missile[Player_num],0,WBU_GUIDED,"GUIDED");
813 if (Guided_missile[Player_num]) { //used to be active
814 if (!Guided_in_big_window)
815 do_cockpit_window_view(1,NULL,0,WBU_STATIC,NULL);
816 Guided_missile[Player_num] = NULL;
819 if (Missile_viewer) { //do missile view
820 static int mv_sig=-1;
822 mv_sig = Missile_viewer->signature;
823 if (Missile_view_enabled && Missile_viewer->type!=OBJ_NONE && Missile_viewer->signature == mv_sig) {
824 RenderingType=2+(1<<4);
825 do_cockpit_window_view(1,Missile_viewer,0,WBU_MISSILE,"MISSILE");
829 Missile_viewer = NULL;
832 do_cockpit_window_view(1,NULL,0,WBU_STATIC,NULL);
839 if (w==1 && did_missile_view)
840 continue; //if showing missile view in right window, can't show anything else
842 //show special views if selected
843 switch (Cockpit_3d_view[w]) {
846 do_cockpit_window_view(w,NULL,0,WBU_WEAPON,NULL);
849 if (Rear_view) { //if big window is rear view, show front here
850 RenderingType=3+(w<<4);
851 do_cockpit_window_view(w,ConsoleObject,0,WBU_REAR,"FRONT");
853 else { //show normal rear view
854 RenderingType=3+(w<<4);
855 do_cockpit_window_view(w,ConsoleObject,1,WBU_REAR,"REAR");
860 buddy = find_escort();
862 do_cockpit_window_view(w,NULL,0,WBU_WEAPON,NULL);
863 Cockpit_3d_view[w] = CV_NONE;
866 RenderingType=4+(w<<4);
867 do_cockpit_window_view(w,buddy,0,WBU_ESCORT,guidebot_name);
873 int player = Coop_view_player[w];
875 RenderingType=255; // don't handle coop stuff
877 if (player!=-1 && Players[player].connected && ((Game_mode & GM_MULTI_COOP) || ((Game_mode & GM_TEAM) && (get_team(player) == get_team(Player_num)))))
878 do_cockpit_window_view(w,&Objects[Players[Coop_view_player[w]].objnum],0,WBU_COOP,Players[Coop_view_player[w]].callsign);
880 do_cockpit_window_view(w,NULL,0,WBU_WEAPON,NULL);
881 Cockpit_3d_view[w] = CV_NONE;
888 RenderingType=5+(w<<4);
889 if (Marker_viewer_num[w] == -1 || MarkerObject[Marker_viewer_num[w]] == -1) {
890 Cockpit_3d_view[w] = CV_NONE;
893 sprintf(label,"Marker %d",Marker_viewer_num[w]+1);
894 do_cockpit_window_view(w,&Objects[MarkerObject[Marker_viewer_num[w]]],0,WBU_MARKER,label);
898 Int3(); //invalid window type
902 Newdemo_state = save_newdemo_state;
905 int BigWindowSwitch=0;
906 extern int force_cockpit_redraw;
908 void draw_guided_crosshair(void);
909 void update_cockpits(int force_redraw);
912 //render a frame for the game
913 void game_render_frame_mono(void)
915 grs_canvas Screen_3d_window;
919 gr_init_sub_canvas( &Screen_3d_window, &VR_screen_pages[0],
920 VR_render_sub_buffer[0].cv_bitmap.bm_x,
921 VR_render_sub_buffer[0].cv_bitmap.bm_y,
922 VR_render_sub_buffer[0].cv_bitmap.bm_w,
923 VR_render_sub_buffer[0].cv_bitmap.bm_h);
925 if ( Game_double_buffer )
926 gr_set_current_canvas(&VR_render_sub_buffer[0]);
928 gr_set_current_canvas(&Screen_3d_window);
930 if (Guided_missile[Player_num] && Guided_missile[Player_num]->type==OBJ_WEAPON && Guided_missile[Player_num]->id==GUIDEDMISS_ID && Guided_missile[Player_num]->signature==Guided_missile_sig[Player_num] && Guided_in_big_window) {
931 char *msg = "Guided Missile View";
932 object *viewer_save = Viewer;
935 if (Cockpit_mode==CM_FULL_COCKPIT)
938 force_cockpit_redraw=1;
939 Cockpit_mode=CM_STATUS_BAR;
943 Viewer = Guided_missile[Player_num];
946 update_rendered_data(0, Viewer, 0, 0);
949 wake_up_rendered_objects(Viewer, 0);
950 Viewer = viewer_save;
952 gr_set_curfont( GAME_FONT ); //GAME_FONT );
953 gr_set_fontcolor(gr_getcolor(27,0,0), -1 );
954 gr_get_string_size(msg, &w, &h, &aw );
956 gr_printf((grd_curcanv->cv_bitmap.bm_w-w)/2, 3, msg );
958 draw_guided_crosshair();
961 HUD_render_message_frame();
969 force_cockpit_redraw=1;
970 Cockpit_mode=CM_FULL_COCKPIT;
974 update_rendered_data(0, Viewer, Rear_view, 0);
978 if ( Game_double_buffer )
979 gr_set_current_canvas(&VR_render_sub_buffer[0]);
981 gr_set_current_canvas(&Screen_3d_window);
984 game_draw_hud_stuff();
986 if (Game_paused) { //render pause message over off-screen 3d (to minimize flicker)
987 extern char *Pause_msg;
988 ubyte *save_data = VR_screen_pages[VR_current_page].cv_bitmap.bm_data;
990 VR_screen_pages[VR_current_page].cv_bitmap.bm_data=VR_render_buffer[VR_current_page].cv_bitmap.bm_data;
991 show_boxed_message(Pause_msg);
992 VR_screen_pages[VR_current_page].cv_bitmap.bm_data=save_data;
995 if ( Game_double_buffer ) { //copy to visible screen
996 // if ( !Game_cockpit_copy_code ) {
997 if ( VR_screen_flags&VRF_USE_PAGING ) {
998 VR_current_page = !VR_current_page;
999 gr_set_current_canvas( &VR_screen_pages[VR_current_page] );
1000 gr_bm_ubitblt( VR_render_sub_buffer[0].cv_w, VR_render_sub_buffer[0].cv_h, VR_render_sub_buffer[0].cv_bitmap.bm_x, VR_render_sub_buffer[0].cv_bitmap.bm_y, 0, 0, &VR_render_sub_buffer[0].cv_bitmap, &VR_screen_pages[VR_current_page].cv_bitmap );
1001 gr_wait_for_retrace = 0;
1002 gr_show_canvas( &VR_screen_pages[VR_current_page] );
1003 gr_wait_for_retrace = 1;
1005 gr_bm_ubitblt( VR_render_sub_buffer[0].cv_w,
1006 VR_render_sub_buffer[0].cv_h,
1007 VR_render_sub_buffer[0].cv_bitmap.bm_x,
1008 VR_render_sub_buffer[0].cv_bitmap.bm_y,
1010 &VR_render_sub_buffer[0].cv_bitmap,
1011 &VR_screen_pages[0].cv_bitmap );
1016 gr_ibitblt( &VR_render_buffer[0].cv_bitmap, &VR_screen_pages[0].cv_bitmap, Game_cockpit_copy_code );
1017 #else //def MACINTOSH
1018 gr_ibitblt( &VR_render_sub_buffer[0].cv_bitmap, &VR_screen_pages[0].cv_bitmap );
1026 show_extra_views(); //missile view, buddy bot, etc.
1028 if (Cockpit_mode==CM_FULL_COCKPIT || Cockpit_mode==CM_STATUS_BAR) {
1030 if ( (Newdemo_state == ND_STATE_PLAYBACK) )
1031 Game_mode = Newdemo_game_mode;
1035 if ( (Newdemo_state == ND_STATE_PLAYBACK) )
1036 Game_mode = GM_NORMAL;
1047 void toggle_cockpit()
1051 switch (Cockpit_mode) {
1053 case CM_FULL_COCKPIT: {
1054 int max_h = grd_curscreen->sc_h - GameBitmaps[cockpit_bitmap[CM_STATUS_BAR+(Current_display_mode?(Num_cockpits/2):0)].index].bm_h;
1055 if (Game_window_h > max_h) //too big for statusbar
1056 new_mode = CM_FULL_SCREEN;
1058 new_mode = CM_STATUS_BAR;
1063 case CM_FULL_SCREEN:
1066 new_mode = CM_FULL_COCKPIT;
1072 return; //do nothing
1077 select_cockpit(new_mode);
1078 HUD_clear_messages();
1079 write_player_file();
1083 #define WINDOW_W_DELTA ((max_window_w / 16)&~1) //24 //20
1084 #define WINDOW_H_DELTA ((max_window_h / 16)&~1) //12 //10
1086 #define WINDOW_MIN_W ((max_window_w * 10) / 22) //160
1087 #define WINDOW_MIN_H ((max_window_h * 10) / 22)
1089 //#define WINDOW_W_DELTA 32
1090 //#define WINDOW_H_DELTA 16
1092 #define WINDOW_W_DELTA ((max_window_w / 16) & ~15) // double word aligned
1093 #define WINDOW_H_DELTA ((max_window_h / 16) & ~15) // double word aligned
1095 #define WINDOW_MIN_W (max_window_w-(WINDOW_W_DELTA*11))
1096 #define WINDOW_MIN_H (max_window_h-(WINDOW_H_DELTA*11))
1101 if (Cockpit_mode == CM_FULL_COCKPIT) {
1102 Game_window_h = max_window_h;
1103 Game_window_w = max_window_w;
1105 HUD_init_message("Press F3 to return to Cockpit mode");
1109 if (Cockpit_mode != CM_STATUS_BAR && (VR_screen_flags & VRF_ALLOW_COCKPIT))
1112 if (Game_window_h>=max_window_h || Game_window_w>=max_window_w) {
1113 //Game_window_w = max_window_w;
1114 //Game_window_h = max_window_h;
1115 select_cockpit(CM_FULL_SCREEN);
1119 Game_window_w += WINDOW_W_DELTA;
1120 Game_window_h += WINDOW_H_DELTA;
1122 if (Game_window_h > max_window_h)
1123 Game_window_h = max_window_h;
1125 if (Game_window_w > max_window_w)
1126 Game_window_w = max_window_w;
1128 Game_window_x = (max_window_w - Game_window_w)/2;
1129 Game_window_y = (max_window_h - Game_window_h)/2;
1131 game_init_render_sub_buffers( Game_window_x, Game_window_y, Game_window_w, Game_window_h );
1134 HUD_clear_messages(); // @mk, 11/11/94
1136 write_player_file();
1139 // grs_bitmap background_bitmap; already declared in line 434 (samir 4/10/94)
1141 extern grs_bitmap background_bitmap;
1143 void copy_background_rect(int left,int top,int right,int bot)
1145 grs_bitmap *bm = &background_bitmap;
1147 int tile_left,tile_right,tile_top,tile_bot;
1151 if (right < left || bot < top)
1154 tile_left = left / bm->bm_w;
1155 tile_right = right / bm->bm_w;
1156 tile_top = top / bm->bm_h;
1157 tile_bot = bot / bm->bm_h;
1159 ofs_y = top % bm->bm_h;
1162 for (y=tile_top;y<=tile_bot;y++) {
1165 ofs_x = left % bm->bm_w;
1168 //h = (bot < dest_y+bm->bm_h)?(bot-dest_y+1):(bm->bm_h-ofs_y);
1169 h = min(bot-dest_y+1,bm->bm_h-ofs_y);
1171 for (x=tile_left;x<=tile_right;x++) {
1173 //w = (right < dest_x+bm->bm_w)?(right-dest_x+1):(bm->bm_w-ofs_x);
1174 w = min(right-dest_x+1,bm->bm_w-ofs_x);
1176 gr_bm_ubitblt(w,h,dest_x,dest_y,ofs_x,ofs_y,
1177 &background_bitmap,&grd_curcanv->cv_bitmap);
1188 //fills int the background surrounding the 3d window
1189 void fill_background()
1201 gr_set_current_canvas(&VR_screen_pages[VR_current_page]);
1202 copy_background_rect(x-dx,y-dy,x-1,y+h+dy-1);
1203 copy_background_rect(x+w,y-dy,grd_curcanv->cv_w-1,y+h+dy-1);
1204 copy_background_rect(x,y-dy,x+w-1,y-1);
1205 copy_background_rect(x,y+h,x+w-1,y+h+dy-1);
1207 if (VR_screen_flags & VRF_USE_PAGING) {
1208 gr_set_current_canvas(&VR_screen_pages[!VR_current_page]);
1209 copy_background_rect(x-dx,y-dy,x-1,y+h+dy-1);
1210 copy_background_rect(x+w,y-dy,x+w+dx-1,y+h+dy-1);
1211 copy_background_rect(x,y-dy,x+w-1,y-1);
1212 copy_background_rect(x,y+h,x+w-1,y+h+dy-1);
1216 void shrink_window()
1218 mprintf((0,"%d ",FrameCount));
1220 // mprintf ((0,"W=%d H=%d\n",Game_window_w,Game_window_h));
1222 if (Cockpit_mode == CM_FULL_COCKPIT && (VR_screen_flags & VRF_ALLOW_COCKPIT)) {
1223 Game_window_h = max_window_h;
1224 Game_window_w = max_window_w;
1225 //!!toggle_cockpit();
1226 select_cockpit(CM_STATUS_BAR);
1229 HUD_init_message("Press F3 to return to Cockpit mode");
1230 write_player_file();
1234 if (Cockpit_mode == CM_FULL_SCREEN && (VR_screen_flags & VRF_ALLOW_COCKPIT))
1236 //Game_window_w = max_window_w;
1237 //Game_window_h = max_window_h;
1238 select_cockpit(CM_STATUS_BAR);
1239 write_player_file();
1243 if (Cockpit_mode != CM_STATUS_BAR && (VR_screen_flags & VRF_ALLOW_COCKPIT))
1246 mprintf ((0,"Cockpit mode=%d\n",Cockpit_mode));
1248 if (Game_window_w > WINDOW_MIN_W) {
1251 Game_window_w -= WINDOW_W_DELTA;
1252 Game_window_h -= WINDOW_H_DELTA;
1255 mprintf ((0,"NewW=%d NewH=%d VW=%d maxH=%d\n",Game_window_w,Game_window_h,max_window_w,max_window_h));
1257 if ( Game_window_w < WINDOW_MIN_W )
1258 Game_window_w = WINDOW_MIN_W;
1260 if ( Game_window_h < WINDOW_MIN_H )
1261 Game_window_h = WINDOW_MIN_H;
1263 Game_window_x = (max_window_w - Game_window_w)/2;
1264 Game_window_y = (max_window_h - Game_window_h)/2;
1268 game_init_render_sub_buffers( Game_window_x, Game_window_y, Game_window_w, Game_window_h );
1269 HUD_clear_messages();
1270 write_player_file();
1275 int last_drawn_cockpit[2] = { -1, -1 };
1276 extern void ogl_loadbmtexture(grs_bitmap *bm);
1278 // This actually renders the new cockpit onto the screen.
1279 void update_cockpits(int force_redraw)
1283 //Redraw the on-screen cockpit bitmaps
1284 if (VR_render_mode != VR_NONE ) return;
1286 switch( Cockpit_mode ) {
1287 case CM_FULL_COCKPIT:
1289 gr_set_current_canvas(&VR_screen_pages[VR_current_page]);
1290 PIGGY_PAGE_IN(cockpit_bitmap[Cockpit_mode+(Current_display_mode?(Num_cockpits/2):0)]);
1291 gr_ubitmapm(0,0, &GameBitmaps[cockpit_bitmap[Cockpit_mode+(Current_display_mode?(Num_cockpits/2):0)].index]);
1294 case CM_FULL_SCREEN:
1295 Game_window_x = (max_window_w - Game_window_w)/2;
1296 Game_window_y = (max_window_h - Game_window_h)/2;
1302 gr_set_current_canvas(&VR_screen_pages[VR_current_page]);
1304 PIGGY_PAGE_IN(cockpit_bitmap[Cockpit_mode+(Current_display_mode?(Num_cockpits/2):0)]);
1305 gr_ubitmapm(0,max_window_h,&GameBitmaps[cockpit_bitmap[Cockpit_mode+(Current_display_mode?(Num_cockpits/2):0)].index]);
1307 Game_window_x = (max_window_w - Game_window_w)/2;
1308 Game_window_y = (max_window_h - Game_window_h)/2;
1313 gr_set_current_canvas(&VR_screen_pages[VR_current_page]);
1314 gr_clear_canvas( BM_XRGB(0,0,0) );
1316 // In a modex mode, clear the other buffer.
1317 if (grd_curcanv->cv_bitmap.bm_type == BM_MODEX) {
1318 gr_set_current_canvas(&VR_screen_pages[VR_current_page^1]);
1319 gr_clear_canvas( BM_XRGB(0,0,0) );
1320 gr_set_current_canvas(&VR_screen_pages[VR_current_page]);
1326 gr_set_current_canvas(&VR_screen_pages[VR_current_page]);
1328 if (Cockpit_mode != last_drawn_cockpit[VR_current_page] || force_redraw )
1329 last_drawn_cockpit[VR_current_page] = Cockpit_mode;
1333 if (Cockpit_mode==CM_FULL_COCKPIT || Cockpit_mode==CM_STATUS_BAR)
1339 void game_render_frame()
1341 set_screen_mode( SCREEN_GAME );
1343 // update_cockpits(0);
1345 play_homing_warning();
1347 if (VR_render_mode == VR_NONE )
1348 game_render_frame_mono();
1350 game_render_frame_stereo();
1353 // Make sure palette is faded in
1355 gr_palette_fade_in( gr_palette, 32, 0 );
1361 extern int Color_0_31_0;
1363 //draw a crosshair for the guided missile
1364 void draw_guided_crosshair(void)
1368 gr_setcolor(Color_0_31_0);
1370 w = grd_curcanv->cv_w>>5;
1374 h = i2f(w) / grd_curscreen->sc_aspect;
1376 x = grd_curcanv->cv_w / 2;
1377 y = grd_curcanv->cv_h / 2;
1379 gr_scanline(x-w/2,x+w/2,y);
1380 gr_uline(i2f(x),i2f(y-h/2),i2f(x),i2f(y+h/2));
1384 typedef struct bkg {
1385 short x, y, w, h; // The location of the menu.
1386 grs_bitmap * bmp; // The background under the menu.
1389 bkg bg = {0,0,0,0,NULL};
1391 #define BOX_BORDER (MenuHires?60:30)
1393 //show a message in a nice little box
1394 void show_boxed_message(char *msg)
1399 gr_set_current_canvas(&VR_screen_pages[VR_current_page]);
1400 gr_set_curfont( MEDIUM1_FONT );
1402 gr_get_string_size(msg,&w,&h,&aw);
1404 x = (grd_curscreen->sc_w-w)/2;
1405 y = (grd_curscreen->sc_h-h)/2;
1408 gr_free_bitmap(bg.bmp);
1412 // Save the background of the display
1413 bg.x=x; bg.y=y; bg.w=w; bg.h=h;
1415 bg.bmp = gr_create_bitmap( w+BOX_BORDER, h+BOX_BORDER );
1417 gr_bm_ubitblt(w+BOX_BORDER, h+BOX_BORDER, 0, 0, x-BOX_BORDER/2, y-BOX_BORDER/2, &(grd_curcanv->cv_bitmap), bg.bmp );
1419 nm_draw_background(x-BOX_BORDER/2,y-BOX_BORDER/2,x+w+BOX_BORDER/2-1,y+h+BOX_BORDER/2-1);
1421 gr_set_fontcolor( gr_getcolor(31, 31, 31), -1 );
1423 gr_ustring( 0x8000, y, msg );
1426 void clear_boxed_message()
1431 gr_bitmap(bg.x-BOX_BORDER/2, bg.y-BOX_BORDER/2, bg.bmp);
1433 gr_free_bitmap(bg.bmp);