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.
15 char game_rcsid[] = "$Id: game.c,v 1.5 2001-01-28 05:53:04 bradleyb Exp $";
32 #include <StandardFile.h>
33 #include <Quickdraw.h>
40 #include "pa_enabl.h" //$$POLY_ACC
101 #include "cntrlcen.h"
105 #include "multibot.h"
108 #include "playsave.h"
113 #include "ogl_init.h"
116 int VGA_current_mode;
119 #include <profiler.h>
122 //#define TEST_TIMER 1 //if this is set, do checking on timer
124 #define SHOW_EXIT_PATH 1
127 #include "editor\editor.h"
132 #if __WATCOMC__ < 1000
133 #include <wsample.h> //should come after inferno.h to get mark setting
138 extern void ReadControls(void); // located in gamecntl.c
139 extern int Current_display_mode;
140 extern void do_final_boss_frame(void);
142 int Speedtest_on = 0;
145 int Mark_count = 0; // number of debugging marks set
146 int Speedtest_start_time;
147 int Speedtest_segnum;
148 int Speedtest_sidenum;
149 int Speedtest_frame_start;
150 int Speedtest_count=0; // number of times to do the debug test.
153 static fix last_timer_value=0;
156 #if defined(TIMER_TEST) && !defined(NDEBUG)
157 fix _timer_value,actual_last_timer_value,_last_frametime;
158 int stop_count,start_count;
159 int time_stopped,time_started;
163 ubyte * Game_cockpit_copy_code = NULL;
165 ubyte Game_cockpit_copy_code = 0;
166 ubyte Scanline_double = 1;
169 int VR_screen_mode = 0;
171 ubyte VR_screen_flags = 0; //see values in screens.h
172 ubyte VR_current_page = 0;
173 fix VR_eye_width = F1_0;
174 int VR_render_mode = VR_NONE;
175 int VR_low_res = 3; // Default to low res
177 int VR_sensitivity = 1; // 0 - 2
180 int VR_eye_offset = 0;
181 int VR_eye_switch = 0;
182 int VR_eye_offset_changed = 0;
183 int VR_use_reg_code = 0;
185 grs_canvas *VR_offscreen_buffer = NULL; // The offscreen data buffer
186 grs_canvas VR_render_buffer[2]; // Two offscreen buffers for left/right eyes.
187 grs_canvas VR_render_sub_buffer[2]; // Two sub buffers for left/right eyes.
188 grs_canvas VR_screen_pages[2]; // Two pages of VRAM if paging is available
189 grs_canvas VR_editor_canvas; // The canvas that the editor writes to.
192 //@@ LPDIRECTDRAWSURFACE _lpDDSMask = NULL;
193 dd_grs_canvas *dd_VR_offscreen_buffer = NULL;
194 dd_grs_canvas dd_VR_screen_pages[2];
195 dd_grs_canvas dd_VR_render_buffer[2];
196 dd_grs_canvas dd_VR_render_sub_buffer[2];
198 void game_win_init_cockpit_mask(int sram);
201 //do menus work in 640x480 or 320x200?
202 //PC version sets this in main(). Mac versios is always high-res, so set to 1 here
203 int MenuHiresAvailable = 1; //can we do highres menus?
204 int MenuHires = 1; //are we currently in highres menus?
206 int Debug_pause=0; //John's debugging pause system
208 int Cockpit_mode=CM_FULL_COCKPIT; //set game.h for values
210 int Cockpit_mode_save=-1; //set while in letterbox or rear view, or -1
211 int force_cockpit_redraw=0;
213 cvar_t r_framerate = {"r_framerate","0"};
215 int PaletteRedAdd, PaletteGreenAdd, PaletteBlueAdd;
217 // Toggle_var points at a variable which gets !ed on ctrl-alt-T press.
219 int *Toggle_var = &Dummy_var;
222 //flag for whether initial fade-in has been done
226 #ifndef NDEBUG //these only exist if debugging
228 int Game_double_buffer = 1; //double buffer by default
229 fix fixed_frametime=0; //if non-zero, set frametime to this
233 int Game_suspended=0; //if non-zero, nothing moves but player
236 fix Auto_fire_fusion_cannon_time = 0;
237 fix Fusion_charge = 0;
238 fix Fusion_next_sound_time = 0;
239 fix Fusion_last_sound_time = 0;
242 int Game_turbo_mode = 0;
244 int Game_mode = GM_GAME_OVER;
246 int Global_laser_firing_count = 0;
247 int Global_missile_firing_count = 0;
249 grs_bitmap background_bitmap;
253 #define BACKGROUND_NAME "statback.pcx"
255 // Function prototypes for GAME.C exclusively.
257 void GameLoop(int RenderFlag, int ReadControlsFlag);
258 void FireLaser(void);
259 void slide_textures(void);
260 void powerup_grab_cheat_all(void);
263 extern void multi_check_for_killgoal_winner();
264 extern void RestoreGameSurfaces();
268 void grow_window(void);
269 void shrink_window(void);
273 void fill_background();
276 void show_framerate(void);
277 void ftoa(char *string, fix f);
280 extern ubyte DefiningMarkerMessage;
281 extern char Marker_input[];
283 // ==============================================================================================
285 extern char john_head_on;
287 void load_background_bitmap()
292 if (background_bitmap.bm_data)
293 d_free(background_bitmap.bm_data);
295 background_bitmap.bm_data=NULL;
296 pcx_error = pcx_read_bitmap(john_head_on?"johnhead.pcx":BACKGROUND_NAME,&background_bitmap,BM_LINEAR,pal);
297 if (pcx_error != PCX_ERROR_NONE)
298 Error("File %s - PCX error: %s",BACKGROUND_NAME,pcx_errormsg(pcx_error));
299 gr_remap_bitmap_good( &background_bitmap, pal, -1, -1 );
303 //this is called once per game
306 atexit(close_game); //for cleanup
310 init_special_effects();
314 init_gauge_canvases();
316 init_exploding_walls();
318 load_background_bitmap();
320 Clear_window = 2; // do portal only window clear.
322 set_detail_level_parameters(Detail_level);
324 build_mission_list(0); // This also loads mission 0.
327 cvar_registervariable(&r_framerate);
332 void reset_palette_add()
337 //gr_palette_step_up( PaletteRedAdd, PaletteGreenAdd, PaletteBlueAdd );
342 void win_get_span_list(grs_bitmap *bm, int miny, int maxy)
348 int lspan=0, rspan=0, span=0;
352 //@@ fp = fopen("cockspan.dat", "w");
354 for (y = 0; y < miny; y++)
355 win_cockpit_mask[y].num = 0;
357 for (y = miny; y <= maxy; y++)
360 //@@ fprintf(fp, "line %d: ", y);
361 for (x = 0; x < bm->bm_w; x++)
363 offset = y*bm->bm_rowsize + x;
365 if (data[offset] == 255) {
368 case 0: // Start Mode
370 win_cockpit_mask[y].span[span].xmin = x;
372 //@@ fprintf(fp, "<%d,", lspan);
375 case 1: // Transparency mode
377 win_cockpit_mask[y].span[span].xmax = x;
380 case 2: // Switch from Draw mode to transparent
382 win_cockpit_mask[y].span[span].xmin = x;
383 //@@ fprintf(fp, "<%d,", lspan);
391 case 0: // Start mode
395 case 1: // Switching from transparent to Draw
398 win_cockpit_mask[y].span[span].xmax = x;
400 //@@ fprintf(fp, "%d> ", rspan);
409 //@@ fprintf(fp, "%d> ", rspan);
410 win_cockpit_mask[y].span[span].xmax = rspan;
413 win_cockpit_mask[y].num = span;
414 //@@ fprintf(fp, "\n");
417 win_cockpit_mask[y].num = 255;
422 void game_show_warning(char *s)
425 if (!((Game_mode & GM_MULTI) && (Function_mode == FMODE_GAME)))
428 nm_messagebox( TXT_WARNING, 1, TXT_OK, s );
430 if (!((Game_mode & GM_MULTI) && (Function_mode == FMODE_GAME)))
435 //these should be in gr.h
436 #define cv_w cv_bitmap.bm_w
437 #define cv_h cv_bitmap.bm_h
439 int Game_window_x = 0;
440 int Game_window_y = 0;
441 int Game_window_w = 0;
442 int Game_window_h = 0;
443 int max_window_w = 0;
444 int max_window_h = 0;
446 extern void newdemo_record_cockpit_change(int);
448 //initialize the various canvases on the game screen
449 //called every time the screen mode or cockpit changes
452 int minx, maxx, miny, maxy;
454 #if defined(POLY_ACC)
455 pa_flush(); // get rid of undrawn polys.
456 pa_clear_buffer(1, 0);
459 //Initialize the on-screen canvases
461 if (Newdemo_state==ND_STATE_RECORDING)
464 newdemo_record_cockpit_change(Cockpit_mode);
467 if ( VR_render_mode != VR_NONE )
468 Cockpit_mode = CM_FULL_SCREEN;
470 if (!(VR_screen_flags & VRF_ALLOW_COCKPIT) && (Cockpit_mode==CM_FULL_COCKPIT || Cockpit_mode==CM_STATUS_BAR || Cockpit_mode==CM_REAR_VIEW) )
471 Cockpit_mode = CM_FULL_SCREEN;
473 if ( Screen_mode == SCREEN_EDITOR )
474 Cockpit_mode = CM_FULL_SCREEN;
477 dd_gr_set_current_canvas(NULL),
478 gr_set_current_canvas(NULL)
480 gr_set_curfont( GAME_FONT );
482 #if !defined(MACINTOSH) && !defined(WINDOWS)
483 if (Game_cockpit_copy_code)
484 d_free(Game_cockpit_copy_code);
485 Game_cockpit_copy_code = NULL;
487 if (Game_cockpit_copy_code)
488 Game_cockpit_copy_code = 0;
492 //@@ if (_lpDDSMask) { DDFreeSurface(_lpDDSMask); _lpDDSMask = NULL; }
496 game_win_init_cockpit_mask(0);
499 switch( Cockpit_mode )
501 case CM_FULL_COCKPIT:
503 grs_bitmap *bm = &GameBitmaps[cockpit_bitmap[Cockpit_mode+(Current_display_mode?(Num_cockpits/2):0)].index];
505 PIGGY_PAGE_IN(cockpit_bitmap[Cockpit_mode+(Current_display_mode?(Num_cockpits/2):0)]);
508 dd_gr_set_current_canvas(NULL);
509 game_win_init_cockpit_mask(1);
510 dd_gr_set_current_canvas(dd_VR_offscreen_buffer);
512 gr_set_current_canvas(VR_offscreen_buffer)
515 WIN(DDGRLOCK(dd_grd_curcanv));
516 gr_bitmap( 0, 0, bm );
517 bm = &VR_offscreen_buffer->cv_bitmap;
518 bm->bm_flags = BM_FLAG_TRANSPARENT;
519 gr_ibitblt_find_hole_size ( bm, &minx, &miny, &maxx, &maxy );
520 WIN( win_get_span_list(bm, miny, maxy);
521 DDGRUNLOCK(dd_grd_curcanv)
525 #if 1 // def MACINTOSH
526 gr_ibitblt_create_mask( bm, minx, miny, maxx-minx+1, maxy-miny+1, VR_offscreen_buffer->cv_bitmap.bm_rowsize);
528 if ( Current_display_mode )
530 #if defined(POLY_ACC)
531 Game_cockpit_copy_code = gr_ibitblt_create_mask_pa( bm, minx, miny, maxx-minx+1, maxy-miny+1, VR_offscreen_buffer->cv_bitmap.bm_rowsize );
532 pa_clear_buffer(1, 0); // clear offscreen to reduce white flash.
534 Game_cockpit_copy_code = gr_ibitblt_create_mask_svga( bm, minx, miny, maxx-minx+1, maxy-miny+1, VR_offscreen_buffer->cv_bitmap.bm_rowsize );
537 Game_cockpit_copy_code = gr_ibitblt_create_mask( bm, minx, miny, maxx-minx+1, maxy-miny+1, VR_offscreen_buffer->cv_bitmap.bm_rowsize );
539 bm->bm_flags = 0; // Clear all flags for offscreen canvas
541 Game_cockpit_copy_code = (ubyte *)(1);
542 bm->bm_flags = 0; // Clear all flags for offscreen canvas
544 game_init_render_sub_buffers( 0, 0, maxx-minx+1, maxy-miny+1 );
550 max_window_h = grd_curscreen->sc_h;
552 if (Game_window_h > max_window_h || VR_screen_flags&VRF_ALLOW_COCKPIT)
553 Game_window_h = max_window_h;
555 if (Game_window_w > max_window_w || VR_screen_flags&VRF_ALLOW_COCKPIT)
556 Game_window_w = max_window_w;
558 Game_window_x = (max_window_w - Game_window_w)/2;
559 Game_window_y = (max_window_h - Game_window_h)/2;
561 game_init_render_sub_buffers( Game_window_x, Game_window_y, Game_window_w, Game_window_h );
566 max_window_h = grd_curscreen->sc_h - GameBitmaps[cockpit_bitmap[CM_STATUS_BAR+(Current_display_mode?(Num_cockpits/2):0)].index].bm_h;
568 if (Game_window_h > max_window_h)
569 Game_window_h = max_window_h;
571 if (Game_window_w > max_window_w)
572 Game_window_w = max_window_w;
574 Game_window_x = (max_window_w - Game_window_w)/2;
575 Game_window_y = (max_window_h - Game_window_h)/2;
577 game_init_render_sub_buffers( Game_window_x, Game_window_y, Game_window_w, Game_window_h );
583 x = 0; w = VR_render_buffer[0].cv_bitmap.bm_w; //VR_render_width;
584 h = (VR_render_buffer[0].cv_bitmap.bm_h * 7) / 10;
585 y = (VR_render_buffer[0].cv_bitmap.bm_h-h)/2;
587 game_init_render_sub_buffers( x, y, w, h );
594 dd_gr_set_current_canvas(NULL),
595 gr_set_current_canvas(NULL)
599 //selects a given cockpit (or lack of one). See types in game.h
600 void select_cockpit(int mode)
602 if (mode != Cockpit_mode) { //new mode
608 extern int last_drawn_cockpit[2];
610 //force cockpit redraw next time. call this if you've trashed the screen
613 force_cockpit_redraw=1;
614 last_drawn_cockpit[0] = -1;
615 last_drawn_cockpit[1] = -1;
618 // void HUD_clear_messages(); //Already declared in gauges.h
621 void VR_reset_params()
623 VR_eye_width = VR_SEPARATION;
624 VR_eye_offset = VR_PIXEL_SHIFT;
625 VR_eye_offset_changed = 2;
628 void game_init_render_sub_buffers( int x, int y, int w, int h )
631 dd_gr_init_sub_canvas( &dd_VR_render_sub_buffer[0], &dd_VR_render_buffer[0], x, y, w, h );
632 dd_gr_init_sub_canvas( &dd_VR_render_sub_buffer[1], &dd_VR_render_buffer[1], x, y, w, h );
634 dd_VR_render_sub_buffer[0].canvas.cv_bitmap.bm_x = 0;
635 dd_VR_render_sub_buffer[0].canvas.cv_bitmap.bm_y = 0;
636 dd_VR_render_sub_buffer[0].xoff = x;
637 dd_VR_render_sub_buffer[0].yoff = y;
638 dd_VR_render_sub_buffer[1].canvas.cv_bitmap.bm_x = 0;
639 dd_VR_render_sub_buffer[1].canvas.cv_bitmap.bm_y = 0;
640 dd_VR_render_sub_buffer[1].xoff = x;
641 dd_VR_render_sub_buffer[1].yoff = y;
644 if (Scanline_double) {
648 gr_init_sub_canvas( &VR_render_sub_buffer[0], &VR_render_buffer[0], x, y, w/2, (h/2)+1);
649 gr_init_sub_canvas( &VR_render_sub_buffer[1], &VR_render_buffer[1], x, y, w/2, (h/2)+1);
652 gr_init_sub_canvas( &VR_render_sub_buffer[0], &VR_render_buffer[0], x, y, w, h );
653 gr_init_sub_canvas( &VR_render_sub_buffer[1], &VR_render_buffer[1], x, y, w, h );
663 newBounds.right = x + w;
665 newBounds.bottom = y + h;
667 pa_set_context(kGamePlayDrawContextID, &newBounds); // must resize/create new context
673 VR_render_sub_buffer[0].cv_bitmap.bm_x = 0;
674 VR_render_sub_buffer[0].cv_bitmap.bm_y = 0;
675 VR_render_sub_buffer[1].cv_bitmap.bm_x = 0;
676 VR_render_sub_buffer[1].cv_bitmap.bm_y = 0;
682 // Sets up the canvases we will be rendering to (WIN95)
683 void game_init_render_buffers(int screen_mode, int render_w, int render_h, int render_method, int flags )
685 // Hack for switching to higher that 640x480 modes (DDraw doesn't allow
686 // creating surfaces greater than the current resolution
688 if (GRMODEINFO(rw) < render_w || GRMODEINFO(rh) < render_h) {
689 render_w = GRMODEINFO(rw);
690 render_h = GRMODEINFO(rh);
693 VR_screen_mode = screen_mode;
695 VR_screen_flags = flags;
698 VR_render_mode = render_method;
700 Game_window_w = render_w;
701 Game_window_h = render_h;
703 if (dd_VR_offscreen_buffer && dd_VR_offscreen_buffer != dd_grd_backcanv) {
704 dd_gr_free_canvas(dd_VR_offscreen_buffer);
707 if ( (VR_render_mode==VR_AREA_DET) || (VR_render_mode==VR_INTERLACED ) ) {
708 if ( render_h*2 < 200 ) {
709 Int3(); // Not Supported yet!!!
710 // VR_offscreen_buffer = gr_create_canvas( render_w, 200 );
713 Int3(); // Not Supported yet!!!
714 // VR_offscreen_buffer = gr_create_canvas( render_w, render_h*2 );
717 Int3(); // Not Supported yet!!!
718 // gr_init_sub_canvas( &VR_render_buffer[0], VR_offscreen_buffer, 0, 0, render_w, render_h );
719 // gr_init_sub_canvas( &VR_render_buffer[1], VR_offscreen_buffer, 0, render_h, render_w, render_h );
721 else if (GRMODEINFO(paged) && !GRMODEINFO(dbuf)) {
722 // Here we will make the VR_offscreen_buffer the 2nd page and hopefully
723 // we can just flip it, saving a blt.
725 dd_VR_offscreen_buffer = dd_grd_backcanv;
726 VR_offscreen_buffer = & dd_grd_backcanv->canvas;
728 else if (GRMODEINFO(dbuf)||GRMODEINFO(emul)) {
729 // The offscreen buffer will be created. We will just blt this
730 // to the screen (which may be blted to the primary surface)
731 if ( render_h < 200 ) {
732 dd_VR_offscreen_buffer = dd_gr_create_canvas(render_w, 200);
733 VR_offscreen_buffer = &dd_VR_offscreen_buffer->canvas;
736 dd_VR_offscreen_buffer = dd_gr_create_canvas(render_w, render_h);
737 VR_offscreen_buffer = &dd_VR_offscreen_buffer->canvas;
741 dd_gr_init_sub_canvas( &dd_VR_render_buffer[0], dd_VR_offscreen_buffer, 0, 0, render_w, render_h );
742 dd_gr_init_sub_canvas( &dd_VR_render_buffer[1], dd_VR_offscreen_buffer, 0, 0, render_w, render_h );
743 gr_init_sub_canvas( &VR_render_buffer[0], VR_offscreen_buffer, 0, 0, render_w, render_h );
744 gr_init_sub_canvas( &VR_render_buffer[1], VR_offscreen_buffer, 0, 0, render_w, render_h );
746 game_init_render_sub_buffers( 0, 0, render_w, render_h );
751 // Sets up the canvases we will be rendering to (NORMAL VERSION)
752 void game_init_render_buffers(int screen_mode, int render_w, int render_h, int render_method, int flags )
754 // if (vga_check_mode(screen_mode) != 0)
755 // Error("Cannot set requested video mode");
757 VR_screen_mode = screen_mode;
759 VR_screen_flags = flags;
763 VR_render_mode = render_method;
765 Game_window_w = render_w;
766 Game_window_h = render_h;
768 if (VR_offscreen_buffer) {
769 gr_free_canvas(VR_offscreen_buffer);
772 if ( (VR_render_mode==VR_AREA_DET) || (VR_render_mode==VR_INTERLACED ) ) {
773 if ( render_h*2 < 200 ) {
774 VR_offscreen_buffer = gr_create_canvas( render_w, 200 );
777 VR_offscreen_buffer = gr_create_canvas( render_w, render_h*2 );
780 gr_init_sub_canvas( &VR_render_buffer[0], VR_offscreen_buffer, 0, 0, render_w, render_h );
781 gr_init_sub_canvas( &VR_render_buffer[1], VR_offscreen_buffer, 0, render_h, render_w, render_h );
784 if ( render_h < 200 ) {
785 VR_offscreen_buffer = gr_create_canvas( render_w, 200 );
788 #if defined(POLY_ACC)
790 VR_offscreen_buffer = gr_create_canvas( render_w, render_h );
791 d_free(VR_offscreen_buffer->cv_bitmap.bm_data);
792 gr_init_canvas(VR_offscreen_buffer, pa_get_buffer_address(1), BM_LINEAR15, render_w, render_h);
794 if ( PAEnabled || gConfigInfo.mAcceleration ) {
795 Cockpit_mode=CM_FULL_SCREEN; // HACK HACK HACK HACK HACK!!!!
796 VR_offscreen_buffer = gr_create_canvas2(render_w, render_h, BM_LINEAR15);
798 VR_offscreen_buffer = gr_create_canvas( render_w, render_h );
801 VR_offscreen_buffer = gr_create_canvas( render_w, render_h );
806 VR_offscreen_buffer->cv_bitmap.bm_type = BM_OGL;
809 gr_init_sub_canvas( &VR_render_buffer[0], VR_offscreen_buffer, 0, 0, render_w, render_h );
810 gr_init_sub_canvas( &VR_render_buffer[1], VR_offscreen_buffer, 0, 0, render_w, render_h );
813 game_init_render_sub_buffers( 0, 0, render_w, render_h );
817 //called to get the screen in a mode compatible with popup menus.
818 //if we can't have popups over the game screen, switch to menu mode.
819 void set_popup_screen(void)
821 //WIN(LoadCursorWin(MOUSE_DEFAULT_CURSOR));
823 if (! (VR_screen_flags & VRF_COMPATIBLE_MENUS))
824 set_screen_mode(SCREEN_MENU); //must switch to menu mode
828 //called to change the screen mode. Parameter sm is the new mode, one of
829 //SMODE_GAME or SMODE_EDITOR. returns mode acutally set (could be other
830 //mode if cannot init requested mode)
831 int set_screen_mode(int sm)
833 WIN(static int force_mode_change=0);
834 WIN(static int saved_window_w);
835 WIN(static int saved_window_h);
838 if ( (sm==SCREEN_MENU) && (Screen_mode==SCREEN_EDITOR) ) {
839 gr_set_current_canvas( Canv_editor );
845 if ( Screen_mode == sm && W95DisplayMode == VR_screen_mode) {
846 dd_gr_set_current_canvas( &dd_VR_screen_pages[VR_current_page] );
850 if ( Screen_mode == sm && VGA_current_mode == VR_screen_mode) {
851 gr_set_current_canvas( &VR_screen_pages[VR_current_page] );
857 if ((Screen_mode == sm) && !((sm==SCREEN_GAME) && (grd_curscreen->sc_mode != VR_screen_mode) && (Screen_mode == SCREEN_GAME))) {
859 gr_set_current_canvas( &VR_screen_pages[VR_current_page] );
860 ogl_set_screen_mode();
871 switch( Screen_mode )
877 if (!(VR_screen_flags & VRF_COMPATIBLE_MENUS)) {
878 // HACK!!! Meant to save window size when switching from
879 // non-compat menu mode to menu mode.
880 saved_window_w = Game_window_w;
881 saved_window_h = Game_window_h;
882 force_mode_change = 1;
884 if (W95DisplayMode != SM95_640x480x8) {
885 //@@ piggy_bitmap_page_out_all_w(); // 2D GFX Flush cache.
886 DDSETDISPLAYMODE(SM95_640x480x8);
888 if (!gr_palette_faded_out) gr_palette_load(gr_palette);
891 dd_gr_init_sub_canvas(&dd_VR_screen_pages[0], dd_grd_screencanv,
893 dd_grd_screencanv->canvas.cv_bitmap.bm_w,
894 dd_grd_screencanv->canvas.cv_bitmap.bm_h);
895 dd_gr_init_sub_canvas(&dd_VR_screen_pages[1], dd_grd_screencanv,
897 dd_grd_screencanv->canvas.cv_bitmap.bm_w,
898 dd_grd_screencanv->canvas.cv_bitmap.bm_h);
906 MenuHires = MenuHiresAvailable; //do highres if we can
908 #if defined(POLY_ACC)
910 menu_mode = MenuHires?SM(640,480):SM(320,200);
912 menu_mode = PAEnabled?SM_640x480x15xPA:SM_640x480V;
915 menu_mode = MenuHires?SM(640,480):SM(320,200);
918 if (VGA_current_mode != menu_mode) {
919 if (gr_set_mode(menu_mode))
920 Error("Cannot set screen mode for menu");
921 if (!gr_palette_faded_out)
922 gr_palette_load(gr_palette);
925 gr_init_sub_canvas( &VR_screen_pages[0], &grd_curscreen->sc_canvas, 0, 0, grd_curscreen->sc_w, grd_curscreen->sc_h );
926 gr_init_sub_canvas( &VR_screen_pages[1], &grd_curscreen->sc_canvas, 0, 0, grd_curscreen->sc_w, grd_curscreen->sc_h );
928 FontHires = MenuHires;
938 if (force_mode_change || (W95DisplayMode != VR_screen_mode)) {
940 DDSETDISPLAYMODE(VR_screen_mode);
941 //@@ piggy_bitmap_page_out_all_w(); // 2D GFX Flush cache.
943 mprintf((0, "Reinitializing render buffers due to display mode change.\n"));
944 game_init_render_buffers(W95DisplayMode,
945 GRMODEINFO(rw), GRMODEINFO(rh),
946 VR_render_mode, VR_screen_flags);
951 if (VGA_current_mode != VR_screen_mode) {
952 if (gr_set_mode(VR_screen_mode)) {
953 Error("Cannot set desired screen mode for game!");
954 //we probably should do something else here, like select a standard mode
957 if ( (Config_control_type == 1) && (Function_mode == FMODE_GAME) )
964 if ( VR_render_mode == VR_NONE )
966 max_window_w = grd_curscreen->sc_w;
967 max_window_h = grd_curscreen->sc_h;
969 if (VR_screen_flags & VRF_ALLOW_COCKPIT) {
970 if (Cockpit_mode == CM_STATUS_BAR)
971 max_window_h = grd_curscreen->sc_h - GameBitmaps[cockpit_bitmap[CM_STATUS_BAR+(Current_display_mode?(Num_cockpits/2):0)].index].bm_h;
973 else if (Cockpit_mode != CM_LETTERBOX)
974 Cockpit_mode = CM_FULL_SCREEN;
976 if (Game_window_h==0 || Game_window_h > max_window_h || Game_window_w==0 || Game_window_w > max_window_w) {
977 Game_window_w = max_window_w;
978 Game_window_h = max_window_h;
983 Cockpit_mode = CM_FULL_SCREEN;
986 // Super hack. If we are switching from a 320x200 game to 640x480.
987 // and we were in a menumode when switching, we don't
988 // restore Game_window vals
989 if (force_mode_change && (W95DisplayMode == SM95_320x200x8X)) {
990 Game_window_w = saved_window_w;
991 Game_window_h = saved_window_h;
992 force_mode_change = 0;
997 // Define screen pages for game mode
998 // If we designate through screen_flags to use paging, then do so.
1000 dd_gr_init_sub_canvas( &dd_VR_screen_pages[0], dd_grd_screencanv, 0, 0, grd_curscreen->sc_w, grd_curscreen->sc_h ),
1001 gr_init_sub_canvas( &VR_screen_pages[0], &grd_curscreen->sc_canvas, 0, 0, grd_curscreen->sc_w, grd_curscreen->sc_h )
1004 if ( VR_screen_flags&VRF_USE_PAGING ) {
1006 dd_gr_init_sub_canvas( &dd_VR_screen_pages[1], dd_grd_backcanv, 0, 0, grd_curscreen->sc_w, grd_curscreen->sc_h ),
1007 gr_init_sub_canvas( &VR_screen_pages[1], &grd_curscreen->sc_canvas, 0, grd_curscreen->sc_h, grd_curscreen->sc_w, grd_curscreen->sc_h )
1012 dd_gr_init_sub_canvas( &dd_VR_screen_pages[1], dd_grd_screencanv, 0, 0, grd_curscreen->sc_w, grd_curscreen->sc_h ),
1013 gr_init_sub_canvas( &VR_screen_pages[1], &grd_curscreen->sc_canvas, 0, 0, grd_curscreen->sc_w, grd_curscreen->sc_h )
1020 FontHires = (Current_display_mode != 0);
1023 FontHires = MenuHires = ((Current_display_mode != 0) && (Current_display_mode != 2));
1026 if ( VR_render_mode != VR_NONE ) {
1027 // for 640x480 or higher, use hires font.
1028 if ( grd_curscreen->sc_h > 400 )
1037 if (VGA_current_mode != SM_800x600V) {
1039 if ((gr_error=gr_set_mode(SM_800x600V))!=0) { //force into game scrren
1040 Warning("Cannot init editor screen (error=%d)",gr_error);
1044 gr_palette_load( gr_palette );
1046 gr_init_sub_canvas( &VR_editor_canvas, &grd_curscreen->sc_canvas, 0, 0, grd_curscreen->sc_w, grd_curscreen->sc_h );
1047 Canv_editor = &VR_editor_canvas;
1048 gr_init_sub_canvas( &VR_screen_pages[0], Canv_editor, 0, 0, Canv_editor->cv_w, Canv_editor->cv_h );
1049 gr_init_sub_canvas( &VR_screen_pages[1], Canv_editor, 0, 0, Canv_editor->cv_w, Canv_editor->cv_h );
1050 gr_set_current_canvas( Canv_editor );
1051 init_editor_screen(); //setup other editor stuff
1055 Error("Invalid screen mode %d",sm);
1058 VR_current_page = 0;
1061 dd_gr_set_current_canvas(&dd_VR_screen_pages[VR_current_page]),
1062 gr_set_current_canvas( &VR_screen_pages[VR_current_page] )
1065 if ( VR_screen_flags&VRF_USE_PAGING ) {
1068 gr_show_canvas( &VR_screen_pages[VR_current_page] )
1072 ogl_set_screen_mode();
1078 static int timer_paused=0;
1082 if (timer_paused==0) {
1084 time = timer_get_fixed_seconds();
1085 last_timer_value = time - last_timer_value;
1086 if (last_timer_value < 0) {
1087 #if defined(TIMER_TEST) && !defined(NDEBUG)
1088 Int3(); //get Matt!!!!
1090 last_timer_value = 0;
1092 #if defined(TIMER_TEST) && !defined(NDEBUG)
1093 time_stopped = time;
1098 #if defined(TIMER_TEST) && !defined(NDEBUG)
1106 Assert(timer_paused >= 0);
1107 if (timer_paused==0) {
1109 time = timer_get_fixed_seconds();
1110 #if defined(TIMER_TEST) && !defined(NDEBUG)
1111 if (last_timer_value < 0)
1112 Int3(); //get Matt!!!!
1115 last_timer_value = time - last_timer_value;
1116 #if defined(TIMER_TEST) && !defined(NDEBUG)
1117 time_started = time;
1121 #if defined(TIMER_TEST) && !defined(NDEBUG)
1126 MAC(extern ubyte joydefs_calibrating;)
1128 void game_flush_inputs()
1135 if ( (Function_mode != FMODE_MENU) && !joydefs_calibrating ) // only reset mouse when not in menu or not calibrating
1137 mouse_get_delta( &dx, &dy ); // Read mouse
1138 memset(&Controls,0,sizeof(control_info));
1143 last_timer_value = timer_get_fixed_seconds();
1148 extern int Saving_movie_frames;
1149 int Movie_fixed_frametime;
1151 #define Saving_movie_frames 0
1152 #define Movie_fixed_frametime 0
1155 static const int max_fps = 80;
1157 void calc_frame_time()
1159 fix timer_value,last_frametime = FrameTime;
1161 #if defined(TIMER_TEST) && !defined(NDEBUG)
1162 _last_frametime = last_frametime;
1165 timer_value = timer_get_fixed_seconds();
1166 FrameTime = timer_value - last_timer_value;
1169 timer_value = timer_get_fixed_seconds();
1170 FrameTime = timer_value - last_timer_value;
1171 if (FrameTime < f1_0/max_fps);
1175 } while (FrameTime < f1_0/max_fps);
1177 #if defined(TIMER_TEST) && !defined(NDEBUG)
1178 _timer_value = timer_value;
1182 if (!(((FrameTime > 0) && (FrameTime <= F1_0)) || (Function_mode == FMODE_EDITOR) || (Newdemo_state == ND_STATE_PLAYBACK))) {
1183 mprintf((1,"Bad FrameTime - value = %x\n",FrameTime));
1185 Int3(); // Call Mike or Matt or John! Your interrupts are probably trashed!
1186 // if ( !dpmi_virtual_memory )
1187 // Int3(); //Get MATT if hit this!
1191 #if defined(TIMER_TEST) && !defined(NDEBUG)
1192 actual_last_timer_value = last_timer_value;
1195 if ( Game_turbo_mode )
1198 // Limit frametime to be between 5 and 150 fps.
1199 RealFrameTime = FrameTime;
1200 if ( FrameTime < F1_0/150 ) FrameTime = F1_0/150;
1201 if ( FrameTime > F1_0/5 ) FrameTime = F1_0/5;
1203 last_timer_value = timer_value;
1205 if (FrameTime < 0) //if bogus frametime...
1206 FrameTime = last_frametime; //...then use time from last frame
1209 if (fixed_frametime) FrameTime = fixed_frametime;
1214 if ( Debug_pause ) {
1224 last_timer_value = timer_get_fixed_seconds();
1232 #if defined(TIMER_TEST) && !defined(NDEBUG)
1233 stop_count = start_count = 0;
1236 // Set value to determine whether homing missile can see target.
1237 // The lower frametime is, the more likely that it can see its target.
1238 if (FrameTime <= F1_0/64)
1239 Min_trackable_dot = MIN_TRACKABLE_DOT; // -- 3*(F1_0 - MIN_TRACKABLE_DOT)/4 + MIN_TRACKABLE_DOT;
1240 else if (FrameTime < F1_0/32)
1241 Min_trackable_dot = MIN_TRACKABLE_DOT + F1_0/64 - 2*FrameTime; // -- fixmul(F1_0 - MIN_TRACKABLE_DOT, F1_0-4*FrameTime) + MIN_TRACKABLE_DOT;
1242 else if (FrameTime < F1_0/4)
1243 Min_trackable_dot = MIN_TRACKABLE_DOT + F1_0/64 - F1_0/16 - FrameTime; // -- fixmul(F1_0 - MIN_TRACKABLE_DOT, F1_0-4*FrameTime) + MIN_TRACKABLE_DOT;
1245 Min_trackable_dot = MIN_TRACKABLE_DOT + F1_0/64 - F1_0/8;
1249 //--unused-- int Auto_flythrough=0; //if set, start flythough automatically
1251 void move_player_2_segment(segment *seg,int side)
1255 compute_segment_center(&ConsoleObject->pos,seg);
1256 compute_center_point_on_side(&vp,seg,side);
1257 vm_vec_sub2(&vp,&ConsoleObject->pos);
1258 vm_vector_2_matrix(&ConsoleObject->orient,&vp,NULL,NULL);
1260 obj_relink( ConsoleObject-Objects, SEG_PTR_2_NUM(seg) );
1265 void game_draw_time_left()
1267 char temp_string[30];
1271 gr_set_curfont( GAME_FONT ); //GAME_FONT
1272 gr_set_fontcolor(gr_getcolor(0,63,0), -1 );
1274 timevar=i2f (Netgame.PlayTimeAllowed*5*60);
1275 i=f2i(timevar-ThisLevelTime);
1278 sprintf( temp_string, "Time left: %d secs", i );
1281 gr_string(0, 32, temp_string );
1286 extern int Game_pause;
1289 void level_with_floor();
1291 void modex_clear_box(int x,int y,int w,int h)
1293 grs_canvas *temp_canv,*save_canv;
1295 save_canv = grd_curcanv;
1296 temp_canv = gr_create_canvas(w,h);
1297 gr_set_current_canvas(temp_canv);
1298 gr_clear_canvas(BM_XRGB(0,0,0));
1299 gr_set_current_canvas(save_canv);
1300 gr_bitmapm(x,y,&temp_canv->cv_bitmap);
1301 gr_free_canvas(temp_canv);
1305 extern void modex_printf(int x,int y,char *s,grs_font *font,int color);
1307 // mac routine to drop contents of screen to a pict file using copybits
1308 // save a PICT to a file
1311 void SavePictScreen(int multiplayer)
1314 int parid, i, count;
1315 char *pfilename, filename[50], buf[512], cwd[FILENAME_MAX];
1318 PicHandle pict_handle;
1319 static int multi_count = 0;
1320 StandardFileReply sf_reply;
1322 // dump the contents of the GameWindow into a picture using copybits
1324 pict_handle = OpenPicture(&GameWindow->portRect);
1325 if (pict_handle == NULL)
1328 CopyBits(&GameWindow->portBits, &GameWindow->portBits, &GameWindow->portRect, &GameWindow->portRect, srcBic, NULL);
1331 // get the cwd to restore with chdir when done -- this keeps the mac world sane
1332 if (!getcwd(cwd, FILENAME_MAX))
1334 // create the fsspec
1336 sprintf(filename, "screen%d", multi_count++);
1337 pfilename = c2pstr(filename);
1340 StandardPutFile("\pSave PICT as:", pfilename, &sf_reply);
1341 if (!sf_reply.sfGood)
1343 memcpy( &spec, &(sf_reply.sfFile), sizeof(FSSpec) );
1344 if (sf_reply.sfReplacing)
1346 err = FSpCreate( &spec, 'ttxt', 'PICT', smSystemScript );
1350 // parid = GetAppDirId();
1351 err = FSMakeFSSpec(0, 0, pfilename, &spec);
1356 err = FSpCreate(&spec, 'ttxt', 'PICT', smSystemScript);
1361 // write the PICT file
1362 if ( FSpOpenDF(&spec, fsRdWrPerm, &fd) )
1364 memset(buf, 0, sizeof(buf));
1366 if ( FSWrite(fd, &count, buf) )
1368 count = GetHandleSize((Handle)pict_handle);
1369 HLock((Handle)pict_handle);
1370 if ( FSWrite(fd, &count, *pict_handle) ) {
1376 HUnlock((Handle)pict_handle);
1377 DisposeHandle((Handle)pict_handle);
1385 //automap_flag is now unused, since we just check if the screen we're
1386 //writing to is modex
1387 //if called from automap, current canvas is set to visible screen
1389 void save_screen_shot(int automap_flag)
1391 #if defined(WINDOWS)
1392 mprintf((0, "Doing screen shot thing.\n"));
1393 win95_save_pcx_shot();
1395 #elif !defined(MACINTOSH)
1398 grs_canvas *screen_canv=&grd_curscreen->sc_canvas;
1399 grs_font *save_font;
1400 static int savenum=0;
1401 static int stereo_savenum=0;
1402 grs_canvas *temp_canv,*temp_canv2,*save_canv;
1403 char savename[FILENAME_LEN],savename2[FILENAME_LEN];
1411 // // Can't do screen shots in VR modes.
1412 // if ( VR_render_mode != VR_NONE )
1417 save_canv = grd_curcanv;
1419 if ( VR_render_mode != VR_NONE && !automap_flag && Function_mode==FMODE_GAME && Screen_mode==SCREEN_GAME)
1423 temp_canv = gr_create_canvas(VR_render_buffer[0].cv_bitmap.bm_w,VR_render_buffer[0].cv_bitmap.bm_h);
1424 gr_set_current_canvas(temp_canv);
1425 gr_ubitmap(0,0,&VR_render_buffer[0].cv_bitmap);
1427 temp_canv2 = gr_create_canvas(VR_render_buffer[1].cv_bitmap.bm_w,VR_render_buffer[1].cv_bitmap.bm_h);
1428 gr_set_current_canvas(temp_canv2);
1429 gr_ubitmap(0,0,&VR_render_buffer[1].cv_bitmap);
1432 temp_canv = gr_create_canvas(screen_canv->cv_bitmap.bm_w,screen_canv->cv_bitmap.bm_h);
1433 gr_set_current_canvas(temp_canv);
1434 gr_ubitmap(0,0,&screen_canv->cv_bitmap);
1437 gr_set_current_canvas(save_canv);
1439 if ( savenum > 99 ) savenum = 0;
1440 if ( stereo_savenum > 99 ) stereo_savenum = 0;
1443 sprintf(savename,"left%02d.pcx",stereo_savenum);
1444 sprintf(savename2,"right%02d.pcx",stereo_savenum);
1445 if (VR_eye_switch) {char t[FILENAME_LEN]; strcpy(t,savename); strcpy(savename,savename2); strcpy(savename2,t);}
1447 sprintf( message, "%s '%s' & '%s'", TXT_DUMPING_SCREEN, savename, savename2 );
1450 sprintf(savename,"screen%02d.pcx",savenum++);
1451 sprintf( message, "%s '%s'", TXT_DUMPING_SCREEN, savename );
1454 if (!automap_flag) //if from automap, curcanv is already visible canv
1455 gr_set_current_canvas(NULL);
1456 modex_flag = (grd_curcanv->cv_bitmap.bm_type==BM_MODEX);
1457 if (!automap_flag && modex_flag)
1458 gr_set_current_canvas(&VR_screen_pages[VR_current_page]);
1460 save_font = grd_curcanv->cv_font;
1461 gr_set_curfont(GAME_FONT);
1462 gr_set_fontcolor(gr_find_closest_color_current(0,31,0),-1);
1463 gr_get_string_size(message,&w,&h,&aw);
1468 //I changed how these coords were calculated for the high-res automap. -MT
1469 //x = (VR_screen_pages[VR_current_page].cv_w-w)/2;
1470 //y = (VR_screen_pages[VR_current_page].cv_h-h)/2;
1471 x = (grd_curcanv->cv_w-w)/2;
1472 y = (grd_curcanv->cv_h-h)/2;
1475 modex_clear_box(x-2,y-2,w+4,h+4);
1476 modex_printf(x, y, message,GAME_FONT,gr_find_closest_color_current(0,31,0));
1478 gr_setcolor(gr_find_closest_color_current(0,0,0));
1479 gr_rect(x-2,y-2,x+w+2,y+h+2);
1480 gr_printf(x,y,message);
1481 gr_set_curfont(save_font);
1483 t1 = timer_get_fixed_seconds() + F1_0;
1485 gr_palette_read(pal); //get actual palette from the hardware
1486 pcx_write_bitmap(savename,&temp_canv->cv_bitmap,pal);
1488 pcx_write_bitmap(savename2,&temp_canv2->cv_bitmap,pal);
1490 while ( timer_get_fixed_seconds() < t1 ); // Wait so that messag stays up at least 1 second.
1492 gr_set_current_canvas(screen_canv);
1494 if (grd_curcanv->cv_bitmap.bm_type!=BM_MODEX && !stereo)
1495 gr_ubitmap(0,0,&temp_canv->cv_bitmap);
1497 gr_free_canvas(temp_canv);
1499 gr_free_canvas(temp_canv2);
1501 gr_set_current_canvas(save_canv);
1507 grs_canvas *screen_canv = &grd_curscreen->sc_canvas;
1508 grs_canvas *temp_canv, *save_canv;
1510 // Can't do screen shots in VR modes.
1511 if ( VR_render_mode != VR_NONE )
1516 save_canv = grd_curcanv;
1517 temp_canv = gr_create_canvas( screen_canv->cv_bitmap.bm_w, screen_canv->cv_bitmap.bm_h );
1520 gr_set_current_canvas( temp_canv );
1521 gr_ubitmap( 0, 0, &screen_canv->cv_bitmap );
1522 gr_set_current_canvas( &VR_screen_pages[VR_current_page] );
1526 if (Game_mode & GM_MULTI)
1533 gr_set_current_canvas(screen_canv);
1535 // if (!automap_flag)
1536 gr_ubitmap( 0, 0, &temp_canv->cv_bitmap);
1538 gr_free_canvas(temp_canv);
1540 gr_set_current_canvas(save_canv);
1549 void fly_init(object *obj)
1551 obj->control_type = CT_FLYING;
1552 obj->movement_type = MT_PHYSICS;
1554 vm_vec_zero(&obj->mtype.phys_info.velocity);
1555 vm_vec_zero(&obj->mtype.phys_info.thrust);
1556 vm_vec_zero(&obj->mtype.phys_info.rotvel);
1557 vm_vec_zero(&obj->mtype.phys_info.rotthrust);
1560 //void morph_test(), morph_step();
1563 // ------------------------------------------------------------------------------------
1565 void test_anim_states();
1569 //put up the help message
1576 extern int been_in_editor;
1578 // ------------------------------------------------------------------------------------
1579 void do_cloak_stuff(void)
1582 for (i = 0; i < N_players; i++)
1583 if (Players[i].flags & PLAYER_FLAGS_CLOAKED) {
1584 // mprintf(0, "Cloak time left: %7.3f\n", f2fl(CLOAK_TIME_MAX - (GameTime - Players[Player_num].cloak_time)));
1585 if (GameTime - Players[i].cloak_time > CLOAK_TIME_MAX) {
1586 Players[i].flags &= ~PLAYER_FLAGS_CLOAKED;
1587 if (i == Player_num) {
1588 digi_play_sample( SOUND_CLOAK_OFF, F1_0);
1590 if (Game_mode & GM_MULTI)
1591 multi_send_play_sound(SOUND_CLOAK_OFF, F1_0);
1592 maybe_drop_net_powerup(POW_CLOAK);
1593 multi_send_decloak(); // For demo recording
1595 // mprintf((0, " --- You have been DE-CLOAKED! ---\n"));
1603 // ------------------------------------------------------------------------------------
1604 void do_invulnerable_stuff(void)
1606 if (Players[Player_num].flags & PLAYER_FLAGS_INVULNERABLE) {
1607 if (GameTime - Players[Player_num].invulnerable_time > INVULNERABLE_TIME_MAX) {
1608 Players[Player_num].flags ^= PLAYER_FLAGS_INVULNERABLE;
1611 digi_play_sample( SOUND_INVULNERABILITY_OFF, F1_0);
1613 if (Game_mode & GM_MULTI)
1615 multi_send_play_sound(SOUND_INVULNERABILITY_OFF, F1_0);
1616 maybe_drop_net_powerup(POW_INVULNERABILITY);
1619 mprintf((0, " --- You have been DE-INVULNERABLEIZED! ---\n"));
1626 ubyte Last_afterburner_state = 0;
1627 fix Last_afterburner_charge = 0;
1629 #define AFTERBURNER_LOOP_START ((digi_sample_rate==SAMPLE_RATE_22K)?32027:(32027/2)) //20098
1630 #define AFTERBURNER_LOOP_END ((digi_sample_rate==SAMPLE_RATE_22K)?48452:(48452/2)) //25776
1634 //@@// ------------------------------------------------------------------------------------
1635 //@@void afterburner_shake(void)
1639 //@@ rx = (Ab_scale * fixmul(d_rand() - 16384, F1_0/8 + (((GameTime + 0x4000)*4) & 0x3fff)))/16;
1640 //@@ rz = (Ab_scale * fixmul(d_rand() - 16384, F1_0/2 + ((GameTime*4) & 0xffff)))/16;
1642 //@@ // -- mprintf((0, "AB: %8x %8x\n", rx, rz));
1643 //@@ ConsoleObject->mtype.phys_info.rotvel.x += rx;
1644 //@@ ConsoleObject->mtype.phys_info.rotvel.z += rz;
1648 // ------------------------------------------------------------------------------------
1650 extern void multi_send_sound_function (char,char);
1653 void do_afterburner_stuff(void)
1655 if (!(Players[Player_num].flags & PLAYER_FLAGS_AFTERBURNER))
1656 Afterburner_charge=0;
1658 if (Endlevel_sequence || Player_is_dead)
1660 digi_kill_sound_linked_to_object( Players[Player_num].objnum);
1662 multi_send_sound_function (0,0);
1666 if ((Controls.afterburner_state != Last_afterburner_state && Last_afterburner_charge) || (Last_afterburner_state && Last_afterburner_charge && !Afterburner_charge)) {
1668 if (Afterburner_charge && Controls.afterburner_state && (Players[Player_num].flags & PLAYER_FLAGS_AFTERBURNER)) {
1669 digi_link_sound_to_object3( SOUND_AFTERBURNER_IGNITE, Players[Player_num].objnum, 1, F1_0, i2f(256), AFTERBURNER_LOOP_START, AFTERBURNER_LOOP_END );
1671 if (Game_mode & GM_MULTI)
1672 multi_send_sound_function (3,SOUND_AFTERBURNER_IGNITE);
1675 digi_kill_sound_linked_to_object( Players[Player_num].objnum);
1676 digi_link_sound_to_object2( SOUND_AFTERBURNER_PLAY, Players[Player_num].objnum, 0, F1_0, i2f(256));
1678 if (Game_mode & GM_MULTI)
1679 multi_send_sound_function (0,0);
1681 mprintf((0,"Killing afterburner sound\n"));
1685 //@@if (Controls.afterburner_state && Afterburner_charge)
1686 //@@ afterburner_shake();
1688 Last_afterburner_state = Controls.afterburner_state;
1689 Last_afterburner_charge = Afterburner_charge;
1692 // -- // ------------------------------------------------------------------------------------
1693 // -- // if energy < F1_0/2, recharge up to F1_0/2
1694 // -- void recharge_energy_frame(void)
1696 // -- if (Players[Player_num].energy < Weapon_info[0].energy_usage) {
1697 // -- Players[Player_num].energy += FrameTime/4;
1699 // -- if (Players[Player_num].energy > Weapon_info[0].energy_usage)
1700 // -- Players[Player_num].energy = Weapon_info[0].energy_usage;
1704 // Amount to diminish guns towards normal, per second.
1705 #define DIMINISH_RATE 16 // gots to be a power of 2, else change the code in diminish_palette_towards_normal
1707 extern fix Flash_effect;
1709 //adds to rgb values for palette flash
1710 void PALETTE_FLASH_ADD(int _dr,int _dg,int _db)
1714 PaletteRedAdd += _dr;
1715 PaletteGreenAdd += _dg;
1716 PaletteBlueAdd += _db;
1718 // -- mprintf((0, "Palette add: %3i %3i %3i\n", PaletteRedAdd, PaletteGreenAdd, PaletteBlueAdd));
1723 maxval = MAX_PALETTE_ADD;
1725 if (PaletteRedAdd > maxval)
1726 PaletteRedAdd = maxval;
1728 if (PaletteGreenAdd > maxval)
1729 PaletteGreenAdd = maxval;
1731 if (PaletteBlueAdd > maxval)
1732 PaletteBlueAdd = maxval;
1734 if (PaletteRedAdd < -maxval)
1735 PaletteRedAdd = -maxval;
1737 if (PaletteGreenAdd < -maxval)
1738 PaletteGreenAdd = -maxval;
1740 if (PaletteBlueAdd < -maxval)
1741 PaletteBlueAdd = -maxval;
1744 fix Time_flash_last_played;
1747 void game_palette_step_up( int r, int g, int b );
1748 // ------------------------------------------------------------------------------------
1749 // Diminish palette effects towards normal.
1750 void diminish_palette_towards_normal(void)
1754 // Diminish at DIMINISH_RATE units/second.
1755 // For frame rates > DIMINISH_RATE Hz, use randomness to achieve this.
1756 if (FrameTime < F1_0/DIMINISH_RATE) {
1757 if (d_rand() < FrameTime*DIMINISH_RATE/2) // Note: d_rand() is in 0..32767, and 8 Hz means decrement every frame
1760 dec_amount = f2i(FrameTime*DIMINISH_RATE); // one second = DIMINISH_RATE counts
1761 if (dec_amount == 0)
1762 dec_amount++; // make sure we decrement by something
1768 // Part of hack system to force update of palette after exiting a menu.
1769 if (Time_flash_last_played) {
1771 PaletteRedAdd ^= 1; // Very Tricky! In gr_palette_step_up, if all stepups same as last time, won't do anything!
1774 if ((Time_flash_last_played + F1_0/8 < GameTime) || (Time_flash_last_played > GameTime)) {
1775 digi_play_sample( SOUND_CLOAK_OFF, Flash_effect/4);
1776 Time_flash_last_played = GameTime;
1779 Flash_effect -= FrameTime;
1780 if (Flash_effect < 0)
1783 if (force_do || (d_rand() > 4096 )) {
1784 if ( (Newdemo_state==ND_STATE_RECORDING) && (PaletteRedAdd || PaletteGreenAdd || PaletteBlueAdd) )
1785 newdemo_record_palette_effect(PaletteRedAdd, PaletteGreenAdd, PaletteBlueAdd);
1787 game_palette_step_up( PaletteRedAdd, PaletteGreenAdd, PaletteBlueAdd );
1794 if (PaletteRedAdd > 0 ) { PaletteRedAdd -= dec_amount; if (PaletteRedAdd < 0 ) PaletteRedAdd = 0; }
1795 if (PaletteRedAdd < 0 ) { PaletteRedAdd += dec_amount; if (PaletteRedAdd > 0 ) PaletteRedAdd = 0; }
1797 if (PaletteGreenAdd > 0 ) { PaletteGreenAdd -= dec_amount; if (PaletteGreenAdd < 0 ) PaletteGreenAdd = 0; }
1798 if (PaletteGreenAdd < 0 ) { PaletteGreenAdd += dec_amount; if (PaletteGreenAdd > 0 ) PaletteGreenAdd = 0; }
1800 if (PaletteBlueAdd > 0 ) { PaletteBlueAdd -= dec_amount; if (PaletteBlueAdd < 0 ) PaletteBlueAdd = 0; }
1801 if (PaletteBlueAdd < 0 ) { PaletteBlueAdd += dec_amount; if (PaletteBlueAdd > 0 ) PaletteBlueAdd = 0; }
1803 if ( (Newdemo_state==ND_STATE_RECORDING) && (PaletteRedAdd || PaletteGreenAdd || PaletteBlueAdd) )
1804 newdemo_record_palette_effect(PaletteRedAdd, PaletteGreenAdd, PaletteBlueAdd);
1806 game_palette_step_up( PaletteRedAdd, PaletteGreenAdd, PaletteBlueAdd );
1808 //mprintf(0, "%2i %2i %2i\n", PaletteRedAdd, PaletteGreenAdd, PaletteBlueAdd);
1811 int Redsave, Bluesave, Greensave;
1813 void palette_save(void)
1815 Redsave = PaletteRedAdd; Bluesave = PaletteBlueAdd; Greensave = PaletteGreenAdd;
1818 extern void gr_palette_step_up_vr( int r, int g, int b, int white, int black );
1820 void game_palette_step_up( int r, int g, int b )
1822 if ( VR_use_reg_code ) {
1824 // gr_palette_step_up_vr( r, g, b, VR_WHITE_INDEX, VR_BLACK_INDEX );
1827 gr_palette_step_up( r, g, b );
1831 void palette_restore(void)
1833 PaletteRedAdd = Redsave; PaletteBlueAdd = Bluesave; PaletteGreenAdd = Greensave;
1834 game_palette_step_up( PaletteRedAdd, PaletteGreenAdd, PaletteBlueAdd );
1836 // Forces flash effect to fixup palette next frame.
1837 Time_flash_last_played = 0;
1840 extern void dead_player_frame(void);
1843 // --------------------------------------------------------------------------------------------------
1844 int allowed_to_fire_laser(void)
1846 if (Player_is_dead) {
1847 Global_missile_firing_count = 0;
1851 // Make sure enough time has elapsed to fire laser, but if it looks like it will
1852 // be a long while before laser can be fired, then there must be some mistake!
1853 if (Next_laser_fire_time > GameTime)
1854 if (Next_laser_fire_time < GameTime + 2*F1_0)
1860 fix Next_flare_fire_time = 0;
1861 #define FLARE_BIG_DELAY (F1_0*2)
1863 int allowed_to_fire_flare(void)
1865 if (Next_flare_fire_time > GameTime)
1866 if (Next_flare_fire_time < GameTime + FLARE_BIG_DELAY) // In case time is bogus, never wait > 1 second.
1869 if (Players[Player_num].energy >= Weapon_info[FLARE_ID].energy_usage)
1870 Next_flare_fire_time = GameTime + F1_0/4;
1872 Next_flare_fire_time = GameTime + FLARE_BIG_DELAY;
1877 int allowed_to_fire_missile(void)
1879 // mprintf(0, "Next fire = %7.3f, Cur time = %7.3f\n", f2fl(Next_missile_fire_time), f2fl(GameTime));
1880 // Make sure enough time has elapsed to fire missile, but if it looks like it will
1881 // be a long while before missile can be fired, then there must be some mistake!
1882 if (Next_missile_fire_time > GameTime)
1883 if (Next_missile_fire_time < GameTime + 5*F1_0)
1889 void full_palette_save(void)
1892 apply_modified_palette();
1893 reset_palette_add();
1894 gr_palette_load( gr_palette );
1897 extern int Death_sequence_aborted;
1898 extern int newmenu_dotiny2( char * title, char * subtitle, int nitems, newmenu_item * item, void (*subfunction)(int nitems,newmenu_item * items, int * last_key, int citem) );
1905 char command_help[64], pixel_double_help[64], save_help[64], restore_help[64];
1908 m[ 0].type = NM_TYPE_TEXT; m[ 0].text = TXT_HELP_ESC;
1910 m[ 1].type = NM_TYPE_TEXT; m[ 1].text = TXT_HELP_ALT_F2;
1911 m[ 2].type = NM_TYPE_TEXT; m[ 2].text = TXT_HELP_ALT_F3;
1913 sprintf(save_help, "OPT-F2 (%c-s)\t Save Game", 133);
1914 sprintf(restore_help, "OPT-F3 (%c-o)\t Load Game", 133);
1915 m[ 1].type = NM_TYPE_TEXT; m[1].text = save_help;
1916 m[ 2].type = NM_TYPE_TEXT; m[2].text = restore_help;
1918 m[ 3].type = NM_TYPE_TEXT; m[ 3].text = TXT_HELP_F2;
1919 m[ 4].type = NM_TYPE_TEXT; m[ 4].text = TXT_HELP_F3;
1920 m[ 5].type = NM_TYPE_TEXT; m[ 5].text = TXT_HELP_F4;
1921 m[ 6].type = NM_TYPE_TEXT; m[ 6].text = TXT_HELP_F5;
1923 m[ 7].type = NM_TYPE_TEXT; m[ 7].text = TXT_HELP_PAUSE;
1925 m[ 7].type = NM_TYPE_TEXT; m[ 7].text = "Pause (F15)\t Pause";
1927 m[ 8].type = NM_TYPE_TEXT; m[ 8].text = TXT_HELP_MINUSPLUS;
1929 m[ 9].type = NM_TYPE_TEXT; m[ 9].text = TXT_HELP_PRTSCN;
1931 m[ 9].type = NM_TYPE_TEXT; m[ 9].text = "printscrn (F13)\t save screen shot";
1933 m[10].type = NM_TYPE_TEXT; m[10].text = TXT_HELP_1TO5;
1934 m[11].type = NM_TYPE_TEXT; m[11].text = TXT_HELP_6TO10;
1935 m[12].type = NM_TYPE_TEXT; m[12].text = "Shift-F1\t Cycle left window";
1936 m[13].type = NM_TYPE_TEXT; m[13].text = "Shift-F2\t Cycle right window";
1937 m[14].type = NM_TYPE_TEXT; m[14].text = "Shift-F4\t GuideBot menu";
1939 m[15].type = NM_TYPE_TEXT; m[15].text = "Alt-Shift-F4\t Rename GuideBot";
1941 m[15].type = NM_TYPE_TEXT; m[15].text = "Opt-Shift-F4\t Rename GuideBot";
1943 m[16].type = NM_TYPE_TEXT; m[16].text = "Shift-F5\t Drop primary";
1944 m[17].type = NM_TYPE_TEXT; m[17].text = "Shift-F6\t Drop secondary";
1945 m[18].type = NM_TYPE_TEXT; m[18].text = "Shift-F7\t Calibrate joystick";
1946 m[19].type = NM_TYPE_TEXT; m[19].text = "Shift-number\t GuideBot commands";
1949 sprintf(pixel_double_help, "%c-D\t Toggle Pixel Double Mode", 133);
1950 m[20].type = NM_TYPE_TEXT; m[20].text = pixel_double_help;
1951 m[21].type = NM_TYPE_TEXT; m[21].text = "";
1952 sprintf(command_help, "(Use %c-# for F#. i.e. %c-1 for F1)", 133, 133);
1953 m[22].type = NM_TYPE_TEXT; m[22].text = command_help;
1957 full_palette_save();
1959 newmenu_dotiny2( NULL, TXT_KEYS, nitems, m, NULL );
1964 //temp function until Matt cleans up game sequencing
1965 extern void temp_reset_stuff_on_level();
1967 //deal with rear view - switch it on, or off, or whatever
1968 void check_rear_view()
1971 #define LEAVE_TIME 0x1000 //how long until we decide key is down (Used to be 0x4000)
1973 static int leave_mode;
1974 static fix entry_time;
1976 if ( Controls.rear_view_down_count ) { //key/button has gone down
1980 if (Cockpit_mode==CM_REAR_VIEW) {
1981 select_cockpit(Cockpit_mode_save);
1982 Cockpit_mode_save = -1;
1984 if (Newdemo_state == ND_STATE_RECORDING)
1985 newdemo_record_restore_rearview();
1989 leave_mode = 0; //means wait for another key
1990 entry_time = timer_get_fixed_seconds();
1991 if (Cockpit_mode == CM_FULL_COCKPIT) {
1992 Cockpit_mode_save = Cockpit_mode;
1993 select_cockpit(CM_REAR_VIEW);
1995 if (Newdemo_state == ND_STATE_RECORDING)
1996 newdemo_record_rearview();
2000 if (Controls.rear_view_down_state) {
2002 if (leave_mode==0 && (timer_get_fixed_seconds()-entry_time)>LEAVE_TIME)
2007 //@@if (leave_mode==1 && Cockpit_mode==CM_REAR_VIEW) {
2009 if (leave_mode==1 && Rear_view) {
2011 if (Cockpit_mode==CM_REAR_VIEW) {
2012 select_cockpit(Cockpit_mode_save);
2013 Cockpit_mode_save = -1;
2015 if (Newdemo_state == ND_STATE_RECORDING)
2016 newdemo_record_restore_rearview();
2021 void reset_rear_view(void)
2024 if (Newdemo_state == ND_STATE_RECORDING)
2025 newdemo_record_restore_rearview();
2030 if (!(Cockpit_mode == CM_FULL_COCKPIT || Cockpit_mode == CM_STATUS_BAR || Cockpit_mode == CM_FULL_SCREEN)) {
2031 if (!(Cockpit_mode_save == CM_FULL_COCKPIT || Cockpit_mode_save == CM_STATUS_BAR || Cockpit_mode_save == CM_FULL_SCREEN))
2032 Cockpit_mode_save = CM_FULL_COCKPIT;
2033 select_cockpit(Cockpit_mode_save);
2034 Cockpit_mode_save = -1;
2040 int Config_menu_flag;
2044 int Cheats_enabled=0;
2046 extern int Laser_rapid_fire;
2047 extern void do_lunacy_on(), do_lunacy_off();
2049 extern int Physics_cheat_flag,Robots_kill_robots_cheat;
2050 extern char BounceCheat,HomingCheat,OldHomingState[20];
2051 extern char AcidCheatOn,old_IntMethod, Monster_mode;
2052 extern int Buddy_dude_cheat;
2054 //turns off active cheats
2055 void turn_cheats_off()
2061 Weapon_info[i].homing_flag=OldHomingState[i];
2066 Interpolation_method=old_IntMethod;
2069 Buddy_dude_cheat = 0;
2073 Laser_rapid_fire = 0;
2074 Physics_cheat_flag = 0;
2076 Robots_kill_robots_cheat=0;
2077 Robot_firing_enabled = 1;
2080 //turns off all cheats & resets cheater flag
2081 void game_disable_cheats()
2089 // ----------------------------------------------------------------------------
2091 void game_setup(void)
2093 //@@int demo_playing=0;
2094 //@@int multi_game=0;
2096 do_lunacy_on(); // Copy values for insane into copy buffer in ai.c
2097 do_lunacy_off(); // Restore true insane mode.
2100 last_drawn_cockpit[0] = -1; // Force cockpit to redraw next time a frame renders.
2101 last_drawn_cockpit[1] = -1; // Force cockpit to redraw next time a frame renders.
2102 Endlevel_sequence = 0;
2104 //@@if ( Newdemo_state == ND_STATE_PLAYBACK )
2105 //@@ demo_playing = 1;
2106 //@@if ( Game_mode & GM_MULTI )
2107 //@@ multi_game = 1;
2109 set_screen_mode(SCREEN_GAME);
2110 reset_palette_add();
2112 set_warn_func(game_show_warning);
2116 //digi_init_sounds();
2118 //keyd_repeat = 0; // Don't allow repeat in game
2119 keyd_repeat = 1; // Do allow repeat in game
2121 #if !defined(WINDOWS) && !defined(MACINTOSH)
2122 //_MARK_("start of game");
2126 if (Segments[ConsoleObject->segnum].segnum == -1) //segment no longer exists
2127 obj_relink( ConsoleObject-Objects, SEG_PTR_2_NUM(Cursegp) );
2129 if (!check_obj_seg(ConsoleObject))
2130 move_player_2_segment(Cursegp,Curside);
2133 Viewer = ConsoleObject;
2134 fly_init(ConsoleObject);
2139 FrameTime = 0; //make first frame zero
2142 if (Current_level_num == 0) { //not a real level
2143 init_player_stats_game();
2150 game_flush_inputs();
2156 extern char IWasKicked;
2160 // ------------------------------------------------------------------------------------
2161 //this function is the game. called when game mode selected. runs until
2162 //editor mode or exit selected
2165 game_setup(); // Replaces what was here earlier.
2166 // Good for Windows Sake.
2169 ProfilerSetStatus(1);
2172 if ( setjmp(LeaveGame)==0 ) {
2178 Config_menu_flag = 0;
2180 if ( ConsoleObject != &Objects[Players[Player_num].objnum] )
2182 mprintf ((0,"Player_num=%d objnum=%d",Player_num,Players[Player_num].objnum));
2183 //Assert( ConsoleObject == &Objects[Players[Player_num].objnum] );
2186 player_shields = Players[Player_num].shields;
2191 DoMessageStuff(&msg); // Do Windows event handling.
2192 if (_RedrawScreen) {
2193 _RedrawScreen = FALSE;
2194 load_palette(Current_level_palette,1,1);
2195 gr_palette_load(gr_palette);
2200 ExtGameStatus=GAMESTAT_RUNNING;
2201 GameLoop( 1, 1 ); // Do game loop with rendering and reading controls.
2203 //if the player is taking damage, give up guided missile control
2204 if (Players[Player_num].shields != player_shields)
2205 release_guided_missile(Player_num);
2207 //see if redbook song needs to be restarted
2208 songs_check_redbook_repeat(); // Handle RedBook Audio Repeating.
2210 if (Config_menu_flag) {
2211 int double_save = Scanline_double;
2213 //WIN(mouse_set_mode(0));
2214 if (!(Game_mode&GM_MULTI)) {palette_save(); reset_palette_add(); apply_modified_palette(); gr_palette_load( gr_palette ); }
2216 if (Scanline_double != double_save) init_cockpit();
2217 if (!(Game_mode&GM_MULTI)) palette_restore();
2218 //WIN(mouse_set_mode(1));
2222 int save_w=Game_window_w,save_h=Game_window_h;
2224 Screen_mode=-1; set_screen_mode(SCREEN_GAME);
2225 Game_window_w=save_w; Game_window_h=save_h;
2227 last_drawn_cockpit[0] = -1;
2228 last_drawn_cockpit[1] = -1;
2231 if ( (Function_mode != FMODE_GAME) && Auto_demo && (Newdemo_state != ND_STATE_NORMAL) ) {
2233 fmode = Function_mode;
2234 Function_mode = FMODE_GAME;
2236 apply_modified_palette();
2237 reset_palette_add();
2238 gr_palette_load( gr_palette );
2239 choice=nm_messagebox( NULL, 2, TXT_YES, TXT_NO, TXT_ABORT_AUTODEMO );
2241 Function_mode = fmode;
2244 newdemo_stop_playback();
2245 Function_mode = FMODE_MENU;
2247 Function_mode = FMODE_GAME;
2251 if ( (Function_mode != FMODE_GAME ) && (Newdemo_state != ND_STATE_PLAYBACK ) && (Function_mode!=FMODE_EDITOR)
2257 fmode = Function_mode;
2258 Function_mode = FMODE_GAME;
2260 apply_modified_palette();
2261 reset_palette_add();
2262 gr_palette_load( gr_palette );
2263 ExtGameStatus=GAMESTAT_ABORT_GAME;
2264 choice=nm_messagebox( NULL, 2, TXT_YES, TXT_NO, TXT_ABORT_GAME );
2266 Function_mode = fmode;
2268 Function_mode = FMODE_GAME;
2274 if (Function_mode != FMODE_GAME)
2275 longjmp(LeaveGame,0);
2278 if ( (keyd_time_when_last_pressed + (F1_0 * 60)) < timer_get_fixed_seconds() ) // idle in game for 1 minutes means exit
2279 longjmp(LeaveGame,0);
2285 ProfilerSetStatus(0);
2290 if ( (Newdemo_state == ND_STATE_RECORDING) || (Newdemo_state == ND_STATE_PAUSED) )
2291 newdemo_stop_recording();
2297 if ( Newdemo_state == ND_STATE_PLAYBACK )
2298 newdemo_stop_playback();
2300 if (Cockpit_mode_save!=-1)
2302 Cockpit_mode=Cockpit_mode_save;
2303 Cockpit_mode_save=-1;
2306 if (Function_mode != FMODE_EDITOR)
2307 gr_palette_fade_out(gr_palette,32,0); // Fade out before going to menu
2309 //@@ if ( (!demo_playing) && (!multi_game) && (Function_mode != FMODE_EDITOR)) {
2310 //@@ scores_maybe_add_player(Game_aborted);
2313 #if !defined(WINDOWS) && !defined(MACINTOSH)
2314 //_MARK_("end of game");
2317 clear_warn_func(game_show_warning); //don't use this func anymore
2319 game_disable_cheats();
2322 Function_mode = FMODE_EXIT; // get out of game in Apple OEM version
2326 //called at the end of the program
2330 if (dd_VR_offscreen_buffer) {
2331 if (dd_grd_backcanv != dd_VR_offscreen_buffer) {
2332 dd_gr_free_canvas(dd_VR_offscreen_buffer);
2334 dd_VR_offscreen_buffer = NULL;
2335 VR_offscreen_buffer = NULL;
2338 if (VR_offscreen_buffer) {
2339 gr_free_canvas(VR_offscreen_buffer);
2340 VR_offscreen_buffer = NULL;
2344 close_gauge_canvases();
2346 restore_effect_bitmap_icons();
2348 #if !defined(MACINTOSH) && !defined(WINDOWS)
2349 if (Game_cockpit_copy_code) {
2350 d_free(Game_cockpit_copy_code);
2351 Game_cockpit_copy_code = NULL;
2354 if (Game_cockpit_copy_code)
2355 Game_cockpit_copy_code = 0;
2358 if (background_bitmap.bm_data)
2359 d_free(background_bitmap.bm_data);
2361 clear_warn_func(game_show_warning); //don't use this func anymore
2365 dd_grs_canvas * get_current_game_screen()
2367 return &dd_VR_screen_pages[VR_current_page];
2372 grs_canvas * get_current_game_screen()
2374 return &VR_screen_pages[VR_current_page];
2379 extern void kconfig_center_headset();
2383 void speedtest_frame(void);
2384 int Debug_slowdown=0;
2388 extern void player_follow_path(object *objp);
2389 extern void check_create_player_path(void);
2393 extern int Do_appearance_effect;
2395 object *Missile_viewer=NULL;
2397 int Missile_view_enabled = 1;
2399 int Marker_viewer_num[2]={-1,-1};
2400 int Coop_view_player[2]={-1,-1};
2401 int Cockpit_3d_view[2]={CV_NONE,CV_NONE};
2403 //returns ptr to escort robot, or NULL
2404 object *find_escort()
2408 for (i=0; i<=Highest_object_index; i++)
2409 if (Objects[i].type == OBJ_ROBOT)
2410 if (Robot_info[Objects[i].id].companion)
2416 extern void process_super_mines_frame(void);
2417 extern void do_seismic_stuff(void);
2420 int Saving_movie_frames=0;
2421 int __Movie_frame_num=0;
2423 #define MAX_MOVIE_BUFFER_FRAMES 250
2424 #define MOVIE_FRAME_SIZE (320 * 200)
2426 ubyte *Movie_frame_buffer;
2427 int Movie_frame_counter;
2428 ubyte Movie_pal[768];
2429 char movie_path[50] = ".\\";
2431 grs_bitmap Movie_bm;
2433 void flush_movie_buffer()
2440 mprintf((0,"Flushing movie buffer..."));
2442 Movie_bm.bm_data = Movie_frame_buffer;
2444 for (f=0;f<Movie_frame_counter;f++) {
2445 sprintf(savename, "%sfrm%04d.pcx",movie_path,__Movie_frame_num);
2446 __Movie_frame_num++;
2447 pcx_write_bitmap(savename,&Movie_bm,Movie_pal);
2448 Movie_bm.bm_data += MOVIE_FRAME_SIZE;
2451 mprintf((0,"%3d/%3d\10\10\10\10\10\10\10",f,Movie_frame_counter));
2454 Movie_frame_counter=0;
2456 mprintf((0,"done \n"));
2461 void toggle_movie_saving()
2465 Saving_movie_frames = !Saving_movie_frames;
2467 if (Saving_movie_frames) {
2470 m[0].type=NM_TYPE_INPUT; m[0].text_len = 50; m[0].text = movie_path;
2471 exit = newmenu_do( NULL, "Directory for movie frames?" , 1, &(m[0]), NULL );
2474 Saving_movie_frames = 0;
2478 while (isspace(movie_path[strlen(movie_path)-1]))
2479 movie_path[strlen(movie_path)-1] = 0;
2480 if (movie_path[strlen(movie_path)-1]!='\\' && movie_path[strlen(movie_path)-1]!=':')
2481 strcat(movie_path,"\\");
2484 if (!Movie_frame_buffer) {
2485 Movie_frame_buffer = d_malloc(MAX_MOVIE_BUFFER_FRAMES * MOVIE_FRAME_SIZE);
2486 if (!Movie_frame_buffer) {
2488 Saving_movie_frames=0;
2491 Movie_frame_counter=0;
2493 Movie_bm.bm_x = Movie_bm.bm_y = 0;
2494 Movie_bm.bm_w = 320;
2495 Movie_bm.bm_h = 200;
2496 Movie_bm.bm_type = BM_LINEAR;
2497 Movie_bm.bm_flags = 0;
2498 Movie_bm.bm_rowsize = 320;
2499 Movie_bm.bm_handle = 0;
2501 gr_palette_read(Movie_pal); //get actual palette from the hardware
2503 if (Newdemo_state == ND_STATE_PLAYBACK)
2504 Newdemo_do_interpolate = 0;
2508 flush_movie_buffer();
2510 if (Newdemo_state == ND_STATE_PLAYBACK)
2511 Newdemo_do_interpolate = 1;
2516 void save_movie_frame()
2518 memcpy(Movie_frame_buffer+Movie_frame_counter*MOVIE_FRAME_SIZE,grd_curscreen->sc_canvas.cv_bitmap.bm_data,MOVIE_FRAME_SIZE);
2520 Movie_frame_counter++;
2522 if (Movie_frame_counter == MAX_MOVIE_BUFFER_FRAMES)
2523 flush_movie_buffer();
2529 extern int Level_shake_duration;
2531 //if water or fire level, make occasional sound
2532 void do_ambient_sounds()
2534 int has_water,has_lava;
2537 has_lava = (Segment2s[ConsoleObject->segnum].s2_flags & S2F_AMBIENT_LAVA);
2538 has_water = (Segment2s[ConsoleObject->segnum].s2_flags & S2F_AMBIENT_WATER);
2540 if (has_lava) { //has lava
2541 sound = SOUND_AMBIENT_LAVA;
2542 if (has_water && (d_rand() & 1)) //both, pick one
2543 sound = SOUND_AMBIENT_WATER;
2545 else if (has_water) //just water
2546 sound = SOUND_AMBIENT_WATER;
2550 if (((d_rand() << 3) < FrameTime)) { //play the sound
2551 fix volume = d_rand() + f1_0/2;
2552 digi_play_sample(sound,volume);
2556 // -- extern void lightning_frame(void);
2558 void game_render_frame();
2559 extern void omega_charge_frame(void);
2561 extern time_t t_current_time, t_saved_time;
2563 void flicker_lights();
2565 void GameLoop(int RenderFlag, int ReadControlsFlag )
2569 // Used to slow down frame rate for testing things.
2570 // RenderFlag = 1; // DEBUG
2571 if (Debug_slowdown) {
2574 for (h=0; h<Debug_slowdown; h++)
2575 for (i=0; i<1000; i++)
2582 static int desc_dead_countdown=100; /* used if player shouldn't be playing */
2584 if (desc_id_exit_num) { // are we supposed to be checking
2585 if (!(--desc_dead_countdown)) {// if so, at zero, then pull the plug
2586 char time_str[32], time_str2[32];
2588 _ctime(&t_saved_time, time_str);
2589 _ctime(&t_current_time, time_str2);
2591 Error ("EXPIRES %s. YOUR TIME %s.\n", time_str, time_str2);
2592 Error ("Loading overlay -- error number: %d\n", (int)desc_id_exit_num);
2599 if (FindArg("-invulnerability"))
2600 Players[Player_num].flags |= PLAYER_FLAGS_INVULNERABLE;
2604 update_player_stats();
2605 diminish_palette_towards_normal(); // Should leave palette effect up for as long as possible by putting right before render.
2606 do_afterburner_stuff();
2608 do_invulnerable_stuff();
2609 remove_obsolete_stuck_objects();
2611 do_final_boss_frame();
2612 // -- lightning_frame();
2613 // -- recharge_energy_frame();
2615 if ((Players[Player_num].flags & PLAYER_FLAGS_HEADLIGHT) && (Players[Player_num].flags & PLAYER_FLAGS_HEADLIGHT_ON)) {
2616 static int turned_off=0;
2617 Players[Player_num].energy -= (FrameTime*3/8);
2618 if (Players[Player_num].energy < i2f(10)) {
2620 Players[Player_num].flags &= ~PLAYER_FLAGS_HEADLIGHT_ON;
2623 if (Game_mode & GM_MULTI)
2624 multi_send_flags(Player_num);
2631 if (Players[Player_num].energy <= 0) {
2632 Players[Player_num].energy = 0;
2633 Players[Player_num].flags &= ~PLAYER_FLAGS_HEADLIGHT_ON;
2635 if (Game_mode & GM_MULTI)
2636 multi_send_flags(Player_num);
2643 check_create_player_path();
2644 player_follow_path(ConsoleObject);
2648 if (Game_mode & GM_MULTI)
2651 if (Netgame.PlayTimeAllowed && ThisLevelTime>=i2f((Netgame.PlayTimeAllowed*5*60)))
2652 multi_check_for_killgoal_winner();
2658 if (force_cockpit_redraw) { //screen need redrawing?
2660 force_cockpit_redraw=0;
2662 game_render_frame();
2663 //show_extra_views(); //missile view, buddy bot, etc.
2666 if (Saving_movie_frames)
2673 //mprintf(0,"Velocity %2.2f\n", f2fl(vm_vec_mag(&ConsoleObject->phys_info.velocity)));
2677 dead_player_frame();
2678 if (Newdemo_state != ND_STATE_PLAYBACK)
2679 do_controlcen_dead_frame();
2681 process_super_mines_frame();
2683 do_ambient_sounds();
2690 if (ReadControlsFlag)
2693 memset(&Controls, 0, sizeof(Controls));
2695 GameTime += FrameTime;
2697 if (f2i(GameTime)/10 != f2i(GameTime-FrameTime)/10)
2698 mprintf((0,"Gametime = %d secs\n",f2i(GameTime)));
2700 if (GameTime < 0 || GameTime > i2f(0x7fff - 600)) {
2701 GameTime = FrameTime; //wrap when goes negative, or gets within 10 minutes
2702 mprintf((0,"GameTime reset to 0\n"));
2706 if (FindArg("-checktime") != 0)
2707 if (GameTime >= i2f(600)) //wrap after 10 minutes
2708 GameTime = FrameTime;
2712 if ((Game_mode & GM_MULTI) && Netgame.PlayTimeAllowed)
2713 ThisLevelTime +=FrameTime;
2718 if (Endlevel_sequence) {
2719 do_endlevel_frame();
2720 powerup_grab_cheat_all();
2721 do_special_effects();
2722 return; //skip everything else
2725 if (Newdemo_state != ND_STATE_PLAYBACK)
2726 do_exploding_wall_frame();
2727 if ((Newdemo_state != ND_STATE_PLAYBACK) || (Newdemo_vcr_state != ND_STATE_PAUSED)) {
2728 do_special_effects();
2729 wall_frame_process();
2730 triggers_frame_process();
2734 if (Control_center_destroyed) {
2735 if (Newdemo_state==ND_STATE_RECORDING )
2736 newdemo_record_control_center_destroyed();
2741 if ( Newdemo_state == ND_STATE_PLAYBACK ) {
2742 newdemo_playback_one_frame();
2743 if ( Newdemo_state != ND_STATE_PLAYBACK ) {
2744 longjmp( LeaveGame, 0 ); // Go back to menu
2747 { // Note the link to above!
2749 Players[Player_num].homing_object_dist = -1; // Assume not being tracked. Laser_do_weapon_sequence modifies this.
2752 powerup_grab_cheat_all();
2754 if (Endlevel_sequence) //might have been started during move
2757 fuelcen_update_all();
2761 if (allowed_to_fire_laser())
2762 FireLaser(); // Fire Laser!
2764 if (Auto_fire_fusion_cannon_time) {
2765 if (Primary_weapon != FUSION_INDEX)
2766 Auto_fire_fusion_cannon_time = 0;
2767 else if (GameTime + FrameTime/2 >= Auto_fire_fusion_cannon_time) {
2768 Auto_fire_fusion_cannon_time = 0;
2769 Global_laser_firing_count = 1;
2771 vms_vector rand_vec;
2774 Global_laser_firing_count = 0;
2776 ConsoleObject->mtype.phys_info.rotvel.x += (d_rand() - 16384)/8;
2777 ConsoleObject->mtype.phys_info.rotvel.z += (d_rand() - 16384)/8;
2778 make_random_vector(&rand_vec);
2780 bump_amount = F1_0*4;
2782 if (Fusion_charge > F1_0*2)
2783 bump_amount = Fusion_charge*4;
2785 bump_one_object(ConsoleObject, &rand_vec, bump_amount);
2789 if (Global_laser_firing_count) {
2790 // Don't cap here, gets capped in Laser_create_new and is based on whether in multiplayer mode, MK, 3/27/95
2791 // if (Fusion_charge > F1_0*2)
2792 // Fusion_charge = F1_0*2;
2793 Global_laser_firing_count -= do_laser_firing_player(); //do_laser_firing(Players[Player_num].objnum, Primary_weapon);
2796 if (Global_laser_firing_count < 0)
2797 Global_laser_firing_count = 0;
2800 if (Do_appearance_effect) {
2801 create_player_appearance_effect(ConsoleObject);
2802 Do_appearance_effect = 0;
2804 if ((Game_mode & GM_MULTI) && Netgame.invul)
2806 Players[Player_num].flags |= PLAYER_FLAGS_INVULNERABLE;
2807 Players[Player_num].invulnerable_time = GameTime-i2f(27);
2814 omega_charge_frame();
2818 //!!hoard_light_pulse(); //do cool hoard light pulsing
2822 //!!extern int Goal_blue_segnum,Goal_red_segnum;
2823 //!!extern int Hoard_goal_eclip;
2825 //!!//do cool pulsing lights in hoard goals
2826 //!!hoard_light_pulse()
2828 //!! if (Game_mode & GM_HOARD) {
2832 //!! frame = Effects[Hoard_goal_eclip].frame_count;
2836 //!! if (frame >= Effects[Hoard_goal_eclip].vc.num_frames)
2839 //!! light = abs(frame - 5) * f1_0 / 5;
2841 //!! Segment2s[Goal_red_segnum].static_light = Segment2s[Goal_blue_segnum].static_light = light;
2846 ubyte Slide_segs[MAX_SEGMENTS];
2847 int Slide_segs_computed;
2849 void compute_slide_segs(void)
2851 int segnum, sidenum;
2853 for (segnum=0;segnum<=Highest_segment_index;segnum++) {
2854 Slide_segs[segnum] = 0;
2855 for (sidenum=0;sidenum<6;sidenum++) {
2856 int tmn = Segments[segnum].sides[sidenum].tmap_num;
2857 if (TmapInfo[tmn].slide_u != 0 || TmapInfo[tmn].slide_v != 0)
2858 Slide_segs[segnum] |= 1 << sidenum;
2862 Slide_segs_computed = 1;
2865 // -----------------------------------------------------------------------------
2866 void slide_textures(void)
2868 int segnum,sidenum,i;
2870 if (!Slide_segs_computed)
2871 compute_slide_segs();
2873 for (segnum=0;segnum<=Highest_segment_index;segnum++) {
2874 if (Slide_segs[segnum]) {
2875 for (sidenum=0;sidenum<6;sidenum++) {
2876 if (Slide_segs[segnum] & (1 << sidenum)) {
2877 int tmn = Segments[segnum].sides[sidenum].tmap_num;
2878 if (TmapInfo[tmn].slide_u != 0 || TmapInfo[tmn].slide_v != 0) {
2880 Segments[segnum].sides[sidenum].uvls[i].u += fixmul(FrameTime,TmapInfo[tmn].slide_u<<8);
2881 Segments[segnum].sides[sidenum].uvls[i].v += fixmul(FrameTime,TmapInfo[tmn].slide_v<<8);
2882 if (Segments[segnum].sides[sidenum].uvls[i].u > f2_0) {
2885 Segments[segnum].sides[sidenum].uvls[j].u -= f1_0;
2887 if (Segments[segnum].sides[sidenum].uvls[i].v > f2_0) {
2890 Segments[segnum].sides[sidenum].uvls[j].v -= f1_0;
2892 if (Segments[segnum].sides[sidenum].uvls[i].u < -f2_0) {
2895 Segments[segnum].sides[sidenum].uvls[j].u += f1_0;
2897 if (Segments[segnum].sides[sidenum].uvls[i].v < -f2_0) {
2900 Segments[segnum].sides[sidenum].uvls[j].v += f1_0;
2910 flickering_light Flickering_lights[MAX_FLICKERING_LIGHTS];
2912 int Num_flickering_lights=0;
2914 void flicker_lights()
2917 flickering_light *f;
2919 f = Flickering_lights;
2921 for (l=0;l<Num_flickering_lights;l++,f++) {
2922 segment *segp = &Segments[f->segnum];
2924 //make sure this is actually a light
2925 if (! (WALL_IS_DOORWAY(segp, f->sidenum) & WID_RENDER_FLAG))
2927 if (! (TmapInfo[segp->sides[f->sidenum].tmap_num].lighting | TmapInfo[segp->sides[f->sidenum].tmap_num2 & 0x3fff].lighting))
2930 if (f->timer == 0x80000000) //disabled
2933 if ((f->timer -= FrameTime) < 0) {
2935 while (f->timer < 0)
2936 f->timer += f->delay;
2938 f->mask = ((f->mask&0x80000000)?1:0) + (f->mask<<1);
2941 add_light(f->segnum,f->sidenum);
2943 subtract_light(f->segnum,f->sidenum);
2948 //returns ptr to flickering light structure, or NULL if can't find
2949 flickering_light *find_flicker(int segnum,int sidenum)
2952 flickering_light *f;
2954 //see if there's already an entry for this seg/side
2956 f = Flickering_lights;
2958 for (l=0;l<Num_flickering_lights;l++,f++)
2959 if (f->segnum == segnum && f->sidenum == sidenum) //found it!
2965 //turn flickering off (because light has been turned off)
2966 void disable_flicker(int segnum,int sidenum)
2968 flickering_light *f;
2970 if ((f=find_flicker(segnum,sidenum)) != NULL)
2971 f->timer = 0x80000000;
2974 //turn flickering off (because light has been turned on)
2975 void enable_flicker(int segnum,int sidenum)
2977 flickering_light *f;
2979 if ((f=find_flicker(segnum,sidenum)) != NULL)
2986 //returns 1 if ok, 0 if error
2987 int add_flicker(int segnum,int sidenum,fix delay,ulong mask)
2990 flickering_light *f;
2992 mprintf((0,"add_flicker: %d:%d %x %x\n",segnum,sidenum,delay,mask));
2994 //see if there's already an entry for this seg/side
2996 f = Flickering_lights;
2998 for (l=0;l<Num_flickering_lights;l++,f++)
2999 if (f->segnum == segnum && f->sidenum == sidenum) //found it!
3002 if (mask==0) { //clearing entry
3003 if (l == Num_flickering_lights)
3007 for (i=l;i<Num_flickering_lights-1;i++)
3008 Flickering_lights[i] = Flickering_lights[i+1];
3009 Num_flickering_lights--;
3014 if (l == Num_flickering_lights)
3015 if (Num_flickering_lights == MAX_FLICKERING_LIGHTS)
3018 Num_flickering_lights++;
3021 f->sidenum = sidenum;
3022 f->delay = f->timer = delay;
3030 // -----------------------------------------------------------------------------
3031 // Fire Laser: Registers a laser fire, and performs special stuff for the fusion
3036 Global_laser_firing_count += Weapon_info[Primary_weapon_to_weapon_info[Primary_weapon]].fire_count * (Controls.fire_primary_state || Controls.fire_primary_down_count);
3038 if ((Primary_weapon == FUSION_INDEX) && (Global_laser_firing_count)) {
3039 if ((Players[Player_num].energy < F1_0*2) && (Auto_fire_fusion_cannon_time == 0)) {
3040 Global_laser_firing_count = 0;
3042 if (Fusion_charge == 0)
3043 Players[Player_num].energy -= F1_0*2;
3045 Fusion_charge += FrameTime;
3046 Players[Player_num].energy -= FrameTime;
3048 if (Players[Player_num].energy <= 0) {
3049 Players[Player_num].energy = 0;
3050 Auto_fire_fusion_cannon_time = GameTime -1; // Fire now!
3052 Auto_fire_fusion_cannon_time = GameTime + FrameTime/2 + 1;
3053 // Fire the fusion cannon at this time in the future.
3055 if (Fusion_charge < F1_0*2)
3056 PALETTE_FLASH_ADD(Fusion_charge >> 11, 0, Fusion_charge >> 11);
3058 PALETTE_FLASH_ADD(Fusion_charge >> 11, Fusion_charge >> 11, 0);
3060 if (GameTime < Fusion_last_sound_time) //gametime has wrapped
3061 Fusion_next_sound_time = Fusion_last_sound_time = GameTime;
3063 if (Fusion_next_sound_time < GameTime) {
3064 if (Fusion_charge > F1_0*2) {
3065 digi_play_sample( 11, F1_0 );
3066 apply_damage_to_player(ConsoleObject, ConsoleObject, d_rand() * 4);
3068 create_awareness_event(ConsoleObject, PA_WEAPON_ROBOT_COLLISION);
3069 digi_play_sample( SOUND_FUSION_WARMUP, F1_0 );
3071 if (Game_mode & GM_MULTI)
3072 multi_send_play_sound(SOUND_FUSION_WARMUP, F1_0);
3075 Fusion_last_sound_time = GameTime;
3076 Fusion_next_sound_time = GameTime + F1_0/8 + d_rand()/4;
3084 // -------------------------------------------------------------------------------------------------------
3085 // If player is close enough to objnum, which ought to be a powerup, pick it up!
3086 // This could easily be made difficulty level dependent.
3087 void powerup_grab_cheat(object *player, int objnum)
3093 Assert(Objects[objnum].type == OBJ_POWERUP);
3095 powerup_size = Objects[objnum].size;
3096 player_size = player->size;
3098 dist = vm_vec_dist_quick(&Objects[objnum].pos, &player->pos);
3100 if ((dist < 2*(powerup_size + player_size)) && !(Objects[objnum].flags & OF_SHOULD_BE_DEAD)) {
3101 vms_vector collision_point;
3103 vm_vec_avg(&collision_point, &Objects[objnum].pos, &player->pos);
3104 collide_player_and_powerup(player, &Objects[objnum], &collision_point);
3108 // -------------------------------------------------------------------------------------------------------
3109 // Make it easier to pick up powerups.
3110 // For all powerups in this segment, pick them up at up to twice pickuppable distance based on dot product
3111 // from player to powerup and player's forward vector.
3112 // This has the effect of picking them up more easily left/right and up/down, but not making them disappear
3113 // way before the player gets there.
3114 void powerup_grab_cheat_all(void)
3119 segp = &Segments[ConsoleObject->segnum];
3120 objnum = segp->objects;
3122 while (objnum != -1) {
3123 if (Objects[objnum].type == OBJ_POWERUP)
3124 powerup_grab_cheat(ConsoleObject, objnum);
3125 objnum = Objects[objnum].next;
3130 int Last_level_path_created = -1;
3132 #ifdef SHOW_EXIT_PATH
3134 // ------------------------------------------------------------------------------------------------------------------
3135 // Create path for player from current segment to goal segment.
3136 // Return true if path created, else return false.
3137 int mark_player_path_to_segment(int segnum)
3140 object *objp = ConsoleObject;
3141 short player_path_length=0;
3142 int player_hide_index=-1;
3144 if (Last_level_path_created == Current_level_num) {
3148 Last_level_path_created = Current_level_num;
3150 if (create_path_points(objp, objp->segnum, segnum, Point_segs_free_ptr, &player_path_length, 100, 0, 0, -1) == -1) {
3151 mprintf((0, "Unable to form path of length %i for myself\n", 100));
3155 player_hide_index = Point_segs_free_ptr - Point_segs;
3156 Point_segs_free_ptr += player_path_length;
3158 if (Point_segs_free_ptr - Point_segs + MAX_PATH_LENGTH*2 > MAX_POINT_SEGS) {
3159 mprintf((1, "Can't create path. Not enough point_segs.\n"));
3160 ai_reset_all_paths();
3164 for (i=1; i<player_path_length; i++) {
3166 vms_vector seg_center;
3169 segnum = Point_segs[player_hide_index+i].segnum;
3170 mprintf((0, "%3i ", segnum));
3171 seg_center = Point_segs[player_hide_index+i].point;
3173 objnum = obj_create( OBJ_POWERUP, POW_ENERGY, segnum, &seg_center, &vmd_identity_matrix, Powerup_info[POW_ENERGY].size, CT_POWERUP, MT_NONE, RT_POWERUP);
3175 Int3(); // Unable to drop energy powerup for path
3179 obj = &Objects[objnum];
3180 obj->rtype.vclip_info.vclip_num = Powerup_info[obj->id].vclip_num;
3181 obj->rtype.vclip_info.frametime = Vclip[obj->rtype.vclip_info.vclip_num].frame_time;
3182 obj->rtype.vclip_info.framenum = 0;
3183 obj->lifeleft = F1_0*100 + d_rand() * 4;
3190 // Return true if it happened, else return false.
3191 int create_special_path(void)
3195 // ---------- Find exit doors ----------
3196 for (i=0; i<=Highest_segment_index; i++)
3197 for (j=0; j<MAX_SIDES_PER_SEGMENT; j++)
3198 if (Segments[i].children[j] == -2) {
3199 mprintf((0, "Exit at segment %i\n", i));
3200 return mark_player_path_to_segment(i);
3210 int Max_obj_count_mike = 0;
3212 // Shows current number of used objects.
3213 void show_free_objects(void)
3215 if (!(FrameCount & 8)) {
3219 mprintf((0, "Highest_object_index = %3i, MAX_OBJECTS = %3i, now used = ", Highest_object_index, MAX_OBJECTS));
3221 for (i=0; i<=Highest_object_index; i++)
3222 if (Objects[i].type != OBJ_NONE)
3225 mprintf((0, "%3i", count));
3227 if (count > Max_obj_count_mike) {
3228 Max_obj_count_mike = count;
3229 mprintf((0, " ***"));
3240 void game_win_init_cockpit_mask(int sram)
3242 if (dd_VR_offscreen_buffer && dd_VR_offscreen_buffer != dd_grd_backcanv) {
3243 dd_gr_free_canvas(dd_VR_offscreen_buffer);
3246 if (GRMODEINFO(paged) && !GRMODEINFO(dbuf)) {
3247 // Here we will make the VR_offscreen_buffer the 2nd page and hopefully
3248 // we can just flip it, saving a blt.
3251 else if (GRMODEINFO(dbuf)||GRMODEINFO(emul)) {
3252 // The offscreen buffer will be created. We will just blt this
3253 // to the screen (which may be blted to the primary surface)
3254 if ( grd_curscreen->sc_h < 200 ) {
3255 dd_VR_offscreen_buffer = dd_gr_create_canvas(grd_curscreen->sc_w, 200);
3256 VR_offscreen_buffer = &dd_VR_offscreen_buffer->canvas;
3258 DDFreeSurface(dd_VR_offscreen_buffer->lpdds);
3259 dd_VR_offscreen_buffer->lpdds = DDCreateSysMemSurface(grd_curscreen->sc_w, 200);
3260 dd_VR_offscreen_buffer->sram = 1;
3264 dd_VR_offscreen_buffer = dd_gr_create_canvas(grd_curscreen->sc_w, grd_curscreen->sc_h);
3265 VR_offscreen_buffer = &dd_VR_offscreen_buffer->canvas;
3267 DDFreeSurface(dd_VR_offscreen_buffer->lpdds);
3268 dd_VR_offscreen_buffer->lpdds = DDCreateSysMemSurface(grd_curscreen->sc_w, grd_curscreen->sc_h);
3269 dd_VR_offscreen_buffer->sram = 1;
3274 dd_gr_init_sub_canvas( &dd_VR_render_buffer[0], dd_VR_offscreen_buffer, 0, 0, grd_curscreen->sc_w, grd_curscreen->sc_h );
3275 dd_gr_init_sub_canvas( &dd_VR_render_buffer[1], dd_VR_offscreen_buffer, 0, 0, grd_curscreen->sc_w, grd_curscreen->sc_h );
3276 gr_init_sub_canvas( &VR_render_buffer[0], VR_offscreen_buffer, 0, 0, grd_curscreen->sc_w, grd_curscreen->sc_h );
3277 gr_init_sub_canvas( &VR_render_buffer[1], VR_offscreen_buffer, 0, 0, grd_curscreen->sc_w, grd_curscreen->sc_h );
3279 game_init_render_sub_buffers( 0, 0, grd_curscreen->sc_w, grd_curscreen->sc_h );
3282 //@@void game_win_init_cockpit_mask()
3284 //@@ char title_pal[768];
3285 //@@ dd_grs_canvas ccanv;
3287 //@@ LPDIRECTDRAWSURFACE dds;
3289 //@@ dds = DDCreateSurface(GRMODEINFO(w), GRMODEINFO(h), 1);
3290 //@@ Assert(dds != NULL);
3292 //@@ _lpDDSMask = dds;
3293 //@@ ccanv.lpdds = dds;
3294 //@@ dd_gr_reinit_canvas(&ccanv);
3296 //@@ dd_gr_set_current_canvas(&ccanv);
3297 //@@ DDGRLOCK(dd_grd_curcanv)
3299 //@@ if (W95DisplayMode == SM95_640x480x8) {
3300 //@@ pcx_error=pcx_read_bitmap( "MASKB.PCX", &grd_curcanv->cv_bitmap,
3301 //@@ grd_curcanv->cv_bitmap.bm_type,
3305 //@@ pcx_error=pcx_read_bitmap( "MASK.PCX", &grd_curcanv->cv_bitmap,
3306 //@@ grd_curcanv->cv_bitmap.bm_type,
3310 //@@ DDGRUNLOCK(dd_grd_curcanv);
3312 //@@ Assert(pcx_error == PCX_ERROR_NONE);
3313 //@@ Game_cockpit_copy_code = (ubyte *)(0xABADC0DE);