1 /* $Id: gamerend.c,v 1.13 2003-10-12 09:38:48 btb 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.13 2003-10-12 09:38:48 btb Exp $";
40 #include "pa_enabl.h" //$$POLY_ACC
78 extern fix Cruise_speed;
79 extern int LinearSVGABuffer;
80 extern int Current_display_mode;
81 extern cvar_t r_framerate;
85 cockpit_span_line win_cockpit_mask[480];
86 void win_do_emul_ibitblt(dd_grs_canvas *csrc, dd_grs_canvas *cdest);
91 extern int Debug_pause; //John's debugging pause system
95 extern int Saving_movie_frames;
97 #define Saving_movie_frames 0
100 // Returns the length of the first 'n' characters of a string.
101 int string_width( char * s, int n )
107 gr_get_string_size( s, &w, &h, &aw );
112 // Draw string 's' centered on a canvas... if wider than
113 // canvas, then wrap it.
114 void draw_centered_text( int y, char * s )
121 if ( string_width( s, l ) < grd_curcanv->cv_bitmap.bm_w ) {
122 gr_string( 0x8000, y, s );
126 for (i=0; i<l; i++ ) {
127 if ( string_width(s,i) > (grd_curcanv->cv_bitmap.bm_w - 16) ) {
130 gr_string( 0x8000, y, s );
132 gr_string( 0x8000, y+grd_curcanv->cv_font->ft_h+1, &s[i] );
138 extern ubyte DefiningMarkerMessage;
139 extern char Marker_input[];
141 #define MAX_MARKER_MESSAGE_LEN 120
142 void game_draw_marker_message()
144 char temp_string[MAX_MARKER_MESSAGE_LEN+25];
146 if ( DefiningMarkerMessage)
148 gr_set_curfont( GAME_FONT ); //GAME_FONT
149 gr_set_fontcolor(gr_getcolor(0,63,0), -1 );
150 sprintf( temp_string, "Marker: %s_", Marker_input );
151 draw_centered_text(grd_curcanv->cv_bitmap.bm_h/2-16, temp_string );
157 void game_draw_multi_message()
159 char temp_string[MAX_MULTI_MESSAGE_LEN+25];
161 if ( (Game_mode&GM_MULTI) && (multi_sending_message)) {
162 gr_set_curfont( GAME_FONT ); //GAME_FONT );
163 gr_set_fontcolor(gr_getcolor(0,63,0), -1 );
164 sprintf( temp_string, "%s: %s_", TXT_MESSAGE, Network_message );
165 draw_centered_text(grd_curcanv->cv_bitmap.bm_h/2-16, temp_string );
169 if ( (Game_mode&GM_MULTI) && (multi_defining_message)) {
170 gr_set_curfont( GAME_FONT ); //GAME_FONT );
171 gr_set_fontcolor(gr_getcolor(0,63,0), -1 );
172 sprintf( temp_string, "%s #%d: %s_", TXT_MACRO, multi_defining_message, Network_message );
173 draw_centered_text(grd_curcanv->cv_bitmap.bm_h/2-16, temp_string );
178 //these should be in gr.h
179 #define cv_w cv_bitmap.bm_w
180 #define cv_h cv_bitmap.bm_h
182 fix frame_time_list[8] = {0,0,0,0,0,0,0,0};
183 fix frame_time_total=0;
184 int frame_time_cntr=0;
186 void ftoa(char *string, fix f)
188 int decimal, fractional;
191 fractional = ((f & 0xffff)*100)/65536;
194 if (fractional > 99 ) fractional = 99;
195 sprintf( string, "%d.%02d", decimal, fractional );
198 void show_framerate()
204 int x = 8, y = 5; // position measured from lower right corner
206 frame_time_total += RealFrameTime - frame_time_list[frame_time_cntr];
207 frame_time_list[frame_time_cntr] = RealFrameTime;
208 frame_time_cntr = (frame_time_cntr+1)%8;
210 rate = fixdiv(f1_0*8,frame_time_total);
212 gr_set_curfont( GAME_FONT );
213 gr_set_fontcolor(gr_getcolor(0,31,0),-1 );
215 ftoa( temp, rate ); // Convert fixed to string
216 if (Game_mode & GM_MULTI)
218 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 );
219 // if ( !( q++ % 30 ) )
220 // mprintf( (0,"fps: %s\n", temp ) );
225 fix Show_view_text_timer = -1;
227 void draw_window_label()
229 if ( Show_view_text_timer > 0 )
231 char *viewer_name,*control_name;
233 Show_view_text_timer -= FrameTime;
234 gr_set_curfont( GAME_FONT );
237 switch( Viewer->type )
239 case OBJ_FIREBALL: viewer_name = "Fireball"; break;
240 case OBJ_ROBOT: viewer_name = "Robot";
242 viewer_id = Robot_names[Viewer->id];
245 case OBJ_HOSTAGE: viewer_name = "Hostage"; break;
246 case OBJ_PLAYER: viewer_name = "Player"; break;
247 case OBJ_WEAPON: viewer_name = "Weapon"; break;
248 case OBJ_CAMERA: viewer_name = "Camera"; break;
249 case OBJ_POWERUP: viewer_name = "Powerup";
251 viewer_id = Powerup_names[Viewer->id];
254 case OBJ_DEBRIS: viewer_name = "Debris"; break;
255 case OBJ_CNTRLCEN: viewer_name = "Reactor"; break;
256 default: viewer_name = "Unknown"; break;
259 switch ( Viewer->control_type) {
260 case CT_NONE: control_name = "Stopped"; break;
261 case CT_AI: control_name = "AI"; break;
262 case CT_FLYING: control_name = "Flying"; break;
263 case CT_SLEW: control_name = "Slew"; break;
264 case CT_FLYTHROUGH: control_name = "Flythrough"; break;
265 case CT_MORPH: control_name = "Morphing"; break;
266 default: control_name = "Unknown"; break;
269 gr_set_fontcolor( gr_getcolor(31, 0, 0), -1 );
270 gr_printf( 0x8000, 45, "%i: %s [%s] View - %s",Viewer-Objects, viewer_name, viewer_id, control_name );
276 extern int Game_window_x;
277 extern int Game_window_y;
278 extern int Game_window_w;
279 extern int Game_window_h;
280 extern int max_window_w;
281 extern int max_window_h;
283 void render_countdown_gauge()
285 if (!Endlevel_sequence && Control_center_destroyed && (Countdown_seconds_left>-1)) { // && (Countdown_seconds_left<127)) {
288 if (!is_D2_OEM && !is_MAC_SHARE && !is_SHAREWARE) // no countdown on registered only
290 // On last level, we don't want a countdown.
291 if ((Current_mission_num == Builtin_mission_num) && (Current_level_num == Last_level))
293 if (!(Game_mode & GM_MULTI))
295 if (Game_mode & GM_MULTI_ROBOTS)
300 gr_set_curfont( SMALL_FONT );
301 gr_set_fontcolor(gr_getcolor(0,63,0), -1 );
302 y = SMALL_FONT->ft_h*4;
303 if (Cockpit_mode == CM_FULL_SCREEN)
304 y += SMALL_FONT->ft_h*2;
307 y += SMALL_FONT->ft_h*2;
309 //if (!((Cockpit_mode == CM_STATUS_BAR) && (Game_window_y >= 19)))
311 gr_printf(0x8000, y, "T-%d s", Countdown_seconds_left );
315 void game_draw_hud_stuff()
318 int odisplay_mode = Current_display_mode;
319 if (Scanline_double) {
321 Current_display_mode = 0;
326 //mprintf ((0,"Linear is %d!\n",LinearSVGABuffer));
330 gr_set_curfont( MEDIUM1_FONT );
331 gr_set_fontcolor( gr_getcolor(31, 31, 31), -1 ); // gr_getcolor(31,0,0));
332 gr_ustring( 0x8000, 85/2, "Debug Pause - Press P to exit" );
341 game_draw_multi_message();
344 game_draw_marker_message();
346 // if (Game_mode & GM_MULTI)
348 // if (Netgame.PlayTimeAllowed)
349 // game_draw_time_left ();
352 if ((Newdemo_state == ND_STATE_PLAYBACK) || (Newdemo_state == ND_STATE_RECORDING)) {
356 if (Newdemo_state == ND_STATE_PLAYBACK) {
357 if (Newdemo_vcr_state != ND_STATE_PRINTSCREEN) {
358 sprintf(message, "%s (%d%%%% %s)", TXT_DEMO_PLAYBACK, newdemo_get_percent_done(), TXT_DONE);
360 sprintf (message, " ");
363 sprintf (message, TXT_DEMO_RECORDING);
365 gr_set_curfont( GAME_FONT ); //GAME_FONT );
366 gr_set_fontcolor(gr_getcolor(27,0,0), -1 );
368 gr_get_string_size(message, &w, &h, &aw );
370 if (Scanline_double) // double height if scanline doubling since we have the correct
371 h += h; // font for printing, but the wrong height.
373 if (Cockpit_mode == CM_FULL_COCKPIT) {
374 if (grd_curcanv->cv_bitmap.bm_h > 240)
378 } else if ( Cockpit_mode == CM_LETTERBOX )
380 if (Cockpit_mode != CM_REAR_VIEW && !Saving_movie_frames)
381 gr_printf((grd_curcanv->cv_bitmap.bm_w-w)/2, grd_curcanv->cv_bitmap.bm_h - h - 2, message );
384 render_countdown_gauge();
386 if ( Player_num > -1 && Viewer->type==OBJ_PLAYER && Viewer->id==Player_num ) {
388 int y = grd_curcanv->cv_bitmap.bm_h;
390 gr_set_curfont( GAME_FONT );
391 gr_set_fontcolor( gr_getcolor(0, 31, 0), -1 );
392 if (Cruise_speed > 0) {
393 int line_spacing = GAME_FONT->ft_h + GAME_FONT->ft_h/4;
395 mprintf((0,"line_spacing=%d ",line_spacing));
397 if (Cockpit_mode==CM_FULL_SCREEN) {
398 if (Game_mode & GM_MULTI)
399 y -= line_spacing * 11; //64
401 y -= line_spacing * 6; //32
402 } else if (Cockpit_mode == CM_STATUS_BAR) {
403 if (Game_mode & GM_MULTI)
404 y -= line_spacing * 8; //48
406 y -= line_spacing * 4; //24
408 y = line_spacing * 2; //12
412 gr_printf( x, y, "%s %2d%%", TXT_CRUISE, f2i(Cruise_speed) );
416 if (r_framerate.value)
419 if ( (Newdemo_state == ND_STATE_PLAYBACK) )
420 Game_mode = Newdemo_game_mode;
424 if ( (Newdemo_state == ND_STATE_PLAYBACK) )
425 Game_mode = GM_NORMAL;
427 if ( Player_is_dead )
428 player_dead_message();
431 if (Scanline_double) {
433 Current_display_mode = odisplay_mode;
438 extern int gr_bitblt_dest_step_shift;
439 extern int gr_wait_for_retrace;
440 extern int gr_bitblt_double;
443 void expand_row(ubyte * dest, ubyte * src, int num_src_pixels );
444 #pragma aux expand_row parm [edi] [esi] [ecx] modify exact [ecx esi edi eax ebx] = \
462 void expand_row(ubyte * dest, ubyte * src, int num_src_pixels )
466 for (i = 0; i < num_src_pixels; i++) {
473 // doubles the size in x or y of a bitmap in place.
474 void game_expand_bitmap( grs_bitmap * bmp, uint flags )
477 ubyte * dptr, * sptr;
481 Assert( bmp->bm_rowsize == bmp->bm_w*2 );
482 dptr = &bmp->bm_data[(bmp->bm_h-1)*bmp->bm_rowsize];
483 for (i=bmp->bm_h-1; i>=0; i-- ) {
484 expand_row( dptr, dptr, bmp->bm_w );
485 dptr -= bmp->bm_rowsize;
490 dptr = &bmp->bm_data[(2*(bmp->bm_h-1)+1)*bmp->bm_rowsize];
491 sptr = &bmp->bm_data[(bmp->bm_h-1)*bmp->bm_rowsize];
492 for (i=bmp->bm_h-1; i>=0; i-- ) {
493 memcpy( dptr, sptr, bmp->bm_w );
494 dptr -= bmp->bm_rowsize;
495 memcpy( dptr, sptr, bmp->bm_w );
496 dptr -= bmp->bm_rowsize;
497 sptr -= bmp->bm_rowsize;
501 case 3: // expand x & y
502 Assert( bmp->bm_rowsize == bmp->bm_w*2 );
503 dptr = &bmp->bm_data[(2*(bmp->bm_h-1)+1)*bmp->bm_rowsize];
504 sptr = &bmp->bm_data[(bmp->bm_h-1)*bmp->bm_rowsize];
505 for (i=bmp->bm_h-1; i>=0; i-- ) {
506 expand_row( dptr, sptr, bmp->bm_w );
507 dptr -= bmp->bm_rowsize;
508 expand_row( dptr, sptr, bmp->bm_w );
509 dptr -= bmp->bm_rowsize;
510 sptr -= bmp->bm_rowsize;
518 extern int SW_drawn[2], SW_x[2], SW_y[2], SW_w[2], SW_h[2];
520 extern int Guided_in_big_window;
523 //render a frame for the game in stereo
524 void game_render_frame_stereo()
528 fix actual_eye_width;
529 int actual_eye_offset;
530 grs_canvas RenderCanvas[2];
533 save_aspect = grd_curscreen->sc_aspect;
534 grd_curscreen->sc_aspect *= 2; //Muck with aspect ratio
536 sw = dw = VR_render_buffer[0].cv_bitmap.bm_w;
537 sh = dh = VR_render_buffer[0].cv_bitmap.bm_h;
539 if (VR_low_res & 1) {
541 grd_curscreen->sc_aspect *= 2; //Muck with aspect ratio
543 if (VR_low_res & 2) {
545 grd_curscreen->sc_aspect /= 2; //Muck with aspect ratio
548 gr_init_sub_canvas( &RenderCanvas[0], &VR_render_buffer[0], 0, 0, sw, sh );
549 gr_init_sub_canvas( &RenderCanvas[1], &VR_render_buffer[1], 0, 0, sw, sh );
551 // Draw the left eye's view
553 actual_eye_width = -VR_eye_width;
554 actual_eye_offset = -VR_eye_offset;
556 actual_eye_width = VR_eye_width;
557 actual_eye_offset = VR_eye_offset;
560 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)
561 actual_eye_offset = 0;
563 gr_set_current_canvas(&RenderCanvas[0]);
565 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) {
566 char *msg = "Guided Missile View";
567 object *viewer_save = Viewer;
570 Viewer = Guided_missile[Player_num];
572 WIN(DDGRLOCK(dd_grd_curcanv)); // Must lock DD canvas!!!
578 update_rendered_data(0, Viewer, 0, 0);
580 #if defined(POLY_ACC) && !defined(MACINTOSH) // dma stuff not support on mac via RAVE
584 wake_up_rendered_objects(Viewer, 0);
585 Viewer = viewer_save;
587 gr_set_curfont( GAME_FONT ); //GAME_FONT );
588 gr_set_fontcolor(gr_getcolor(27,0,0), -1 );
589 gr_get_string_size(msg, &w, &h, &aw );
591 gr_printf((grd_curcanv->cv_bitmap.bm_w-w)/2, 3, msg );
593 draw_guided_crosshair();
595 WIN(DDGRUNLOCK(dd_grd_curcanv));
597 HUD_render_message_frame();
606 render_frame(actual_eye_width, 0); // switch eye positions for rear view
608 render_frame(-actual_eye_width, 0); // Left eye
611 game_expand_bitmap( &RenderCanvas[0].cv_bitmap, VR_low_res );
613 { //render small window into left eye's canvas
614 grs_canvas *save=grd_curcanv;
615 fix save_aspect2 = grd_curscreen->sc_aspect;
616 grd_curscreen->sc_aspect = save_aspect*2;
617 SW_drawn[0] = SW_drawn[1] = 0;
619 gr_set_current_canvas(save);
620 grd_curscreen->sc_aspect = save_aspect2;
624 if (actual_eye_offset > 0 ) {
625 gr_setcolor( gr_getcolor(0,0,0) );
626 gr_rect( grd_curcanv->cv_bitmap.bm_w-labs(actual_eye_offset)*2, 0,
627 grd_curcanv->cv_bitmap.bm_w-1, grd_curcanv->cv_bitmap.bm_h );
628 } else if (actual_eye_offset < 0 ) {
629 gr_setcolor( gr_getcolor(0,0,0) );
630 gr_rect( 0, 0, labs(actual_eye_offset)*2-1, grd_curcanv->cv_bitmap.bm_h );
633 if ( VR_show_hud && !no_draw_hud ) {
635 if (actual_eye_offset < 0 ) {
636 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 );
638 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 );
640 gr_set_current_canvas( &tmp );
641 game_draw_hud_stuff();
645 // Draw the right eye's view
646 gr_set_current_canvas(&RenderCanvas[1]);
648 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)
649 gr_bitmap(0,0,&RenderCanvas[0].cv_bitmap);
652 render_frame(-actual_eye_width, 0); // switch eye positions for rear view
654 render_frame(actual_eye_width, 0); // Right eye
657 game_expand_bitmap( &RenderCanvas[1].cv_bitmap, VR_low_res );
661 { //copy small window from left eye
666 gr_init_sub_canvas(&temp,&RenderCanvas[0],SW_x[w],SW_y[w],SW_w[w],SW_h[w]);
667 gr_bitmap(SW_x[w]+actual_eye_offset*2,SW_y[w],&temp.cv_bitmap);
673 if (actual_eye_offset>0) {
674 gr_setcolor( gr_getcolor(0,0,0) );
675 gr_rect( 0, 0, labs(actual_eye_offset)*2-1, grd_curcanv->cv_bitmap.bm_h );
676 } else if ( actual_eye_offset < 0 ) {
677 gr_setcolor( gr_getcolor(0,0,0) );
678 gr_rect( grd_curcanv->cv_bitmap.bm_w-labs(actual_eye_offset)*2, 0,
679 grd_curcanv->cv_bitmap.bm_w-1, grd_curcanv->cv_bitmap.bm_h );
682 //NEWVR (Add the next 2 lines)
683 if ( VR_show_hud && !no_draw_hud ) {
685 if (actual_eye_offset > 0 ) {
686 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 );
688 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 );
690 gr_set_current_canvas( &tmp );
691 game_draw_hud_stuff();
695 // Draws white and black registration encoding lines
696 // and Accounts for pixel-shift adjustment in upcoming bitblts
697 if (VR_use_reg_code) {
698 int width, height, quarter;
700 width = RenderCanvas[0].cv_bitmap.bm_w;
701 height = RenderCanvas[0].cv_bitmap.bm_h;
704 // black out left-hand side of left page
706 // draw registration code for left eye
708 gr_set_current_canvas( &RenderCanvas[1] );
710 gr_set_current_canvas( &RenderCanvas[0] );
711 gr_setcolor( VR_WHITE_INDEX );
712 gr_scanline( 0, quarter, height-1 );
713 gr_setcolor( VR_BLACK_INDEX );
714 gr_scanline( quarter, width-1, height-1 );
717 gr_set_current_canvas( &RenderCanvas[0] );
719 gr_set_current_canvas( &RenderCanvas[1] );
720 gr_setcolor( VR_WHITE_INDEX );
721 gr_scanline( 0, quarter*3, height-1 );
722 gr_setcolor( VR_BLACK_INDEX );
723 gr_scanline( quarter*3, width-1, height-1 );
726 // Copy left eye, then right eye
727 if ( VR_screen_flags&VRF_USE_PAGING )
728 VR_current_page = !VR_current_page;
731 gr_set_current_canvas( &VR_screen_pages[VR_current_page] );
735 if ( VR_eye_offset_changed > 0 ) {
736 VR_eye_offset_changed--;
740 sw = dw = VR_render_buffer[0].cv_bitmap.bm_w;
741 sh = dh = VR_render_buffer[0].cv_bitmap.bm_h;
743 // Copy left eye, then right eye
744 gr_bitblt_dest_step_shift = 1; // Skip every other scanline.
746 if (VR_render_mode == VR_INTERLACED ) {
747 if ( actual_eye_offset > 0 ) {
748 int xoff = labs(actual_eye_offset);
749 gr_bm_ubitblt( dw-xoff, dh, xoff, 0, 0, 0, &RenderCanvas[0].cv_bitmap, &VR_screen_pages[VR_current_page].cv_bitmap);
750 gr_bm_ubitblt( dw-xoff, dh, 0, 1, xoff, 0, &RenderCanvas[1].cv_bitmap, &VR_screen_pages[VR_current_page].cv_bitmap);
751 } else if ( actual_eye_offset < 0 ) {
752 int xoff = labs(actual_eye_offset);
753 gr_bm_ubitblt( dw-xoff, dh, 0, 0, xoff, 0, &RenderCanvas[0].cv_bitmap, &VR_screen_pages[VR_current_page].cv_bitmap);
754 gr_bm_ubitblt( dw-xoff, dh, xoff, 1, 0, 0, &RenderCanvas[1].cv_bitmap, &VR_screen_pages[VR_current_page].cv_bitmap);
756 gr_bm_ubitblt( dw, dh, 0, 0, 0, 0, &RenderCanvas[0].cv_bitmap, &VR_screen_pages[VR_current_page].cv_bitmap);
757 gr_bm_ubitblt( dw, dh, 0, 1, 0, 0, &RenderCanvas[1].cv_bitmap, &VR_screen_pages[VR_current_page].cv_bitmap);
759 } else if (VR_render_mode == VR_AREA_DET) {
761 gr_bm_ubitblt( dw, dh, 0, VR_current_page, 0, 0, &RenderCanvas[0].cv_bitmap, &VR_screen_pages[0].cv_bitmap);
762 gr_bm_ubitblt( dw, dh, dw, VR_current_page, 0, 0, &RenderCanvas[1].cv_bitmap, &VR_screen_pages[0].cv_bitmap);
767 gr_bitblt_dest_step_shift = 0;
769 //if ( Game_vfx_flag )
770 // vfx_set_page(VR_current_page); // 0 or 1
772 if ( VR_screen_flags&VRF_USE_PAGING ) {
773 gr_wait_for_retrace = 0;
775 // Added by Samir from John's code
776 if ( (VR_screen_pages[VR_current_page].cv_bitmap.bm_type == BM_MODEX) && (Game_3dmax_flag==3) ) {
777 int old_x, old_y, new_x;
778 old_x = VR_screen_pages[VR_current_page].cv_bitmap.bm_x;
779 old_y = VR_screen_pages[VR_current_page].cv_bitmap.bm_y;
780 new_x = old_y*VR_screen_pages[VR_current_page].cv_bitmap.bm_rowsize;
782 VR_screen_pages[VR_current_page].cv_bitmap.bm_x = new_x;
783 VR_screen_pages[VR_current_page].cv_bitmap.bm_y = 0;
784 VR_screen_pages[VR_current_page].cv_bitmap.bm_type = BM_SVGA;
785 gr_show_canvas( &VR_screen_pages[VR_current_page] );
786 VR_screen_pages[VR_current_page].cv_bitmap.bm_type = BM_MODEX;
787 VR_screen_pages[VR_current_page].cv_bitmap.bm_x = old_x;
788 VR_screen_pages[VR_current_page].cv_bitmap.bm_y = old_y;
790 gr_show_canvas( &VR_screen_pages[VR_current_page] );
792 gr_wait_for_retrace = 1;
794 grd_curscreen->sc_aspect=save_aspect;
797 ubyte RenderingType=0;
798 ubyte DemoDoingRight=0,DemoDoingLeft=0;
799 extern ubyte DemoDoRight,DemoDoLeft;
800 extern object DemoRightExtra,DemoLeftExtra;
802 char DemoWBUType[]={0,WBU_MISSILE,WBU_MISSILE,WBU_REAR,WBU_ESCORT,WBU_MARKER,WBU_MISSILE};
803 char DemoRearCheck[]={0,0,0,1,0,0,0};
804 char *DemoExtraMessage[]={"PLAYER","GUIDED","MISSILE","REAR","GUIDE-BOT","MARKER","SHIP"};
806 extern char guidebot_name[];
808 void show_extra_views()
810 int did_missile_view=0;
811 int save_newdemo_state = Newdemo_state;
814 if (Newdemo_state==ND_STATE_PLAYBACK)
818 DemoDoingLeft=DemoDoLeft;
821 do_cockpit_window_view(0,ConsoleObject,1,WBU_REAR,"REAR");
823 do_cockpit_window_view(0,&DemoLeftExtra,DemoRearCheck[DemoDoLeft],DemoWBUType[DemoDoLeft],DemoExtraMessage[DemoDoLeft]);
826 do_cockpit_window_view(0,NULL,0,WBU_WEAPON,NULL);
830 DemoDoingRight=DemoDoRight;
833 do_cockpit_window_view(1,ConsoleObject,1,WBU_REAR,"REAR");
835 do_cockpit_window_view(1,&DemoRightExtra,DemoRearCheck[DemoDoRight],DemoWBUType[DemoDoRight],DemoExtraMessage[DemoDoRight]);
838 do_cockpit_window_view(1,NULL,0,WBU_WEAPON,NULL);
840 DemoDoLeft=DemoDoRight=0;
841 DemoDoingLeft=DemoDoingRight=0;
846 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]) {
847 if (Guided_in_big_window)
849 RenderingType=6+(1<<4);
850 do_cockpit_window_view(1,Viewer,0,WBU_MISSILE,"SHIP");
854 RenderingType=1+(1<<4);
855 do_cockpit_window_view(1,Guided_missile[Player_num],0,WBU_GUIDED,"GUIDED");
862 if (Guided_missile[Player_num]) { //used to be active
863 if (!Guided_in_big_window)
864 do_cockpit_window_view(1,NULL,0,WBU_STATIC,NULL);
865 Guided_missile[Player_num] = NULL;
868 if (Missile_viewer) { //do missile view
869 static int mv_sig=-1;
871 mv_sig = Missile_viewer->signature;
872 if (Missile_view_enabled && Missile_viewer->type!=OBJ_NONE && Missile_viewer->signature == mv_sig) {
873 RenderingType=2+(1<<4);
874 do_cockpit_window_view(1,Missile_viewer,0,WBU_MISSILE,"MISSILE");
878 Missile_viewer = NULL;
881 do_cockpit_window_view(1,NULL,0,WBU_STATIC,NULL);
888 if (w==1 && did_missile_view)
889 continue; //if showing missile view in right window, can't show anything else
891 //show special views if selected
892 switch (Cockpit_3d_view[w]) {
895 do_cockpit_window_view(w,NULL,0,WBU_WEAPON,NULL);
898 if (Rear_view) { //if big window is rear view, show front here
899 RenderingType=3+(w<<4);
900 do_cockpit_window_view(w,ConsoleObject,0,WBU_REAR,"FRONT");
902 else { //show normal rear view
903 RenderingType=3+(w<<4);
904 do_cockpit_window_view(w,ConsoleObject,1,WBU_REAR,"REAR");
909 buddy = find_escort();
911 do_cockpit_window_view(w,NULL,0,WBU_WEAPON,NULL);
912 Cockpit_3d_view[w] = CV_NONE;
915 RenderingType=4+(w<<4);
916 do_cockpit_window_view(w,buddy,0,WBU_ESCORT,guidebot_name);
922 int player = Coop_view_player[w];
924 RenderingType=255; // don't handle coop stuff
926 if (player!=-1 && Players[player].connected && ((Game_mode & GM_MULTI_COOP) || ((Game_mode & GM_TEAM) && (get_team(player) == get_team(Player_num)))))
927 do_cockpit_window_view(w,&Objects[Players[Coop_view_player[w]].objnum],0,WBU_COOP,Players[Coop_view_player[w]].callsign);
929 do_cockpit_window_view(w,NULL,0,WBU_WEAPON,NULL);
930 Cockpit_3d_view[w] = CV_NONE;
937 RenderingType=5+(w<<4);
938 if (Marker_viewer_num[w] == -1 || MarkerObject[Marker_viewer_num[w]] == -1) {
939 Cockpit_3d_view[w] = CV_NONE;
942 sprintf(label,"Marker %d",Marker_viewer_num[w]+1);
943 do_cockpit_window_view(w,&Objects[MarkerObject[Marker_viewer_num[w]]],0,WBU_MARKER,label);
947 Int3(); //invalid window type
951 Newdemo_state = save_newdemo_state;
954 int BigWindowSwitch=0;
955 extern int force_cockpit_redraw;
957 extern ubyte * Game_cockpit_copy_code;
959 extern ubyte Game_cockpit_copy_code;
962 void draw_guided_crosshair(void);
965 // special code to render a frame w/hw acceleration
967 // next routine is called as a callback from the current hardware engine being used. The
968 // routine is called once all of the accelerated drawing is done. We now overlay the
969 // backbuffer with hud stuff.
971 void pa_mac_render_extras( void )
973 grs_canvas Screen_3d_window;
975 gr_init_sub_canvas( &Screen_3d_window, &VR_screen_pages[0],
976 VR_render_sub_buffer[0].cv_bitmap.bm_x,
977 VR_render_sub_buffer[0].cv_bitmap.bm_y,
978 VR_render_sub_buffer[0].cv_bitmap.bm_w,
979 VR_render_sub_buffer[0].cv_bitmap.bm_h);
981 gr_set_current_canvas( &Screen_3d_window ); // set to current screen
983 if (Guided_missile[Player_num] &&
984 Guided_missile[Player_num]->type==OBJ_WEAPON &&
985 Guided_missile[Player_num]->id==GUIDEDMISS_ID &&
986 Guided_missile[Player_num]->signature==Guided_missile_sig[Player_num] &&
987 Guided_in_big_window)
989 char *msg = "Guided Missile View";
992 gr_set_curfont( GAME_FONT ); //GAME_FONT );
993 gr_set_fontcolor(gr_getcolor(27,0,0), -1 );
994 gr_get_string_size(msg, &w, &h, &aw );
996 gr_printf((grd_curcanv->cv_bitmap.bm_w-w)/2, 3, msg );
998 draw_guided_crosshair();
1000 HUD_render_message_frame();
1004 game_draw_hud_stuff(); // draw hud stuff when not doing missle view in big window
1007 if (Game_paused) { //render pause message over off-screen 3d (to minimize flicker)
1008 extern char *Pause_msg;
1009 ubyte *save_data = VR_screen_pages[VR_current_page].cv_bitmap.bm_data;
1011 WIN(Int3()); // Not supported yet.
1012 VR_screen_pages[VR_current_page].cv_bitmap.bm_data=VR_render_buffer[VR_current_page].cv_bitmap.bm_data;
1013 show_boxed_message(Pause_msg);
1014 VR_screen_pages[VR_current_page].cv_bitmap.bm_data=save_data;
1020 void pa_mac_game_render_frame( void )
1022 Assert ( !Scanline_double );
1023 Assert ( PAEnabled );
1025 gr_set_current_canvas(&VR_render_sub_buffer[0]); // set up the right canvas so rendering is done to correct size
1029 if (Guided_missile[Player_num] &&
1030 Guided_missile[Player_num]->type==OBJ_WEAPON &&
1031 Guided_missile[Player_num]->id==GUIDEDMISS_ID &&
1032 Guided_missile[Player_num]->signature==Guided_missile_sig[Player_num] &&
1033 Guided_in_big_window)
1035 char *msg = "Guided Missile View";
1036 object *viewer_save = Viewer;
1039 if (Cockpit_mode==CM_FULL_COCKPIT) {
1041 force_cockpit_redraw=1;
1042 Cockpit_mode=CM_STATUS_BAR;
1047 Viewer = Guided_missile[Player_num];
1048 update_rendered_data(0, Viewer, 0, 0);
1050 wake_up_rendered_objects(Viewer, 0);
1051 Viewer = viewer_save;
1055 if (BigWindowSwitch)
1057 force_cockpit_redraw=1;
1058 Cockpit_mode=CM_FULL_COCKPIT;
1064 update_rendered_data(0, Viewer, Rear_view, 0);
1068 if (Cockpit_mode == CM_FULL_SCREEN)
1076 // NOTE: Hud stuff is drawn using a RAVE call back which draws onto the back buffer
1077 // after rendering finishes but before the page flip
1079 if (Cockpit_mode != CM_FULL_SCREEN)
1081 show_extra_views(); //missile view, buddy bot, etc.
1084 // Draw Gauges straight to screen
1085 if (Cockpit_mode==CM_FULL_COCKPIT || Cockpit_mode==CM_STATUS_BAR)
1088 if ( (Newdemo_state == ND_STATE_PLAYBACK) )
1090 Game_mode = Newdemo_game_mode;
1093 Current_display_mode = 1;
1095 Current_display_mode = -1;
1097 if ( (Newdemo_state == ND_STATE_PLAYBACK) )
1099 Game_mode = GM_NORMAL;
1106 //render a frame for the game
1108 // will render everything to dd_VR_render_sub_buffer
1109 // which all leads to the dd_VR_offscreen_buffer
1110 void game_render_frame_mono(void)
1113 dd_grs_canvas Screen_3d_window,
1114 grs_canvas Screen_3d_window
1118 #if defined(MACINTOSH)
1120 pa_mac_game_render_frame();
1127 dd_gr_init_sub_canvas(&Screen_3d_window, &dd_VR_screen_pages[0],
1128 dd_VR_render_sub_buffer[0].canvas.cv_bitmap.bm_x,
1129 dd_VR_render_sub_buffer[0].canvas.cv_bitmap.bm_y,
1130 dd_VR_render_sub_buffer[0].canvas.cv_bitmap.bm_w,
1131 dd_VR_render_sub_buffer[0].canvas.cv_bitmap.bm_h),
1132 gr_init_sub_canvas( &Screen_3d_window, &VR_screen_pages[0],
1133 VR_render_sub_buffer[0].cv_bitmap.bm_x,
1134 VR_render_sub_buffer[0].cv_bitmap.bm_y,
1135 VR_render_sub_buffer[0].cv_bitmap.bm_w,
1136 VR_render_sub_buffer[0].cv_bitmap.bm_h)
1139 if ( Game_double_buffer ) {
1141 dd_gr_set_current_canvas(&dd_VR_render_sub_buffer[0]),
1142 gr_set_current_canvas(&VR_render_sub_buffer[0])
1147 dd_gr_set_current_canvas(&Screen_3d_window),
1148 gr_set_current_canvas(&Screen_3d_window)
1152 #if defined(POLY_ACC) && !defined(MACINTOSH) // begin s3 relocation of cockpit drawing.
1156 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)
1160 WIN(DDGRLOCK(dd_grd_curcanv));
1161 game_draw_hud_stuff();
1162 WIN(DDGRUNLOCK(dd_grd_curcanv));
1165 show_extra_views(); //missile view, buddy bot, etc.
1168 if (Game_paused) { //render pause message over off-screen 3d (to minimize flicker)
1169 extern char *Pause_msg;
1170 ubyte *save_data = VR_screen_pages[VR_current_page].cv_bitmap.bm_data;
1172 WIN(Int3()); // Not supported yet.
1173 VR_screen_pages[VR_current_page].cv_bitmap.bm_data=VR_render_buffer[VR_current_page].cv_bitmap.bm_data;
1174 show_boxed_message(Pause_msg);
1175 VR_screen_pages[VR_current_page].cv_bitmap.bm_data=save_data;
1178 if ( Game_double_buffer ) { //copy to visible screen
1179 if ( !Game_cockpit_copy_code ) {
1180 if ( VR_screen_flags&VRF_USE_PAGING ) {
1181 VR_current_page = !VR_current_page;
1182 gr_set_current_canvas( &VR_screen_pages[VR_current_page] );
1183 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 );
1184 gr_wait_for_retrace = 0;
1185 gr_show_canvas( &VR_screen_pages[VR_current_page] );
1186 gr_wait_for_retrace = 1;
1188 #ifdef POLY_ACC //$$
1192 VR_render_sub_buffer[0].cv_w, VR_render_sub_buffer[0].cv_h,
1193 VR_render_sub_buffer[0].cv_bitmap.bm_x, VR_render_sub_buffer[0].cv_bitmap.bm_y,
1194 VR_render_sub_buffer[0].cv_bitmap.bm_x, VR_render_sub_buffer[0].cv_bitmap.bm_y,
1195 &VR_render_sub_buffer[0].cv_bitmap, &VR_screen_pages[0].cv_bitmap
1199 #ifdef POLY_ACC //$$
1202 gr_ibitblt( &VR_render_buffer[0].cv_bitmap, &VR_screen_pages[0].cv_bitmap, Game_cockpit_copy_code );
1206 if (Cockpit_mode==CM_FULL_COCKPIT || Cockpit_mode==CM_STATUS_BAR) {
1208 if ( (Newdemo_state == ND_STATE_PLAYBACK) )
1209 Game_mode = Newdemo_game_mode;
1213 if ( (Newdemo_state == ND_STATE_PLAYBACK) )
1214 Game_mode = GM_NORMAL;
1217 // restore current canvas.
1218 if ( Game_double_buffer ) {
1220 dd_gr_set_current_canvas(&dd_VR_render_sub_buffer[0]),
1221 gr_set_current_canvas(&VR_render_sub_buffer[0])
1226 dd_gr_set_current_canvas(&Screen_3d_window),
1227 gr_set_current_canvas(&Screen_3d_window)
1231 #endif // end s3 relocation of cockpit drawing.
1233 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) {
1234 char *msg = "Guided Missile View";
1235 object *viewer_save = Viewer;
1238 if (Cockpit_mode==CM_FULL_COCKPIT)
1241 force_cockpit_redraw=1;
1242 Cockpit_mode=CM_STATUS_BAR;
1246 Viewer = Guided_missile[Player_num];
1248 WIN(DDGRLOCK(dd_grd_curcanv)); // Must lock DD canvas!!!
1251 if (Scanline_double)
1254 update_rendered_data(0, Viewer, 0, 0);
1257 wake_up_rendered_objects(Viewer, 0);
1258 Viewer = viewer_save;
1260 gr_set_curfont( GAME_FONT ); //GAME_FONT );
1261 gr_set_fontcolor(gr_getcolor(27,0,0), -1 );
1262 gr_get_string_size(msg, &w, &h, &aw );
1264 gr_printf((grd_curcanv->cv_bitmap.bm_w-w)/2, 3, msg );
1266 draw_guided_crosshair();
1268 WIN(DDGRUNLOCK(dd_grd_curcanv));
1270 HUD_render_message_frame();
1272 if (Scanline_double)
1280 if (BigWindowSwitch)
1282 force_cockpit_redraw=1;
1283 Cockpit_mode=CM_FULL_COCKPIT;
1287 WIN(DDGRLOCK(dd_grd_curcanv)); // Must lock DD canvas!!!
1288 update_rendered_data(0, Viewer, Rear_view, 0);
1290 #if defined(POLY_ACC) && !defined(MACINTOSH) // dma stuff not supported on mac via RAVE
1293 WIN(DDGRUNLOCK(dd_grd_curcanv));
1296 if ( Game_double_buffer ) {
1298 dd_gr_set_current_canvas(&dd_VR_render_sub_buffer[0]),
1299 gr_set_current_canvas(&VR_render_sub_buffer[0])
1304 dd_gr_set_current_canvas(&Screen_3d_window),
1305 gr_set_current_canvas(&Screen_3d_window)
1309 #if !defined(POLY_ACC) || defined(MACINTOSH)
1312 WIN(DDGRLOCK(dd_grd_curcanv));
1313 game_draw_hud_stuff();
1314 WIN(DDGRUNLOCK(dd_grd_curcanv));
1317 show_extra_views(); //missile view, buddy bot, etc.
1320 if (Game_paused) { //render pause message over off-screen 3d (to minimize flicker)
1321 extern char *Pause_msg;
1322 // LPDIRECTDRAWSURFACE save_dds = dd_VR_screen_pages[VR_current_page].lpdds;
1324 // dd_VR_screen_pages[VR_current_page].lpdds = dd_VR_render_buffer[VR_current_page].lpdds;
1325 show_boxed_message(Pause_msg);
1326 // dd_VR_screen_pages[VR_current_page].lpdds = save_dds;
1329 if (Game_paused) { //render pause message over off-screen 3d (to minimize flicker)
1330 extern char *Pause_msg;
1331 ubyte *save_data = VR_screen_pages[VR_current_page].cv_bitmap.bm_data;
1333 VR_screen_pages[VR_current_page].cv_bitmap.bm_data=VR_render_buffer[VR_current_page].cv_bitmap.bm_data;
1334 show_boxed_message(Pause_msg);
1335 VR_screen_pages[VR_current_page].cv_bitmap.bm_data=save_data;
1339 if ( Game_double_buffer ) { //copy to visible screen
1340 if ( !Game_cockpit_copy_code ) {
1341 if ( VR_screen_flags&VRF_USE_PAGING ) {
1342 VR_current_page = !VR_current_page;
1344 dd_gr_set_current_canvas(&dd_VR_screen_pages[VR_current_page]);
1347 gr_set_current_canvas( &VR_screen_pages[VR_current_page] );
1348 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 );
1349 gr_wait_for_retrace = 0;
1350 gr_show_canvas( &VR_screen_pages[VR_current_page] );
1351 gr_wait_for_retrace = 1;
1355 if (Scanline_double)
1356 gr_bm_ubitblt_double( 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[0].cv_bitmap );
1358 #endif // NOTE LINK TO ABOVE IF
1360 if (GRMODEINFO(emul) || GRMODEINFO(modex) || GRMODEINFO(dbuf))
1361 // From render buffer to screen buffer.
1362 dd_gr_blt_notrans(&dd_VR_render_sub_buffer[0],
1364 dd_VR_render_sub_buffer[0].canvas.cv_w,
1365 dd_VR_render_sub_buffer[0].canvas.cv_h,
1367 dd_VR_render_sub_buffer[0].xoff,
1368 dd_VR_render_sub_buffer[0].yoff,
1369 dd_VR_render_sub_buffer[0].canvas.cv_w,
1370 dd_VR_render_sub_buffer[0].canvas.cv_h);
1373 // Puts back canvas to front canvas by blt or flip
1374 if (GRMODEINFO(modex)) {
1375 //@@VR_current_page = !VR_current_page;
1380 gr_bm_ubitblt( VR_render_sub_buffer[0].cv_w,
1381 VR_render_sub_buffer[0].cv_h,
1382 VR_render_sub_buffer[0].cv_bitmap.bm_x,
1383 VR_render_sub_buffer[0].cv_bitmap.bm_y,
1385 &VR_render_sub_buffer[0].cv_bitmap,
1386 &VR_screen_pages[0].cv_bitmap );
1395 #if 1 //def MACINTOSH
1396 gr_ibitblt( &VR_render_sub_buffer[0].cv_bitmap, &VR_screen_pages[0].cv_bitmap, Scanline_double );
1399 gr_ibitblt( &VR_render_buffer[0].cv_bitmap, &VR_screen_pages[0].cv_bitmap, Game_cockpit_copy_code );
1401 win_do_emul_ibitblt( &dd_VR_render_sub_buffer[0], dd_grd_screencanv);
1403 if (GRMODEINFO(modex)) {
1404 //@@VR_current_page = !VR_current_page;
1413 if (Cockpit_mode==CM_FULL_COCKPIT || Cockpit_mode==CM_STATUS_BAR) {
1415 if ( (Newdemo_state == ND_STATE_PLAYBACK) )
1416 Game_mode = Newdemo_game_mode;
1420 if ( (Newdemo_state == ND_STATE_PLAYBACK) )
1421 Game_mode = GM_NORMAL;
1426 VR_current_page = !VR_current_page;
1441 void toggle_cockpit()
1445 switch (Cockpit_mode) {
1447 case CM_FULL_COCKPIT: {
1448 int max_h = grd_curscreen->sc_h - GameBitmaps[cockpit_bitmap[CM_STATUS_BAR+(Current_display_mode?(Num_cockpits/2):0)].index].bm_h;
1449 if (Game_window_h > max_h) //too big for statusbar
1450 new_mode = CM_FULL_SCREEN;
1452 new_mode = CM_STATUS_BAR;
1457 case CM_FULL_SCREEN:
1460 new_mode = CM_FULL_COCKPIT;
1466 return; //do nothing
1471 select_cockpit(new_mode);
1472 HUD_clear_messages();
1473 write_player_file();
1477 #define WINDOW_W_DELTA ((max_window_w / 16)&~1) //24 //20
1478 #define WINDOW_H_DELTA ((max_window_h / 16)&~1) //12 //10
1480 #define WINDOW_MIN_W ((max_window_w * 10) / 22) //160
1481 #define WINDOW_MIN_H ((max_window_h * 10) / 22)
1483 //#define WINDOW_W_DELTA 32
1484 //#define WINDOW_H_DELTA 16
1486 #define WINDOW_W_DELTA ((max_window_w / 16) & ~15) // double word aligned
1487 #define WINDOW_H_DELTA ((max_window_h / 16) & ~15) // double word aligned
1489 #define WINDOW_MIN_W (max_window_w-(WINDOW_W_DELTA*11))
1490 #define WINDOW_MIN_H (max_window_h-(WINDOW_H_DELTA*11))
1495 if (Cockpit_mode == CM_FULL_COCKPIT) {
1496 Game_window_h = max_window_h;
1497 Game_window_w = max_window_w;
1499 HUD_init_message("Press F3 to return to Cockpit mode");
1503 if (Cockpit_mode != CM_STATUS_BAR && (VR_screen_flags & VRF_ALLOW_COCKPIT))
1506 if (Game_window_h>=max_window_h || Game_window_w>=max_window_w) {
1507 //Game_window_w = max_window_w;
1508 //Game_window_h = max_window_h;
1509 select_cockpit(CM_FULL_SCREEN);
1513 Game_window_w += WINDOW_W_DELTA;
1514 Game_window_h += WINDOW_H_DELTA;
1516 #ifdef MACINTOSH // horrible hack to ensure that height is even to satisfy pixel doubling blitter
1517 if ( Scanline_double && (Game_window_h & 1) )
1521 if (Game_window_h > max_window_h)
1522 Game_window_h = max_window_h;
1524 if (Game_window_w > max_window_w)
1525 Game_window_w = max_window_w;
1527 Game_window_x = (max_window_w - Game_window_w)/2;
1528 Game_window_y = (max_window_h - Game_window_h)/2;
1530 game_init_render_sub_buffers( Game_window_x, Game_window_y, Game_window_w, Game_window_h );
1533 HUD_clear_messages(); // @mk, 11/11/94
1535 write_player_file();
1538 // grs_bitmap background_bitmap; already declared in line 434 (samir 4/10/94)
1540 extern grs_bitmap background_bitmap;
1542 void copy_background_rect(int left,int top,int right,int bot)
1544 grs_bitmap *bm = &background_bitmap;
1546 int tile_left,tile_right,tile_top,tile_bot;
1550 if (right < left || bot < top)
1553 tile_left = left / bm->bm_w;
1554 tile_right = right / bm->bm_w;
1555 tile_top = top / bm->bm_h;
1556 tile_bot = bot / bm->bm_h;
1558 ofs_y = top % bm->bm_h;
1561 WIN(DDGRLOCK(dd_grd_curcanv))
1563 for (y=tile_top;y<=tile_bot;y++) {
1566 ofs_x = left % bm->bm_w;
1569 //h = (bot < dest_y+bm->bm_h)?(bot-dest_y+1):(bm->bm_h-ofs_y);
1570 h = min(bot-dest_y+1,bm->bm_h-ofs_y);
1572 for (x=tile_left;x<=tile_right;x++) {
1574 //w = (right < dest_x+bm->bm_w)?(right-dest_x+1):(bm->bm_w-ofs_x);
1575 w = min(right-dest_x+1,bm->bm_w-ofs_x);
1577 gr_bm_ubitblt(w,h,dest_x,dest_y,ofs_x,ofs_y,
1578 &background_bitmap,&grd_curcanv->cv_bitmap);
1588 WIN(DDGRUNLOCK(dd_grd_curcanv));
1593 int force_background_fill=0;
1596 //fills int the background surrounding the 3d window
1597 void fill_background()
1609 WINDOS( dd_gr_set_current_canvas(&dd_VR_screen_pages[VR_current_page]),
1610 gr_set_current_canvas(&VR_screen_pages[VR_current_page])
1612 copy_background_rect(x-dx,y-dy,x-1,y+h+dy-1);
1613 copy_background_rect(x+w,y-dy,grd_curcanv->cv_w-1,y+h+dy-1);
1614 copy_background_rect(x,y-dy,x+w-1,y-1);
1615 copy_background_rect(x,y+h,x+w-1,y+h+dy-1);
1618 if (GRMODEINFO(modex)) {
1619 copy_background_rect(x-dx,y-dy,x-1,y+h+dy-1);
1620 copy_background_rect(x+w,y-dy,grd_curcanv->cv_w-1,y+h+dy-1);
1621 copy_background_rect(x,y-dy,x+w-1,y-1);
1622 copy_background_rect(x,y+h,x+w-1,y+h+dy-1);
1626 if (VR_screen_flags & VRF_USE_PAGING) {
1627 WINDOS( dd_gr_set_current_canvas(&dd_VR_screen_pages[!VR_current_page]),
1628 gr_set_current_canvas(&VR_screen_pages[!VR_current_page])
1630 copy_background_rect(x-dx,y-dy,x-1,y+h+dy-1);
1631 copy_background_rect(x+w,y-dy,x+w+dx-1,y+h+dy-1);
1632 copy_background_rect(x,y-dy,x+w-1,y-1);
1633 copy_background_rect(x,y+h,x+w-1,y+h+dy-1);
1637 if (GRMODEINFO(modex) && force_background_fill==0) //double-buffered
1638 force_background_fill=2;
1642 void shrink_window()
1645 //When you shrink the window twice in two frames, the background doens't
1646 //restore properly. So this hack keeps you from shrinking the window
1647 //before two frames have been drawn
1648 static int last_shrink_framecount=-1;
1649 if (FrameCount - last_shrink_framecount < 2)
1651 last_shrink_framecount = FrameCount;
1654 mprintf((0,"%d ",FrameCount));
1656 // mprintf ((0,"W=%d H=%d\n",Game_window_w,Game_window_h));
1658 if (Cockpit_mode == CM_FULL_COCKPIT && (VR_screen_flags & VRF_ALLOW_COCKPIT)) {
1659 Game_window_h = max_window_h;
1660 Game_window_w = max_window_w;
1661 //!!toggle_cockpit();
1662 select_cockpit(CM_STATUS_BAR);
1665 HUD_init_message("Press F3 to return to Cockpit mode");
1666 write_player_file();
1670 if (Cockpit_mode == CM_FULL_SCREEN && (VR_screen_flags & VRF_ALLOW_COCKPIT))
1672 //Game_window_w = max_window_w;
1673 //Game_window_h = max_window_h;
1674 select_cockpit(CM_STATUS_BAR);
1675 write_player_file();
1679 if (Cockpit_mode != CM_STATUS_BAR && (VR_screen_flags & VRF_ALLOW_COCKPIT))
1682 mprintf ((0,"Cockpit mode=%d\n",Cockpit_mode));
1684 if (Game_window_w > WINDOW_MIN_W) {
1687 Game_window_w -= WINDOW_W_DELTA;
1688 Game_window_h -= WINDOW_H_DELTA;
1691 mprintf ((0,"NewW=%d NewH=%d VW=%d maxH=%d\n",Game_window_w,Game_window_h,max_window_w,max_window_h));
1693 if ( Game_window_w < WINDOW_MIN_W )
1694 Game_window_w = WINDOW_MIN_W;
1696 if ( Game_window_h < WINDOW_MIN_H )
1697 Game_window_h = WINDOW_MIN_H;
1699 #ifdef MACINTOSH // horrible hack to ensure that height is even to satisfy pixel doubling blitter
1700 if ( Scanline_double && (Game_window_h & 1) )
1704 Game_window_x = (max_window_w - Game_window_w)/2;
1705 Game_window_y = (max_window_h - Game_window_h)/2;
1709 game_init_render_sub_buffers( Game_window_x, Game_window_y, Game_window_w, Game_window_h );
1710 HUD_clear_messages();
1711 write_player_file();
1716 int last_drawn_cockpit[2] = { -1, -1 };
1718 // This actually renders the new cockpit onto the screen.
1719 void update_cockpits(int force_redraw)
1723 if (Cockpit_mode != last_drawn_cockpit[VR_current_page] || force_redraw )
1724 last_drawn_cockpit[VR_current_page] = Cockpit_mode;
1728 //Redraw the on-screen cockpit bitmaps
1729 if (VR_render_mode != VR_NONE ) return;
1731 switch( Cockpit_mode ) {
1732 case CM_FULL_COCKPIT:
1735 dd_gr_set_current_canvas(&dd_VR_screen_pages[VR_current_page]),
1736 gr_set_current_canvas(&VR_screen_pages[VR_current_page])
1738 PIGGY_PAGE_IN(cockpit_bitmap[Cockpit_mode+(Current_display_mode?(Num_cockpits/2):0)]);
1740 WIN(DDGRLOCK(dd_grd_curcanv));
1741 gr_ubitmapm(0,0, &GameBitmaps[cockpit_bitmap[Cockpit_mode+(Current_display_mode?(Num_cockpits/2):0)].index]);
1742 WIN(DDGRUNLOCK(dd_grd_curcanv));
1745 case CM_FULL_SCREEN:
1746 Game_window_x = (max_window_w - Game_window_w)/2;
1747 Game_window_y = (max_window_h - Game_window_h)/2;
1753 WINDOS ( dd_gr_set_current_canvas(&dd_VR_screen_pages[VR_current_page]),
1754 gr_set_current_canvas(&VR_screen_pages[VR_current_page])
1757 PIGGY_PAGE_IN(cockpit_bitmap[Cockpit_mode+(Current_display_mode?(Num_cockpits/2):0)]);
1759 WIN(DDGRLOCK(dd_grd_curcanv));
1760 gr_ubitmapm(0,max_window_h,&GameBitmaps[cockpit_bitmap[Cockpit_mode+(Current_display_mode?(Num_cockpits/2):0)].index]);
1761 WIN(DDGRUNLOCK(dd_grd_curcanv));
1763 #ifdef MACINTOSH // hideously horrible hack to put grey line 1 scanline above because of pixel doubling "oddness"
1764 if (Scanline_double)
1766 gr_setcolor(BM_XRGB(13,13,13)); // color of top of status bar
1767 gr_uscanline( 0, grd_curcanv->cv_w, max_window_h-1 );
1771 Game_window_x = (max_window_w - Game_window_w)/2;
1772 Game_window_y = (max_window_h - Game_window_h)/2;
1777 WINDOS( dd_gr_set_current_canvas(&dd_VR_screen_pages[VR_current_page]),
1778 gr_set_current_canvas(&VR_screen_pages[VR_current_page])
1780 WINDOS ( dd_gr_clear_canvas( BM_XRGB(0,0,0) ),
1781 gr_clear_canvas( BM_XRGB(0,0,0) ) );
1783 // In a modex mode, clear the other buffer.
1784 if (grd_curcanv->cv_bitmap.bm_type == BM_MODEX) {
1785 gr_set_current_canvas(&VR_screen_pages[VR_current_page^1]);
1786 gr_clear_canvas( BM_XRGB(0,0,0) );
1787 gr_set_current_canvas(&VR_screen_pages[VR_current_page]);
1793 WINDOS ( dd_gr_set_current_canvas(&dd_VR_screen_pages[VR_current_page]),
1794 gr_set_current_canvas(&VR_screen_pages[VR_current_page])
1797 if (Cockpit_mode==CM_FULL_COCKPIT || Cockpit_mode==CM_STATUS_BAR)
1803 void game_render_frame()
1805 set_screen_mode( SCREEN_GAME );
1810 if (force_background_fill) {
1812 force_background_fill--;
1816 play_homing_warning();
1818 if (VR_render_mode == VR_NONE )
1819 game_render_frame_mono();
1821 game_render_frame_stereo();
1824 // Make sure palette is faded in
1826 gr_palette_fade_in( gr_palette, 32, 0 );
1832 extern int Color_0_31_0;
1834 //draw a crosshair for the guided missile
1835 void draw_guided_crosshair(void)
1839 gr_setcolor(Color_0_31_0);
1841 w = grd_curcanv->cv_w>>5;
1845 h = i2f(w) / grd_curscreen->sc_aspect;
1847 x = grd_curcanv->cv_w / 2;
1848 y = grd_curcanv->cv_h / 2;
1850 gr_scanline(x-w/2,x+w/2,y);
1851 gr_uline(i2f(x),i2f(y-h/2),i2f(x),i2f(y+h/2));
1855 typedef struct bkg {
1856 short x, y, w, h; // The location of the menu.
1857 grs_bitmap * bmp; // The background under the menu.
1860 bkg bg = {0,0,0,0,NULL};
1862 #define BOX_BORDER (MenuHires?60:30)
1864 //show a message in a nice little box
1865 void show_boxed_message(char *msg)
1871 dd_gr_set_current_canvas(&dd_VR_screen_pages[VR_current_page]),
1872 gr_set_current_canvas(&VR_screen_pages[VR_current_page])
1874 gr_set_curfont( MEDIUM1_FONT );
1876 gr_get_string_size(msg,&w,&h,&aw);
1878 x = (grd_curscreen->sc_w-w)/2;
1879 y = (grd_curscreen->sc_h-h)/2;
1882 gr_free_bitmap(bg.bmp);
1886 // Save the background of the display
1887 bg.x=x; bg.y=y; bg.w=w; bg.h=h;
1889 #if defined(POLY_ACC)
1890 bg.bmp = gr_create_bitmap2( w+BOX_BORDER, h+BOX_BORDER, grd_curcanv->cv_bitmap.bm_type, NULL );
1892 bg.bmp = gr_create_bitmap( w+BOX_BORDER, h+BOX_BORDER );
1895 WIN( DDGRLOCK(dd_grd_curcanv));
1896 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 );
1897 WIN( DDGRUNLOCK(dd_grd_curcanv));
1899 nm_draw_background(x-BOX_BORDER/2,y-BOX_BORDER/2,x+w+BOX_BORDER/2-1,y+h+BOX_BORDER/2-1);
1901 gr_set_fontcolor( gr_getcolor(31, 31, 31), -1 );
1903 WIN( DDGRLOCK(dd_grd_curcanv));
1904 gr_ustring( 0x8000, y, msg );
1905 WIN( DDGRUNLOCK(dd_grd_curcanv));
1909 void clear_boxed_message()
1914 WIN(DDGRLOCK(dd_grd_curcanv));
1915 gr_bitmap(bg.x-BOX_BORDER/2, bg.y-BOX_BORDER/2, bg.bmp);
1916 WIN(DDGRUNLOCK(dd_grd_curcanv));
1919 gr_free_bitmap(bg.bmp);
1926 void win_do_emul_ibitblt(dd_grs_canvas *csrc, dd_grs_canvas *cdest)
1933 WIN(DDGRLOCK(csrc));
1934 WIN(DDGRLOCK(cdest));
1935 src_data = csrc->canvas.cv_bitmap.bm_data;
1936 dest_data = cdest->canvas.cv_bitmap.bm_data;
1938 // mprintf((0, "Render Ptr: %x; Dest Ptr: %x;\n",src_data, dest_data));
1940 for (line = 0; line < 480; line++,
1941 dest_data += cdest->canvas.cv_bitmap.bm_rowsize)
1943 cockpit_span_line *sline;
1945 sline = &win_cockpit_mask[line];
1947 if (!sline->num) continue;
1948 if (sline->num == 255) break;
1949 for (span = 0; span < sline->num; span++)
1951 if ((sline->span[span].xmax-sline->span[span].xmin+1) < 10) {
1952 gr_winckpit_blt_span(sline->span[span].xmin,
1953 sline->span[span].xmax,
1954 src_data, dest_data);
1957 gr_winckpit_blt_span_long(sline->span[span].xmin,
1958 sline->span[span].xmax,
1959 src_data, dest_data);
1962 src_data += csrc->canvas.cv_bitmap.bm_rowsize;
1964 WIN(DDGRUNLOCK(cdest));
1965 WIN(DDGRUNLOCK(csrc));
1969 //@@void win_do_emul_ibitblt(dd_grs_canvas *csrc, dd_grs_canvas *cdest)
1973 //@@ RECT srect, drect;
1975 //@@// Do Render Blt to Mask Surface (dest blt 1-255)
1976 //@@ bltfx.dwSize = sizeof(bltfx);
1977 //@@ bltfx.ddckDestColorkey.dwColorSpaceLowValue = 1;
1978 //@@ bltfx.ddckDestColorkey.dwColorSpaceHighValue = 255;
1979 //@@ SetRect(&srect, 0,0, csrc->canvas.cv_w, csrc->canvas.cv_h);
1980 //@@ SetRect(&drect, 0,0, csrc->canvas.cv_w, csrc->canvas.cv_h);
1982 //@@ res = IDirectDrawSurface_Blt(_lpDDSMask, &drect, csrc->lpdds, &srect,
1983 //@@ DDBLT_WAIT | DDBLT_KEYDESTOVERRIDE,
1985 //@@ if (res != DD_OK)
1986 //@@ Error("win_ibitblt: ddraw blt to mask err: %x.\n", res);
1988 //@@// Do Mask Blt to Screen (src blt !0)
1989 //@@ bltfx.dwSize = sizeof(bltfx);
1990 //@@ bltfx.ddckSrcColorkey.dwColorSpaceLowValue = 0;
1991 //@@ bltfx.ddckSrcColorkey.dwColorSpaceHighValue = 0;
1993 //@@ res = IDirectDrawSurface_Blt(cdest->lpdds, &drect, _lpDDSMask, &srect,
1994 //@@ DDBLT_WAIT | DDBLT_KEYSRCOVERRIDE,
1996 //@@ if (res != DD_OK)
1997 //@@ Error("win_ibitblt: ddraw blt to screen err: %x.\n", res);