2 THE COMPUTER CODE CONTAINED HEREIN IS THE SOLE PROPERTY OF PARALLAX
3 SOFTWARE CORPORATION ("PARALLAX"). PARALLAX, IN DISTRIBUTING THE CODE TO
4 END-USERS, AND SUBJECT TO ALL OF THE TERMS AND CONDITIONS HEREIN, GRANTS A
5 ROYALTY-FREE, PERPETUAL LICENSE TO SUCH END-USERS FOR USE BY SUCH END-USERS
6 IN USING, DISPLAYING, AND CREATING DERIVATIVE WORKS THEREOF, SO LONG AS
7 SUCH USE, DISPLAY OR CREATION IS FOR NON-COMMERCIAL, ROYALTY OR REVENUE
8 FREE PURPOSES. IN NO EVENT SHALL THE END-USER USE THE COMPUTER CODE
9 CONTAINED HEREIN FOR REVENUE-BEARING PURPOSES. THE END-USER UNDERSTANDS
10 AND AGREES TO THE TERMS HEREIN AND ACCEPTS THE SAME BY USE OF THIS FILE.
11 COPYRIGHT 1993-1999 PARALLAX SOFTWARE CORPORATION. ALL RIGHTS RESERVED.
19 static char rcsid[] = "$Id: gamerend.c,v 1.10 2003-06-06 19:04:27 btb Exp $";
33 #include "pa_enabl.h" //$$POLY_ACC
71 extern fix Cruise_speed;
72 extern int LinearSVGABuffer;
73 extern int Current_display_mode;
74 extern cvar_t r_framerate;
78 cockpit_span_line win_cockpit_mask[480];
79 void win_do_emul_ibitblt(dd_grs_canvas *csrc, dd_grs_canvas *cdest);
84 extern int Debug_pause; //John's debugging pause system
88 extern int Saving_movie_frames;
90 #define Saving_movie_frames 0
93 // Returns the length of the first 'n' characters of a string.
94 int string_width( char * s, int n )
100 gr_get_string_size( s, &w, &h, &aw );
105 // Draw string 's' centered on a canvas... if wider than
106 // canvas, then wrap it.
107 void draw_centered_text( int y, char * s )
114 if ( string_width( s, l ) < grd_curcanv->cv_bitmap.bm_w ) {
115 gr_string( 0x8000, y, s );
119 for (i=0; i<l; i++ ) {
120 if ( string_width(s,i) > (grd_curcanv->cv_bitmap.bm_w - 16) ) {
123 gr_string( 0x8000, y, s );
125 gr_string( 0x8000, y+grd_curcanv->cv_font->ft_h+1, &s[i] );
131 extern ubyte DefiningMarkerMessage;
132 extern char Marker_input[];
134 #define MAX_MARKER_MESSAGE_LEN 120
135 void game_draw_marker_message()
137 char temp_string[MAX_MARKER_MESSAGE_LEN+25];
139 if ( DefiningMarkerMessage)
141 gr_set_curfont( GAME_FONT ); //GAME_FONT
142 gr_set_fontcolor(gr_getcolor(0,63,0), -1 );
143 sprintf( temp_string, "Marker: %s_", Marker_input );
144 draw_centered_text(grd_curcanv->cv_bitmap.bm_h/2-16, temp_string );
150 void game_draw_multi_message()
152 char temp_string[MAX_MULTI_MESSAGE_LEN+25];
154 if ( (Game_mode&GM_MULTI) && (multi_sending_message)) {
155 gr_set_curfont( GAME_FONT ); //GAME_FONT );
156 gr_set_fontcolor(gr_getcolor(0,63,0), -1 );
157 sprintf( temp_string, "%s: %s_", TXT_MESSAGE, Network_message );
158 draw_centered_text(grd_curcanv->cv_bitmap.bm_h/2-16, temp_string );
162 if ( (Game_mode&GM_MULTI) && (multi_defining_message)) {
163 gr_set_curfont( GAME_FONT ); //GAME_FONT );
164 gr_set_fontcolor(gr_getcolor(0,63,0), -1 );
165 sprintf( temp_string, "%s #%d: %s_", TXT_MACRO, multi_defining_message, Network_message );
166 draw_centered_text(grd_curcanv->cv_bitmap.bm_h/2-16, temp_string );
171 //these should be in gr.h
172 #define cv_w cv_bitmap.bm_w
173 #define cv_h cv_bitmap.bm_h
175 fix frame_time_list[8] = {0,0,0,0,0,0,0,0};
176 fix frame_time_total=0;
177 int frame_time_cntr=0;
179 void ftoa(char *string, fix f)
181 int decimal, fractional;
184 fractional = ((f & 0xffff)*100)/65536;
187 if (fractional > 99 ) fractional = 99;
188 sprintf( string, "%d.%02d", decimal, fractional );
191 void show_framerate()
197 int x = 8, y = 5; // position measured from lower right corner
199 frame_time_total += RealFrameTime - frame_time_list[frame_time_cntr];
200 frame_time_list[frame_time_cntr] = RealFrameTime;
201 frame_time_cntr = (frame_time_cntr+1)%8;
203 rate = fixdiv(f1_0*8,frame_time_total);
205 gr_set_curfont( GAME_FONT );
206 gr_set_fontcolor(gr_getcolor(0,31,0),-1 );
208 ftoa( temp, rate ); // Convert fixed to string
209 if (Game_mode & GM_MULTI)
211 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 );
212 // if ( !( q++ % 30 ) )
213 // mprintf( (0,"fps: %s\n", temp ) );
218 fix Show_view_text_timer = -1;
220 void draw_window_label()
222 if ( Show_view_text_timer > 0 )
224 char *viewer_name,*control_name;
226 Show_view_text_timer -= FrameTime;
227 gr_set_curfont( GAME_FONT );
230 switch( Viewer->type )
232 case OBJ_FIREBALL: viewer_name = "Fireball"; break;
233 case OBJ_ROBOT: viewer_name = "Robot";
235 viewer_id = Robot_names[Viewer->id];
238 case OBJ_HOSTAGE: viewer_name = "Hostage"; break;
239 case OBJ_PLAYER: viewer_name = "Player"; break;
240 case OBJ_WEAPON: viewer_name = "Weapon"; break;
241 case OBJ_CAMERA: viewer_name = "Camera"; break;
242 case OBJ_POWERUP: viewer_name = "Powerup";
244 viewer_id = Powerup_names[Viewer->id];
247 case OBJ_DEBRIS: viewer_name = "Debris"; break;
248 case OBJ_CNTRLCEN: viewer_name = "Reactor"; break;
249 default: viewer_name = "Unknown"; break;
252 switch ( Viewer->control_type) {
253 case CT_NONE: control_name = "Stopped"; break;
254 case CT_AI: control_name = "AI"; break;
255 case CT_FLYING: control_name = "Flying"; break;
256 case CT_SLEW: control_name = "Slew"; break;
257 case CT_FLYTHROUGH: control_name = "Flythrough"; break;
258 case CT_MORPH: control_name = "Morphing"; break;
259 default: control_name = "Unknown"; break;
262 gr_set_fontcolor( gr_getcolor(31, 0, 0), -1 );
263 gr_printf( 0x8000, 45, "%i: %s [%s] View - %s",Viewer-Objects, viewer_name, viewer_id, control_name );
269 extern int Game_window_x;
270 extern int Game_window_y;
271 extern int Game_window_w;
272 extern int Game_window_h;
273 extern int max_window_w;
274 extern int max_window_h;
276 void render_countdown_gauge()
278 if (!Endlevel_sequence && Control_center_destroyed && (Countdown_seconds_left>-1)) { // && (Countdown_seconds_left<127)) {
281 #if !defined(D2_OEM) && !defined(SHAREWARE) // no countdown on registered only
282 // On last level, we don't want a countdown.
283 if ((Current_mission_num == Builtin_mission_num) && (Current_level_num == Last_level))
285 if (!(Game_mode & GM_MULTI))
287 if (Game_mode & GM_MULTI_ROBOTS)
292 gr_set_curfont( SMALL_FONT );
293 gr_set_fontcolor(gr_getcolor(0,63,0), -1 );
294 y = SMALL_FONT->ft_h*4;
295 if (Cockpit_mode == CM_FULL_SCREEN)
296 y += SMALL_FONT->ft_h*2;
299 y += SMALL_FONT->ft_h*2;
301 //if (!((Cockpit_mode == CM_STATUS_BAR) && (Game_window_y >= 19)))
303 gr_printf(0x8000, y, "T-%d s", Countdown_seconds_left );
307 void game_draw_hud_stuff()
310 int odisplay_mode = Current_display_mode;
311 if (Scanline_double) {
313 Current_display_mode = 0;
318 //mprintf ((0,"Linear is %d!\n",LinearSVGABuffer));
322 gr_set_curfont( MEDIUM1_FONT );
323 gr_set_fontcolor( gr_getcolor(31, 31, 31), -1 ); // gr_getcolor(31,0,0));
324 gr_ustring( 0x8000, 85/2, "Debug Pause - Press P to exit" );
333 game_draw_multi_message();
336 game_draw_marker_message();
338 // if (Game_mode & GM_MULTI)
340 // if (Netgame.PlayTimeAllowed)
341 // game_draw_time_left ();
344 if ((Newdemo_state == ND_STATE_PLAYBACK) || (Newdemo_state == ND_STATE_RECORDING)) {
348 if (Newdemo_state == ND_STATE_PLAYBACK) {
349 if (Newdemo_vcr_state != ND_STATE_PRINTSCREEN) {
350 sprintf(message, "%s (%d%%%% %s)", TXT_DEMO_PLAYBACK, newdemo_get_percent_done(), TXT_DONE);
352 sprintf (message, " ");
355 sprintf (message, TXT_DEMO_RECORDING);
357 gr_set_curfont( GAME_FONT ); //GAME_FONT );
358 gr_set_fontcolor(gr_getcolor(27,0,0), -1 );
360 gr_get_string_size(message, &w, &h, &aw );
362 if (Scanline_double) // double height if scanline doubling since we have the correct
363 h += h; // font for printing, but the wrong height.
365 if (Cockpit_mode == CM_FULL_COCKPIT) {
366 if (grd_curcanv->cv_bitmap.bm_h > 240)
370 } else if ( Cockpit_mode == CM_LETTERBOX )
372 if (Cockpit_mode != CM_REAR_VIEW && !Saving_movie_frames)
373 gr_printf((grd_curcanv->cv_bitmap.bm_w-w)/2, grd_curcanv->cv_bitmap.bm_h - h - 2, message );
376 render_countdown_gauge();
378 if ( Player_num > -1 && Viewer->type==OBJ_PLAYER && Viewer->id==Player_num ) {
380 int y = grd_curcanv->cv_bitmap.bm_h;
382 gr_set_curfont( GAME_FONT );
383 gr_set_fontcolor( gr_getcolor(0, 31, 0), -1 );
384 if (Cruise_speed > 0) {
385 int line_spacing = GAME_FONT->ft_h + GAME_FONT->ft_h/4;
387 mprintf((0,"line_spacing=%d ",line_spacing));
389 if (Cockpit_mode==CM_FULL_SCREEN) {
390 if (Game_mode & GM_MULTI)
391 y -= line_spacing * 11; //64
393 y -= line_spacing * 6; //32
394 } else if (Cockpit_mode == CM_STATUS_BAR) {
395 if (Game_mode & GM_MULTI)
396 y -= line_spacing * 8; //48
398 y -= line_spacing * 4; //24
400 y = line_spacing * 2; //12
404 gr_printf( x, y, "%s %2d%%", TXT_CRUISE, f2i(Cruise_speed) );
408 if (r_framerate.value)
411 if ( (Newdemo_state == ND_STATE_PLAYBACK) )
412 Game_mode = Newdemo_game_mode;
416 if ( (Newdemo_state == ND_STATE_PLAYBACK) )
417 Game_mode = GM_NORMAL;
419 if ( Player_is_dead )
420 player_dead_message();
423 if (Scanline_double) {
425 Current_display_mode = odisplay_mode;
430 extern int gr_bitblt_dest_step_shift;
431 extern int gr_wait_for_retrace;
432 extern int gr_bitblt_double;
435 void expand_row(ubyte * dest, ubyte * src, int num_src_pixels );
436 #pragma aux expand_row parm [edi] [esi] [ecx] modify exact [ecx esi edi eax ebx] = \
454 void expand_row(ubyte * dest, ubyte * src, int num_src_pixels )
458 for (i = 0; i < num_src_pixels; i++) {
465 // doubles the size in x or y of a bitmap in place.
466 void game_expand_bitmap( grs_bitmap * bmp, uint flags )
469 ubyte * dptr, * sptr;
473 Assert( bmp->bm_rowsize == bmp->bm_w*2 );
474 dptr = &bmp->bm_data[(bmp->bm_h-1)*bmp->bm_rowsize];
475 for (i=bmp->bm_h-1; i>=0; i-- ) {
476 expand_row( dptr, dptr, bmp->bm_w );
477 dptr -= bmp->bm_rowsize;
482 dptr = &bmp->bm_data[(2*(bmp->bm_h-1)+1)*bmp->bm_rowsize];
483 sptr = &bmp->bm_data[(bmp->bm_h-1)*bmp->bm_rowsize];
484 for (i=bmp->bm_h-1; i>=0; i-- ) {
485 memcpy( dptr, sptr, bmp->bm_w );
486 dptr -= bmp->bm_rowsize;
487 memcpy( dptr, sptr, bmp->bm_w );
488 dptr -= bmp->bm_rowsize;
489 sptr -= bmp->bm_rowsize;
493 case 3: // expand x & y
494 Assert( bmp->bm_rowsize == bmp->bm_w*2 );
495 dptr = &bmp->bm_data[(2*(bmp->bm_h-1)+1)*bmp->bm_rowsize];
496 sptr = &bmp->bm_data[(bmp->bm_h-1)*bmp->bm_rowsize];
497 for (i=bmp->bm_h-1; i>=0; i-- ) {
498 expand_row( dptr, sptr, bmp->bm_w );
499 dptr -= bmp->bm_rowsize;
500 expand_row( dptr, sptr, bmp->bm_w );
501 dptr -= bmp->bm_rowsize;
502 sptr -= bmp->bm_rowsize;
510 extern int SW_drawn[2], SW_x[2], SW_y[2], SW_w[2], SW_h[2];
512 extern int Guided_in_big_window;
515 //render a frame for the game in stereo
516 void game_render_frame_stereo()
520 fix actual_eye_width;
521 int actual_eye_offset;
522 grs_canvas RenderCanvas[2];
525 save_aspect = grd_curscreen->sc_aspect;
526 grd_curscreen->sc_aspect *= 2; //Muck with aspect ratio
528 sw = dw = VR_render_buffer[0].cv_bitmap.bm_w;
529 sh = dh = VR_render_buffer[0].cv_bitmap.bm_h;
531 if (VR_low_res & 1) {
533 grd_curscreen->sc_aspect *= 2; //Muck with aspect ratio
535 if (VR_low_res & 2) {
537 grd_curscreen->sc_aspect /= 2; //Muck with aspect ratio
540 gr_init_sub_canvas( &RenderCanvas[0], &VR_render_buffer[0], 0, 0, sw, sh );
541 gr_init_sub_canvas( &RenderCanvas[1], &VR_render_buffer[1], 0, 0, sw, sh );
543 // Draw the left eye's view
545 actual_eye_width = -VR_eye_width;
546 actual_eye_offset = -VR_eye_offset;
548 actual_eye_width = VR_eye_width;
549 actual_eye_offset = VR_eye_offset;
552 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)
553 actual_eye_offset = 0;
555 gr_set_current_canvas(&RenderCanvas[0]);
557 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) {
558 char *msg = "Guided Missile View";
559 object *viewer_save = Viewer;
562 Viewer = Guided_missile[Player_num];
564 WIN(DDGRLOCK(dd_grd_curcanv)); // Must lock DD canvas!!!
570 update_rendered_data(0, Viewer, 0, 0);
572 #if defined(POLY_ACC) && !defined(MACINTOSH) // dma stuff not support on mac via RAVE
576 wake_up_rendered_objects(Viewer, 0);
577 Viewer = viewer_save;
579 gr_set_curfont( GAME_FONT ); //GAME_FONT );
580 gr_set_fontcolor(gr_getcolor(27,0,0), -1 );
581 gr_get_string_size(msg, &w, &h, &aw );
583 gr_printf((grd_curcanv->cv_bitmap.bm_w-w)/2, 3, msg );
585 draw_guided_crosshair();
587 WIN(DDGRUNLOCK(dd_grd_curcanv));
589 HUD_render_message_frame();
598 render_frame(actual_eye_width, 0); // switch eye positions for rear view
600 render_frame(-actual_eye_width, 0); // Left eye
603 game_expand_bitmap( &RenderCanvas[0].cv_bitmap, VR_low_res );
605 { //render small window into left eye's canvas
606 grs_canvas *save=grd_curcanv;
607 fix save_aspect2 = grd_curscreen->sc_aspect;
608 grd_curscreen->sc_aspect = save_aspect*2;
609 SW_drawn[0] = SW_drawn[1] = 0;
611 gr_set_current_canvas(save);
612 grd_curscreen->sc_aspect = save_aspect2;
616 if (actual_eye_offset > 0 ) {
617 gr_setcolor( gr_getcolor(0,0,0) );
618 gr_rect( grd_curcanv->cv_bitmap.bm_w-labs(actual_eye_offset)*2, 0,
619 grd_curcanv->cv_bitmap.bm_w-1, grd_curcanv->cv_bitmap.bm_h );
620 } else if (actual_eye_offset < 0 ) {
621 gr_setcolor( gr_getcolor(0,0,0) );
622 gr_rect( 0, 0, labs(actual_eye_offset)*2-1, grd_curcanv->cv_bitmap.bm_h );
625 if ( VR_show_hud && !no_draw_hud ) {
627 if (actual_eye_offset < 0 ) {
628 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 );
630 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 );
632 gr_set_current_canvas( &tmp );
633 game_draw_hud_stuff();
637 // Draw the right eye's view
638 gr_set_current_canvas(&RenderCanvas[1]);
640 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)
641 gr_bitmap(0,0,&RenderCanvas[0].cv_bitmap);
644 render_frame(-actual_eye_width, 0); // switch eye positions for rear view
646 render_frame(actual_eye_width, 0); // Right eye
649 game_expand_bitmap( &RenderCanvas[1].cv_bitmap, VR_low_res );
653 { //copy small window from left eye
658 gr_init_sub_canvas(&temp,&RenderCanvas[0],SW_x[w],SW_y[w],SW_w[w],SW_h[w]);
659 gr_bitmap(SW_x[w]+actual_eye_offset*2,SW_y[w],&temp.cv_bitmap);
665 if (actual_eye_offset>0) {
666 gr_setcolor( gr_getcolor(0,0,0) );
667 gr_rect( 0, 0, labs(actual_eye_offset)*2-1, grd_curcanv->cv_bitmap.bm_h );
668 } else if ( actual_eye_offset < 0 ) {
669 gr_setcolor( gr_getcolor(0,0,0) );
670 gr_rect( grd_curcanv->cv_bitmap.bm_w-labs(actual_eye_offset)*2, 0,
671 grd_curcanv->cv_bitmap.bm_w-1, grd_curcanv->cv_bitmap.bm_h );
674 //NEWVR (Add the next 2 lines)
675 if ( VR_show_hud && !no_draw_hud ) {
677 if (actual_eye_offset > 0 ) {
678 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 );
680 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 );
682 gr_set_current_canvas( &tmp );
683 game_draw_hud_stuff();
687 // Draws white and black registration encoding lines
688 // and Accounts for pixel-shift adjustment in upcoming bitblts
689 if (VR_use_reg_code) {
690 int width, height, quarter;
692 width = RenderCanvas[0].cv_bitmap.bm_w;
693 height = RenderCanvas[0].cv_bitmap.bm_h;
696 // black out left-hand side of left page
698 // draw registration code for left eye
700 gr_set_current_canvas( &RenderCanvas[1] );
702 gr_set_current_canvas( &RenderCanvas[0] );
703 gr_setcolor( VR_WHITE_INDEX );
704 gr_scanline( 0, quarter, height-1 );
705 gr_setcolor( VR_BLACK_INDEX );
706 gr_scanline( quarter, width-1, height-1 );
709 gr_set_current_canvas( &RenderCanvas[0] );
711 gr_set_current_canvas( &RenderCanvas[1] );
712 gr_setcolor( VR_WHITE_INDEX );
713 gr_scanline( 0, quarter*3, height-1 );
714 gr_setcolor( VR_BLACK_INDEX );
715 gr_scanline( quarter*3, width-1, height-1 );
718 // Copy left eye, then right eye
719 if ( VR_screen_flags&VRF_USE_PAGING )
720 VR_current_page = !VR_current_page;
723 gr_set_current_canvas( &VR_screen_pages[VR_current_page] );
727 if ( VR_eye_offset_changed > 0 ) {
728 VR_eye_offset_changed--;
732 sw = dw = VR_render_buffer[0].cv_bitmap.bm_w;
733 sh = dh = VR_render_buffer[0].cv_bitmap.bm_h;
735 // Copy left eye, then right eye
736 gr_bitblt_dest_step_shift = 1; // Skip every other scanline.
738 if (VR_render_mode == VR_INTERLACED ) {
739 if ( actual_eye_offset > 0 ) {
740 int xoff = labs(actual_eye_offset);
741 gr_bm_ubitblt( dw-xoff, dh, xoff, 0, 0, 0, &RenderCanvas[0].cv_bitmap, &VR_screen_pages[VR_current_page].cv_bitmap);
742 gr_bm_ubitblt( dw-xoff, dh, 0, 1, xoff, 0, &RenderCanvas[1].cv_bitmap, &VR_screen_pages[VR_current_page].cv_bitmap);
743 } else if ( actual_eye_offset < 0 ) {
744 int xoff = labs(actual_eye_offset);
745 gr_bm_ubitblt( dw-xoff, dh, 0, 0, xoff, 0, &RenderCanvas[0].cv_bitmap, &VR_screen_pages[VR_current_page].cv_bitmap);
746 gr_bm_ubitblt( dw-xoff, dh, xoff, 1, 0, 0, &RenderCanvas[1].cv_bitmap, &VR_screen_pages[VR_current_page].cv_bitmap);
748 gr_bm_ubitblt( dw, dh, 0, 0, 0, 0, &RenderCanvas[0].cv_bitmap, &VR_screen_pages[VR_current_page].cv_bitmap);
749 gr_bm_ubitblt( dw, dh, 0, 1, 0, 0, &RenderCanvas[1].cv_bitmap, &VR_screen_pages[VR_current_page].cv_bitmap);
751 } else if (VR_render_mode == VR_AREA_DET) {
753 gr_bm_ubitblt( dw, dh, 0, VR_current_page, 0, 0, &RenderCanvas[0].cv_bitmap, &VR_screen_pages[0].cv_bitmap);
754 gr_bm_ubitblt( dw, dh, dw, VR_current_page, 0, 0, &RenderCanvas[1].cv_bitmap, &VR_screen_pages[0].cv_bitmap);
759 gr_bitblt_dest_step_shift = 0;
761 //if ( Game_vfx_flag )
762 // vfx_set_page(VR_current_page); // 0 or 1
764 if ( VR_screen_flags&VRF_USE_PAGING ) {
765 gr_wait_for_retrace = 0;
767 // Added by Samir from John's code
768 if ( (VR_screen_pages[VR_current_page].cv_bitmap.bm_type == BM_MODEX) && (Game_3dmax_flag==3) ) {
769 int old_x, old_y, new_x;
770 old_x = VR_screen_pages[VR_current_page].cv_bitmap.bm_x;
771 old_y = VR_screen_pages[VR_current_page].cv_bitmap.bm_y;
772 new_x = old_y*VR_screen_pages[VR_current_page].cv_bitmap.bm_rowsize;
774 VR_screen_pages[VR_current_page].cv_bitmap.bm_x = new_x;
775 VR_screen_pages[VR_current_page].cv_bitmap.bm_y = 0;
776 VR_screen_pages[VR_current_page].cv_bitmap.bm_type = BM_SVGA;
777 gr_show_canvas( &VR_screen_pages[VR_current_page] );
778 VR_screen_pages[VR_current_page].cv_bitmap.bm_type = BM_MODEX;
779 VR_screen_pages[VR_current_page].cv_bitmap.bm_x = old_x;
780 VR_screen_pages[VR_current_page].cv_bitmap.bm_y = old_y;
782 gr_show_canvas( &VR_screen_pages[VR_current_page] );
784 gr_wait_for_retrace = 1;
786 grd_curscreen->sc_aspect=save_aspect;
789 ubyte RenderingType=0;
790 ubyte DemoDoingRight=0,DemoDoingLeft=0;
791 extern ubyte DemoDoRight,DemoDoLeft;
792 extern object DemoRightExtra,DemoLeftExtra;
794 char DemoWBUType[]={0,WBU_MISSILE,WBU_MISSILE,WBU_REAR,WBU_ESCORT,WBU_MARKER,WBU_MISSILE};
795 char DemoRearCheck[]={0,0,0,1,0,0,0};
796 char *DemoExtraMessage[]={"PLAYER","GUIDED","MISSILE","REAR","GUIDE-BOT","MARKER","SHIP"};
798 extern char guidebot_name[];
800 void show_extra_views()
802 int did_missile_view=0;
803 int save_newdemo_state = Newdemo_state;
806 if (Newdemo_state==ND_STATE_PLAYBACK)
810 DemoDoingLeft=DemoDoLeft;
813 do_cockpit_window_view(0,ConsoleObject,1,WBU_REAR,"REAR");
815 do_cockpit_window_view(0,&DemoLeftExtra,DemoRearCheck[DemoDoLeft],DemoWBUType[DemoDoLeft],DemoExtraMessage[DemoDoLeft]);
818 do_cockpit_window_view(0,NULL,0,WBU_WEAPON,NULL);
822 DemoDoingRight=DemoDoRight;
825 do_cockpit_window_view(1,ConsoleObject,1,WBU_REAR,"REAR");
827 do_cockpit_window_view(1,&DemoRightExtra,DemoRearCheck[DemoDoRight],DemoWBUType[DemoDoRight],DemoExtraMessage[DemoDoRight]);
830 do_cockpit_window_view(1,NULL,0,WBU_WEAPON,NULL);
832 DemoDoLeft=DemoDoRight=0;
833 DemoDoingLeft=DemoDoingRight=0;
838 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]) {
839 if (Guided_in_big_window)
841 RenderingType=6+(1<<4);
842 do_cockpit_window_view(1,Viewer,0,WBU_MISSILE,"SHIP");
846 RenderingType=1+(1<<4);
847 do_cockpit_window_view(1,Guided_missile[Player_num],0,WBU_GUIDED,"GUIDED");
854 if (Guided_missile[Player_num]) { //used to be active
855 if (!Guided_in_big_window)
856 do_cockpit_window_view(1,NULL,0,WBU_STATIC,NULL);
857 Guided_missile[Player_num] = NULL;
860 if (Missile_viewer) { //do missile view
861 static int mv_sig=-1;
863 mv_sig = Missile_viewer->signature;
864 if (Missile_view_enabled && Missile_viewer->type!=OBJ_NONE && Missile_viewer->signature == mv_sig) {
865 RenderingType=2+(1<<4);
866 do_cockpit_window_view(1,Missile_viewer,0,WBU_MISSILE,"MISSILE");
870 Missile_viewer = NULL;
873 do_cockpit_window_view(1,NULL,0,WBU_STATIC,NULL);
880 if (w==1 && did_missile_view)
881 continue; //if showing missile view in right window, can't show anything else
883 //show special views if selected
884 switch (Cockpit_3d_view[w]) {
887 do_cockpit_window_view(w,NULL,0,WBU_WEAPON,NULL);
890 if (Rear_view) { //if big window is rear view, show front here
891 RenderingType=3+(w<<4);
892 do_cockpit_window_view(w,ConsoleObject,0,WBU_REAR,"FRONT");
894 else { //show normal rear view
895 RenderingType=3+(w<<4);
896 do_cockpit_window_view(w,ConsoleObject,1,WBU_REAR,"REAR");
901 buddy = find_escort();
903 do_cockpit_window_view(w,NULL,0,WBU_WEAPON,NULL);
904 Cockpit_3d_view[w] = CV_NONE;
907 RenderingType=4+(w<<4);
908 do_cockpit_window_view(w,buddy,0,WBU_ESCORT,guidebot_name);
914 int player = Coop_view_player[w];
916 RenderingType=255; // don't handle coop stuff
918 if (player!=-1 && Players[player].connected && ((Game_mode & GM_MULTI_COOP) || ((Game_mode & GM_TEAM) && (get_team(player) == get_team(Player_num)))))
919 do_cockpit_window_view(w,&Objects[Players[Coop_view_player[w]].objnum],0,WBU_COOP,Players[Coop_view_player[w]].callsign);
921 do_cockpit_window_view(w,NULL,0,WBU_WEAPON,NULL);
922 Cockpit_3d_view[w] = CV_NONE;
929 RenderingType=5+(w<<4);
930 if (Marker_viewer_num[w] == -1 || MarkerObject[Marker_viewer_num[w]] == -1) {
931 Cockpit_3d_view[w] = CV_NONE;
934 sprintf(label,"Marker %d",Marker_viewer_num[w]+1);
935 do_cockpit_window_view(w,&Objects[MarkerObject[Marker_viewer_num[w]]],0,WBU_MARKER,label);
939 Int3(); //invalid window type
943 Newdemo_state = save_newdemo_state;
946 int BigWindowSwitch=0;
947 extern int force_cockpit_redraw;
949 extern ubyte * Game_cockpit_copy_code;
951 extern ubyte Game_cockpit_copy_code;
954 void draw_guided_crosshair(void);
957 // special code to render a frame w/hw acceleration
959 // next routine is called as a callback from the current hardware engine being used. The
960 // routine is called once all of the accelerated drawing is done. We now overlay the
961 // backbuffer with hud stuff.
963 void pa_mac_render_extras( void )
965 grs_canvas Screen_3d_window;
967 gr_init_sub_canvas( &Screen_3d_window, &VR_screen_pages[0],
968 VR_render_sub_buffer[0].cv_bitmap.bm_x,
969 VR_render_sub_buffer[0].cv_bitmap.bm_y,
970 VR_render_sub_buffer[0].cv_bitmap.bm_w,
971 VR_render_sub_buffer[0].cv_bitmap.bm_h);
973 gr_set_current_canvas( &Screen_3d_window ); // set to current screen
975 if (Guided_missile[Player_num] &&
976 Guided_missile[Player_num]->type==OBJ_WEAPON &&
977 Guided_missile[Player_num]->id==GUIDEDMISS_ID &&
978 Guided_missile[Player_num]->signature==Guided_missile_sig[Player_num] &&
979 Guided_in_big_window)
981 char *msg = "Guided Missile View";
984 gr_set_curfont( GAME_FONT ); //GAME_FONT );
985 gr_set_fontcolor(gr_getcolor(27,0,0), -1 );
986 gr_get_string_size(msg, &w, &h, &aw );
988 gr_printf((grd_curcanv->cv_bitmap.bm_w-w)/2, 3, msg );
990 draw_guided_crosshair();
992 HUD_render_message_frame();
996 game_draw_hud_stuff(); // draw hud stuff when not doing missle view in big window
999 if (Game_paused) { //render pause message over off-screen 3d (to minimize flicker)
1000 extern char *Pause_msg;
1001 ubyte *save_data = VR_screen_pages[VR_current_page].cv_bitmap.bm_data;
1003 WIN(Int3()); // Not supported yet.
1004 VR_screen_pages[VR_current_page].cv_bitmap.bm_data=VR_render_buffer[VR_current_page].cv_bitmap.bm_data;
1005 show_boxed_message(Pause_msg);
1006 VR_screen_pages[VR_current_page].cv_bitmap.bm_data=save_data;
1012 void pa_mac_game_render_frame( void )
1014 Assert ( !Scanline_double );
1015 Assert ( PAEnabled );
1017 gr_set_current_canvas(&VR_render_sub_buffer[0]); // set up the right canvas so rendering is done to correct size
1021 if (Guided_missile[Player_num] &&
1022 Guided_missile[Player_num]->type==OBJ_WEAPON &&
1023 Guided_missile[Player_num]->id==GUIDEDMISS_ID &&
1024 Guided_missile[Player_num]->signature==Guided_missile_sig[Player_num] &&
1025 Guided_in_big_window)
1027 char *msg = "Guided Missile View";
1028 object *viewer_save = Viewer;
1031 if (Cockpit_mode==CM_FULL_COCKPIT) {
1033 force_cockpit_redraw=1;
1034 Cockpit_mode=CM_STATUS_BAR;
1039 Viewer = Guided_missile[Player_num];
1040 update_rendered_data(0, Viewer, 0, 0);
1042 wake_up_rendered_objects(Viewer, 0);
1043 Viewer = viewer_save;
1047 if (BigWindowSwitch)
1049 force_cockpit_redraw=1;
1050 Cockpit_mode=CM_FULL_COCKPIT;
1056 update_rendered_data(0, Viewer, Rear_view, 0);
1060 if (Cockpit_mode == CM_FULL_SCREEN)
1068 // NOTE: Hud stuff is drawn using a RAVE call back which draws onto the back buffer
1069 // after rendering finishes but before the page flip
1071 if (Cockpit_mode != CM_FULL_SCREEN)
1073 show_extra_views(); //missile view, buddy bot, etc.
1076 // Draw Gauges straight to screen
1077 if (Cockpit_mode==CM_FULL_COCKPIT || Cockpit_mode==CM_STATUS_BAR)
1080 if ( (Newdemo_state == ND_STATE_PLAYBACK) )
1082 Game_mode = Newdemo_game_mode;
1085 Current_display_mode = 1;
1087 Current_display_mode = -1;
1089 if ( (Newdemo_state == ND_STATE_PLAYBACK) )
1091 Game_mode = GM_NORMAL;
1098 //render a frame for the game
1100 // will render everything to dd_VR_render_sub_buffer
1101 // which all leads to the dd_VR_offscreen_buffer
1102 void game_render_frame_mono(void)
1105 dd_grs_canvas Screen_3d_window,
1106 grs_canvas Screen_3d_window
1110 #if defined(MACINTOSH)
1112 pa_mac_game_render_frame();
1119 dd_gr_init_sub_canvas(&Screen_3d_window, &dd_VR_screen_pages[0],
1120 dd_VR_render_sub_buffer[0].canvas.cv_bitmap.bm_x,
1121 dd_VR_render_sub_buffer[0].canvas.cv_bitmap.bm_y,
1122 dd_VR_render_sub_buffer[0].canvas.cv_bitmap.bm_w,
1123 dd_VR_render_sub_buffer[0].canvas.cv_bitmap.bm_h),
1124 gr_init_sub_canvas( &Screen_3d_window, &VR_screen_pages[0],
1125 VR_render_sub_buffer[0].cv_bitmap.bm_x,
1126 VR_render_sub_buffer[0].cv_bitmap.bm_y,
1127 VR_render_sub_buffer[0].cv_bitmap.bm_w,
1128 VR_render_sub_buffer[0].cv_bitmap.bm_h)
1131 if ( Game_double_buffer ) {
1133 dd_gr_set_current_canvas(&dd_VR_render_sub_buffer[0]),
1134 gr_set_current_canvas(&VR_render_sub_buffer[0])
1139 dd_gr_set_current_canvas(&Screen_3d_window),
1140 gr_set_current_canvas(&Screen_3d_window)
1144 #if defined(POLY_ACC) && !defined(MACINTOSH) // begin s3 relocation of cockpit drawing.
1148 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)
1152 WIN(DDGRLOCK(dd_grd_curcanv));
1153 game_draw_hud_stuff();
1154 WIN(DDGRUNLOCK(dd_grd_curcanv));
1157 show_extra_views(); //missile view, buddy bot, etc.
1160 if (Game_paused) { //render pause message over off-screen 3d (to minimize flicker)
1161 extern char *Pause_msg;
1162 ubyte *save_data = VR_screen_pages[VR_current_page].cv_bitmap.bm_data;
1164 WIN(Int3()); // Not supported yet.
1165 VR_screen_pages[VR_current_page].cv_bitmap.bm_data=VR_render_buffer[VR_current_page].cv_bitmap.bm_data;
1166 show_boxed_message(Pause_msg);
1167 VR_screen_pages[VR_current_page].cv_bitmap.bm_data=save_data;
1170 if ( Game_double_buffer ) { //copy to visible screen
1171 if ( !Game_cockpit_copy_code ) {
1172 if ( VR_screen_flags&VRF_USE_PAGING ) {
1173 VR_current_page = !VR_current_page;
1174 gr_set_current_canvas( &VR_screen_pages[VR_current_page] );
1175 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 );
1176 gr_wait_for_retrace = 0;
1177 gr_show_canvas( &VR_screen_pages[VR_current_page] );
1178 gr_wait_for_retrace = 1;
1180 #ifdef POLY_ACC //$$
1184 VR_render_sub_buffer[0].cv_w, VR_render_sub_buffer[0].cv_h,
1185 VR_render_sub_buffer[0].cv_bitmap.bm_x, VR_render_sub_buffer[0].cv_bitmap.bm_y,
1186 VR_render_sub_buffer[0].cv_bitmap.bm_x, VR_render_sub_buffer[0].cv_bitmap.bm_y,
1187 &VR_render_sub_buffer[0].cv_bitmap, &VR_screen_pages[0].cv_bitmap
1191 #ifdef POLY_ACC //$$
1194 gr_ibitblt( &VR_render_buffer[0].cv_bitmap, &VR_screen_pages[0].cv_bitmap, Game_cockpit_copy_code );
1198 if (Cockpit_mode==CM_FULL_COCKPIT || Cockpit_mode==CM_STATUS_BAR) {
1200 if ( (Newdemo_state == ND_STATE_PLAYBACK) )
1201 Game_mode = Newdemo_game_mode;
1205 if ( (Newdemo_state == ND_STATE_PLAYBACK) )
1206 Game_mode = GM_NORMAL;
1209 // restore current canvas.
1210 if ( Game_double_buffer ) {
1212 dd_gr_set_current_canvas(&dd_VR_render_sub_buffer[0]),
1213 gr_set_current_canvas(&VR_render_sub_buffer[0])
1218 dd_gr_set_current_canvas(&Screen_3d_window),
1219 gr_set_current_canvas(&Screen_3d_window)
1223 #endif // end s3 relocation of cockpit drawing.
1225 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) {
1226 char *msg = "Guided Missile View";
1227 object *viewer_save = Viewer;
1230 if (Cockpit_mode==CM_FULL_COCKPIT)
1233 force_cockpit_redraw=1;
1234 Cockpit_mode=CM_STATUS_BAR;
1238 Viewer = Guided_missile[Player_num];
1240 WIN(DDGRLOCK(dd_grd_curcanv)); // Must lock DD canvas!!!
1243 if (Scanline_double)
1246 update_rendered_data(0, Viewer, 0, 0);
1249 wake_up_rendered_objects(Viewer, 0);
1250 Viewer = viewer_save;
1252 gr_set_curfont( GAME_FONT ); //GAME_FONT );
1253 gr_set_fontcolor(gr_getcolor(27,0,0), -1 );
1254 gr_get_string_size(msg, &w, &h, &aw );
1256 gr_printf((grd_curcanv->cv_bitmap.bm_w-w)/2, 3, msg );
1258 draw_guided_crosshair();
1260 WIN(DDGRUNLOCK(dd_grd_curcanv));
1262 HUD_render_message_frame();
1264 if (Scanline_double)
1272 if (BigWindowSwitch)
1274 force_cockpit_redraw=1;
1275 Cockpit_mode=CM_FULL_COCKPIT;
1279 WIN(DDGRLOCK(dd_grd_curcanv)); // Must lock DD canvas!!!
1280 update_rendered_data(0, Viewer, Rear_view, 0);
1282 #if defined(POLY_ACC) && !defined(MACINTOSH) // dma stuff not supported on mac via RAVE
1285 WIN(DDGRUNLOCK(dd_grd_curcanv));
1288 if ( Game_double_buffer ) {
1290 dd_gr_set_current_canvas(&dd_VR_render_sub_buffer[0]),
1291 gr_set_current_canvas(&VR_render_sub_buffer[0])
1296 dd_gr_set_current_canvas(&Screen_3d_window),
1297 gr_set_current_canvas(&Screen_3d_window)
1301 #if !defined(POLY_ACC) || defined(MACINTOSH)
1304 WIN(DDGRLOCK(dd_grd_curcanv));
1305 game_draw_hud_stuff();
1306 WIN(DDGRUNLOCK(dd_grd_curcanv));
1309 show_extra_views(); //missile view, buddy bot, etc.
1312 if (Game_paused) { //render pause message over off-screen 3d (to minimize flicker)
1313 extern char *Pause_msg;
1314 // LPDIRECTDRAWSURFACE save_dds = dd_VR_screen_pages[VR_current_page].lpdds;
1316 // dd_VR_screen_pages[VR_current_page].lpdds = dd_VR_render_buffer[VR_current_page].lpdds;
1317 show_boxed_message(Pause_msg);
1318 // dd_VR_screen_pages[VR_current_page].lpdds = save_dds;
1321 if (Game_paused) { //render pause message over off-screen 3d (to minimize flicker)
1322 extern char *Pause_msg;
1323 ubyte *save_data = VR_screen_pages[VR_current_page].cv_bitmap.bm_data;
1325 VR_screen_pages[VR_current_page].cv_bitmap.bm_data=VR_render_buffer[VR_current_page].cv_bitmap.bm_data;
1326 show_boxed_message(Pause_msg);
1327 VR_screen_pages[VR_current_page].cv_bitmap.bm_data=save_data;
1331 if ( Game_double_buffer ) { //copy to visible screen
1332 if ( !Game_cockpit_copy_code ) {
1333 if ( VR_screen_flags&VRF_USE_PAGING ) {
1334 VR_current_page = !VR_current_page;
1336 dd_gr_set_current_canvas(&dd_VR_screen_pages[VR_current_page]);
1339 gr_set_current_canvas( &VR_screen_pages[VR_current_page] );
1340 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 );
1341 gr_wait_for_retrace = 0;
1342 gr_show_canvas( &VR_screen_pages[VR_current_page] );
1343 gr_wait_for_retrace = 1;
1347 if (Scanline_double)
1348 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 );
1350 #endif // NOTE LINK TO ABOVE IF
1352 if (GRMODEINFO(emul) || GRMODEINFO(modex) || GRMODEINFO(dbuf))
1353 // From render buffer to screen buffer.
1354 dd_gr_blt_notrans(&dd_VR_render_sub_buffer[0],
1356 dd_VR_render_sub_buffer[0].canvas.cv_w,
1357 dd_VR_render_sub_buffer[0].canvas.cv_h,
1359 dd_VR_render_sub_buffer[0].xoff,
1360 dd_VR_render_sub_buffer[0].yoff,
1361 dd_VR_render_sub_buffer[0].canvas.cv_w,
1362 dd_VR_render_sub_buffer[0].canvas.cv_h);
1365 // Puts back canvas to front canvas by blt or flip
1366 if (GRMODEINFO(modex)) {
1367 //@@VR_current_page = !VR_current_page;
1372 gr_bm_ubitblt( VR_render_sub_buffer[0].cv_w,
1373 VR_render_sub_buffer[0].cv_h,
1374 VR_render_sub_buffer[0].cv_bitmap.bm_x,
1375 VR_render_sub_buffer[0].cv_bitmap.bm_y,
1377 &VR_render_sub_buffer[0].cv_bitmap,
1378 &VR_screen_pages[0].cv_bitmap );
1387 #if 1 //def MACINTOSH
1388 gr_ibitblt( &VR_render_sub_buffer[0].cv_bitmap, &VR_screen_pages[0].cv_bitmap, Scanline_double );
1391 gr_ibitblt( &VR_render_buffer[0].cv_bitmap, &VR_screen_pages[0].cv_bitmap, Game_cockpit_copy_code );
1393 win_do_emul_ibitblt( &dd_VR_render_sub_buffer[0], dd_grd_screencanv);
1395 if (GRMODEINFO(modex)) {
1396 //@@VR_current_page = !VR_current_page;
1405 if (Cockpit_mode==CM_FULL_COCKPIT || Cockpit_mode==CM_STATUS_BAR) {
1407 if ( (Newdemo_state == ND_STATE_PLAYBACK) )
1408 Game_mode = Newdemo_game_mode;
1412 if ( (Newdemo_state == ND_STATE_PLAYBACK) )
1413 Game_mode = GM_NORMAL;
1418 VR_current_page = !VR_current_page;
1433 void toggle_cockpit()
1437 switch (Cockpit_mode) {
1439 case CM_FULL_COCKPIT: {
1440 int max_h = grd_curscreen->sc_h - GameBitmaps[cockpit_bitmap[CM_STATUS_BAR+(Current_display_mode?(Num_cockpits/2):0)].index].bm_h;
1441 if (Game_window_h > max_h) //too big for statusbar
1442 new_mode = CM_FULL_SCREEN;
1444 new_mode = CM_STATUS_BAR;
1449 case CM_FULL_SCREEN:
1452 new_mode = CM_FULL_COCKPIT;
1458 return; //do nothing
1463 select_cockpit(new_mode);
1464 HUD_clear_messages();
1465 write_player_file();
1469 #define WINDOW_W_DELTA ((max_window_w / 16)&~1) //24 //20
1470 #define WINDOW_H_DELTA ((max_window_h / 16)&~1) //12 //10
1472 #define WINDOW_MIN_W ((max_window_w * 10) / 22) //160
1473 #define WINDOW_MIN_H ((max_window_h * 10) / 22)
1475 //#define WINDOW_W_DELTA 32
1476 //#define WINDOW_H_DELTA 16
1478 #define WINDOW_W_DELTA ((max_window_w / 16) & ~15) // double word aligned
1479 #define WINDOW_H_DELTA ((max_window_h / 16) & ~15) // double word aligned
1481 #define WINDOW_MIN_W (max_window_w-(WINDOW_W_DELTA*11))
1482 #define WINDOW_MIN_H (max_window_h-(WINDOW_H_DELTA*11))
1487 if (Cockpit_mode == CM_FULL_COCKPIT) {
1488 Game_window_h = max_window_h;
1489 Game_window_w = max_window_w;
1491 HUD_init_message("Press F3 to return to Cockpit mode");
1495 if (Cockpit_mode != CM_STATUS_BAR && (VR_screen_flags & VRF_ALLOW_COCKPIT))
1498 if (Game_window_h>=max_window_h || Game_window_w>=max_window_w) {
1499 //Game_window_w = max_window_w;
1500 //Game_window_h = max_window_h;
1501 select_cockpit(CM_FULL_SCREEN);
1505 Game_window_w += WINDOW_W_DELTA;
1506 Game_window_h += WINDOW_H_DELTA;
1508 #ifdef MACINTOSH // horrible hack to ensure that height is even to satisfy pixel doubling blitter
1509 if ( Scanline_double && (Game_window_h & 1) )
1513 if (Game_window_h > max_window_h)
1514 Game_window_h = max_window_h;
1516 if (Game_window_w > max_window_w)
1517 Game_window_w = max_window_w;
1519 Game_window_x = (max_window_w - Game_window_w)/2;
1520 Game_window_y = (max_window_h - Game_window_h)/2;
1522 game_init_render_sub_buffers( Game_window_x, Game_window_y, Game_window_w, Game_window_h );
1525 HUD_clear_messages(); // @mk, 11/11/94
1527 write_player_file();
1530 // grs_bitmap background_bitmap; already declared in line 434 (samir 4/10/94)
1532 extern grs_bitmap background_bitmap;
1534 void copy_background_rect(int left,int top,int right,int bot)
1536 grs_bitmap *bm = &background_bitmap;
1538 int tile_left,tile_right,tile_top,tile_bot;
1542 if (right < left || bot < top)
1545 tile_left = left / bm->bm_w;
1546 tile_right = right / bm->bm_w;
1547 tile_top = top / bm->bm_h;
1548 tile_bot = bot / bm->bm_h;
1550 ofs_y = top % bm->bm_h;
1553 WIN(DDGRLOCK(dd_grd_curcanv))
1555 for (y=tile_top;y<=tile_bot;y++) {
1558 ofs_x = left % bm->bm_w;
1561 //h = (bot < dest_y+bm->bm_h)?(bot-dest_y+1):(bm->bm_h-ofs_y);
1562 h = min(bot-dest_y+1,bm->bm_h-ofs_y);
1564 for (x=tile_left;x<=tile_right;x++) {
1566 //w = (right < dest_x+bm->bm_w)?(right-dest_x+1):(bm->bm_w-ofs_x);
1567 w = min(right-dest_x+1,bm->bm_w-ofs_x);
1569 gr_bm_ubitblt(w,h,dest_x,dest_y,ofs_x,ofs_y,
1570 &background_bitmap,&grd_curcanv->cv_bitmap);
1580 WIN(DDGRUNLOCK(dd_grd_curcanv));
1585 int force_background_fill=0;
1588 //fills int the background surrounding the 3d window
1589 void fill_background()
1601 WINDOS( dd_gr_set_current_canvas(&dd_VR_screen_pages[VR_current_page]),
1602 gr_set_current_canvas(&VR_screen_pages[VR_current_page])
1604 copy_background_rect(x-dx,y-dy,x-1,y+h+dy-1);
1605 copy_background_rect(x+w,y-dy,grd_curcanv->cv_w-1,y+h+dy-1);
1606 copy_background_rect(x,y-dy,x+w-1,y-1);
1607 copy_background_rect(x,y+h,x+w-1,y+h+dy-1);
1610 if (GRMODEINFO(modex)) {
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);
1618 if (VR_screen_flags & VRF_USE_PAGING) {
1619 WINDOS( dd_gr_set_current_canvas(&dd_VR_screen_pages[!VR_current_page]),
1620 gr_set_current_canvas(&VR_screen_pages[!VR_current_page])
1622 copy_background_rect(x-dx,y-dy,x-1,y+h+dy-1);
1623 copy_background_rect(x+w,y-dy,x+w+dx-1,y+h+dy-1);
1624 copy_background_rect(x,y-dy,x+w-1,y-1);
1625 copy_background_rect(x,y+h,x+w-1,y+h+dy-1);
1629 if (GRMODEINFO(modex) && force_background_fill==0) //double-buffered
1630 force_background_fill=2;
1634 void shrink_window()
1637 //When you shrink the window twice in two frames, the background doens't
1638 //restore properly. So this hack keeps you from shrinking the window
1639 //before two frames have been drawn
1640 static int last_shrink_framecount=-1;
1641 if (FrameCount - last_shrink_framecount < 2)
1643 last_shrink_framecount = FrameCount;
1646 mprintf((0,"%d ",FrameCount));
1648 // mprintf ((0,"W=%d H=%d\n",Game_window_w,Game_window_h));
1650 if (Cockpit_mode == CM_FULL_COCKPIT && (VR_screen_flags & VRF_ALLOW_COCKPIT)) {
1651 Game_window_h = max_window_h;
1652 Game_window_w = max_window_w;
1653 //!!toggle_cockpit();
1654 select_cockpit(CM_STATUS_BAR);
1657 HUD_init_message("Press F3 to return to Cockpit mode");
1658 write_player_file();
1662 if (Cockpit_mode == CM_FULL_SCREEN && (VR_screen_flags & VRF_ALLOW_COCKPIT))
1664 //Game_window_w = max_window_w;
1665 //Game_window_h = max_window_h;
1666 select_cockpit(CM_STATUS_BAR);
1667 write_player_file();
1671 if (Cockpit_mode != CM_STATUS_BAR && (VR_screen_flags & VRF_ALLOW_COCKPIT))
1674 mprintf ((0,"Cockpit mode=%d\n",Cockpit_mode));
1676 if (Game_window_w > WINDOW_MIN_W) {
1679 Game_window_w -= WINDOW_W_DELTA;
1680 Game_window_h -= WINDOW_H_DELTA;
1683 mprintf ((0,"NewW=%d NewH=%d VW=%d maxH=%d\n",Game_window_w,Game_window_h,max_window_w,max_window_h));
1685 if ( Game_window_w < WINDOW_MIN_W )
1686 Game_window_w = WINDOW_MIN_W;
1688 if ( Game_window_h < WINDOW_MIN_H )
1689 Game_window_h = WINDOW_MIN_H;
1691 #ifdef MACINTOSH // horrible hack to ensure that height is even to satisfy pixel doubling blitter
1692 if ( Scanline_double && (Game_window_h & 1) )
1696 Game_window_x = (max_window_w - Game_window_w)/2;
1697 Game_window_y = (max_window_h - Game_window_h)/2;
1701 game_init_render_sub_buffers( Game_window_x, Game_window_y, Game_window_w, Game_window_h );
1702 HUD_clear_messages();
1703 write_player_file();
1708 int last_drawn_cockpit[2] = { -1, -1 };
1710 // This actually renders the new cockpit onto the screen.
1711 void update_cockpits(int force_redraw)
1715 if (Cockpit_mode != last_drawn_cockpit[VR_current_page] || force_redraw )
1716 last_drawn_cockpit[VR_current_page] = Cockpit_mode;
1720 //Redraw the on-screen cockpit bitmaps
1721 if (VR_render_mode != VR_NONE ) return;
1723 switch( Cockpit_mode ) {
1724 case CM_FULL_COCKPIT:
1727 dd_gr_set_current_canvas(&dd_VR_screen_pages[VR_current_page]),
1728 gr_set_current_canvas(&VR_screen_pages[VR_current_page])
1730 PIGGY_PAGE_IN(cockpit_bitmap[Cockpit_mode+(Current_display_mode?(Num_cockpits/2):0)]);
1732 WIN(DDGRLOCK(dd_grd_curcanv));
1733 gr_ubitmapm(0,0, &GameBitmaps[cockpit_bitmap[Cockpit_mode+(Current_display_mode?(Num_cockpits/2):0)].index]);
1734 WIN(DDGRUNLOCK(dd_grd_curcanv));
1737 case CM_FULL_SCREEN:
1738 Game_window_x = (max_window_w - Game_window_w)/2;
1739 Game_window_y = (max_window_h - Game_window_h)/2;
1745 WINDOS ( dd_gr_set_current_canvas(&dd_VR_screen_pages[VR_current_page]),
1746 gr_set_current_canvas(&VR_screen_pages[VR_current_page])
1749 PIGGY_PAGE_IN(cockpit_bitmap[Cockpit_mode+(Current_display_mode?(Num_cockpits/2):0)]);
1751 WIN(DDGRLOCK(dd_grd_curcanv));
1752 gr_ubitmapm(0,max_window_h,&GameBitmaps[cockpit_bitmap[Cockpit_mode+(Current_display_mode?(Num_cockpits/2):0)].index]);
1753 WIN(DDGRUNLOCK(dd_grd_curcanv));
1755 #ifdef MACINTOSH // hideously horrible hack to put grey line 1 scanline above because of pixel doubling "oddness"
1756 if (Scanline_double)
1758 gr_setcolor(BM_XRGB(13,13,13)); // color of top of status bar
1759 gr_uscanline( 0, grd_curcanv->cv_w, max_window_h-1 );
1763 Game_window_x = (max_window_w - Game_window_w)/2;
1764 Game_window_y = (max_window_h - Game_window_h)/2;
1769 WINDOS( dd_gr_set_current_canvas(&dd_VR_screen_pages[VR_current_page]),
1770 gr_set_current_canvas(&VR_screen_pages[VR_current_page])
1772 WINDOS ( dd_gr_clear_canvas( BM_XRGB(0,0,0) ),
1773 gr_clear_canvas( BM_XRGB(0,0,0) ) );
1775 // In a modex mode, clear the other buffer.
1776 if (grd_curcanv->cv_bitmap.bm_type == BM_MODEX) {
1777 gr_set_current_canvas(&VR_screen_pages[VR_current_page^1]);
1778 gr_clear_canvas( BM_XRGB(0,0,0) );
1779 gr_set_current_canvas(&VR_screen_pages[VR_current_page]);
1785 WINDOS ( dd_gr_set_current_canvas(&dd_VR_screen_pages[VR_current_page]),
1786 gr_set_current_canvas(&VR_screen_pages[VR_current_page])
1789 if (Cockpit_mode==CM_FULL_COCKPIT || Cockpit_mode==CM_STATUS_BAR)
1795 void game_render_frame()
1797 set_screen_mode( SCREEN_GAME );
1802 if (force_background_fill) {
1804 force_background_fill--;
1808 play_homing_warning();
1810 if (VR_render_mode == VR_NONE )
1811 game_render_frame_mono();
1813 game_render_frame_stereo();
1816 // Make sure palette is faded in
1818 gr_palette_fade_in( gr_palette, 32, 0 );
1824 extern int Color_0_31_0;
1826 //draw a crosshair for the guided missile
1827 void draw_guided_crosshair(void)
1831 gr_setcolor(Color_0_31_0);
1833 w = grd_curcanv->cv_w>>5;
1837 h = i2f(w) / grd_curscreen->sc_aspect;
1839 x = grd_curcanv->cv_w / 2;
1840 y = grd_curcanv->cv_h / 2;
1842 gr_scanline(x-w/2,x+w/2,y);
1843 gr_uline(i2f(x),i2f(y-h/2),i2f(x),i2f(y+h/2));
1847 typedef struct bkg {
1848 short x, y, w, h; // The location of the menu.
1849 grs_bitmap * bmp; // The background under the menu.
1852 bkg bg = {0,0,0,0,NULL};
1854 #define BOX_BORDER (MenuHires?60:30)
1856 //show a message in a nice little box
1857 void show_boxed_message(char *msg)
1863 dd_gr_set_current_canvas(&dd_VR_screen_pages[VR_current_page]),
1864 gr_set_current_canvas(&VR_screen_pages[VR_current_page])
1866 gr_set_curfont( MEDIUM1_FONT );
1868 gr_get_string_size(msg,&w,&h,&aw);
1870 x = (grd_curscreen->sc_w-w)/2;
1871 y = (grd_curscreen->sc_h-h)/2;
1874 gr_free_bitmap(bg.bmp);
1878 // Save the background of the display
1879 bg.x=x; bg.y=y; bg.w=w; bg.h=h;
1881 #if defined(POLY_ACC)
1882 bg.bmp = gr_create_bitmap2( w+BOX_BORDER, h+BOX_BORDER, grd_curcanv->cv_bitmap.bm_type, NULL );
1884 bg.bmp = gr_create_bitmap( w+BOX_BORDER, h+BOX_BORDER );
1887 WIN( DDGRLOCK(dd_grd_curcanv));
1888 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 );
1889 WIN( DDGRUNLOCK(dd_grd_curcanv));
1891 nm_draw_background(x-BOX_BORDER/2,y-BOX_BORDER/2,x+w+BOX_BORDER/2-1,y+h+BOX_BORDER/2-1);
1893 gr_set_fontcolor( gr_getcolor(31, 31, 31), -1 );
1895 WIN( DDGRLOCK(dd_grd_curcanv));
1896 gr_ustring( 0x8000, y, msg );
1897 WIN( DDGRUNLOCK(dd_grd_curcanv));
1901 void clear_boxed_message()
1906 WIN(DDGRLOCK(dd_grd_curcanv));
1907 gr_bitmap(bg.x-BOX_BORDER/2, bg.y-BOX_BORDER/2, bg.bmp);
1908 WIN(DDGRUNLOCK(dd_grd_curcanv));
1911 gr_free_bitmap(bg.bmp);
1918 void win_do_emul_ibitblt(dd_grs_canvas *csrc, dd_grs_canvas *cdest)
1925 WIN(DDGRLOCK(csrc));
1926 WIN(DDGRLOCK(cdest));
1927 src_data = csrc->canvas.cv_bitmap.bm_data;
1928 dest_data = cdest->canvas.cv_bitmap.bm_data;
1930 // mprintf((0, "Render Ptr: %x; Dest Ptr: %x;\n",src_data, dest_data));
1932 for (line = 0; line < 480; line++,
1933 dest_data += cdest->canvas.cv_bitmap.bm_rowsize)
1935 cockpit_span_line *sline;
1937 sline = &win_cockpit_mask[line];
1939 if (!sline->num) continue;
1940 if (sline->num == 255) break;
1941 for (span = 0; span < sline->num; span++)
1943 if ((sline->span[span].xmax-sline->span[span].xmin+1) < 10) {
1944 gr_winckpit_blt_span(sline->span[span].xmin,
1945 sline->span[span].xmax,
1946 src_data, dest_data);
1949 gr_winckpit_blt_span_long(sline->span[span].xmin,
1950 sline->span[span].xmax,
1951 src_data, dest_data);
1954 src_data += csrc->canvas.cv_bitmap.bm_rowsize;
1956 WIN(DDGRUNLOCK(cdest));
1957 WIN(DDGRUNLOCK(csrc));
1961 //@@void win_do_emul_ibitblt(dd_grs_canvas *csrc, dd_grs_canvas *cdest)
1965 //@@ RECT srect, drect;
1967 //@@// Do Render Blt to Mask Surface (dest blt 1-255)
1968 //@@ bltfx.dwSize = sizeof(bltfx);
1969 //@@ bltfx.ddckDestColorkey.dwColorSpaceLowValue = 1;
1970 //@@ bltfx.ddckDestColorkey.dwColorSpaceHighValue = 255;
1971 //@@ SetRect(&srect, 0,0, csrc->canvas.cv_w, csrc->canvas.cv_h);
1972 //@@ SetRect(&drect, 0,0, csrc->canvas.cv_w, csrc->canvas.cv_h);
1974 //@@ res = IDirectDrawSurface_Blt(_lpDDSMask, &drect, csrc->lpdds, &srect,
1975 //@@ DDBLT_WAIT | DDBLT_KEYDESTOVERRIDE,
1977 //@@ if (res != DD_OK)
1978 //@@ Error("win_ibitblt: ddraw blt to mask err: %x.\n", res);
1980 //@@// Do Mask Blt to Screen (src blt !0)
1981 //@@ bltfx.dwSize = sizeof(bltfx);
1982 //@@ bltfx.ddckSrcColorkey.dwColorSpaceLowValue = 0;
1983 //@@ bltfx.ddckSrcColorkey.dwColorSpaceHighValue = 0;
1985 //@@ res = IDirectDrawSurface_Blt(cdest->lpdds, &drect, _lpDDSMask, &srect,
1986 //@@ DDBLT_WAIT | DDBLT_KEYSRCOVERRIDE,
1988 //@@ if (res != DD_OK)
1989 //@@ Error("win_ibitblt: ddraw blt to screen err: %x.\n", res);