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.
16 static char rcsid[] = "$Id: gamerend.c,v 1.2 2001-01-20 13:49:15 bradleyb Exp $";
32 #include "pa_enabl.h" //$$POLY_ACC
66 extern fix Cruise_speed;
67 extern int LinearSVGABuffer;
68 extern int Current_display_mode;
69 extern cvar_t r_framerate;
73 cockpit_span_line win_cockpit_mask[480];
74 void win_do_emul_ibitblt(dd_grs_canvas *csrc, dd_grs_canvas *cdest);
79 extern int Debug_pause; //John's debugging pause system
83 extern int Saving_movie_frames;
85 #define Saving_movie_frames 0
88 // Returns the length of the first 'n' characters of a string.
89 int string_width( char * s, int n )
95 gr_get_string_size( s, &w, &h, &aw );
100 // Draw string 's' centered on a canvas... if wider than
101 // canvas, then wrap it.
102 void draw_centered_text( int y, char * s )
109 if ( string_width( s, l ) < grd_curcanv->cv_bitmap.bm_w ) {
110 gr_string( 0x8000, y, s );
114 for (i=0; i<l; i++ ) {
115 if ( string_width(s,i) > (grd_curcanv->cv_bitmap.bm_w - 16) ) {
118 gr_string( 0x8000, y, s );
120 gr_string( 0x8000, y+grd_curcanv->cv_font->ft_h+1, &s[i] );
126 extern ubyte DefiningMarkerMessage;
127 extern char Marker_input[];
129 #define MAX_MARKER_MESSAGE_LEN 120
130 void game_draw_marker_message()
132 char temp_string[MAX_MARKER_MESSAGE_LEN+25];
134 if ( DefiningMarkerMessage)
136 gr_set_curfont( GAME_FONT ); //GAME_FONT
137 gr_set_fontcolor(gr_getcolor(0,63,0), -1 );
138 sprintf( temp_string, "Marker: %s_", Marker_input );
139 draw_centered_text(grd_curcanv->cv_bitmap.bm_h/2-16, temp_string );
145 void game_draw_multi_message()
147 char temp_string[MAX_MULTI_MESSAGE_LEN+25];
149 if ( (Game_mode&GM_MULTI) && (multi_sending_message)) {
150 gr_set_curfont( GAME_FONT ); //GAME_FONT );
151 gr_set_fontcolor(gr_getcolor(0,63,0), -1 );
152 sprintf( temp_string, "%s: %s_", TXT_MESSAGE, Network_message );
153 draw_centered_text(grd_curcanv->cv_bitmap.bm_h/2-16, temp_string );
157 if ( (Game_mode&GM_MULTI) && (multi_defining_message)) {
158 gr_set_curfont( GAME_FONT ); //GAME_FONT );
159 gr_set_fontcolor(gr_getcolor(0,63,0), -1 );
160 sprintf( temp_string, "%s #%d: %s_", TXT_MACRO, multi_defining_message, Network_message );
161 draw_centered_text(grd_curcanv->cv_bitmap.bm_h/2-16, temp_string );
166 //these should be in gr.h
167 #define cv_w cv_bitmap.bm_w
168 #define cv_h cv_bitmap.bm_h
170 fix frame_time_list[8] = {0,0,0,0,0,0,0,0};
171 fix frame_time_total=0;
172 int frame_time_cntr=0;
174 void ftoa(char *string, fix f)
176 int decimal, fractional;
179 fractional = ((f & 0xffff)*100)/65536;
182 if (fractional > 99 ) fractional = 99;
183 sprintf( string, "%d.%02d", decimal, fractional );
186 void show_framerate()
193 frame_time_total += RealFrameTime - frame_time_list[frame_time_cntr];
194 frame_time_list[frame_time_cntr] = RealFrameTime;
195 frame_time_cntr = (frame_time_cntr+1)%8;
197 rate = fixdiv(f1_0*8,frame_time_total);
199 gr_set_curfont( GAME_FONT );
200 gr_set_fontcolor(gr_getcolor(0,31,0),-1 );
202 ftoa( temp, rate ); // Convert fixed to string
203 gr_printf(grd_curcanv->cv_w-(8*GAME_FONT->ft_w),grd_curcanv->cv_h-5*(GAME_FONT->ft_h+GAME_FONT->ft_h/4),"FPS: %s ", temp );
204 // if ( !( q++ % 30 ) )
205 // mprintf( (0,"fps: %s\n", temp ) );
210 fix Show_view_text_timer = -1;
212 void draw_window_label()
214 if ( Show_view_text_timer > 0 )
216 char *viewer_name,*control_name;
218 Show_view_text_timer -= FrameTime;
219 gr_set_curfont( GAME_FONT );
222 switch( Viewer->type )
224 case OBJ_FIREBALL: viewer_name = "Fireball"; break;
225 case OBJ_ROBOT: viewer_name = "Robot";
227 viewer_id = Robot_names[Viewer->id];
230 case OBJ_HOSTAGE: viewer_name = "Hostage"; break;
231 case OBJ_PLAYER: viewer_name = "Player"; break;
232 case OBJ_WEAPON: viewer_name = "Weapon"; break;
233 case OBJ_CAMERA: viewer_name = "Camera"; break;
234 case OBJ_POWERUP: viewer_name = "Powerup";
236 viewer_id = Powerup_names[Viewer->id];
239 case OBJ_DEBRIS: viewer_name = "Debris"; break;
240 case OBJ_CNTRLCEN: viewer_name = "Reactor"; break;
241 default: viewer_name = "Unknown"; break;
244 switch ( Viewer->control_type) {
245 case CT_NONE: control_name = "Stopped"; break;
246 case CT_AI: control_name = "AI"; break;
247 case CT_FLYING: control_name = "Flying"; break;
248 case CT_SLEW: control_name = "Slew"; break;
249 case CT_FLYTHROUGH: control_name = "Flythrough"; break;
250 case CT_MORPH: control_name = "Morphing"; break;
251 default: control_name = "Unknown"; break;
254 gr_set_fontcolor( gr_getcolor(31, 0, 0), -1 );
255 gr_printf( 0x8000, 45, "%i: %s [%s] View - %s",Viewer-Objects, viewer_name, viewer_id, control_name );
261 extern int Game_window_x;
262 extern int Game_window_y;
263 extern int Game_window_w;
264 extern int Game_window_h;
265 extern int max_window_w;
266 extern int max_window_h;
268 void render_countdown_gauge()
270 if (!Endlevel_sequence && Control_center_destroyed && (Countdown_seconds_left>-1)) { // && (Countdown_seconds_left<127)) {
273 #if !defined(D2_OEM) && !defined(SHAREWARE) // no countdown on registered only
274 // On last level, we don't want a countdown.
275 if ((Current_mission_num == 0) && (Current_level_num == Last_level))
277 if (!(Game_mode & GM_MULTI))
279 if (Game_mode & GM_MULTI_ROBOTS)
284 gr_set_curfont( SMALL_FONT );
285 gr_set_fontcolor(gr_getcolor(0,63,0), -1 );
286 y = SMALL_FONT->ft_h*4;
287 if (Cockpit_mode == CM_FULL_SCREEN)
288 y += SMALL_FONT->ft_h*2;
291 y += SMALL_FONT->ft_h*2;
293 //if (!((Cockpit_mode == CM_STATUS_BAR) && (Game_window_y >= 19)))
295 gr_printf(0x8000, y, "T-%d s", Countdown_seconds_left );
299 void game_draw_hud_stuff()
302 int odisplay_mode = Current_display_mode;
303 if (Scanline_double) {
305 Current_display_mode = 0;
310 //mprintf ((0,"Linear is %d!\n",LinearSVGABuffer));
314 gr_set_curfont( MEDIUM1_FONT );
315 gr_set_fontcolor( gr_getcolor(31, 31, 31), -1 ); // gr_getcolor(31,0,0));
316 gr_ustring( 0x8000, 85/2, "Debug Pause - Press P to exit" );
325 game_draw_multi_message();
328 game_draw_marker_message();
330 // if (Game_mode & GM_MULTI)
332 // if (Netgame.PlayTimeAllowed)
333 // game_draw_time_left ();
336 if ((Newdemo_state == ND_STATE_PLAYBACK) || (Newdemo_state == ND_STATE_RECORDING)) {
340 if (Newdemo_state == ND_STATE_PLAYBACK) {
341 if (Newdemo_vcr_state != ND_STATE_PRINTSCREEN) {
342 sprintf(message, "%s (%d%%%% %s)", TXT_DEMO_PLAYBACK, newdemo_get_percent_done(), TXT_DONE);
344 sprintf (message, " ");
347 sprintf (message, TXT_DEMO_RECORDING);
349 gr_set_curfont( GAME_FONT ); //GAME_FONT );
350 gr_set_fontcolor(gr_getcolor(27,0,0), -1 );
352 gr_get_string_size(message, &w, &h, &aw );
354 if (Scanline_double) // double height if scanline doubling since we have the correct
355 h += h; // font for printing, but the wrong height.
357 if (Cockpit_mode == CM_FULL_COCKPIT) {
358 if (grd_curcanv->cv_bitmap.bm_h > 240)
362 } else if ( Cockpit_mode == CM_LETTERBOX )
364 if (Cockpit_mode != CM_REAR_VIEW && !Saving_movie_frames)
365 gr_printf((grd_curcanv->cv_bitmap.bm_w-w)/2, grd_curcanv->cv_bitmap.bm_h - h - 2, message );
368 render_countdown_gauge();
370 if ( Player_num > -1 && Viewer->type==OBJ_PLAYER && Viewer->id==Player_num ) {
372 int y = grd_curcanv->cv_bitmap.bm_h;
374 gr_set_curfont( GAME_FONT );
375 gr_set_fontcolor( gr_getcolor(0, 31, 0), -1 );
376 if (Cruise_speed > 0) {
377 int line_spacing = GAME_FONT->ft_h + GAME_FONT->ft_h/4;
379 mprintf((0,"line_spacing=%d ",line_spacing));
381 if (Cockpit_mode==CM_FULL_SCREEN) {
382 if (Game_mode & GM_MULTI)
383 y -= line_spacing * 11; //64
385 y -= line_spacing * 6; //32
386 } else if (Cockpit_mode == CM_STATUS_BAR) {
387 if (Game_mode & GM_MULTI)
388 y -= line_spacing * 8; //48
390 y -= line_spacing * 4; //24
392 y = line_spacing * 2; //12
396 gr_printf( x, y, "%s %2d%%", TXT_CRUISE, f2i(Cruise_speed) );
400 if (r_framerate.value)
403 if ( (Newdemo_state == ND_STATE_PLAYBACK) )
404 Game_mode = Newdemo_game_mode;
408 if ( (Newdemo_state == ND_STATE_PLAYBACK) )
409 Game_mode = GM_NORMAL;
411 if ( Player_is_dead )
412 player_dead_message();
415 if (Scanline_double) {
417 Current_display_mode = odisplay_mode;
422 extern int gr_bitblt_dest_step_shift;
423 extern int gr_wait_for_retrace;
424 extern int gr_bitblt_double;
426 #if !defined MACINTOSH && !defined __ENV_LINUX__ && !defined __ENV_DJGPP__
427 void expand_row(ubyte * dest, ubyte * src, int num_src_pixels );
428 #pragma aux expand_row parm [edi] [esi] [ecx] modify exact [ecx esi edi eax ebx] = \
446 void expand_row(ubyte * dest, ubyte * src, int num_src_pixels )
450 for (i = 0; i < num_src_pixels; i++) {
457 // doubles the size in x or y of a bitmap in place.
458 void game_expand_bitmap( grs_bitmap * bmp, uint flags )
461 ubyte * dptr, * sptr;
465 Assert( bmp->bm_rowsize == bmp->bm_w*2 );
466 dptr = &bmp->bm_data[(bmp->bm_h-1)*bmp->bm_rowsize];
467 for (i=bmp->bm_h-1; i>=0; i-- ) {
468 expand_row( dptr, dptr, bmp->bm_w );
469 dptr -= bmp->bm_rowsize;
474 dptr = &bmp->bm_data[(2*(bmp->bm_h-1)+1)*bmp->bm_rowsize];
475 sptr = &bmp->bm_data[(bmp->bm_h-1)*bmp->bm_rowsize];
476 for (i=bmp->bm_h-1; i>=0; i-- ) {
477 memcpy( dptr, sptr, bmp->bm_w );
478 dptr -= bmp->bm_rowsize;
479 memcpy( dptr, sptr, bmp->bm_w );
480 dptr -= bmp->bm_rowsize;
481 sptr -= bmp->bm_rowsize;
485 case 3: // expand x & y
486 Assert( bmp->bm_rowsize == bmp->bm_w*2 );
487 dptr = &bmp->bm_data[(2*(bmp->bm_h-1)+1)*bmp->bm_rowsize];
488 sptr = &bmp->bm_data[(bmp->bm_h-1)*bmp->bm_rowsize];
489 for (i=bmp->bm_h-1; i>=0; i-- ) {
490 expand_row( dptr, sptr, bmp->bm_w );
491 dptr -= bmp->bm_rowsize;
492 expand_row( dptr, sptr, bmp->bm_w );
493 dptr -= bmp->bm_rowsize;
494 sptr -= bmp->bm_rowsize;
502 extern int SW_drawn[2], SW_x[2], SW_y[2], SW_w[2], SW_h[2];
504 extern int Guided_in_big_window;
507 //render a frame for the game in stereo
508 void game_render_frame_stereo()
512 fix actual_eye_width;
513 int actual_eye_offset;
514 grs_canvas RenderCanvas[2];
517 save_aspect = grd_curscreen->sc_aspect;
518 grd_curscreen->sc_aspect *= 2; //Muck with aspect ratio
520 sw = dw = VR_render_buffer[0].cv_bitmap.bm_w;
521 sh = dh = VR_render_buffer[0].cv_bitmap.bm_h;
523 if (VR_low_res & 1) {
525 grd_curscreen->sc_aspect *= 2; //Muck with aspect ratio
527 if (VR_low_res & 2) {
529 grd_curscreen->sc_aspect /= 2; //Muck with aspect ratio
532 gr_init_sub_canvas( &RenderCanvas[0], &VR_render_buffer[0], 0, 0, sw, sh );
533 gr_init_sub_canvas( &RenderCanvas[1], &VR_render_buffer[1], 0, 0, sw, sh );
535 // Draw the left eye's view
537 actual_eye_width = -VR_eye_width;
538 actual_eye_offset = -VR_eye_offset;
540 actual_eye_width = VR_eye_width;
541 actual_eye_offset = VR_eye_offset;
544 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)
545 actual_eye_offset = 0;
547 gr_set_current_canvas(&RenderCanvas[0]);
549 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) {
550 char *msg = "Guided Missile View";
551 object *viewer_save = Viewer;
554 Viewer = Guided_missile[Player_num];
556 WIN(DDGRLOCK(dd_grd_curcanv)); // Must lock DD canvas!!!
562 update_rendered_data(0, Viewer, 0, 0);
564 #if defined(POLY_ACC) && !defined(MACINTOSH) // dma stuff not support on mac via RAVE
568 wake_up_rendered_objects(Viewer, 0);
569 Viewer = viewer_save;
571 gr_set_curfont( GAME_FONT ); //GAME_FONT );
572 gr_set_fontcolor(gr_getcolor(27,0,0), -1 );
573 gr_get_string_size(msg, &w, &h, &aw );
575 gr_printf((grd_curcanv->cv_bitmap.bm_w-w)/2, 3, msg );
577 draw_guided_crosshair();
579 WIN(DDGRUNLOCK(dd_grd_curcanv));
581 HUD_render_message_frame();
590 render_frame(actual_eye_width, 0); // switch eye positions for rear view
592 render_frame(-actual_eye_width, 0); // Left eye
595 game_expand_bitmap( &RenderCanvas[0].cv_bitmap, VR_low_res );
597 { //render small window into left eye's canvas
598 grs_canvas *save=grd_curcanv;
599 fix save_aspect2 = grd_curscreen->sc_aspect;
600 grd_curscreen->sc_aspect = save_aspect*2;
601 SW_drawn[0] = SW_drawn[1] = 0;
603 gr_set_current_canvas(save);
604 grd_curscreen->sc_aspect = save_aspect2;
608 if (actual_eye_offset > 0 ) {
609 gr_setcolor( gr_getcolor(0,0,0) );
610 gr_rect( grd_curcanv->cv_bitmap.bm_w-labs(actual_eye_offset)*2, 0,
611 grd_curcanv->cv_bitmap.bm_w-1, grd_curcanv->cv_bitmap.bm_h );
612 } else if (actual_eye_offset < 0 ) {
613 gr_setcolor( gr_getcolor(0,0,0) );
614 gr_rect( 0, 0, labs(actual_eye_offset)*2-1, grd_curcanv->cv_bitmap.bm_h );
617 if ( VR_show_hud && !no_draw_hud ) {
619 if (actual_eye_offset < 0 ) {
620 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 );
622 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 );
624 gr_set_current_canvas( &tmp );
625 game_draw_hud_stuff();
629 // Draw the right eye's view
630 gr_set_current_canvas(&RenderCanvas[1]);
632 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)
633 gr_bitmap(0,0,&RenderCanvas[0].cv_bitmap);
636 render_frame(-actual_eye_width, 0); // switch eye positions for rear view
638 render_frame(actual_eye_width, 0); // Right eye
641 game_expand_bitmap( &RenderCanvas[1].cv_bitmap, VR_low_res );
645 { //copy small window from left eye
650 gr_init_sub_canvas(&temp,&RenderCanvas[0],SW_x[w],SW_y[w],SW_w[w],SW_h[w]);
651 gr_bitmap(SW_x[w]+actual_eye_offset*2,SW_y[w],&temp.cv_bitmap);
657 if (actual_eye_offset>0) {
658 gr_setcolor( gr_getcolor(0,0,0) );
659 gr_rect( 0, 0, labs(actual_eye_offset)*2-1, grd_curcanv->cv_bitmap.bm_h );
660 } else if ( actual_eye_offset < 0 ) {
661 gr_setcolor( gr_getcolor(0,0,0) );
662 gr_rect( grd_curcanv->cv_bitmap.bm_w-labs(actual_eye_offset)*2, 0,
663 grd_curcanv->cv_bitmap.bm_w-1, grd_curcanv->cv_bitmap.bm_h );
666 //NEWVR (Add the next 2 lines)
667 if ( VR_show_hud && !no_draw_hud ) {
669 if (actual_eye_offset > 0 ) {
670 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 );
672 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 );
674 gr_set_current_canvas( &tmp );
675 game_draw_hud_stuff();
679 // Draws white and black registration encoding lines
680 // and Accounts for pixel-shift adjustment in upcoming bitblts
681 if (VR_use_reg_code) {
682 int width, height, quarter;
684 width = RenderCanvas[0].cv_bitmap.bm_w;
685 height = RenderCanvas[0].cv_bitmap.bm_h;
688 // black out left-hand side of left page
690 // draw registration code for left eye
692 gr_set_current_canvas( &RenderCanvas[1] );
694 gr_set_current_canvas( &RenderCanvas[0] );
695 gr_setcolor( VR_WHITE_INDEX );
696 gr_scanline( 0, quarter, height-1 );
697 gr_setcolor( VR_BLACK_INDEX );
698 gr_scanline( quarter, width-1, height-1 );
701 gr_set_current_canvas( &RenderCanvas[0] );
703 gr_set_current_canvas( &RenderCanvas[1] );
704 gr_setcolor( VR_WHITE_INDEX );
705 gr_scanline( 0, quarter*3, height-1 );
706 gr_setcolor( VR_BLACK_INDEX );
707 gr_scanline( quarter*3, width-1, height-1 );
710 // Copy left eye, then right eye
711 if ( VR_screen_flags&VRF_USE_PAGING )
712 VR_current_page = !VR_current_page;
715 gr_set_current_canvas( &VR_screen_pages[VR_current_page] );
719 if ( VR_eye_offset_changed > 0 ) {
720 VR_eye_offset_changed--;
724 sw = dw = VR_render_buffer[0].cv_bitmap.bm_w;
725 sh = dh = VR_render_buffer[0].cv_bitmap.bm_h;
727 // Copy left eye, then right eye
728 gr_bitblt_dest_step_shift = 1; // Skip every other scanline.
730 if (VR_render_mode == VR_INTERLACED ) {
731 if ( actual_eye_offset > 0 ) {
732 int xoff = labs(actual_eye_offset);
733 gr_bm_ubitblt( dw-xoff, dh, xoff, 0, 0, 0, &RenderCanvas[0].cv_bitmap, &VR_screen_pages[VR_current_page].cv_bitmap);
734 gr_bm_ubitblt( dw-xoff, dh, 0, 1, xoff, 0, &RenderCanvas[1].cv_bitmap, &VR_screen_pages[VR_current_page].cv_bitmap);
735 } else if ( actual_eye_offset < 0 ) {
736 int xoff = labs(actual_eye_offset);
737 gr_bm_ubitblt( dw-xoff, dh, 0, 0, xoff, 0, &RenderCanvas[0].cv_bitmap, &VR_screen_pages[VR_current_page].cv_bitmap);
738 gr_bm_ubitblt( dw-xoff, dh, xoff, 1, 0, 0, &RenderCanvas[1].cv_bitmap, &VR_screen_pages[VR_current_page].cv_bitmap);
740 gr_bm_ubitblt( dw, dh, 0, 0, 0, 0, &RenderCanvas[0].cv_bitmap, &VR_screen_pages[VR_current_page].cv_bitmap);
741 gr_bm_ubitblt( dw, dh, 0, 1, 0, 0, &RenderCanvas[1].cv_bitmap, &VR_screen_pages[VR_current_page].cv_bitmap);
743 } else if (VR_render_mode == VR_AREA_DET) {
745 gr_bm_ubitblt( dw, dh, 0, VR_current_page, 0, 0, &RenderCanvas[0].cv_bitmap, &VR_screen_pages[0].cv_bitmap);
746 gr_bm_ubitblt( dw, dh, dw, VR_current_page, 0, 0, &RenderCanvas[1].cv_bitmap, &VR_screen_pages[0].cv_bitmap);
751 gr_bitblt_dest_step_shift = 0;
753 //if ( Game_vfx_flag )
754 // vfx_set_page(VR_current_page); // 0 or 1
756 if ( VR_screen_flags&VRF_USE_PAGING ) {
757 gr_wait_for_retrace = 0;
759 // Added by Samir from John's code
760 if ( (VR_screen_pages[VR_current_page].cv_bitmap.bm_type == BM_MODEX) && (Game_3dmax_flag==3) ) {
761 int old_x, old_y, new_x;
762 old_x = VR_screen_pages[VR_current_page].cv_bitmap.bm_x;
763 old_y = VR_screen_pages[VR_current_page].cv_bitmap.bm_y;
764 new_x = old_y*VR_screen_pages[VR_current_page].cv_bitmap.bm_rowsize;
766 VR_screen_pages[VR_current_page].cv_bitmap.bm_x = new_x;
767 VR_screen_pages[VR_current_page].cv_bitmap.bm_y = 0;
768 VR_screen_pages[VR_current_page].cv_bitmap.bm_type = BM_SVGA;
769 gr_show_canvas( &VR_screen_pages[VR_current_page] );
770 VR_screen_pages[VR_current_page].cv_bitmap.bm_type = BM_MODEX;
771 VR_screen_pages[VR_current_page].cv_bitmap.bm_x = old_x;
772 VR_screen_pages[VR_current_page].cv_bitmap.bm_y = old_y;
774 gr_show_canvas( &VR_screen_pages[VR_current_page] );
776 gr_wait_for_retrace = 1;
778 grd_curscreen->sc_aspect=save_aspect;
781 ubyte RenderingType=0;
782 ubyte DemoDoingRight=0,DemoDoingLeft=0;
783 extern ubyte DemoDoRight,DemoDoLeft;
784 extern object DemoRightExtra,DemoLeftExtra;
786 char DemoWBUType[]={0,WBU_MISSILE,WBU_MISSILE,WBU_REAR,WBU_ESCORT,WBU_MARKER,WBU_MISSILE};
787 char DemoRearCheck[]={0,0,0,1,0,0,0};
788 char *DemoExtraMessage[]={"PLAYER","GUIDED","MISSILE","REAR","GUIDE-BOT","MARKER","SHIP"};
790 extern char guidebot_name[];
792 void show_extra_views()
794 int did_missile_view=0;
795 int save_newdemo_state = Newdemo_state;
798 if (Newdemo_state==ND_STATE_PLAYBACK)
802 DemoDoingLeft=DemoDoLeft;
805 do_cockpit_window_view(0,ConsoleObject,1,WBU_REAR,"REAR");
807 do_cockpit_window_view(0,&DemoLeftExtra,DemoRearCheck[DemoDoLeft],DemoWBUType[DemoDoLeft],DemoExtraMessage[DemoDoLeft]);
810 do_cockpit_window_view(0,NULL,0,WBU_WEAPON,NULL);
814 DemoDoingRight=DemoDoRight;
817 do_cockpit_window_view(1,ConsoleObject,1,WBU_REAR,"REAR");
819 do_cockpit_window_view(1,&DemoRightExtra,DemoRearCheck[DemoDoRight],DemoWBUType[DemoDoRight],DemoExtraMessage[DemoDoRight]);
822 do_cockpit_window_view(1,NULL,0,WBU_WEAPON,NULL);
824 DemoDoLeft=DemoDoRight=0;
825 DemoDoingLeft=DemoDoingRight=0;
830 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]) {
831 if (Guided_in_big_window)
833 RenderingType=6+(1<<4);
834 do_cockpit_window_view(1,Viewer,0,WBU_MISSILE,"SHIP");
838 RenderingType=1+(1<<4);
839 do_cockpit_window_view(1,Guided_missile[Player_num],0,WBU_GUIDED,"GUIDED");
846 if (Guided_missile[Player_num]) { //used to be active
847 if (!Guided_in_big_window)
848 do_cockpit_window_view(1,NULL,0,WBU_STATIC,NULL);
849 Guided_missile[Player_num] = NULL;
852 if (Missile_viewer) { //do missile view
853 static int mv_sig=-1;
855 mv_sig = Missile_viewer->signature;
856 if (Missile_view_enabled && Missile_viewer->type!=OBJ_NONE && Missile_viewer->signature == mv_sig) {
857 RenderingType=2+(1<<4);
858 do_cockpit_window_view(1,Missile_viewer,0,WBU_MISSILE,"MISSILE");
862 Missile_viewer = NULL;
865 do_cockpit_window_view(1,NULL,0,WBU_STATIC,NULL);
872 if (w==1 && did_missile_view)
873 continue; //if showing missile view in right window, can't show anything else
875 //show special views if selected
876 switch (Cockpit_3d_view[w]) {
879 do_cockpit_window_view(w,NULL,0,WBU_WEAPON,NULL);
882 if (Rear_view) { //if big window is rear view, show front here
883 RenderingType=3+(w<<4);
884 do_cockpit_window_view(w,ConsoleObject,0,WBU_REAR,"FRONT");
886 else { //show normal rear view
887 RenderingType=3+(w<<4);
888 do_cockpit_window_view(w,ConsoleObject,1,WBU_REAR,"REAR");
893 buddy = find_escort();
895 do_cockpit_window_view(w,NULL,0,WBU_WEAPON,NULL);
896 Cockpit_3d_view[w] = CV_NONE;
899 RenderingType=4+(w<<4);
900 do_cockpit_window_view(w,buddy,0,WBU_ESCORT,guidebot_name);
906 int player = Coop_view_player[w];
908 RenderingType=255; // don't handle coop stuff
910 if (player!=-1 && Players[player].connected && ((Game_mode & GM_MULTI_COOP) || ((Game_mode & GM_TEAM) && (get_team(player) == get_team(Player_num)))))
911 do_cockpit_window_view(w,&Objects[Players[Coop_view_player[w]].objnum],0,WBU_COOP,Players[Coop_view_player[w]].callsign);
913 do_cockpit_window_view(w,NULL,0,WBU_WEAPON,NULL);
914 Cockpit_3d_view[w] = CV_NONE;
921 RenderingType=5+(w<<4);
922 if (Marker_viewer_num[w] == -1 || MarkerObject[Marker_viewer_num[w]] == -1) {
923 Cockpit_3d_view[w] = CV_NONE;
926 sprintf(label,"Marker %d",Marker_viewer_num[w]+1);
927 do_cockpit_window_view(w,&Objects[MarkerObject[Marker_viewer_num[w]]],0,WBU_MARKER,label);
931 Int3(); //invalid window type
935 Newdemo_state = save_newdemo_state;
938 int BigWindowSwitch=0;
939 extern int force_cockpit_redraw;
941 extern ubyte * Game_cockpit_copy_code;
943 extern ubyte Game_cockpit_copy_code;
946 void draw_guided_crosshair(void);
949 // special code to render a frame w/hw acceleration
951 // next routine is called as a callback from the current hardware engine being used. The
952 // routine is called once all of the accelerated drawing is done. We now overlay the
953 // backbuffer with hud stuff.
955 void pa_mac_render_extras( void )
957 grs_canvas Screen_3d_window;
959 gr_init_sub_canvas( &Screen_3d_window, &VR_screen_pages[0],
960 VR_render_sub_buffer[0].cv_bitmap.bm_x,
961 VR_render_sub_buffer[0].cv_bitmap.bm_y,
962 VR_render_sub_buffer[0].cv_bitmap.bm_w,
963 VR_render_sub_buffer[0].cv_bitmap.bm_h);
965 gr_set_current_canvas( &Screen_3d_window ); // set to current screen
967 if (Guided_missile[Player_num] &&
968 Guided_missile[Player_num]->type==OBJ_WEAPON &&
969 Guided_missile[Player_num]->id==GUIDEDMISS_ID &&
970 Guided_missile[Player_num]->signature==Guided_missile_sig[Player_num] &&
971 Guided_in_big_window)
973 char *msg = "Guided Missile View";
976 gr_set_curfont( GAME_FONT ); //GAME_FONT );
977 gr_set_fontcolor(gr_getcolor(27,0,0), -1 );
978 gr_get_string_size(msg, &w, &h, &aw );
980 gr_printf((grd_curcanv->cv_bitmap.bm_w-w)/2, 3, msg );
982 draw_guided_crosshair();
984 HUD_render_message_frame();
988 game_draw_hud_stuff(); // draw hud stuff when not doing missle view in big window
991 if (Game_paused) { //render pause message over off-screen 3d (to minimize flicker)
992 extern char *Pause_msg;
993 ubyte *save_data = VR_screen_pages[VR_current_page].cv_bitmap.bm_data;
995 WIN(Int3()); // Not supported yet.
996 VR_screen_pages[VR_current_page].cv_bitmap.bm_data=VR_render_buffer[VR_current_page].cv_bitmap.bm_data;
997 show_boxed_message(Pause_msg);
998 VR_screen_pages[VR_current_page].cv_bitmap.bm_data=save_data;
1004 void pa_mac_game_render_frame( void )
1006 Assert ( !Scanline_double );
1007 Assert ( PAEnabled );
1009 gr_set_current_canvas(&VR_render_sub_buffer[0]); // set up the right canvas so rendering is done to correct size
1013 if (Guided_missile[Player_num] &&
1014 Guided_missile[Player_num]->type==OBJ_WEAPON &&
1015 Guided_missile[Player_num]->id==GUIDEDMISS_ID &&
1016 Guided_missile[Player_num]->signature==Guided_missile_sig[Player_num] &&
1017 Guided_in_big_window)
1019 char *msg = "Guided Missile View";
1020 object *viewer_save = Viewer;
1023 if (Cockpit_mode==CM_FULL_COCKPIT) {
1025 force_cockpit_redraw=1;
1026 Cockpit_mode=CM_STATUS_BAR;
1031 Viewer = Guided_missile[Player_num];
1032 update_rendered_data(0, Viewer, 0, 0);
1034 wake_up_rendered_objects(Viewer, 0);
1035 Viewer = viewer_save;
1039 if (BigWindowSwitch)
1041 force_cockpit_redraw=1;
1042 Cockpit_mode=CM_FULL_COCKPIT;
1048 update_rendered_data(0, Viewer, Rear_view, 0);
1052 if (Cockpit_mode == CM_FULL_SCREEN)
1060 // NOTE: Hud stuff is drawn using a RAVE call back which draws onto the back buffer
1061 // after rendering finishes but before the page flip
1063 if (Cockpit_mode != CM_FULL_SCREEN)
1065 show_extra_views(); //missile view, buddy bot, etc.
1068 // Draw Gauges straight to screen
1069 if (Cockpit_mode==CM_FULL_COCKPIT || Cockpit_mode==CM_STATUS_BAR)
1072 if ( (Newdemo_state == ND_STATE_PLAYBACK) )
1074 Game_mode = Newdemo_game_mode;
1077 Current_display_mode = 1;
1079 Current_display_mode = -1;
1081 if ( (Newdemo_state == ND_STATE_PLAYBACK) )
1083 Game_mode = GM_NORMAL;
1090 //render a frame for the game
1092 // will render everything to dd_VR_render_sub_buffer
1093 // which all leads to the dd_VR_offscreen_buffer
1094 void game_render_frame_mono(void)
1097 dd_grs_canvas Screen_3d_window,
1098 grs_canvas Screen_3d_window
1102 #if defined(MACINTOSH)
1104 pa_mac_game_render_frame();
1111 dd_gr_init_sub_canvas(&Screen_3d_window, &dd_VR_screen_pages[0],
1112 dd_VR_render_sub_buffer[0].canvas.cv_bitmap.bm_x,
1113 dd_VR_render_sub_buffer[0].canvas.cv_bitmap.bm_y,
1114 dd_VR_render_sub_buffer[0].canvas.cv_bitmap.bm_w,
1115 dd_VR_render_sub_buffer[0].canvas.cv_bitmap.bm_h),
1116 gr_init_sub_canvas( &Screen_3d_window, &VR_screen_pages[0],
1117 VR_render_sub_buffer[0].cv_bitmap.bm_x,
1118 VR_render_sub_buffer[0].cv_bitmap.bm_y,
1119 VR_render_sub_buffer[0].cv_bitmap.bm_w,
1120 VR_render_sub_buffer[0].cv_bitmap.bm_h)
1123 if ( Game_double_buffer ) {
1125 dd_gr_set_current_canvas(&dd_VR_render_sub_buffer[0]),
1126 gr_set_current_canvas(&VR_render_sub_buffer[0])
1131 dd_gr_set_current_canvas(&Screen_3d_window),
1132 gr_set_current_canvas(&Screen_3d_window)
1136 #if defined(POLY_ACC) && !defined(MACINTOSH) // begin s3 relocation of cockpit drawing.
1140 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)
1144 WIN(DDGRLOCK(dd_grd_curcanv));
1145 game_draw_hud_stuff();
1146 WIN(DDGRUNLOCK(dd_grd_curcanv));
1149 show_extra_views(); //missile view, buddy bot, etc.
1152 if (Game_paused) { //render pause message over off-screen 3d (to minimize flicker)
1153 extern char *Pause_msg;
1154 ubyte *save_data = VR_screen_pages[VR_current_page].cv_bitmap.bm_data;
1156 WIN(Int3()); // Not supported yet.
1157 VR_screen_pages[VR_current_page].cv_bitmap.bm_data=VR_render_buffer[VR_current_page].cv_bitmap.bm_data;
1158 show_boxed_message(Pause_msg);
1159 VR_screen_pages[VR_current_page].cv_bitmap.bm_data=save_data;
1162 if ( Game_double_buffer ) { //copy to visible screen
1163 if ( !Game_cockpit_copy_code ) {
1164 if ( VR_screen_flags&VRF_USE_PAGING ) {
1165 VR_current_page = !VR_current_page;
1166 gr_set_current_canvas( &VR_screen_pages[VR_current_page] );
1167 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 );
1168 gr_wait_for_retrace = 0;
1169 gr_show_canvas( &VR_screen_pages[VR_current_page] );
1170 gr_wait_for_retrace = 1;
1172 #ifdef POLY_ACC //$$
1176 VR_render_sub_buffer[0].cv_w, VR_render_sub_buffer[0].cv_h,
1177 VR_render_sub_buffer[0].cv_bitmap.bm_x, VR_render_sub_buffer[0].cv_bitmap.bm_y,
1178 VR_render_sub_buffer[0].cv_bitmap.bm_x, VR_render_sub_buffer[0].cv_bitmap.bm_y,
1179 &VR_render_sub_buffer[0].cv_bitmap, &VR_screen_pages[0].cv_bitmap
1183 #ifdef POLY_ACC //$$
1186 gr_ibitblt( &VR_render_buffer[0].cv_bitmap, &VR_screen_pages[0].cv_bitmap, Game_cockpit_copy_code );
1190 if (Cockpit_mode==CM_FULL_COCKPIT || Cockpit_mode==CM_STATUS_BAR) {
1192 if ( (Newdemo_state == ND_STATE_PLAYBACK) )
1193 Game_mode = Newdemo_game_mode;
1197 if ( (Newdemo_state == ND_STATE_PLAYBACK) )
1198 Game_mode = GM_NORMAL;
1201 // restore current canvas.
1202 if ( Game_double_buffer ) {
1204 dd_gr_set_current_canvas(&dd_VR_render_sub_buffer[0]),
1205 gr_set_current_canvas(&VR_render_sub_buffer[0])
1210 dd_gr_set_current_canvas(&Screen_3d_window),
1211 gr_set_current_canvas(&Screen_3d_window)
1215 #endif // end s3 relocation of cockpit drawing.
1217 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) {
1218 char *msg = "Guided Missile View";
1219 object *viewer_save = Viewer;
1222 if (Cockpit_mode==CM_FULL_COCKPIT)
1225 force_cockpit_redraw=1;
1226 Cockpit_mode=CM_STATUS_BAR;
1230 Viewer = Guided_missile[Player_num];
1232 WIN(DDGRLOCK(dd_grd_curcanv)); // Must lock DD canvas!!!
1235 if (Scanline_double)
1238 update_rendered_data(0, Viewer, 0, 0);
1241 wake_up_rendered_objects(Viewer, 0);
1242 Viewer = viewer_save;
1244 gr_set_curfont( GAME_FONT ); //GAME_FONT );
1245 gr_set_fontcolor(gr_getcolor(27,0,0), -1 );
1246 gr_get_string_size(msg, &w, &h, &aw );
1248 gr_printf((grd_curcanv->cv_bitmap.bm_w-w)/2, 3, msg );
1250 draw_guided_crosshair();
1252 WIN(DDGRUNLOCK(dd_grd_curcanv));
1254 HUD_render_message_frame();
1256 if (Scanline_double)
1264 if (BigWindowSwitch)
1266 force_cockpit_redraw=1;
1267 Cockpit_mode=CM_FULL_COCKPIT;
1271 WIN(DDGRLOCK(dd_grd_curcanv)); // Must lock DD canvas!!!
1272 update_rendered_data(0, Viewer, Rear_view, 0);
1274 #if defined(POLY_ACC) && !defined(MACINTOSH) // dma stuff not supported on mac via RAVE
1277 WIN(DDGRUNLOCK(dd_grd_curcanv));
1280 if ( Game_double_buffer ) {
1282 dd_gr_set_current_canvas(&dd_VR_render_sub_buffer[0]),
1283 gr_set_current_canvas(&VR_render_sub_buffer[0])
1288 dd_gr_set_current_canvas(&Screen_3d_window),
1289 gr_set_current_canvas(&Screen_3d_window)
1293 #if !defined(POLY_ACC) || defined(MACINTOSH)
1296 WIN(DDGRLOCK(dd_grd_curcanv));
1297 game_draw_hud_stuff();
1298 WIN(DDGRUNLOCK(dd_grd_curcanv));
1301 show_extra_views(); //missile view, buddy bot, etc.
1304 if (Game_paused) { //render pause message over off-screen 3d (to minimize flicker)
1305 extern char *Pause_msg;
1306 // LPDIRECTDRAWSURFACE save_dds = dd_VR_screen_pages[VR_current_page].lpdds;
1308 // dd_VR_screen_pages[VR_current_page].lpdds = dd_VR_render_buffer[VR_current_page].lpdds;
1309 show_boxed_message(Pause_msg);
1310 // dd_VR_screen_pages[VR_current_page].lpdds = save_dds;
1313 if (Game_paused) { //render pause message over off-screen 3d (to minimize flicker)
1314 extern char *Pause_msg;
1315 ubyte *save_data = VR_screen_pages[VR_current_page].cv_bitmap.bm_data;
1317 VR_screen_pages[VR_current_page].cv_bitmap.bm_data=VR_render_buffer[VR_current_page].cv_bitmap.bm_data;
1318 show_boxed_message(Pause_msg);
1319 VR_screen_pages[VR_current_page].cv_bitmap.bm_data=save_data;
1323 if ( Game_double_buffer ) { //copy to visible screen
1324 if ( !Game_cockpit_copy_code ) {
1325 if ( VR_screen_flags&VRF_USE_PAGING ) {
1326 VR_current_page = !VR_current_page;
1328 dd_gr_set_current_canvas(&dd_VR_screen_pages[VR_current_page]);
1331 gr_set_current_canvas( &VR_screen_pages[VR_current_page] );
1332 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 );
1333 gr_wait_for_retrace = 0;
1334 gr_show_canvas( &VR_screen_pages[VR_current_page] );
1335 gr_wait_for_retrace = 1;
1339 if (Scanline_double)
1340 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 );
1342 #endif // NOTE LINK TO ABOVE IF
1344 if (GRMODEINFO(emul) || GRMODEINFO(modex) || GRMODEINFO(dbuf))
1345 // From render buffer to screen buffer.
1346 dd_gr_blt_notrans(&dd_VR_render_sub_buffer[0],
1348 dd_VR_render_sub_buffer[0].canvas.cv_w,
1349 dd_VR_render_sub_buffer[0].canvas.cv_h,
1351 dd_VR_render_sub_buffer[0].xoff,
1352 dd_VR_render_sub_buffer[0].yoff,
1353 dd_VR_render_sub_buffer[0].canvas.cv_w,
1354 dd_VR_render_sub_buffer[0].canvas.cv_h);
1357 // Puts back canvas to front canvas by blt or flip
1358 if (GRMODEINFO(modex)) {
1359 //@@VR_current_page = !VR_current_page;
1364 gr_bm_ubitblt( VR_render_sub_buffer[0].cv_w,
1365 VR_render_sub_buffer[0].cv_h,
1366 VR_render_sub_buffer[0].cv_bitmap.bm_x,
1367 VR_render_sub_buffer[0].cv_bitmap.bm_y,
1369 &VR_render_sub_buffer[0].cv_bitmap,
1370 &VR_screen_pages[0].cv_bitmap );
1382 #if 1 //def MACINTOSH
1383 gr_ibitblt( &VR_render_sub_buffer[0].cv_bitmap, &VR_screen_pages[0].cv_bitmap, Scanline_double );
1386 gr_ibitblt( &VR_render_buffer[0].cv_bitmap, &VR_screen_pages[0].cv_bitmap, Game_cockpit_copy_code );
1388 win_do_emul_ibitblt( &dd_VR_render_sub_buffer[0], dd_grd_screencanv);
1390 if (GRMODEINFO(modex)) {
1391 //@@VR_current_page = !VR_current_page;
1400 if (Cockpit_mode==CM_FULL_COCKPIT || Cockpit_mode==CM_STATUS_BAR) {
1402 if ( (Newdemo_state == ND_STATE_PLAYBACK) )
1403 Game_mode = Newdemo_game_mode;
1407 if ( (Newdemo_state == ND_STATE_PLAYBACK) )
1408 Game_mode = GM_NORMAL;
1413 VR_current_page = !VR_current_page;
1423 void toggle_cockpit()
1427 switch (Cockpit_mode) {
1429 case CM_FULL_COCKPIT: {
1430 int max_h = grd_curscreen->sc_h - GameBitmaps[cockpit_bitmap[CM_STATUS_BAR+(Current_display_mode?(Num_cockpits/2):0)].index].bm_h;
1431 if (Game_window_h > max_h) //too big for statusbar
1432 new_mode = CM_FULL_SCREEN;
1434 new_mode = CM_STATUS_BAR;
1439 case CM_FULL_SCREEN:
1442 new_mode = CM_FULL_COCKPIT;
1448 return; //do nothing
1453 select_cockpit(new_mode);
1454 HUD_clear_messages();
1455 write_player_file();
1459 #define WINDOW_W_DELTA ((max_window_w / 16)&~1) //24 //20
1460 #define WINDOW_H_DELTA ((max_window_h / 16)&~1) //12 //10
1462 #define WINDOW_MIN_W ((max_window_w * 10) / 22) //160
1463 #define WINDOW_MIN_H ((max_window_h * 10) / 22)
1465 //#define WINDOW_W_DELTA 32
1466 //#define WINDOW_H_DELTA 16
1468 #define WINDOW_W_DELTA ((max_window_w / 16) & ~15) // double word aligned
1469 #define WINDOW_H_DELTA ((max_window_h / 16) & ~15) // double word aligned
1471 #define WINDOW_MIN_W (max_window_w-(WINDOW_W_DELTA*11))
1472 #define WINDOW_MIN_H (max_window_h-(WINDOW_H_DELTA*11))
1477 if (Cockpit_mode == CM_FULL_COCKPIT) {
1478 Game_window_h = max_window_h;
1479 Game_window_w = max_window_w;
1481 HUD_init_message("Press F3 to return to Cockpit mode");
1485 if (Cockpit_mode != CM_STATUS_BAR && (VR_screen_flags & VRF_ALLOW_COCKPIT))
1488 if (Game_window_h>=max_window_h || Game_window_w>=max_window_w) {
1489 //Game_window_w = max_window_w;
1490 //Game_window_h = max_window_h;
1491 select_cockpit(CM_FULL_SCREEN);
1495 Game_window_w += WINDOW_W_DELTA;
1496 Game_window_h += WINDOW_H_DELTA;
1498 #ifdef MACINTOSH // horrible hack to ensure that height is even to satisfy pixel doubling blitter
1499 if ( Scanline_double && (Game_window_h & 1) )
1503 if (Game_window_h > max_window_h)
1504 Game_window_h = max_window_h;
1506 if (Game_window_w > max_window_w)
1507 Game_window_w = max_window_w;
1509 Game_window_x = (max_window_w - Game_window_w)/2;
1510 Game_window_y = (max_window_h - Game_window_h)/2;
1512 game_init_render_sub_buffers( Game_window_x, Game_window_y, Game_window_w, Game_window_h );
1515 HUD_clear_messages(); // @mk, 11/11/94
1517 write_player_file();
1520 // grs_bitmap background_bitmap; already declared in line 434 (samir 4/10/94)
1522 extern grs_bitmap background_bitmap;
1524 void copy_background_rect(int left,int top,int right,int bot)
1526 grs_bitmap *bm = &background_bitmap;
1528 int tile_left,tile_right,tile_top,tile_bot;
1532 if (right < left || bot < top)
1535 tile_left = left / bm->bm_w;
1536 tile_right = right / bm->bm_w;
1537 tile_top = top / bm->bm_h;
1538 tile_bot = bot / bm->bm_h;
1540 ofs_y = top % bm->bm_h;
1543 WIN(DDGRLOCK(dd_grd_curcanv))
1545 for (y=tile_top;y<=tile_bot;y++) {
1548 ofs_x = left % bm->bm_w;
1551 //h = (bot < dest_y+bm->bm_h)?(bot-dest_y+1):(bm->bm_h-ofs_y);
1552 h = min(bot-dest_y+1,bm->bm_h-ofs_y);
1554 for (x=tile_left;x<=tile_right;x++) {
1556 //w = (right < dest_x+bm->bm_w)?(right-dest_x+1):(bm->bm_w-ofs_x);
1557 w = min(right-dest_x+1,bm->bm_w-ofs_x);
1559 gr_bm_ubitblt(w,h,dest_x,dest_y,ofs_x,ofs_y,
1560 &background_bitmap,&grd_curcanv->cv_bitmap);
1570 WIN(DDGRUNLOCK(dd_grd_curcanv));
1575 int force_background_fill=0;
1578 //fills int the background surrounding the 3d window
1579 void fill_background()
1591 WINDOS( dd_gr_set_current_canvas(&dd_VR_screen_pages[VR_current_page]),
1592 gr_set_current_canvas(&VR_screen_pages[VR_current_page])
1594 copy_background_rect(x-dx,y-dy,x-1,y+h+dy-1);
1595 copy_background_rect(x+w,y-dy,grd_curcanv->cv_w-1,y+h+dy-1);
1596 copy_background_rect(x,y-dy,x+w-1,y-1);
1597 copy_background_rect(x,y+h,x+w-1,y+h+dy-1);
1600 if (GRMODEINFO(modex)) {
1601 copy_background_rect(x-dx,y-dy,x-1,y+h+dy-1);
1602 copy_background_rect(x+w,y-dy,grd_curcanv->cv_w-1,y+h+dy-1);
1603 copy_background_rect(x,y-dy,x+w-1,y-1);
1604 copy_background_rect(x,y+h,x+w-1,y+h+dy-1);
1608 if (VR_screen_flags & VRF_USE_PAGING) {
1609 WINDOS( dd_gr_set_current_canvas(&dd_VR_screen_pages[!VR_current_page]),
1610 gr_set_current_canvas(&VR_screen_pages[!VR_current_page])
1612 copy_background_rect(x-dx,y-dy,x-1,y+h+dy-1);
1613 copy_background_rect(x+w,y-dy,x+w+dx-1,y+h+dy-1);
1614 copy_background_rect(x,y-dy,x+w-1,y-1);
1615 copy_background_rect(x,y+h,x+w-1,y+h+dy-1);
1619 if (GRMODEINFO(modex) && force_background_fill==0) //double-buffered
1620 force_background_fill=2;
1624 void shrink_window()
1627 //When you shrink the window twice in two frames, the background doens't
1628 //restore properly. So this hack keeps you from shrinking the window
1629 //before two frames have been drawn
1630 static int last_shrink_framecount=-1;
1631 if (FrameCount - last_shrink_framecount < 2)
1633 last_shrink_framecount = FrameCount;
1636 mprintf((0,"%d ",FrameCount));
1638 // mprintf ((0,"W=%d H=%d\n",Game_window_w,Game_window_h));
1640 if (Cockpit_mode == CM_FULL_COCKPIT && (VR_screen_flags & VRF_ALLOW_COCKPIT)) {
1641 Game_window_h = max_window_h;
1642 Game_window_w = max_window_w;
1643 //!!toggle_cockpit();
1644 select_cockpit(CM_STATUS_BAR);
1647 HUD_init_message("Press F3 to return to Cockpit mode");
1648 write_player_file();
1652 if (Cockpit_mode == CM_FULL_SCREEN && (VR_screen_flags & VRF_ALLOW_COCKPIT))
1654 //Game_window_w = max_window_w;
1655 //Game_window_h = max_window_h;
1656 select_cockpit(CM_STATUS_BAR);
1657 write_player_file();
1661 if (Cockpit_mode != CM_STATUS_BAR && (VR_screen_flags & VRF_ALLOW_COCKPIT))
1664 mprintf ((0,"Cockpit mode=%d\n",Cockpit_mode));
1666 if (Game_window_w > WINDOW_MIN_W) {
1669 Game_window_w -= WINDOW_W_DELTA;
1670 Game_window_h -= WINDOW_H_DELTA;
1673 mprintf ((0,"NewW=%d NewH=%d VW=%d maxH=%d\n",Game_window_w,Game_window_h,max_window_w,max_window_h));
1675 if ( Game_window_w < WINDOW_MIN_W )
1676 Game_window_w = WINDOW_MIN_W;
1678 if ( Game_window_h < WINDOW_MIN_H )
1679 Game_window_h = WINDOW_MIN_H;
1681 #ifdef MACINTOSH // horrible hack to ensure that height is even to satisfy pixel doubling blitter
1682 if ( Scanline_double && (Game_window_h & 1) )
1686 Game_window_x = (max_window_w - Game_window_w)/2;
1687 Game_window_y = (max_window_h - Game_window_h)/2;
1691 game_init_render_sub_buffers( Game_window_x, Game_window_y, Game_window_w, Game_window_h );
1692 HUD_clear_messages();
1693 write_player_file();
1698 int last_drawn_cockpit[2] = { -1, -1 };
1700 // This actually renders the new cockpit onto the screen.
1701 void update_cockpits(int force_redraw)
1705 if (Cockpit_mode != last_drawn_cockpit[VR_current_page] || force_redraw )
1706 last_drawn_cockpit[VR_current_page] = Cockpit_mode;
1710 //Redraw the on-screen cockpit bitmaps
1711 if (VR_render_mode != VR_NONE ) return;
1713 switch( Cockpit_mode ) {
1714 case CM_FULL_COCKPIT:
1717 dd_gr_set_current_canvas(&dd_VR_screen_pages[VR_current_page]),
1718 gr_set_current_canvas(&VR_screen_pages[VR_current_page])
1720 PIGGY_PAGE_IN(cockpit_bitmap[Cockpit_mode+(Current_display_mode?(Num_cockpits/2):0)]);
1722 WIN(DDGRLOCK(dd_grd_curcanv));
1723 gr_ubitmapm(0,0, &GameBitmaps[cockpit_bitmap[Cockpit_mode+(Current_display_mode?(Num_cockpits/2):0)].index]);
1724 WIN(DDGRUNLOCK(dd_grd_curcanv));
1727 case CM_FULL_SCREEN:
1728 Game_window_x = (max_window_w - Game_window_w)/2;
1729 Game_window_y = (max_window_h - Game_window_h)/2;
1735 WINDOS ( dd_gr_set_current_canvas(&dd_VR_screen_pages[VR_current_page]),
1736 gr_set_current_canvas(&VR_screen_pages[VR_current_page])
1739 PIGGY_PAGE_IN(cockpit_bitmap[Cockpit_mode+(Current_display_mode?(Num_cockpits/2):0)]);
1741 WIN(DDGRLOCK(dd_grd_curcanv));
1742 gr_ubitmapm(0,max_window_h,&GameBitmaps[cockpit_bitmap[Cockpit_mode+(Current_display_mode?(Num_cockpits/2):0)].index]);
1743 WIN(DDGRUNLOCK(dd_grd_curcanv));
1745 #ifdef MACINTOSH // hideously horrible hack to put grey line 1 scanline above because of pixel doubling "oddness"
1746 if (Scanline_double)
1748 gr_setcolor(BM_XRGB(13,13,13)); // color of top of status bar
1749 gr_uscanline( 0, grd_curcanv->cv_w, max_window_h-1 );
1753 Game_window_x = (max_window_w - Game_window_w)/2;
1754 Game_window_y = (max_window_h - Game_window_h)/2;
1759 WINDOS( dd_gr_set_current_canvas(&dd_VR_screen_pages[VR_current_page]),
1760 gr_set_current_canvas(&VR_screen_pages[VR_current_page])
1762 WINDOS ( dd_gr_clear_canvas( BM_XRGB(0,0,0) ),
1763 gr_clear_canvas( BM_XRGB(0,0,0) ) );
1765 // In a modex mode, clear the other buffer.
1766 if (grd_curcanv->cv_bitmap.bm_type == BM_MODEX) {
1767 gr_set_current_canvas(&VR_screen_pages[VR_current_page^1]);
1768 gr_clear_canvas( BM_XRGB(0,0,0) );
1769 gr_set_current_canvas(&VR_screen_pages[VR_current_page]);
1775 WINDOS ( dd_gr_set_current_canvas(&dd_VR_screen_pages[VR_current_page]),
1776 gr_set_current_canvas(&VR_screen_pages[VR_current_page])
1779 if (Cockpit_mode==CM_FULL_COCKPIT || Cockpit_mode==CM_STATUS_BAR)
1785 void game_render_frame()
1787 set_screen_mode( SCREEN_GAME );
1792 if (force_background_fill) {
1794 force_background_fill--;
1798 play_homing_warning();
1800 if (VR_render_mode == VR_NONE )
1801 game_render_frame_mono();
1803 game_render_frame_stereo();
1806 // Make sure palette is faded in
1808 gr_palette_fade_in( gr_palette, 32, 0 );
1814 extern int Color_0_31_0;
1816 //draw a crosshair for the guided missile
1817 void draw_guided_crosshair(void)
1821 gr_setcolor(Color_0_31_0);
1823 w = grd_curcanv->cv_w>>5;
1827 h = i2f(w) / grd_curscreen->sc_aspect;
1829 x = grd_curcanv->cv_w / 2;
1830 y = grd_curcanv->cv_h / 2;
1832 gr_scanline(x-w/2,x+w/2,y);
1833 gr_uline(i2f(x),i2f(y-h/2),i2f(x),i2f(y+h/2));
1837 typedef struct bkg {
1838 short x, y, w, h; // The location of the menu.
1839 grs_bitmap * bmp; // The background under the menu.
1842 bkg bg = {0,0,0,0,NULL};
1844 #define BOX_BORDER (MenuHires?60:30)
1846 //show a message in a nice little box
1847 void show_boxed_message(char *msg)
1853 dd_gr_set_current_canvas(&dd_VR_screen_pages[VR_current_page]),
1854 gr_set_current_canvas(&VR_screen_pages[VR_current_page])
1856 gr_set_curfont( MEDIUM1_FONT );
1858 gr_get_string_size(msg,&w,&h,&aw);
1860 x = (grd_curscreen->sc_w-w)/2;
1861 y = (grd_curscreen->sc_h-h)/2;
1864 gr_free_bitmap(bg.bmp);
1868 // Save the background of the display
1869 bg.x=x; bg.y=y; bg.w=w; bg.h=h;
1871 #if defined(POLY_ACC)
1872 bg.bmp = gr_create_bitmap2( w+BOX_BORDER, h+BOX_BORDER, grd_curcanv->cv_bitmap.bm_type, NULL );
1874 bg.bmp = gr_create_bitmap( w+BOX_BORDER, h+BOX_BORDER );
1877 WIN( DDGRLOCK(dd_grd_curcanv));
1878 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 );
1879 WIN( DDGRUNLOCK(dd_grd_curcanv));
1881 nm_draw_background(x-BOX_BORDER/2,y-BOX_BORDER/2,x+w+BOX_BORDER/2-1,y+h+BOX_BORDER/2-1);
1883 gr_set_fontcolor( gr_getcolor(31, 31, 31), -1 );
1885 WIN( DDGRLOCK(dd_grd_curcanv));
1886 gr_ustring( 0x8000, y, msg );
1887 WIN( DDGRUNLOCK(dd_grd_curcanv));
1891 void clear_boxed_message()
1896 WIN(DDGRLOCK(dd_grd_curcanv));
1897 gr_bitmap(bg.x-BOX_BORDER/2, bg.y-BOX_BORDER/2, bg.bmp);
1898 WIN(DDGRUNLOCK(dd_grd_curcanv));
1901 gr_free_bitmap(bg.bmp);
1908 void win_do_emul_ibitblt(dd_grs_canvas *csrc, dd_grs_canvas *cdest)
1915 WIN(DDGRLOCK(csrc));
1916 WIN(DDGRLOCK(cdest));
1917 src_data = csrc->canvas.cv_bitmap.bm_data;
1918 dest_data = cdest->canvas.cv_bitmap.bm_data;
1920 // mprintf((0, "Render Ptr: %x; Dest Ptr: %x;\n",src_data, dest_data));
1922 for (line = 0; line < 480; line++,
1923 dest_data += cdest->canvas.cv_bitmap.bm_rowsize)
1925 cockpit_span_line *sline;
1927 sline = &win_cockpit_mask[line];
1929 if (!sline->num) continue;
1930 if (sline->num == 255) break;
1931 for (span = 0; span < sline->num; span++)
1933 if ((sline->span[span].xmax-sline->span[span].xmin+1) < 10) {
1934 gr_winckpit_blt_span(sline->span[span].xmin,
1935 sline->span[span].xmax,
1936 src_data, dest_data);
1939 gr_winckpit_blt_span_long(sline->span[span].xmin,
1940 sline->span[span].xmax,
1941 src_data, dest_data);
1944 src_data += csrc->canvas.cv_bitmap.bm_rowsize;
1946 WIN(DDGRUNLOCK(cdest));
1947 WIN(DDGRUNLOCK(csrc));
1951 //@@void win_do_emul_ibitblt(dd_grs_canvas *csrc, dd_grs_canvas *cdest)
1955 //@@ RECT srect, drect;
1957 //@@// Do Render Blt to Mask Surface (dest blt 1-255)
1958 //@@ bltfx.dwSize = sizeof(bltfx);
1959 //@@ bltfx.ddckDestColorkey.dwColorSpaceLowValue = 1;
1960 //@@ bltfx.ddckDestColorkey.dwColorSpaceHighValue = 255;
1961 //@@ SetRect(&srect, 0,0, csrc->canvas.cv_w, csrc->canvas.cv_h);
1962 //@@ SetRect(&drect, 0,0, csrc->canvas.cv_w, csrc->canvas.cv_h);
1964 //@@ res = IDirectDrawSurface_Blt(_lpDDSMask, &drect, csrc->lpdds, &srect,
1965 //@@ DDBLT_WAIT | DDBLT_KEYDESTOVERRIDE,
1967 //@@ if (res != DD_OK)
1968 //@@ Error("win_ibitblt: ddraw blt to mask err: %x.\n", res);
1970 //@@// Do Mask Blt to Screen (src blt !0)
1971 //@@ bltfx.dwSize = sizeof(bltfx);
1972 //@@ bltfx.ddckSrcColorkey.dwColorSpaceLowValue = 0;
1973 //@@ bltfx.ddckSrcColorkey.dwColorSpaceHighValue = 0;
1975 //@@ res = IDirectDrawSurface_Blt(cdest->lpdds, &drect, _lpDDSMask, &srect,
1976 //@@ DDBLT_WAIT | DDBLT_KEYSRCOVERRIDE,
1978 //@@ if (res != DD_OK)
1979 //@@ Error("win_ibitblt: ddraw blt to screen err: %x.\n", res);