1 /* $Id: gamerend.c,v 1.11 2003-10-10 09:36:35 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.11 2003-10-10 09:36:35 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 !defined(D2_OEM) && !defined(SHAREWARE) // no countdown on registered only
289 // On last level, we don't want a countdown.
290 if ((Current_mission_num == Builtin_mission_num) && (Current_level_num == Last_level))
292 if (!(Game_mode & GM_MULTI))
294 if (Game_mode & GM_MULTI_ROBOTS)
299 gr_set_curfont( SMALL_FONT );
300 gr_set_fontcolor(gr_getcolor(0,63,0), -1 );
301 y = SMALL_FONT->ft_h*4;
302 if (Cockpit_mode == CM_FULL_SCREEN)
303 y += SMALL_FONT->ft_h*2;
306 y += SMALL_FONT->ft_h*2;
308 //if (!((Cockpit_mode == CM_STATUS_BAR) && (Game_window_y >= 19)))
310 gr_printf(0x8000, y, "T-%d s", Countdown_seconds_left );
314 void game_draw_hud_stuff()
317 int odisplay_mode = Current_display_mode;
318 if (Scanline_double) {
320 Current_display_mode = 0;
325 //mprintf ((0,"Linear is %d!\n",LinearSVGABuffer));
329 gr_set_curfont( MEDIUM1_FONT );
330 gr_set_fontcolor( gr_getcolor(31, 31, 31), -1 ); // gr_getcolor(31,0,0));
331 gr_ustring( 0x8000, 85/2, "Debug Pause - Press P to exit" );
340 game_draw_multi_message();
343 game_draw_marker_message();
345 // if (Game_mode & GM_MULTI)
347 // if (Netgame.PlayTimeAllowed)
348 // game_draw_time_left ();
351 if ((Newdemo_state == ND_STATE_PLAYBACK) || (Newdemo_state == ND_STATE_RECORDING)) {
355 if (Newdemo_state == ND_STATE_PLAYBACK) {
356 if (Newdemo_vcr_state != ND_STATE_PRINTSCREEN) {
357 sprintf(message, "%s (%d%%%% %s)", TXT_DEMO_PLAYBACK, newdemo_get_percent_done(), TXT_DONE);
359 sprintf (message, " ");
362 sprintf (message, TXT_DEMO_RECORDING);
364 gr_set_curfont( GAME_FONT ); //GAME_FONT );
365 gr_set_fontcolor(gr_getcolor(27,0,0), -1 );
367 gr_get_string_size(message, &w, &h, &aw );
369 if (Scanline_double) // double height if scanline doubling since we have the correct
370 h += h; // font for printing, but the wrong height.
372 if (Cockpit_mode == CM_FULL_COCKPIT) {
373 if (grd_curcanv->cv_bitmap.bm_h > 240)
377 } else if ( Cockpit_mode == CM_LETTERBOX )
379 if (Cockpit_mode != CM_REAR_VIEW && !Saving_movie_frames)
380 gr_printf((grd_curcanv->cv_bitmap.bm_w-w)/2, grd_curcanv->cv_bitmap.bm_h - h - 2, message );
383 render_countdown_gauge();
385 if ( Player_num > -1 && Viewer->type==OBJ_PLAYER && Viewer->id==Player_num ) {
387 int y = grd_curcanv->cv_bitmap.bm_h;
389 gr_set_curfont( GAME_FONT );
390 gr_set_fontcolor( gr_getcolor(0, 31, 0), -1 );
391 if (Cruise_speed > 0) {
392 int line_spacing = GAME_FONT->ft_h + GAME_FONT->ft_h/4;
394 mprintf((0,"line_spacing=%d ",line_spacing));
396 if (Cockpit_mode==CM_FULL_SCREEN) {
397 if (Game_mode & GM_MULTI)
398 y -= line_spacing * 11; //64
400 y -= line_spacing * 6; //32
401 } else if (Cockpit_mode == CM_STATUS_BAR) {
402 if (Game_mode & GM_MULTI)
403 y -= line_spacing * 8; //48
405 y -= line_spacing * 4; //24
407 y = line_spacing * 2; //12
411 gr_printf( x, y, "%s %2d%%", TXT_CRUISE, f2i(Cruise_speed) );
415 if (r_framerate.value)
418 if ( (Newdemo_state == ND_STATE_PLAYBACK) )
419 Game_mode = Newdemo_game_mode;
423 if ( (Newdemo_state == ND_STATE_PLAYBACK) )
424 Game_mode = GM_NORMAL;
426 if ( Player_is_dead )
427 player_dead_message();
430 if (Scanline_double) {
432 Current_display_mode = odisplay_mode;
437 extern int gr_bitblt_dest_step_shift;
438 extern int gr_wait_for_retrace;
439 extern int gr_bitblt_double;
442 void expand_row(ubyte * dest, ubyte * src, int num_src_pixels );
443 #pragma aux expand_row parm [edi] [esi] [ecx] modify exact [ecx esi edi eax ebx] = \
461 void expand_row(ubyte * dest, ubyte * src, int num_src_pixels )
465 for (i = 0; i < num_src_pixels; i++) {
472 // doubles the size in x or y of a bitmap in place.
473 void game_expand_bitmap( grs_bitmap * bmp, uint flags )
476 ubyte * dptr, * sptr;
480 Assert( bmp->bm_rowsize == bmp->bm_w*2 );
481 dptr = &bmp->bm_data[(bmp->bm_h-1)*bmp->bm_rowsize];
482 for (i=bmp->bm_h-1; i>=0; i-- ) {
483 expand_row( dptr, dptr, bmp->bm_w );
484 dptr -= bmp->bm_rowsize;
489 dptr = &bmp->bm_data[(2*(bmp->bm_h-1)+1)*bmp->bm_rowsize];
490 sptr = &bmp->bm_data[(bmp->bm_h-1)*bmp->bm_rowsize];
491 for (i=bmp->bm_h-1; i>=0; i-- ) {
492 memcpy( dptr, sptr, bmp->bm_w );
493 dptr -= bmp->bm_rowsize;
494 memcpy( dptr, sptr, bmp->bm_w );
495 dptr -= bmp->bm_rowsize;
496 sptr -= bmp->bm_rowsize;
500 case 3: // expand x & y
501 Assert( bmp->bm_rowsize == bmp->bm_w*2 );
502 dptr = &bmp->bm_data[(2*(bmp->bm_h-1)+1)*bmp->bm_rowsize];
503 sptr = &bmp->bm_data[(bmp->bm_h-1)*bmp->bm_rowsize];
504 for (i=bmp->bm_h-1; i>=0; i-- ) {
505 expand_row( dptr, sptr, bmp->bm_w );
506 dptr -= bmp->bm_rowsize;
507 expand_row( dptr, sptr, bmp->bm_w );
508 dptr -= bmp->bm_rowsize;
509 sptr -= bmp->bm_rowsize;
517 extern int SW_drawn[2], SW_x[2], SW_y[2], SW_w[2], SW_h[2];
519 extern int Guided_in_big_window;
522 //render a frame for the game in stereo
523 void game_render_frame_stereo()
527 fix actual_eye_width;
528 int actual_eye_offset;
529 grs_canvas RenderCanvas[2];
532 save_aspect = grd_curscreen->sc_aspect;
533 grd_curscreen->sc_aspect *= 2; //Muck with aspect ratio
535 sw = dw = VR_render_buffer[0].cv_bitmap.bm_w;
536 sh = dh = VR_render_buffer[0].cv_bitmap.bm_h;
538 if (VR_low_res & 1) {
540 grd_curscreen->sc_aspect *= 2; //Muck with aspect ratio
542 if (VR_low_res & 2) {
544 grd_curscreen->sc_aspect /= 2; //Muck with aspect ratio
547 gr_init_sub_canvas( &RenderCanvas[0], &VR_render_buffer[0], 0, 0, sw, sh );
548 gr_init_sub_canvas( &RenderCanvas[1], &VR_render_buffer[1], 0, 0, sw, sh );
550 // Draw the left eye's view
552 actual_eye_width = -VR_eye_width;
553 actual_eye_offset = -VR_eye_offset;
555 actual_eye_width = VR_eye_width;
556 actual_eye_offset = VR_eye_offset;
559 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)
560 actual_eye_offset = 0;
562 gr_set_current_canvas(&RenderCanvas[0]);
564 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) {
565 char *msg = "Guided Missile View";
566 object *viewer_save = Viewer;
569 Viewer = Guided_missile[Player_num];
571 WIN(DDGRLOCK(dd_grd_curcanv)); // Must lock DD canvas!!!
577 update_rendered_data(0, Viewer, 0, 0);
579 #if defined(POLY_ACC) && !defined(MACINTOSH) // dma stuff not support on mac via RAVE
583 wake_up_rendered_objects(Viewer, 0);
584 Viewer = viewer_save;
586 gr_set_curfont( GAME_FONT ); //GAME_FONT );
587 gr_set_fontcolor(gr_getcolor(27,0,0), -1 );
588 gr_get_string_size(msg, &w, &h, &aw );
590 gr_printf((grd_curcanv->cv_bitmap.bm_w-w)/2, 3, msg );
592 draw_guided_crosshair();
594 WIN(DDGRUNLOCK(dd_grd_curcanv));
596 HUD_render_message_frame();
605 render_frame(actual_eye_width, 0); // switch eye positions for rear view
607 render_frame(-actual_eye_width, 0); // Left eye
610 game_expand_bitmap( &RenderCanvas[0].cv_bitmap, VR_low_res );
612 { //render small window into left eye's canvas
613 grs_canvas *save=grd_curcanv;
614 fix save_aspect2 = grd_curscreen->sc_aspect;
615 grd_curscreen->sc_aspect = save_aspect*2;
616 SW_drawn[0] = SW_drawn[1] = 0;
618 gr_set_current_canvas(save);
619 grd_curscreen->sc_aspect = save_aspect2;
623 if (actual_eye_offset > 0 ) {
624 gr_setcolor( gr_getcolor(0,0,0) );
625 gr_rect( grd_curcanv->cv_bitmap.bm_w-labs(actual_eye_offset)*2, 0,
626 grd_curcanv->cv_bitmap.bm_w-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( 0, 0, labs(actual_eye_offset)*2-1, grd_curcanv->cv_bitmap.bm_h );
632 if ( VR_show_hud && !no_draw_hud ) {
634 if (actual_eye_offset < 0 ) {
635 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 );
637 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 );
639 gr_set_current_canvas( &tmp );
640 game_draw_hud_stuff();
644 // Draw the right eye's view
645 gr_set_current_canvas(&RenderCanvas[1]);
647 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)
648 gr_bitmap(0,0,&RenderCanvas[0].cv_bitmap);
651 render_frame(-actual_eye_width, 0); // switch eye positions for rear view
653 render_frame(actual_eye_width, 0); // Right eye
656 game_expand_bitmap( &RenderCanvas[1].cv_bitmap, VR_low_res );
660 { //copy small window from left eye
665 gr_init_sub_canvas(&temp,&RenderCanvas[0],SW_x[w],SW_y[w],SW_w[w],SW_h[w]);
666 gr_bitmap(SW_x[w]+actual_eye_offset*2,SW_y[w],&temp.cv_bitmap);
672 if (actual_eye_offset>0) {
673 gr_setcolor( gr_getcolor(0,0,0) );
674 gr_rect( 0, 0, labs(actual_eye_offset)*2-1, grd_curcanv->cv_bitmap.bm_h );
675 } else if ( actual_eye_offset < 0 ) {
676 gr_setcolor( gr_getcolor(0,0,0) );
677 gr_rect( grd_curcanv->cv_bitmap.bm_w-labs(actual_eye_offset)*2, 0,
678 grd_curcanv->cv_bitmap.bm_w-1, grd_curcanv->cv_bitmap.bm_h );
681 //NEWVR (Add the next 2 lines)
682 if ( VR_show_hud && !no_draw_hud ) {
684 if (actual_eye_offset > 0 ) {
685 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 );
687 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 );
689 gr_set_current_canvas( &tmp );
690 game_draw_hud_stuff();
694 // Draws white and black registration encoding lines
695 // and Accounts for pixel-shift adjustment in upcoming bitblts
696 if (VR_use_reg_code) {
697 int width, height, quarter;
699 width = RenderCanvas[0].cv_bitmap.bm_w;
700 height = RenderCanvas[0].cv_bitmap.bm_h;
703 // black out left-hand side of left page
705 // draw registration code for left eye
707 gr_set_current_canvas( &RenderCanvas[1] );
709 gr_set_current_canvas( &RenderCanvas[0] );
710 gr_setcolor( VR_WHITE_INDEX );
711 gr_scanline( 0, quarter, height-1 );
712 gr_setcolor( VR_BLACK_INDEX );
713 gr_scanline( quarter, width-1, height-1 );
716 gr_set_current_canvas( &RenderCanvas[0] );
718 gr_set_current_canvas( &RenderCanvas[1] );
719 gr_setcolor( VR_WHITE_INDEX );
720 gr_scanline( 0, quarter*3, height-1 );
721 gr_setcolor( VR_BLACK_INDEX );
722 gr_scanline( quarter*3, width-1, height-1 );
725 // Copy left eye, then right eye
726 if ( VR_screen_flags&VRF_USE_PAGING )
727 VR_current_page = !VR_current_page;
730 gr_set_current_canvas( &VR_screen_pages[VR_current_page] );
734 if ( VR_eye_offset_changed > 0 ) {
735 VR_eye_offset_changed--;
739 sw = dw = VR_render_buffer[0].cv_bitmap.bm_w;
740 sh = dh = VR_render_buffer[0].cv_bitmap.bm_h;
742 // Copy left eye, then right eye
743 gr_bitblt_dest_step_shift = 1; // Skip every other scanline.
745 if (VR_render_mode == VR_INTERLACED ) {
746 if ( actual_eye_offset > 0 ) {
747 int xoff = labs(actual_eye_offset);
748 gr_bm_ubitblt( dw-xoff, dh, xoff, 0, 0, 0, &RenderCanvas[0].cv_bitmap, &VR_screen_pages[VR_current_page].cv_bitmap);
749 gr_bm_ubitblt( dw-xoff, dh, 0, 1, xoff, 0, &RenderCanvas[1].cv_bitmap, &VR_screen_pages[VR_current_page].cv_bitmap);
750 } else if ( actual_eye_offset < 0 ) {
751 int xoff = labs(actual_eye_offset);
752 gr_bm_ubitblt( dw-xoff, dh, 0, 0, xoff, 0, &RenderCanvas[0].cv_bitmap, &VR_screen_pages[VR_current_page].cv_bitmap);
753 gr_bm_ubitblt( dw-xoff, dh, xoff, 1, 0, 0, &RenderCanvas[1].cv_bitmap, &VR_screen_pages[VR_current_page].cv_bitmap);
755 gr_bm_ubitblt( dw, dh, 0, 0, 0, 0, &RenderCanvas[0].cv_bitmap, &VR_screen_pages[VR_current_page].cv_bitmap);
756 gr_bm_ubitblt( dw, dh, 0, 1, 0, 0, &RenderCanvas[1].cv_bitmap, &VR_screen_pages[VR_current_page].cv_bitmap);
758 } else if (VR_render_mode == VR_AREA_DET) {
760 gr_bm_ubitblt( dw, dh, 0, VR_current_page, 0, 0, &RenderCanvas[0].cv_bitmap, &VR_screen_pages[0].cv_bitmap);
761 gr_bm_ubitblt( dw, dh, dw, VR_current_page, 0, 0, &RenderCanvas[1].cv_bitmap, &VR_screen_pages[0].cv_bitmap);
766 gr_bitblt_dest_step_shift = 0;
768 //if ( Game_vfx_flag )
769 // vfx_set_page(VR_current_page); // 0 or 1
771 if ( VR_screen_flags&VRF_USE_PAGING ) {
772 gr_wait_for_retrace = 0;
774 // Added by Samir from John's code
775 if ( (VR_screen_pages[VR_current_page].cv_bitmap.bm_type == BM_MODEX) && (Game_3dmax_flag==3) ) {
776 int old_x, old_y, new_x;
777 old_x = VR_screen_pages[VR_current_page].cv_bitmap.bm_x;
778 old_y = VR_screen_pages[VR_current_page].cv_bitmap.bm_y;
779 new_x = old_y*VR_screen_pages[VR_current_page].cv_bitmap.bm_rowsize;
781 VR_screen_pages[VR_current_page].cv_bitmap.bm_x = new_x;
782 VR_screen_pages[VR_current_page].cv_bitmap.bm_y = 0;
783 VR_screen_pages[VR_current_page].cv_bitmap.bm_type = BM_SVGA;
784 gr_show_canvas( &VR_screen_pages[VR_current_page] );
785 VR_screen_pages[VR_current_page].cv_bitmap.bm_type = BM_MODEX;
786 VR_screen_pages[VR_current_page].cv_bitmap.bm_x = old_x;
787 VR_screen_pages[VR_current_page].cv_bitmap.bm_y = old_y;
789 gr_show_canvas( &VR_screen_pages[VR_current_page] );
791 gr_wait_for_retrace = 1;
793 grd_curscreen->sc_aspect=save_aspect;
796 ubyte RenderingType=0;
797 ubyte DemoDoingRight=0,DemoDoingLeft=0;
798 extern ubyte DemoDoRight,DemoDoLeft;
799 extern object DemoRightExtra,DemoLeftExtra;
801 char DemoWBUType[]={0,WBU_MISSILE,WBU_MISSILE,WBU_REAR,WBU_ESCORT,WBU_MARKER,WBU_MISSILE};
802 char DemoRearCheck[]={0,0,0,1,0,0,0};
803 char *DemoExtraMessage[]={"PLAYER","GUIDED","MISSILE","REAR","GUIDE-BOT","MARKER","SHIP"};
805 extern char guidebot_name[];
807 void show_extra_views()
809 int did_missile_view=0;
810 int save_newdemo_state = Newdemo_state;
813 if (Newdemo_state==ND_STATE_PLAYBACK)
817 DemoDoingLeft=DemoDoLeft;
820 do_cockpit_window_view(0,ConsoleObject,1,WBU_REAR,"REAR");
822 do_cockpit_window_view(0,&DemoLeftExtra,DemoRearCheck[DemoDoLeft],DemoWBUType[DemoDoLeft],DemoExtraMessage[DemoDoLeft]);
825 do_cockpit_window_view(0,NULL,0,WBU_WEAPON,NULL);
829 DemoDoingRight=DemoDoRight;
832 do_cockpit_window_view(1,ConsoleObject,1,WBU_REAR,"REAR");
834 do_cockpit_window_view(1,&DemoRightExtra,DemoRearCheck[DemoDoRight],DemoWBUType[DemoDoRight],DemoExtraMessage[DemoDoRight]);
837 do_cockpit_window_view(1,NULL,0,WBU_WEAPON,NULL);
839 DemoDoLeft=DemoDoRight=0;
840 DemoDoingLeft=DemoDoingRight=0;
845 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]) {
846 if (Guided_in_big_window)
848 RenderingType=6+(1<<4);
849 do_cockpit_window_view(1,Viewer,0,WBU_MISSILE,"SHIP");
853 RenderingType=1+(1<<4);
854 do_cockpit_window_view(1,Guided_missile[Player_num],0,WBU_GUIDED,"GUIDED");
861 if (Guided_missile[Player_num]) { //used to be active
862 if (!Guided_in_big_window)
863 do_cockpit_window_view(1,NULL,0,WBU_STATIC,NULL);
864 Guided_missile[Player_num] = NULL;
867 if (Missile_viewer) { //do missile view
868 static int mv_sig=-1;
870 mv_sig = Missile_viewer->signature;
871 if (Missile_view_enabled && Missile_viewer->type!=OBJ_NONE && Missile_viewer->signature == mv_sig) {
872 RenderingType=2+(1<<4);
873 do_cockpit_window_view(1,Missile_viewer,0,WBU_MISSILE,"MISSILE");
877 Missile_viewer = NULL;
880 do_cockpit_window_view(1,NULL,0,WBU_STATIC,NULL);
887 if (w==1 && did_missile_view)
888 continue; //if showing missile view in right window, can't show anything else
890 //show special views if selected
891 switch (Cockpit_3d_view[w]) {
894 do_cockpit_window_view(w,NULL,0,WBU_WEAPON,NULL);
897 if (Rear_view) { //if big window is rear view, show front here
898 RenderingType=3+(w<<4);
899 do_cockpit_window_view(w,ConsoleObject,0,WBU_REAR,"FRONT");
901 else { //show normal rear view
902 RenderingType=3+(w<<4);
903 do_cockpit_window_view(w,ConsoleObject,1,WBU_REAR,"REAR");
908 buddy = find_escort();
910 do_cockpit_window_view(w,NULL,0,WBU_WEAPON,NULL);
911 Cockpit_3d_view[w] = CV_NONE;
914 RenderingType=4+(w<<4);
915 do_cockpit_window_view(w,buddy,0,WBU_ESCORT,guidebot_name);
921 int player = Coop_view_player[w];
923 RenderingType=255; // don't handle coop stuff
925 if (player!=-1 && Players[player].connected && ((Game_mode & GM_MULTI_COOP) || ((Game_mode & GM_TEAM) && (get_team(player) == get_team(Player_num)))))
926 do_cockpit_window_view(w,&Objects[Players[Coop_view_player[w]].objnum],0,WBU_COOP,Players[Coop_view_player[w]].callsign);
928 do_cockpit_window_view(w,NULL,0,WBU_WEAPON,NULL);
929 Cockpit_3d_view[w] = CV_NONE;
936 RenderingType=5+(w<<4);
937 if (Marker_viewer_num[w] == -1 || MarkerObject[Marker_viewer_num[w]] == -1) {
938 Cockpit_3d_view[w] = CV_NONE;
941 sprintf(label,"Marker %d",Marker_viewer_num[w]+1);
942 do_cockpit_window_view(w,&Objects[MarkerObject[Marker_viewer_num[w]]],0,WBU_MARKER,label);
946 Int3(); //invalid window type
950 Newdemo_state = save_newdemo_state;
953 int BigWindowSwitch=0;
954 extern int force_cockpit_redraw;
956 extern ubyte * Game_cockpit_copy_code;
958 extern ubyte Game_cockpit_copy_code;
961 void draw_guided_crosshair(void);
964 // special code to render a frame w/hw acceleration
966 // next routine is called as a callback from the current hardware engine being used. The
967 // routine is called once all of the accelerated drawing is done. We now overlay the
968 // backbuffer with hud stuff.
970 void pa_mac_render_extras( void )
972 grs_canvas Screen_3d_window;
974 gr_init_sub_canvas( &Screen_3d_window, &VR_screen_pages[0],
975 VR_render_sub_buffer[0].cv_bitmap.bm_x,
976 VR_render_sub_buffer[0].cv_bitmap.bm_y,
977 VR_render_sub_buffer[0].cv_bitmap.bm_w,
978 VR_render_sub_buffer[0].cv_bitmap.bm_h);
980 gr_set_current_canvas( &Screen_3d_window ); // set to current screen
982 if (Guided_missile[Player_num] &&
983 Guided_missile[Player_num]->type==OBJ_WEAPON &&
984 Guided_missile[Player_num]->id==GUIDEDMISS_ID &&
985 Guided_missile[Player_num]->signature==Guided_missile_sig[Player_num] &&
986 Guided_in_big_window)
988 char *msg = "Guided Missile View";
991 gr_set_curfont( GAME_FONT ); //GAME_FONT );
992 gr_set_fontcolor(gr_getcolor(27,0,0), -1 );
993 gr_get_string_size(msg, &w, &h, &aw );
995 gr_printf((grd_curcanv->cv_bitmap.bm_w-w)/2, 3, msg );
997 draw_guided_crosshair();
999 HUD_render_message_frame();
1003 game_draw_hud_stuff(); // draw hud stuff when not doing missle view in big window
1006 if (Game_paused) { //render pause message over off-screen 3d (to minimize flicker)
1007 extern char *Pause_msg;
1008 ubyte *save_data = VR_screen_pages[VR_current_page].cv_bitmap.bm_data;
1010 WIN(Int3()); // Not supported yet.
1011 VR_screen_pages[VR_current_page].cv_bitmap.bm_data=VR_render_buffer[VR_current_page].cv_bitmap.bm_data;
1012 show_boxed_message(Pause_msg);
1013 VR_screen_pages[VR_current_page].cv_bitmap.bm_data=save_data;
1019 void pa_mac_game_render_frame( void )
1021 Assert ( !Scanline_double );
1022 Assert ( PAEnabled );
1024 gr_set_current_canvas(&VR_render_sub_buffer[0]); // set up the right canvas so rendering is done to correct size
1028 if (Guided_missile[Player_num] &&
1029 Guided_missile[Player_num]->type==OBJ_WEAPON &&
1030 Guided_missile[Player_num]->id==GUIDEDMISS_ID &&
1031 Guided_missile[Player_num]->signature==Guided_missile_sig[Player_num] &&
1032 Guided_in_big_window)
1034 char *msg = "Guided Missile View";
1035 object *viewer_save = Viewer;
1038 if (Cockpit_mode==CM_FULL_COCKPIT) {
1040 force_cockpit_redraw=1;
1041 Cockpit_mode=CM_STATUS_BAR;
1046 Viewer = Guided_missile[Player_num];
1047 update_rendered_data(0, Viewer, 0, 0);
1049 wake_up_rendered_objects(Viewer, 0);
1050 Viewer = viewer_save;
1054 if (BigWindowSwitch)
1056 force_cockpit_redraw=1;
1057 Cockpit_mode=CM_FULL_COCKPIT;
1063 update_rendered_data(0, Viewer, Rear_view, 0);
1067 if (Cockpit_mode == CM_FULL_SCREEN)
1075 // NOTE: Hud stuff is drawn using a RAVE call back which draws onto the back buffer
1076 // after rendering finishes but before the page flip
1078 if (Cockpit_mode != CM_FULL_SCREEN)
1080 show_extra_views(); //missile view, buddy bot, etc.
1083 // Draw Gauges straight to screen
1084 if (Cockpit_mode==CM_FULL_COCKPIT || Cockpit_mode==CM_STATUS_BAR)
1087 if ( (Newdemo_state == ND_STATE_PLAYBACK) )
1089 Game_mode = Newdemo_game_mode;
1092 Current_display_mode = 1;
1094 Current_display_mode = -1;
1096 if ( (Newdemo_state == ND_STATE_PLAYBACK) )
1098 Game_mode = GM_NORMAL;
1105 //render a frame for the game
1107 // will render everything to dd_VR_render_sub_buffer
1108 // which all leads to the dd_VR_offscreen_buffer
1109 void game_render_frame_mono(void)
1112 dd_grs_canvas Screen_3d_window,
1113 grs_canvas Screen_3d_window
1117 #if defined(MACINTOSH)
1119 pa_mac_game_render_frame();
1126 dd_gr_init_sub_canvas(&Screen_3d_window, &dd_VR_screen_pages[0],
1127 dd_VR_render_sub_buffer[0].canvas.cv_bitmap.bm_x,
1128 dd_VR_render_sub_buffer[0].canvas.cv_bitmap.bm_y,
1129 dd_VR_render_sub_buffer[0].canvas.cv_bitmap.bm_w,
1130 dd_VR_render_sub_buffer[0].canvas.cv_bitmap.bm_h),
1131 gr_init_sub_canvas( &Screen_3d_window, &VR_screen_pages[0],
1132 VR_render_sub_buffer[0].cv_bitmap.bm_x,
1133 VR_render_sub_buffer[0].cv_bitmap.bm_y,
1134 VR_render_sub_buffer[0].cv_bitmap.bm_w,
1135 VR_render_sub_buffer[0].cv_bitmap.bm_h)
1138 if ( Game_double_buffer ) {
1140 dd_gr_set_current_canvas(&dd_VR_render_sub_buffer[0]),
1141 gr_set_current_canvas(&VR_render_sub_buffer[0])
1146 dd_gr_set_current_canvas(&Screen_3d_window),
1147 gr_set_current_canvas(&Screen_3d_window)
1151 #if defined(POLY_ACC) && !defined(MACINTOSH) // begin s3 relocation of cockpit drawing.
1155 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)
1159 WIN(DDGRLOCK(dd_grd_curcanv));
1160 game_draw_hud_stuff();
1161 WIN(DDGRUNLOCK(dd_grd_curcanv));
1164 show_extra_views(); //missile view, buddy bot, etc.
1167 if (Game_paused) { //render pause message over off-screen 3d (to minimize flicker)
1168 extern char *Pause_msg;
1169 ubyte *save_data = VR_screen_pages[VR_current_page].cv_bitmap.bm_data;
1171 WIN(Int3()); // Not supported yet.
1172 VR_screen_pages[VR_current_page].cv_bitmap.bm_data=VR_render_buffer[VR_current_page].cv_bitmap.bm_data;
1173 show_boxed_message(Pause_msg);
1174 VR_screen_pages[VR_current_page].cv_bitmap.bm_data=save_data;
1177 if ( Game_double_buffer ) { //copy to visible screen
1178 if ( !Game_cockpit_copy_code ) {
1179 if ( VR_screen_flags&VRF_USE_PAGING ) {
1180 VR_current_page = !VR_current_page;
1181 gr_set_current_canvas( &VR_screen_pages[VR_current_page] );
1182 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 );
1183 gr_wait_for_retrace = 0;
1184 gr_show_canvas( &VR_screen_pages[VR_current_page] );
1185 gr_wait_for_retrace = 1;
1187 #ifdef POLY_ACC //$$
1191 VR_render_sub_buffer[0].cv_w, VR_render_sub_buffer[0].cv_h,
1192 VR_render_sub_buffer[0].cv_bitmap.bm_x, VR_render_sub_buffer[0].cv_bitmap.bm_y,
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, &VR_screen_pages[0].cv_bitmap
1198 #ifdef POLY_ACC //$$
1201 gr_ibitblt( &VR_render_buffer[0].cv_bitmap, &VR_screen_pages[0].cv_bitmap, Game_cockpit_copy_code );
1205 if (Cockpit_mode==CM_FULL_COCKPIT || Cockpit_mode==CM_STATUS_BAR) {
1207 if ( (Newdemo_state == ND_STATE_PLAYBACK) )
1208 Game_mode = Newdemo_game_mode;
1212 if ( (Newdemo_state == ND_STATE_PLAYBACK) )
1213 Game_mode = GM_NORMAL;
1216 // restore current canvas.
1217 if ( Game_double_buffer ) {
1219 dd_gr_set_current_canvas(&dd_VR_render_sub_buffer[0]),
1220 gr_set_current_canvas(&VR_render_sub_buffer[0])
1225 dd_gr_set_current_canvas(&Screen_3d_window),
1226 gr_set_current_canvas(&Screen_3d_window)
1230 #endif // end s3 relocation of cockpit drawing.
1232 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) {
1233 char *msg = "Guided Missile View";
1234 object *viewer_save = Viewer;
1237 if (Cockpit_mode==CM_FULL_COCKPIT)
1240 force_cockpit_redraw=1;
1241 Cockpit_mode=CM_STATUS_BAR;
1245 Viewer = Guided_missile[Player_num];
1247 WIN(DDGRLOCK(dd_grd_curcanv)); // Must lock DD canvas!!!
1250 if (Scanline_double)
1253 update_rendered_data(0, Viewer, 0, 0);
1256 wake_up_rendered_objects(Viewer, 0);
1257 Viewer = viewer_save;
1259 gr_set_curfont( GAME_FONT ); //GAME_FONT );
1260 gr_set_fontcolor(gr_getcolor(27,0,0), -1 );
1261 gr_get_string_size(msg, &w, &h, &aw );
1263 gr_printf((grd_curcanv->cv_bitmap.bm_w-w)/2, 3, msg );
1265 draw_guided_crosshair();
1267 WIN(DDGRUNLOCK(dd_grd_curcanv));
1269 HUD_render_message_frame();
1271 if (Scanline_double)
1279 if (BigWindowSwitch)
1281 force_cockpit_redraw=1;
1282 Cockpit_mode=CM_FULL_COCKPIT;
1286 WIN(DDGRLOCK(dd_grd_curcanv)); // Must lock DD canvas!!!
1287 update_rendered_data(0, Viewer, Rear_view, 0);
1289 #if defined(POLY_ACC) && !defined(MACINTOSH) // dma stuff not supported on mac via RAVE
1292 WIN(DDGRUNLOCK(dd_grd_curcanv));
1295 if ( Game_double_buffer ) {
1297 dd_gr_set_current_canvas(&dd_VR_render_sub_buffer[0]),
1298 gr_set_current_canvas(&VR_render_sub_buffer[0])
1303 dd_gr_set_current_canvas(&Screen_3d_window),
1304 gr_set_current_canvas(&Screen_3d_window)
1308 #if !defined(POLY_ACC) || defined(MACINTOSH)
1311 WIN(DDGRLOCK(dd_grd_curcanv));
1312 game_draw_hud_stuff();
1313 WIN(DDGRUNLOCK(dd_grd_curcanv));
1316 show_extra_views(); //missile view, buddy bot, etc.
1319 if (Game_paused) { //render pause message over off-screen 3d (to minimize flicker)
1320 extern char *Pause_msg;
1321 // LPDIRECTDRAWSURFACE save_dds = dd_VR_screen_pages[VR_current_page].lpdds;
1323 // dd_VR_screen_pages[VR_current_page].lpdds = dd_VR_render_buffer[VR_current_page].lpdds;
1324 show_boxed_message(Pause_msg);
1325 // dd_VR_screen_pages[VR_current_page].lpdds = save_dds;
1328 if (Game_paused) { //render pause message over off-screen 3d (to minimize flicker)
1329 extern char *Pause_msg;
1330 ubyte *save_data = VR_screen_pages[VR_current_page].cv_bitmap.bm_data;
1332 VR_screen_pages[VR_current_page].cv_bitmap.bm_data=VR_render_buffer[VR_current_page].cv_bitmap.bm_data;
1333 show_boxed_message(Pause_msg);
1334 VR_screen_pages[VR_current_page].cv_bitmap.bm_data=save_data;
1338 if ( Game_double_buffer ) { //copy to visible screen
1339 if ( !Game_cockpit_copy_code ) {
1340 if ( VR_screen_flags&VRF_USE_PAGING ) {
1341 VR_current_page = !VR_current_page;
1343 dd_gr_set_current_canvas(&dd_VR_screen_pages[VR_current_page]);
1346 gr_set_current_canvas( &VR_screen_pages[VR_current_page] );
1347 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 );
1348 gr_wait_for_retrace = 0;
1349 gr_show_canvas( &VR_screen_pages[VR_current_page] );
1350 gr_wait_for_retrace = 1;
1354 if (Scanline_double)
1355 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 );
1357 #endif // NOTE LINK TO ABOVE IF
1359 if (GRMODEINFO(emul) || GRMODEINFO(modex) || GRMODEINFO(dbuf))
1360 // From render buffer to screen buffer.
1361 dd_gr_blt_notrans(&dd_VR_render_sub_buffer[0],
1363 dd_VR_render_sub_buffer[0].canvas.cv_w,
1364 dd_VR_render_sub_buffer[0].canvas.cv_h,
1366 dd_VR_render_sub_buffer[0].xoff,
1367 dd_VR_render_sub_buffer[0].yoff,
1368 dd_VR_render_sub_buffer[0].canvas.cv_w,
1369 dd_VR_render_sub_buffer[0].canvas.cv_h);
1372 // Puts back canvas to front canvas by blt or flip
1373 if (GRMODEINFO(modex)) {
1374 //@@VR_current_page = !VR_current_page;
1379 gr_bm_ubitblt( VR_render_sub_buffer[0].cv_w,
1380 VR_render_sub_buffer[0].cv_h,
1381 VR_render_sub_buffer[0].cv_bitmap.bm_x,
1382 VR_render_sub_buffer[0].cv_bitmap.bm_y,
1384 &VR_render_sub_buffer[0].cv_bitmap,
1385 &VR_screen_pages[0].cv_bitmap );
1394 #if 1 //def MACINTOSH
1395 gr_ibitblt( &VR_render_sub_buffer[0].cv_bitmap, &VR_screen_pages[0].cv_bitmap, Scanline_double );
1398 gr_ibitblt( &VR_render_buffer[0].cv_bitmap, &VR_screen_pages[0].cv_bitmap, Game_cockpit_copy_code );
1400 win_do_emul_ibitblt( &dd_VR_render_sub_buffer[0], dd_grd_screencanv);
1402 if (GRMODEINFO(modex)) {
1403 //@@VR_current_page = !VR_current_page;
1412 if (Cockpit_mode==CM_FULL_COCKPIT || Cockpit_mode==CM_STATUS_BAR) {
1414 if ( (Newdemo_state == ND_STATE_PLAYBACK) )
1415 Game_mode = Newdemo_game_mode;
1419 if ( (Newdemo_state == ND_STATE_PLAYBACK) )
1420 Game_mode = GM_NORMAL;
1425 VR_current_page = !VR_current_page;
1440 void toggle_cockpit()
1444 switch (Cockpit_mode) {
1446 case CM_FULL_COCKPIT: {
1447 int max_h = grd_curscreen->sc_h - GameBitmaps[cockpit_bitmap[CM_STATUS_BAR+(Current_display_mode?(Num_cockpits/2):0)].index].bm_h;
1448 if (Game_window_h > max_h) //too big for statusbar
1449 new_mode = CM_FULL_SCREEN;
1451 new_mode = CM_STATUS_BAR;
1456 case CM_FULL_SCREEN:
1459 new_mode = CM_FULL_COCKPIT;
1465 return; //do nothing
1470 select_cockpit(new_mode);
1471 HUD_clear_messages();
1472 write_player_file();
1476 #define WINDOW_W_DELTA ((max_window_w / 16)&~1) //24 //20
1477 #define WINDOW_H_DELTA ((max_window_h / 16)&~1) //12 //10
1479 #define WINDOW_MIN_W ((max_window_w * 10) / 22) //160
1480 #define WINDOW_MIN_H ((max_window_h * 10) / 22)
1482 //#define WINDOW_W_DELTA 32
1483 //#define WINDOW_H_DELTA 16
1485 #define WINDOW_W_DELTA ((max_window_w / 16) & ~15) // double word aligned
1486 #define WINDOW_H_DELTA ((max_window_h / 16) & ~15) // double word aligned
1488 #define WINDOW_MIN_W (max_window_w-(WINDOW_W_DELTA*11))
1489 #define WINDOW_MIN_H (max_window_h-(WINDOW_H_DELTA*11))
1494 if (Cockpit_mode == CM_FULL_COCKPIT) {
1495 Game_window_h = max_window_h;
1496 Game_window_w = max_window_w;
1498 HUD_init_message("Press F3 to return to Cockpit mode");
1502 if (Cockpit_mode != CM_STATUS_BAR && (VR_screen_flags & VRF_ALLOW_COCKPIT))
1505 if (Game_window_h>=max_window_h || Game_window_w>=max_window_w) {
1506 //Game_window_w = max_window_w;
1507 //Game_window_h = max_window_h;
1508 select_cockpit(CM_FULL_SCREEN);
1512 Game_window_w += WINDOW_W_DELTA;
1513 Game_window_h += WINDOW_H_DELTA;
1515 #ifdef MACINTOSH // horrible hack to ensure that height is even to satisfy pixel doubling blitter
1516 if ( Scanline_double && (Game_window_h & 1) )
1520 if (Game_window_h > max_window_h)
1521 Game_window_h = max_window_h;
1523 if (Game_window_w > max_window_w)
1524 Game_window_w = max_window_w;
1526 Game_window_x = (max_window_w - Game_window_w)/2;
1527 Game_window_y = (max_window_h - Game_window_h)/2;
1529 game_init_render_sub_buffers( Game_window_x, Game_window_y, Game_window_w, Game_window_h );
1532 HUD_clear_messages(); // @mk, 11/11/94
1534 write_player_file();
1537 // grs_bitmap background_bitmap; already declared in line 434 (samir 4/10/94)
1539 extern grs_bitmap background_bitmap;
1541 void copy_background_rect(int left,int top,int right,int bot)
1543 grs_bitmap *bm = &background_bitmap;
1545 int tile_left,tile_right,tile_top,tile_bot;
1549 if (right < left || bot < top)
1552 tile_left = left / bm->bm_w;
1553 tile_right = right / bm->bm_w;
1554 tile_top = top / bm->bm_h;
1555 tile_bot = bot / bm->bm_h;
1557 ofs_y = top % bm->bm_h;
1560 WIN(DDGRLOCK(dd_grd_curcanv))
1562 for (y=tile_top;y<=tile_bot;y++) {
1565 ofs_x = left % bm->bm_w;
1568 //h = (bot < dest_y+bm->bm_h)?(bot-dest_y+1):(bm->bm_h-ofs_y);
1569 h = min(bot-dest_y+1,bm->bm_h-ofs_y);
1571 for (x=tile_left;x<=tile_right;x++) {
1573 //w = (right < dest_x+bm->bm_w)?(right-dest_x+1):(bm->bm_w-ofs_x);
1574 w = min(right-dest_x+1,bm->bm_w-ofs_x);
1576 gr_bm_ubitblt(w,h,dest_x,dest_y,ofs_x,ofs_y,
1577 &background_bitmap,&grd_curcanv->cv_bitmap);
1587 WIN(DDGRUNLOCK(dd_grd_curcanv));
1592 int force_background_fill=0;
1595 //fills int the background surrounding the 3d window
1596 void fill_background()
1608 WINDOS( dd_gr_set_current_canvas(&dd_VR_screen_pages[VR_current_page]),
1609 gr_set_current_canvas(&VR_screen_pages[VR_current_page])
1611 copy_background_rect(x-dx,y-dy,x-1,y+h+dy-1);
1612 copy_background_rect(x+w,y-dy,grd_curcanv->cv_w-1,y+h+dy-1);
1613 copy_background_rect(x,y-dy,x+w-1,y-1);
1614 copy_background_rect(x,y+h,x+w-1,y+h+dy-1);
1617 if (GRMODEINFO(modex)) {
1618 copy_background_rect(x-dx,y-dy,x-1,y+h+dy-1);
1619 copy_background_rect(x+w,y-dy,grd_curcanv->cv_w-1,y+h+dy-1);
1620 copy_background_rect(x,y-dy,x+w-1,y-1);
1621 copy_background_rect(x,y+h,x+w-1,y+h+dy-1);
1625 if (VR_screen_flags & VRF_USE_PAGING) {
1626 WINDOS( dd_gr_set_current_canvas(&dd_VR_screen_pages[!VR_current_page]),
1627 gr_set_current_canvas(&VR_screen_pages[!VR_current_page])
1629 copy_background_rect(x-dx,y-dy,x-1,y+h+dy-1);
1630 copy_background_rect(x+w,y-dy,x+w+dx-1,y+h+dy-1);
1631 copy_background_rect(x,y-dy,x+w-1,y-1);
1632 copy_background_rect(x,y+h,x+w-1,y+h+dy-1);
1636 if (GRMODEINFO(modex) && force_background_fill==0) //double-buffered
1637 force_background_fill=2;
1641 void shrink_window()
1644 //When you shrink the window twice in two frames, the background doens't
1645 //restore properly. So this hack keeps you from shrinking the window
1646 //before two frames have been drawn
1647 static int last_shrink_framecount=-1;
1648 if (FrameCount - last_shrink_framecount < 2)
1650 last_shrink_framecount = FrameCount;
1653 mprintf((0,"%d ",FrameCount));
1655 // mprintf ((0,"W=%d H=%d\n",Game_window_w,Game_window_h));
1657 if (Cockpit_mode == CM_FULL_COCKPIT && (VR_screen_flags & VRF_ALLOW_COCKPIT)) {
1658 Game_window_h = max_window_h;
1659 Game_window_w = max_window_w;
1660 //!!toggle_cockpit();
1661 select_cockpit(CM_STATUS_BAR);
1664 HUD_init_message("Press F3 to return to Cockpit mode");
1665 write_player_file();
1669 if (Cockpit_mode == CM_FULL_SCREEN && (VR_screen_flags & VRF_ALLOW_COCKPIT))
1671 //Game_window_w = max_window_w;
1672 //Game_window_h = max_window_h;
1673 select_cockpit(CM_STATUS_BAR);
1674 write_player_file();
1678 if (Cockpit_mode != CM_STATUS_BAR && (VR_screen_flags & VRF_ALLOW_COCKPIT))
1681 mprintf ((0,"Cockpit mode=%d\n",Cockpit_mode));
1683 if (Game_window_w > WINDOW_MIN_W) {
1686 Game_window_w -= WINDOW_W_DELTA;
1687 Game_window_h -= WINDOW_H_DELTA;
1690 mprintf ((0,"NewW=%d NewH=%d VW=%d maxH=%d\n",Game_window_w,Game_window_h,max_window_w,max_window_h));
1692 if ( Game_window_w < WINDOW_MIN_W )
1693 Game_window_w = WINDOW_MIN_W;
1695 if ( Game_window_h < WINDOW_MIN_H )
1696 Game_window_h = WINDOW_MIN_H;
1698 #ifdef MACINTOSH // horrible hack to ensure that height is even to satisfy pixel doubling blitter
1699 if ( Scanline_double && (Game_window_h & 1) )
1703 Game_window_x = (max_window_w - Game_window_w)/2;
1704 Game_window_y = (max_window_h - Game_window_h)/2;
1708 game_init_render_sub_buffers( Game_window_x, Game_window_y, Game_window_w, Game_window_h );
1709 HUD_clear_messages();
1710 write_player_file();
1715 int last_drawn_cockpit[2] = { -1, -1 };
1717 // This actually renders the new cockpit onto the screen.
1718 void update_cockpits(int force_redraw)
1722 if (Cockpit_mode != last_drawn_cockpit[VR_current_page] || force_redraw )
1723 last_drawn_cockpit[VR_current_page] = Cockpit_mode;
1727 //Redraw the on-screen cockpit bitmaps
1728 if (VR_render_mode != VR_NONE ) return;
1730 switch( Cockpit_mode ) {
1731 case CM_FULL_COCKPIT:
1734 dd_gr_set_current_canvas(&dd_VR_screen_pages[VR_current_page]),
1735 gr_set_current_canvas(&VR_screen_pages[VR_current_page])
1737 PIGGY_PAGE_IN(cockpit_bitmap[Cockpit_mode+(Current_display_mode?(Num_cockpits/2):0)]);
1739 WIN(DDGRLOCK(dd_grd_curcanv));
1740 gr_ubitmapm(0,0, &GameBitmaps[cockpit_bitmap[Cockpit_mode+(Current_display_mode?(Num_cockpits/2):0)].index]);
1741 WIN(DDGRUNLOCK(dd_grd_curcanv));
1744 case CM_FULL_SCREEN:
1745 Game_window_x = (max_window_w - Game_window_w)/2;
1746 Game_window_y = (max_window_h - Game_window_h)/2;
1752 WINDOS ( dd_gr_set_current_canvas(&dd_VR_screen_pages[VR_current_page]),
1753 gr_set_current_canvas(&VR_screen_pages[VR_current_page])
1756 PIGGY_PAGE_IN(cockpit_bitmap[Cockpit_mode+(Current_display_mode?(Num_cockpits/2):0)]);
1758 WIN(DDGRLOCK(dd_grd_curcanv));
1759 gr_ubitmapm(0,max_window_h,&GameBitmaps[cockpit_bitmap[Cockpit_mode+(Current_display_mode?(Num_cockpits/2):0)].index]);
1760 WIN(DDGRUNLOCK(dd_grd_curcanv));
1762 #ifdef MACINTOSH // hideously horrible hack to put grey line 1 scanline above because of pixel doubling "oddness"
1763 if (Scanline_double)
1765 gr_setcolor(BM_XRGB(13,13,13)); // color of top of status bar
1766 gr_uscanline( 0, grd_curcanv->cv_w, max_window_h-1 );
1770 Game_window_x = (max_window_w - Game_window_w)/2;
1771 Game_window_y = (max_window_h - Game_window_h)/2;
1776 WINDOS( dd_gr_set_current_canvas(&dd_VR_screen_pages[VR_current_page]),
1777 gr_set_current_canvas(&VR_screen_pages[VR_current_page])
1779 WINDOS ( dd_gr_clear_canvas( BM_XRGB(0,0,0) ),
1780 gr_clear_canvas( BM_XRGB(0,0,0) ) );
1782 // In a modex mode, clear the other buffer.
1783 if (grd_curcanv->cv_bitmap.bm_type == BM_MODEX) {
1784 gr_set_current_canvas(&VR_screen_pages[VR_current_page^1]);
1785 gr_clear_canvas( BM_XRGB(0,0,0) );
1786 gr_set_current_canvas(&VR_screen_pages[VR_current_page]);
1792 WINDOS ( dd_gr_set_current_canvas(&dd_VR_screen_pages[VR_current_page]),
1793 gr_set_current_canvas(&VR_screen_pages[VR_current_page])
1796 if (Cockpit_mode==CM_FULL_COCKPIT || Cockpit_mode==CM_STATUS_BAR)
1802 void game_render_frame()
1804 set_screen_mode( SCREEN_GAME );
1809 if (force_background_fill) {
1811 force_background_fill--;
1815 play_homing_warning();
1817 if (VR_render_mode == VR_NONE )
1818 game_render_frame_mono();
1820 game_render_frame_stereo();
1823 // Make sure palette is faded in
1825 gr_palette_fade_in( gr_palette, 32, 0 );
1831 extern int Color_0_31_0;
1833 //draw a crosshair for the guided missile
1834 void draw_guided_crosshair(void)
1838 gr_setcolor(Color_0_31_0);
1840 w = grd_curcanv->cv_w>>5;
1844 h = i2f(w) / grd_curscreen->sc_aspect;
1846 x = grd_curcanv->cv_w / 2;
1847 y = grd_curcanv->cv_h / 2;
1849 gr_scanline(x-w/2,x+w/2,y);
1850 gr_uline(i2f(x),i2f(y-h/2),i2f(x),i2f(y+h/2));
1854 typedef struct bkg {
1855 short x, y, w, h; // The location of the menu.
1856 grs_bitmap * bmp; // The background under the menu.
1859 bkg bg = {0,0,0,0,NULL};
1861 #define BOX_BORDER (MenuHires?60:30)
1863 //show a message in a nice little box
1864 void show_boxed_message(char *msg)
1870 dd_gr_set_current_canvas(&dd_VR_screen_pages[VR_current_page]),
1871 gr_set_current_canvas(&VR_screen_pages[VR_current_page])
1873 gr_set_curfont( MEDIUM1_FONT );
1875 gr_get_string_size(msg,&w,&h,&aw);
1877 x = (grd_curscreen->sc_w-w)/2;
1878 y = (grd_curscreen->sc_h-h)/2;
1881 gr_free_bitmap(bg.bmp);
1885 // Save the background of the display
1886 bg.x=x; bg.y=y; bg.w=w; bg.h=h;
1888 #if defined(POLY_ACC)
1889 bg.bmp = gr_create_bitmap2( w+BOX_BORDER, h+BOX_BORDER, grd_curcanv->cv_bitmap.bm_type, NULL );
1891 bg.bmp = gr_create_bitmap( w+BOX_BORDER, h+BOX_BORDER );
1894 WIN( DDGRLOCK(dd_grd_curcanv));
1895 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 );
1896 WIN( DDGRUNLOCK(dd_grd_curcanv));
1898 nm_draw_background(x-BOX_BORDER/2,y-BOX_BORDER/2,x+w+BOX_BORDER/2-1,y+h+BOX_BORDER/2-1);
1900 gr_set_fontcolor( gr_getcolor(31, 31, 31), -1 );
1902 WIN( DDGRLOCK(dd_grd_curcanv));
1903 gr_ustring( 0x8000, y, msg );
1904 WIN( DDGRUNLOCK(dd_grd_curcanv));
1908 void clear_boxed_message()
1913 WIN(DDGRLOCK(dd_grd_curcanv));
1914 gr_bitmap(bg.x-BOX_BORDER/2, bg.y-BOX_BORDER/2, bg.bmp);
1915 WIN(DDGRUNLOCK(dd_grd_curcanv));
1918 gr_free_bitmap(bg.bmp);
1925 void win_do_emul_ibitblt(dd_grs_canvas *csrc, dd_grs_canvas *cdest)
1932 WIN(DDGRLOCK(csrc));
1933 WIN(DDGRLOCK(cdest));
1934 src_data = csrc->canvas.cv_bitmap.bm_data;
1935 dest_data = cdest->canvas.cv_bitmap.bm_data;
1937 // mprintf((0, "Render Ptr: %x; Dest Ptr: %x;\n",src_data, dest_data));
1939 for (line = 0; line < 480; line++,
1940 dest_data += cdest->canvas.cv_bitmap.bm_rowsize)
1942 cockpit_span_line *sline;
1944 sline = &win_cockpit_mask[line];
1946 if (!sline->num) continue;
1947 if (sline->num == 255) break;
1948 for (span = 0; span < sline->num; span++)
1950 if ((sline->span[span].xmax-sline->span[span].xmin+1) < 10) {
1951 gr_winckpit_blt_span(sline->span[span].xmin,
1952 sline->span[span].xmax,
1953 src_data, dest_data);
1956 gr_winckpit_blt_span_long(sline->span[span].xmin,
1957 sline->span[span].xmax,
1958 src_data, dest_data);
1961 src_data += csrc->canvas.cv_bitmap.bm_rowsize;
1963 WIN(DDGRUNLOCK(cdest));
1964 WIN(DDGRUNLOCK(csrc));
1968 //@@void win_do_emul_ibitblt(dd_grs_canvas *csrc, dd_grs_canvas *cdest)
1972 //@@ RECT srect, drect;
1974 //@@// Do Render Blt to Mask Surface (dest blt 1-255)
1975 //@@ bltfx.dwSize = sizeof(bltfx);
1976 //@@ bltfx.ddckDestColorkey.dwColorSpaceLowValue = 1;
1977 //@@ bltfx.ddckDestColorkey.dwColorSpaceHighValue = 255;
1978 //@@ SetRect(&srect, 0,0, csrc->canvas.cv_w, csrc->canvas.cv_h);
1979 //@@ SetRect(&drect, 0,0, csrc->canvas.cv_w, csrc->canvas.cv_h);
1981 //@@ res = IDirectDrawSurface_Blt(_lpDDSMask, &drect, csrc->lpdds, &srect,
1982 //@@ DDBLT_WAIT | DDBLT_KEYDESTOVERRIDE,
1984 //@@ if (res != DD_OK)
1985 //@@ Error("win_ibitblt: ddraw blt to mask err: %x.\n", res);
1987 //@@// Do Mask Blt to Screen (src blt !0)
1988 //@@ bltfx.dwSize = sizeof(bltfx);
1989 //@@ bltfx.ddckSrcColorkey.dwColorSpaceLowValue = 0;
1990 //@@ bltfx.ddckSrcColorkey.dwColorSpaceHighValue = 0;
1992 //@@ res = IDirectDrawSurface_Blt(cdest->lpdds, &drect, _lpDDSMask, &srect,
1993 //@@ DDBLT_WAIT | DDBLT_KEYSRCOVERRIDE,
1995 //@@ if (res != DD_OK)
1996 //@@ Error("win_ibitblt: ddraw blt to screen err: %x.\n", res);