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.4 2001-01-24 04:42:20 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"
112 #include "ogl_init.h"
115 int VGA_current_mode;
118 #include <profiler.h>
121 //#define TEST_TIMER 1 //if this is set, do checking on timer
123 #define SHOW_EXIT_PATH 1
126 #include "editor\editor.h"
131 #if __WATCOMC__ < 1000
132 #include <wsample.h> //should come after inferno.h to get mark setting
137 extern void ReadControls(void); // located in gamecntl.c
138 extern int Current_display_mode;
139 extern void do_final_boss_frame(void);
141 int Speedtest_on = 0;
144 int Mark_count = 0; // number of debugging marks set
145 int Speedtest_start_time;
146 int Speedtest_segnum;
147 int Speedtest_sidenum;
148 int Speedtest_frame_start;
149 int Speedtest_count=0; // number of times to do the debug test.
152 static fix last_timer_value=0;
155 #if defined(TIMER_TEST) && !defined(NDEBUG)
156 fix _timer_value,actual_last_timer_value,_last_frametime;
157 int stop_count,start_count;
158 int time_stopped,time_started;
162 ubyte * Game_cockpit_copy_code = NULL;
164 ubyte Game_cockpit_copy_code = 0;
165 ubyte Scanline_double = 1;
168 int VR_screen_mode = 0;
170 ubyte VR_screen_flags = 0; //see values in screens.h
171 ubyte VR_current_page = 0;
172 fix VR_eye_width = F1_0;
173 int VR_render_mode = VR_NONE;
174 int VR_low_res = 3; // Default to low res
176 int VR_sensitivity = 1; // 0 - 2
179 int VR_eye_offset = 0;
180 int VR_eye_switch = 0;
181 int VR_eye_offset_changed = 0;
182 int VR_use_reg_code = 0;
184 grs_canvas *VR_offscreen_buffer = NULL; // The offscreen data buffer
185 grs_canvas VR_render_buffer[2]; // Two offscreen buffers for left/right eyes.
186 grs_canvas VR_render_sub_buffer[2]; // Two sub buffers for left/right eyes.
187 grs_canvas VR_screen_pages[2]; // Two pages of VRAM if paging is available
188 grs_canvas VR_editor_canvas; // The canvas that the editor writes to.
191 //@@ LPDIRECTDRAWSURFACE _lpDDSMask = NULL;
192 dd_grs_canvas *dd_VR_offscreen_buffer = NULL;
193 dd_grs_canvas dd_VR_screen_pages[2];
194 dd_grs_canvas dd_VR_render_buffer[2];
195 dd_grs_canvas dd_VR_render_sub_buffer[2];
197 void game_win_init_cockpit_mask(int sram);
200 //do menus work in 640x480 or 320x200?
201 //PC version sets this in main(). Mac versios is always high-res, so set to 1 here
202 int MenuHiresAvailable = 1; //can we do highres menus?
203 int MenuHires = 1; //are we currently in highres menus?
205 int Debug_pause=0; //John's debugging pause system
207 int Cockpit_mode=CM_FULL_COCKPIT; //set game.h for values
209 int Cockpit_mode_save=-1; //set while in letterbox or rear view, or -1
210 int force_cockpit_redraw=0;
212 cvar_t r_framerate = {"r_framerate","0"};
214 int PaletteRedAdd, PaletteGreenAdd, PaletteBlueAdd;
216 // Toggle_var points at a variable which gets !ed on ctrl-alt-T press.
218 int *Toggle_var = &Dummy_var;
221 //flag for whether initial fade-in has been done
225 #ifndef NDEBUG //these only exist if debugging
227 int Game_double_buffer = 1; //double buffer by default
228 fix fixed_frametime=0; //if non-zero, set frametime to this
232 int Game_suspended=0; //if non-zero, nothing moves but player
235 fix Auto_fire_fusion_cannon_time = 0;
236 fix Fusion_charge = 0;
237 fix Fusion_next_sound_time = 0;
238 fix Fusion_last_sound_time = 0;
241 int Game_turbo_mode = 0;
243 int Game_mode = GM_GAME_OVER;
245 int Global_laser_firing_count = 0;
246 int Global_missile_firing_count = 0;
248 grs_bitmap background_bitmap;
252 #define BACKGROUND_NAME "statback.pcx"
254 // Function prototypes for GAME.C exclusively.
256 void GameLoop(int RenderFlag, int ReadControlsFlag);
257 void FireLaser(void);
258 void slide_textures(void);
259 void powerup_grab_cheat_all(void);
262 extern void multi_check_for_killgoal_winner();
263 extern void RestoreGameSurfaces();
267 void grow_window(void);
268 void shrink_window(void);
272 void fill_background();
275 void show_framerate(void);
276 void ftoa(char *string, fix f);
279 extern ubyte DefiningMarkerMessage;
280 extern char Marker_input[];
282 // ==============================================================================================
284 extern char john_head_on;
286 void load_background_bitmap()
291 if (background_bitmap.bm_data)
292 d_free(background_bitmap.bm_data);
294 background_bitmap.bm_data=NULL;
295 pcx_error = pcx_read_bitmap(john_head_on?"johnhead.pcx":BACKGROUND_NAME,&background_bitmap,BM_LINEAR,pal);
296 if (pcx_error != PCX_ERROR_NONE)
297 Error("File %s - PCX error: %s",BACKGROUND_NAME,pcx_errormsg(pcx_error));
298 gr_remap_bitmap_good( &background_bitmap, pal, -1, -1 );
302 //this is called once per game
305 atexit(close_game); //for cleanup
309 init_special_effects();
313 init_gauge_canvases();
315 init_exploding_walls();
317 load_background_bitmap();
319 Clear_window = 2; // do portal only window clear.
321 set_detail_level_parameters(Detail_level);
323 build_mission_list(0); // This also loads mission 0.
326 cvar_registervariable(&r_framerate);
331 void reset_palette_add()
336 //gr_palette_step_up( PaletteRedAdd, PaletteGreenAdd, PaletteBlueAdd );
341 void win_get_span_list(grs_bitmap *bm, int miny, int maxy)
347 int lspan=0, rspan=0, span=0;
351 //@@ fp = fopen("cockspan.dat", "w");
353 for (y = 0; y < miny; y++)
354 win_cockpit_mask[y].num = 0;
356 for (y = miny; y <= maxy; y++)
359 //@@ fprintf(fp, "line %d: ", y);
360 for (x = 0; x < bm->bm_w; x++)
362 offset = y*bm->bm_rowsize + x;
364 if (data[offset] == 255) {
367 case 0: // Start Mode
369 win_cockpit_mask[y].span[span].xmin = x;
371 //@@ fprintf(fp, "<%d,", lspan);
374 case 1: // Transparency mode
376 win_cockpit_mask[y].span[span].xmax = x;
379 case 2: // Switch from Draw mode to transparent
381 win_cockpit_mask[y].span[span].xmin = x;
382 //@@ fprintf(fp, "<%d,", lspan);
390 case 0: // Start mode
394 case 1: // Switching from transparent to Draw
397 win_cockpit_mask[y].span[span].xmax = x;
399 //@@ fprintf(fp, "%d> ", rspan);
408 //@@ fprintf(fp, "%d> ", rspan);
409 win_cockpit_mask[y].span[span].xmax = rspan;
412 win_cockpit_mask[y].num = span;
413 //@@ fprintf(fp, "\n");
416 win_cockpit_mask[y].num = 255;
421 void game_show_warning(char *s)
424 if (!((Game_mode & GM_MULTI) && (Function_mode == FMODE_GAME)))
427 nm_messagebox( TXT_WARNING, 1, TXT_OK, s );
429 if (!((Game_mode & GM_MULTI) && (Function_mode == FMODE_GAME)))
434 //these should be in gr.h
435 #define cv_w cv_bitmap.bm_w
436 #define cv_h cv_bitmap.bm_h
438 int Game_window_x = 0;
439 int Game_window_y = 0;
440 int Game_window_w = 0;
441 int Game_window_h = 0;
442 int max_window_w = 0;
443 int max_window_h = 0;
445 extern void newdemo_record_cockpit_change(int);
447 //initialize the various canvases on the game screen
448 //called every time the screen mode or cockpit changes
451 int minx, maxx, miny, maxy;
453 #if defined(POLY_ACC)
454 pa_flush(); // get rid of undrawn polys.
455 pa_clear_buffer(1, 0);
458 //Initialize the on-screen canvases
460 if (Newdemo_state==ND_STATE_RECORDING)
463 newdemo_record_cockpit_change(Cockpit_mode);
466 if ( VR_render_mode != VR_NONE )
467 Cockpit_mode = CM_FULL_SCREEN;
469 if (!(VR_screen_flags & VRF_ALLOW_COCKPIT) && (Cockpit_mode==CM_FULL_COCKPIT || Cockpit_mode==CM_STATUS_BAR || Cockpit_mode==CM_REAR_VIEW) )
470 Cockpit_mode = CM_FULL_SCREEN;
472 if ( Screen_mode == SCREEN_EDITOR )
473 Cockpit_mode = CM_FULL_SCREEN;
476 dd_gr_set_current_canvas(NULL),
477 gr_set_current_canvas(NULL)
479 gr_set_curfont( GAME_FONT );
481 #if !defined(MACINTOSH) && !defined(WINDOWS)
482 if (Game_cockpit_copy_code)
483 d_free(Game_cockpit_copy_code);
484 Game_cockpit_copy_code = NULL;
486 if (Game_cockpit_copy_code)
487 Game_cockpit_copy_code = 0;
491 //@@ if (_lpDDSMask) { DDFreeSurface(_lpDDSMask); _lpDDSMask = NULL; }
495 game_win_init_cockpit_mask(0);
498 switch( Cockpit_mode )
500 case CM_FULL_COCKPIT:
502 grs_bitmap *bm = &GameBitmaps[cockpit_bitmap[Cockpit_mode+(Current_display_mode?(Num_cockpits/2):0)].index];
504 PIGGY_PAGE_IN(cockpit_bitmap[Cockpit_mode+(Current_display_mode?(Num_cockpits/2):0)]);
507 dd_gr_set_current_canvas(NULL);
508 game_win_init_cockpit_mask(1);
509 dd_gr_set_current_canvas(dd_VR_offscreen_buffer);
511 gr_set_current_canvas(VR_offscreen_buffer)
514 WIN(DDGRLOCK(dd_grd_curcanv));
515 gr_bitmap( 0, 0, bm );
516 bm = &VR_offscreen_buffer->cv_bitmap;
517 bm->bm_flags = BM_FLAG_TRANSPARENT;
518 gr_ibitblt_find_hole_size ( bm, &minx, &miny, &maxx, &maxy );
519 WIN( win_get_span_list(bm, miny, maxy);
520 DDGRUNLOCK(dd_grd_curcanv)
524 #if 1 // def MACINTOSH
525 gr_ibitblt_create_mask( bm, minx, miny, maxx-minx+1, maxy-miny+1, VR_offscreen_buffer->cv_bitmap.bm_rowsize);
527 if ( Current_display_mode )
529 #if defined(POLY_ACC)
530 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 );
531 pa_clear_buffer(1, 0); // clear offscreen to reduce white flash.
533 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 );
536 Game_cockpit_copy_code = gr_ibitblt_create_mask( bm, minx, miny, maxx-minx+1, maxy-miny+1, VR_offscreen_buffer->cv_bitmap.bm_rowsize );
538 bm->bm_flags = 0; // Clear all flags for offscreen canvas
540 Game_cockpit_copy_code = (ubyte *)(1);
541 bm->bm_flags = 0; // Clear all flags for offscreen canvas
543 game_init_render_sub_buffers( 0, 0, maxx-minx+1, maxy-miny+1 );
549 max_window_h = grd_curscreen->sc_h;
551 if (Game_window_h > max_window_h || VR_screen_flags&VRF_ALLOW_COCKPIT)
552 Game_window_h = max_window_h;
554 if (Game_window_w > max_window_w || VR_screen_flags&VRF_ALLOW_COCKPIT)
555 Game_window_w = max_window_w;
557 Game_window_x = (max_window_w - Game_window_w)/2;
558 Game_window_y = (max_window_h - Game_window_h)/2;
560 game_init_render_sub_buffers( Game_window_x, Game_window_y, Game_window_w, Game_window_h );
565 max_window_h = grd_curscreen->sc_h - GameBitmaps[cockpit_bitmap[CM_STATUS_BAR+(Current_display_mode?(Num_cockpits/2):0)].index].bm_h;
567 if (Game_window_h > max_window_h)
568 Game_window_h = max_window_h;
570 if (Game_window_w > max_window_w)
571 Game_window_w = max_window_w;
573 Game_window_x = (max_window_w - Game_window_w)/2;
574 Game_window_y = (max_window_h - Game_window_h)/2;
576 game_init_render_sub_buffers( Game_window_x, Game_window_y, Game_window_w, Game_window_h );
582 x = 0; w = VR_render_buffer[0].cv_bitmap.bm_w; //VR_render_width;
583 h = (VR_render_buffer[0].cv_bitmap.bm_h * 7) / 10;
584 y = (VR_render_buffer[0].cv_bitmap.bm_h-h)/2;
586 game_init_render_sub_buffers( x, y, w, h );
593 dd_gr_set_current_canvas(NULL),
594 gr_set_current_canvas(NULL)
598 //selects a given cockpit (or lack of one). See types in game.h
599 void select_cockpit(int mode)
601 if (mode != Cockpit_mode) { //new mode
607 extern int last_drawn_cockpit[2];
609 //force cockpit redraw next time. call this if you've trashed the screen
612 force_cockpit_redraw=1;
613 last_drawn_cockpit[0] = -1;
614 last_drawn_cockpit[1] = -1;
617 // void HUD_clear_messages(); //Already declared in gauges.h
620 void VR_reset_params()
622 VR_eye_width = VR_SEPARATION;
623 VR_eye_offset = VR_PIXEL_SHIFT;
624 VR_eye_offset_changed = 2;
627 void game_init_render_sub_buffers( int x, int y, int w, int h )
630 dd_gr_init_sub_canvas( &dd_VR_render_sub_buffer[0], &dd_VR_render_buffer[0], x, y, w, h );
631 dd_gr_init_sub_canvas( &dd_VR_render_sub_buffer[1], &dd_VR_render_buffer[1], x, y, w, h );
633 dd_VR_render_sub_buffer[0].canvas.cv_bitmap.bm_x = 0;
634 dd_VR_render_sub_buffer[0].canvas.cv_bitmap.bm_y = 0;
635 dd_VR_render_sub_buffer[0].xoff = x;
636 dd_VR_render_sub_buffer[0].yoff = y;
637 dd_VR_render_sub_buffer[1].canvas.cv_bitmap.bm_x = 0;
638 dd_VR_render_sub_buffer[1].canvas.cv_bitmap.bm_y = 0;
639 dd_VR_render_sub_buffer[1].xoff = x;
640 dd_VR_render_sub_buffer[1].yoff = y;
643 if (Scanline_double) {
647 gr_init_sub_canvas( &VR_render_sub_buffer[0], &VR_render_buffer[0], x, y, w/2, (h/2)+1);
648 gr_init_sub_canvas( &VR_render_sub_buffer[1], &VR_render_buffer[1], x, y, w/2, (h/2)+1);
651 gr_init_sub_canvas( &VR_render_sub_buffer[0], &VR_render_buffer[0], x, y, w, h );
652 gr_init_sub_canvas( &VR_render_sub_buffer[1], &VR_render_buffer[1], x, y, w, h );
662 newBounds.right = x + w;
664 newBounds.bottom = y + h;
666 pa_set_context(kGamePlayDrawContextID, &newBounds); // must resize/create new context
672 VR_render_sub_buffer[0].cv_bitmap.bm_x = 0;
673 VR_render_sub_buffer[0].cv_bitmap.bm_y = 0;
674 VR_render_sub_buffer[1].cv_bitmap.bm_x = 0;
675 VR_render_sub_buffer[1].cv_bitmap.bm_y = 0;
681 // Sets up the canvases we will be rendering to (WIN95)
682 void game_init_render_buffers(int screen_mode, int render_w, int render_h, int render_method, int flags )
684 // Hack for switching to higher that 640x480 modes (DDraw doesn't allow
685 // creating surfaces greater than the current resolution
687 if (GRMODEINFO(rw) < render_w || GRMODEINFO(rh) < render_h) {
688 render_w = GRMODEINFO(rw);
689 render_h = GRMODEINFO(rh);
692 VR_screen_mode = screen_mode;
694 VR_screen_flags = flags;
697 VR_render_mode = render_method;
699 Game_window_w = render_w;
700 Game_window_h = render_h;
702 if (dd_VR_offscreen_buffer && dd_VR_offscreen_buffer != dd_grd_backcanv) {
703 dd_gr_free_canvas(dd_VR_offscreen_buffer);
706 if ( (VR_render_mode==VR_AREA_DET) || (VR_render_mode==VR_INTERLACED ) ) {
707 if ( render_h*2 < 200 ) {
708 Int3(); // Not Supported yet!!!
709 // VR_offscreen_buffer = gr_create_canvas( render_w, 200 );
712 Int3(); // Not Supported yet!!!
713 // VR_offscreen_buffer = gr_create_canvas( render_w, render_h*2 );
716 Int3(); // Not Supported yet!!!
717 // gr_init_sub_canvas( &VR_render_buffer[0], VR_offscreen_buffer, 0, 0, render_w, render_h );
718 // gr_init_sub_canvas( &VR_render_buffer[1], VR_offscreen_buffer, 0, render_h, render_w, render_h );
720 else if (GRMODEINFO(paged) && !GRMODEINFO(dbuf)) {
721 // Here we will make the VR_offscreen_buffer the 2nd page and hopefully
722 // we can just flip it, saving a blt.
724 dd_VR_offscreen_buffer = dd_grd_backcanv;
725 VR_offscreen_buffer = & dd_grd_backcanv->canvas;
727 else if (GRMODEINFO(dbuf)||GRMODEINFO(emul)) {
728 // The offscreen buffer will be created. We will just blt this
729 // to the screen (which may be blted to the primary surface)
730 if ( render_h < 200 ) {
731 dd_VR_offscreen_buffer = dd_gr_create_canvas(render_w, 200);
732 VR_offscreen_buffer = &dd_VR_offscreen_buffer->canvas;
735 dd_VR_offscreen_buffer = dd_gr_create_canvas(render_w, render_h);
736 VR_offscreen_buffer = &dd_VR_offscreen_buffer->canvas;
740 dd_gr_init_sub_canvas( &dd_VR_render_buffer[0], dd_VR_offscreen_buffer, 0, 0, render_w, render_h );
741 dd_gr_init_sub_canvas( &dd_VR_render_buffer[1], dd_VR_offscreen_buffer, 0, 0, render_w, render_h );
742 gr_init_sub_canvas( &VR_render_buffer[0], VR_offscreen_buffer, 0, 0, render_w, render_h );
743 gr_init_sub_canvas( &VR_render_buffer[1], VR_offscreen_buffer, 0, 0, render_w, render_h );
745 game_init_render_sub_buffers( 0, 0, render_w, render_h );
750 // Sets up the canvases we will be rendering to (NORMAL VERSION)
751 void game_init_render_buffers(int screen_mode, int render_w, int render_h, int render_method, int flags )
753 // if (vga_check_mode(screen_mode) != 0)
754 // Error("Cannot set requested video mode");
756 VR_screen_mode = screen_mode;
758 VR_screen_flags = flags;
762 VR_render_mode = render_method;
764 Game_window_w = render_w;
765 Game_window_h = render_h;
767 if (VR_offscreen_buffer) {
768 gr_free_canvas(VR_offscreen_buffer);
771 if ( (VR_render_mode==VR_AREA_DET) || (VR_render_mode==VR_INTERLACED ) ) {
772 if ( render_h*2 < 200 ) {
773 VR_offscreen_buffer = gr_create_canvas( render_w, 200 );
776 VR_offscreen_buffer = gr_create_canvas( render_w, render_h*2 );
779 gr_init_sub_canvas( &VR_render_buffer[0], VR_offscreen_buffer, 0, 0, render_w, render_h );
780 gr_init_sub_canvas( &VR_render_buffer[1], VR_offscreen_buffer, 0, render_h, render_w, render_h );
783 if ( render_h < 200 ) {
784 VR_offscreen_buffer = gr_create_canvas( render_w, 200 );
787 #if defined(POLY_ACC)
789 VR_offscreen_buffer = gr_create_canvas( render_w, render_h );
790 d_free(VR_offscreen_buffer->cv_bitmap.bm_data);
791 gr_init_canvas(VR_offscreen_buffer, pa_get_buffer_address(1), BM_LINEAR15, render_w, render_h);
793 if ( PAEnabled || gConfigInfo.mAcceleration ) {
794 Cockpit_mode=CM_FULL_SCREEN; // HACK HACK HACK HACK HACK!!!!
795 VR_offscreen_buffer = gr_create_canvas2(render_w, render_h, BM_LINEAR15);
797 VR_offscreen_buffer = gr_create_canvas( render_w, render_h );
800 VR_offscreen_buffer = gr_create_canvas( render_w, render_h );
805 VR_offscreen_buffer->cv_bitmap.bm_type = BM_OGL;
808 gr_init_sub_canvas( &VR_render_buffer[0], VR_offscreen_buffer, 0, 0, render_w, render_h );
809 gr_init_sub_canvas( &VR_render_buffer[1], VR_offscreen_buffer, 0, 0, render_w, render_h );
812 game_init_render_sub_buffers( 0, 0, render_w, render_h );
816 //called to get the screen in a mode compatible with popup menus.
817 //if we can't have popups over the game screen, switch to menu mode.
818 void set_popup_screen(void)
820 //WIN(LoadCursorWin(MOUSE_DEFAULT_CURSOR));
822 if (! (VR_screen_flags & VRF_COMPATIBLE_MENUS))
823 set_screen_mode(SCREEN_MENU); //must switch to menu mode
827 //called to change the screen mode. Parameter sm is the new mode, one of
828 //SMODE_GAME or SMODE_EDITOR. returns mode acutally set (could be other
829 //mode if cannot init requested mode)
830 int set_screen_mode(int sm)
832 WIN(static int force_mode_change=0);
833 WIN(static int saved_window_w);
834 WIN(static int saved_window_h);
837 if ( (sm==SCREEN_MENU) && (Screen_mode==SCREEN_EDITOR) ) {
838 gr_set_current_canvas( Canv_editor );
844 if ( Screen_mode == sm && W95DisplayMode == VR_screen_mode) {
845 dd_gr_set_current_canvas( &dd_VR_screen_pages[VR_current_page] );
849 if ( Screen_mode == sm && VGA_current_mode == VR_screen_mode) {
850 gr_set_current_canvas( &VR_screen_pages[VR_current_page] );
856 if ((Screen_mode == sm) && !((sm==SCREEN_GAME) && (grd_curscreen->sc_mode != VR_screen_mode) && (Screen_mode == SCREEN_GAME))) {
858 gr_set_current_canvas( &VR_screen_pages[VR_current_page] );
859 ogl_set_screen_mode();
870 switch( Screen_mode )
876 if (!(VR_screen_flags & VRF_COMPATIBLE_MENUS)) {
877 // HACK!!! Meant to save window size when switching from
878 // non-compat menu mode to menu mode.
879 saved_window_w = Game_window_w;
880 saved_window_h = Game_window_h;
881 force_mode_change = 1;
883 if (W95DisplayMode != SM95_640x480x8) {
884 //@@ piggy_bitmap_page_out_all_w(); // 2D GFX Flush cache.
885 DDSETDISPLAYMODE(SM95_640x480x8);
887 if (!gr_palette_faded_out) gr_palette_load(gr_palette);
890 dd_gr_init_sub_canvas(&dd_VR_screen_pages[0], dd_grd_screencanv,
892 dd_grd_screencanv->canvas.cv_bitmap.bm_w,
893 dd_grd_screencanv->canvas.cv_bitmap.bm_h);
894 dd_gr_init_sub_canvas(&dd_VR_screen_pages[1], dd_grd_screencanv,
896 dd_grd_screencanv->canvas.cv_bitmap.bm_w,
897 dd_grd_screencanv->canvas.cv_bitmap.bm_h);
905 MenuHires = MenuHiresAvailable; //do highres if we can
907 #if defined(POLY_ACC)
909 menu_mode = MenuHires?SM(640,480):SM(320,200);
911 menu_mode = PAEnabled?SM_640x480x15xPA:SM_640x480V;
914 menu_mode = MenuHires?SM(640,480):SM(320,200);
917 if (VGA_current_mode != menu_mode) {
918 if (gr_set_mode(menu_mode))
919 Error("Cannot set screen mode for menu");
920 if (!gr_palette_faded_out)
921 gr_palette_load(gr_palette);
924 gr_init_sub_canvas( &VR_screen_pages[0], &grd_curscreen->sc_canvas, 0, 0, grd_curscreen->sc_w, grd_curscreen->sc_h );
925 gr_init_sub_canvas( &VR_screen_pages[1], &grd_curscreen->sc_canvas, 0, 0, grd_curscreen->sc_w, grd_curscreen->sc_h );
927 FontHires = MenuHires;
937 if (force_mode_change || (W95DisplayMode != VR_screen_mode)) {
939 DDSETDISPLAYMODE(VR_screen_mode);
940 //@@ piggy_bitmap_page_out_all_w(); // 2D GFX Flush cache.
942 mprintf((0, "Reinitializing render buffers due to display mode change.\n"));
943 game_init_render_buffers(W95DisplayMode,
944 GRMODEINFO(rw), GRMODEINFO(rh),
945 VR_render_mode, VR_screen_flags);
950 if (VGA_current_mode != VR_screen_mode) {
951 if (gr_set_mode(VR_screen_mode)) {
952 Error("Cannot set desired screen mode for game!");
953 //we probably should do something else here, like select a standard mode
956 if ( (Config_control_type == 1) && (Function_mode == FMODE_GAME) )
963 if ( VR_render_mode == VR_NONE )
965 max_window_w = grd_curscreen->sc_w;
966 max_window_h = grd_curscreen->sc_h;
968 if (VR_screen_flags & VRF_ALLOW_COCKPIT) {
969 if (Cockpit_mode == CM_STATUS_BAR)
970 max_window_h = grd_curscreen->sc_h - GameBitmaps[cockpit_bitmap[CM_STATUS_BAR+(Current_display_mode?(Num_cockpits/2):0)].index].bm_h;
972 else if (Cockpit_mode != CM_LETTERBOX)
973 Cockpit_mode = CM_FULL_SCREEN;
975 if (Game_window_h==0 || Game_window_h > max_window_h || Game_window_w==0 || Game_window_w > max_window_w) {
976 Game_window_w = max_window_w;
977 Game_window_h = max_window_h;
982 Cockpit_mode = CM_FULL_SCREEN;
985 // Super hack. If we are switching from a 320x200 game to 640x480.
986 // and we were in a menumode when switching, we don't
987 // restore Game_window vals
988 if (force_mode_change && (W95DisplayMode == SM95_320x200x8X)) {
989 Game_window_w = saved_window_w;
990 Game_window_h = saved_window_h;
991 force_mode_change = 0;
996 // Define screen pages for game mode
997 // If we designate through screen_flags to use paging, then do so.
999 dd_gr_init_sub_canvas( &dd_VR_screen_pages[0], dd_grd_screencanv, 0, 0, grd_curscreen->sc_w, grd_curscreen->sc_h ),
1000 gr_init_sub_canvas( &VR_screen_pages[0], &grd_curscreen->sc_canvas, 0, 0, grd_curscreen->sc_w, grd_curscreen->sc_h )
1003 if ( VR_screen_flags&VRF_USE_PAGING ) {
1005 dd_gr_init_sub_canvas( &dd_VR_screen_pages[1], dd_grd_backcanv, 0, 0, grd_curscreen->sc_w, grd_curscreen->sc_h ),
1006 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 )
1011 dd_gr_init_sub_canvas( &dd_VR_screen_pages[1], dd_grd_screencanv, 0, 0, grd_curscreen->sc_w, grd_curscreen->sc_h ),
1012 gr_init_sub_canvas( &VR_screen_pages[1], &grd_curscreen->sc_canvas, 0, 0, grd_curscreen->sc_w, grd_curscreen->sc_h )
1019 FontHires = (Current_display_mode != 0);
1022 FontHires = MenuHires = ((Current_display_mode != 0) && (Current_display_mode != 2));
1025 if ( VR_render_mode != VR_NONE ) {
1026 // for 640x480 or higher, use hires font.
1027 if ( grd_curscreen->sc_h > 400 )
1036 if (VGA_current_mode != SM_800x600V) {
1038 if ((gr_error=gr_set_mode(SM_800x600V))!=0) { //force into game scrren
1039 Warning("Cannot init editor screen (error=%d)",gr_error);
1043 gr_palette_load( gr_palette );
1045 gr_init_sub_canvas( &VR_editor_canvas, &grd_curscreen->sc_canvas, 0, 0, grd_curscreen->sc_w, grd_curscreen->sc_h );
1046 Canv_editor = &VR_editor_canvas;
1047 gr_init_sub_canvas( &VR_screen_pages[0], Canv_editor, 0, 0, Canv_editor->cv_w, Canv_editor->cv_h );
1048 gr_init_sub_canvas( &VR_screen_pages[1], Canv_editor, 0, 0, Canv_editor->cv_w, Canv_editor->cv_h );
1049 gr_set_current_canvas( Canv_editor );
1050 init_editor_screen(); //setup other editor stuff
1054 Error("Invalid screen mode %d",sm);
1057 VR_current_page = 0;
1060 dd_gr_set_current_canvas(&dd_VR_screen_pages[VR_current_page]),
1061 gr_set_current_canvas( &VR_screen_pages[VR_current_page] )
1064 if ( VR_screen_flags&VRF_USE_PAGING ) {
1067 gr_show_canvas( &VR_screen_pages[VR_current_page] )
1071 ogl_set_screen_mode();
1077 static int timer_paused=0;
1081 if (timer_paused==0) {
1083 time = timer_get_fixed_seconds();
1084 last_timer_value = time - last_timer_value;
1085 if (last_timer_value < 0) {
1086 #if defined(TIMER_TEST) && !defined(NDEBUG)
1087 Int3(); //get Matt!!!!
1089 last_timer_value = 0;
1091 #if defined(TIMER_TEST) && !defined(NDEBUG)
1092 time_stopped = time;
1097 #if defined(TIMER_TEST) && !defined(NDEBUG)
1105 Assert(timer_paused >= 0);
1106 if (timer_paused==0) {
1108 time = timer_get_fixed_seconds();
1109 #if defined(TIMER_TEST) && !defined(NDEBUG)
1110 if (last_timer_value < 0)
1111 Int3(); //get Matt!!!!
1114 last_timer_value = time - last_timer_value;
1115 #if defined(TIMER_TEST) && !defined(NDEBUG)
1116 time_started = time;
1120 #if defined(TIMER_TEST) && !defined(NDEBUG)
1125 MAC(extern ubyte joydefs_calibrating;)
1127 void game_flush_inputs()
1134 if ( (Function_mode != FMODE_MENU) && !joydefs_calibrating ) // only reset mouse when not in menu or not calibrating
1136 mouse_get_delta( &dx, &dy ); // Read mouse
1137 memset(&Controls,0,sizeof(control_info));
1142 last_timer_value = timer_get_fixed_seconds();
1147 extern int Saving_movie_frames;
1148 int Movie_fixed_frametime;
1150 #define Saving_movie_frames 0
1151 #define Movie_fixed_frametime 0
1154 void calc_frame_time()
1156 fix timer_value,last_frametime = FrameTime;
1158 #if defined(TIMER_TEST) && !defined(NDEBUG)
1159 _last_frametime = last_frametime;
1162 timer_value = timer_get_fixed_seconds();
1163 FrameTime = timer_value - last_timer_value;
1166 if (Saving_movie_frames || Movie_fixed_frametime) {
1167 if (FrameTime > f1_0/15)
1168 mprintf((0,"slow frame: %x\n",FrameTime));
1171 timer_value = timer_get_fixed_seconds();
1172 FrameTime = timer_value - last_timer_value;
1173 } while (FrameTime < f1_0/15);
1174 FrameTime = f1_0/15;
1178 #if defined(TIMER_TEST) && !defined(NDEBUG)
1179 _timer_value = timer_value;
1183 if (!(((FrameTime > 0) && (FrameTime <= F1_0)) || (Function_mode == FMODE_EDITOR) || (Newdemo_state == ND_STATE_PLAYBACK))) {
1184 mprintf((1,"Bad FrameTime - value = %x\n",FrameTime));
1186 Int3(); // Call Mike or Matt or John! Your interrupts are probably trashed!
1187 // if ( !dpmi_virtual_memory )
1188 // Int3(); //Get MATT if hit this!
1192 #if defined(TIMER_TEST) && !defined(NDEBUG)
1193 actual_last_timer_value = last_timer_value;
1196 if ( Game_turbo_mode )
1199 // Limit frametime to be between 5 and 150 fps.
1200 RealFrameTime = FrameTime;
1201 if ( FrameTime < F1_0/150 ) FrameTime = F1_0/150;
1202 if ( FrameTime > F1_0/5 ) FrameTime = F1_0/5;
1204 last_timer_value = timer_value;
1206 if (FrameTime < 0) //if bogus frametime...
1207 FrameTime = last_frametime; //...then use time from last frame
1210 if (fixed_frametime) FrameTime = fixed_frametime;
1215 if ( Debug_pause ) {
1225 last_timer_value = timer_get_fixed_seconds();
1233 #if defined(TIMER_TEST) && !defined(NDEBUG)
1234 stop_count = start_count = 0;
1237 // Set value to determine whether homing missile can see target.
1238 // The lower frametime is, the more likely that it can see its target.
1239 if (FrameTime <= F1_0/64)
1240 Min_trackable_dot = MIN_TRACKABLE_DOT; // -- 3*(F1_0 - MIN_TRACKABLE_DOT)/4 + MIN_TRACKABLE_DOT;
1241 else if (FrameTime < F1_0/32)
1242 Min_trackable_dot = MIN_TRACKABLE_DOT + F1_0/64 - 2*FrameTime; // -- fixmul(F1_0 - MIN_TRACKABLE_DOT, F1_0-4*FrameTime) + MIN_TRACKABLE_DOT;
1243 else if (FrameTime < F1_0/4)
1244 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;
1246 Min_trackable_dot = MIN_TRACKABLE_DOT + F1_0/64 - F1_0/8;
1250 //--unused-- int Auto_flythrough=0; //if set, start flythough automatically
1252 void move_player_2_segment(segment *seg,int side)
1256 compute_segment_center(&ConsoleObject->pos,seg);
1257 compute_center_point_on_side(&vp,seg,side);
1258 vm_vec_sub2(&vp,&ConsoleObject->pos);
1259 vm_vector_2_matrix(&ConsoleObject->orient,&vp,NULL,NULL);
1261 obj_relink( ConsoleObject-Objects, SEG_PTR_2_NUM(seg) );
1266 void game_draw_time_left()
1268 char temp_string[30];
1272 gr_set_curfont( GAME_FONT ); //GAME_FONT
1273 gr_set_fontcolor(gr_getcolor(0,63,0), -1 );
1275 timevar=i2f (Netgame.PlayTimeAllowed*5*60);
1276 i=f2i(timevar-ThisLevelTime);
1279 sprintf( temp_string, "Time left: %d secs", i );
1282 gr_string(0, 32, temp_string );
1287 extern int Game_pause;
1290 void level_with_floor();
1292 void modex_clear_box(int x,int y,int w,int h)
1294 grs_canvas *temp_canv,*save_canv;
1296 save_canv = grd_curcanv;
1297 temp_canv = gr_create_canvas(w,h);
1298 gr_set_current_canvas(temp_canv);
1299 gr_clear_canvas(BM_XRGB(0,0,0));
1300 gr_set_current_canvas(save_canv);
1301 gr_bitmapm(x,y,&temp_canv->cv_bitmap);
1302 gr_free_canvas(temp_canv);
1306 extern void modex_printf(int x,int y,char *s,grs_font *font,int color);
1308 // mac routine to drop contents of screen to a pict file using copybits
1309 // save a PICT to a file
1312 void SavePictScreen(int multiplayer)
1315 int parid, i, count;
1316 char *pfilename, filename[50], buf[512], cwd[FILENAME_MAX];
1319 PicHandle pict_handle;
1320 static int multi_count = 0;
1321 StandardFileReply sf_reply;
1323 // dump the contents of the GameWindow into a picture using copybits
1325 pict_handle = OpenPicture(&GameWindow->portRect);
1326 if (pict_handle == NULL)
1329 CopyBits(&GameWindow->portBits, &GameWindow->portBits, &GameWindow->portRect, &GameWindow->portRect, srcBic, NULL);
1332 // get the cwd to restore with chdir when done -- this keeps the mac world sane
1333 if (!getcwd(cwd, FILENAME_MAX))
1335 // create the fsspec
1337 sprintf(filename, "screen%d", multi_count++);
1338 pfilename = c2pstr(filename);
1341 StandardPutFile("\pSave PICT as:", pfilename, &sf_reply);
1342 if (!sf_reply.sfGood)
1344 memcpy( &spec, &(sf_reply.sfFile), sizeof(FSSpec) );
1345 if (sf_reply.sfReplacing)
1347 err = FSpCreate( &spec, 'ttxt', 'PICT', smSystemScript );
1351 // parid = GetAppDirId();
1352 err = FSMakeFSSpec(0, 0, pfilename, &spec);
1357 err = FSpCreate(&spec, 'ttxt', 'PICT', smSystemScript);
1362 // write the PICT file
1363 if ( FSpOpenDF(&spec, fsRdWrPerm, &fd) )
1365 memset(buf, 0, sizeof(buf));
1367 if ( FSWrite(fd, &count, buf) )
1369 count = GetHandleSize((Handle)pict_handle);
1370 HLock((Handle)pict_handle);
1371 if ( FSWrite(fd, &count, *pict_handle) ) {
1377 HUnlock((Handle)pict_handle);
1378 DisposeHandle((Handle)pict_handle);
1386 //automap_flag is now unused, since we just check if the screen we're
1387 //writing to is modex
1388 //if called from automap, current canvas is set to visible screen
1390 void save_screen_shot(int automap_flag)
1392 #if defined(WINDOWS)
1393 mprintf((0, "Doing screen shot thing.\n"));
1394 win95_save_pcx_shot();
1396 #elif !defined(MACINTOSH)
1399 grs_canvas *screen_canv=&grd_curscreen->sc_canvas;
1400 grs_font *save_font;
1401 static int savenum=0;
1402 static int stereo_savenum=0;
1403 grs_canvas *temp_canv,*temp_canv2,*save_canv;
1404 char savename[FILENAME_LEN],savename2[FILENAME_LEN];
1412 // // Can't do screen shots in VR modes.
1413 // if ( VR_render_mode != VR_NONE )
1418 save_canv = grd_curcanv;
1420 if ( VR_render_mode != VR_NONE && !automap_flag && Function_mode==FMODE_GAME && Screen_mode==SCREEN_GAME)
1424 temp_canv = gr_create_canvas(VR_render_buffer[0].cv_bitmap.bm_w,VR_render_buffer[0].cv_bitmap.bm_h);
1425 gr_set_current_canvas(temp_canv);
1426 gr_ubitmap(0,0,&VR_render_buffer[0].cv_bitmap);
1428 temp_canv2 = gr_create_canvas(VR_render_buffer[1].cv_bitmap.bm_w,VR_render_buffer[1].cv_bitmap.bm_h);
1429 gr_set_current_canvas(temp_canv2);
1430 gr_ubitmap(0,0,&VR_render_buffer[1].cv_bitmap);
1433 temp_canv = gr_create_canvas(screen_canv->cv_bitmap.bm_w,screen_canv->cv_bitmap.bm_h);
1434 gr_set_current_canvas(temp_canv);
1435 gr_ubitmap(0,0,&screen_canv->cv_bitmap);
1438 gr_set_current_canvas(save_canv);
1440 if ( savenum > 99 ) savenum = 0;
1441 if ( stereo_savenum > 99 ) stereo_savenum = 0;
1444 sprintf(savename,"left%02d.pcx",stereo_savenum);
1445 sprintf(savename2,"right%02d.pcx",stereo_savenum);
1446 if (VR_eye_switch) {char t[FILENAME_LEN]; strcpy(t,savename); strcpy(savename,savename2); strcpy(savename2,t);}
1448 sprintf( message, "%s '%s' & '%s'", TXT_DUMPING_SCREEN, savename, savename2 );
1451 sprintf(savename,"screen%02d.pcx",savenum++);
1452 sprintf( message, "%s '%s'", TXT_DUMPING_SCREEN, savename );
1455 if (!automap_flag) //if from automap, curcanv is already visible canv
1456 gr_set_current_canvas(NULL);
1457 modex_flag = (grd_curcanv->cv_bitmap.bm_type==BM_MODEX);
1458 if (!automap_flag && modex_flag)
1459 gr_set_current_canvas(&VR_screen_pages[VR_current_page]);
1461 save_font = grd_curcanv->cv_font;
1462 gr_set_curfont(GAME_FONT);
1463 gr_set_fontcolor(gr_find_closest_color_current(0,31,0),-1);
1464 gr_get_string_size(message,&w,&h,&aw);
1469 //I changed how these coords were calculated for the high-res automap. -MT
1470 //x = (VR_screen_pages[VR_current_page].cv_w-w)/2;
1471 //y = (VR_screen_pages[VR_current_page].cv_h-h)/2;
1472 x = (grd_curcanv->cv_w-w)/2;
1473 y = (grd_curcanv->cv_h-h)/2;
1476 modex_clear_box(x-2,y-2,w+4,h+4);
1477 modex_printf(x, y, message,GAME_FONT,gr_find_closest_color_current(0,31,0));
1479 gr_setcolor(gr_find_closest_color_current(0,0,0));
1480 gr_rect(x-2,y-2,x+w+2,y+h+2);
1481 gr_printf(x,y,message);
1482 gr_set_curfont(save_font);
1484 t1 = timer_get_fixed_seconds() + F1_0;
1486 gr_palette_read(pal); //get actual palette from the hardware
1487 pcx_write_bitmap(savename,&temp_canv->cv_bitmap,pal);
1489 pcx_write_bitmap(savename2,&temp_canv2->cv_bitmap,pal);
1491 while ( timer_get_fixed_seconds() < t1 ); // Wait so that messag stays up at least 1 second.
1493 gr_set_current_canvas(screen_canv);
1495 if (grd_curcanv->cv_bitmap.bm_type!=BM_MODEX && !stereo)
1496 gr_ubitmap(0,0,&temp_canv->cv_bitmap);
1498 gr_free_canvas(temp_canv);
1500 gr_free_canvas(temp_canv2);
1502 gr_set_current_canvas(save_canv);
1508 grs_canvas *screen_canv = &grd_curscreen->sc_canvas;
1509 grs_canvas *temp_canv, *save_canv;
1511 // Can't do screen shots in VR modes.
1512 if ( VR_render_mode != VR_NONE )
1517 save_canv = grd_curcanv;
1518 temp_canv = gr_create_canvas( screen_canv->cv_bitmap.bm_w, screen_canv->cv_bitmap.bm_h );
1521 gr_set_current_canvas( temp_canv );
1522 gr_ubitmap( 0, 0, &screen_canv->cv_bitmap );
1523 gr_set_current_canvas( &VR_screen_pages[VR_current_page] );
1527 if (Game_mode & GM_MULTI)
1534 gr_set_current_canvas(screen_canv);
1536 // if (!automap_flag)
1537 gr_ubitmap( 0, 0, &temp_canv->cv_bitmap);
1539 gr_free_canvas(temp_canv);
1541 gr_set_current_canvas(save_canv);
1550 void fly_init(object *obj)
1552 obj->control_type = CT_FLYING;
1553 obj->movement_type = MT_PHYSICS;
1555 vm_vec_zero(&obj->mtype.phys_info.velocity);
1556 vm_vec_zero(&obj->mtype.phys_info.thrust);
1557 vm_vec_zero(&obj->mtype.phys_info.rotvel);
1558 vm_vec_zero(&obj->mtype.phys_info.rotthrust);
1561 //void morph_test(), morph_step();
1564 // ------------------------------------------------------------------------------------
1566 void test_anim_states();
1570 //put up the help message
1577 extern int been_in_editor;
1579 // ------------------------------------------------------------------------------------
1580 void do_cloak_stuff(void)
1583 for (i = 0; i < N_players; i++)
1584 if (Players[i].flags & PLAYER_FLAGS_CLOAKED) {
1585 // mprintf(0, "Cloak time left: %7.3f\n", f2fl(CLOAK_TIME_MAX - (GameTime - Players[Player_num].cloak_time)));
1586 if (GameTime - Players[i].cloak_time > CLOAK_TIME_MAX) {
1587 Players[i].flags &= ~PLAYER_FLAGS_CLOAKED;
1588 if (i == Player_num) {
1589 digi_play_sample( SOUND_CLOAK_OFF, F1_0);
1591 if (Game_mode & GM_MULTI)
1592 multi_send_play_sound(SOUND_CLOAK_OFF, F1_0);
1593 maybe_drop_net_powerup(POW_CLOAK);
1594 multi_send_decloak(); // For demo recording
1596 // mprintf((0, " --- You have been DE-CLOAKED! ---\n"));
1604 // ------------------------------------------------------------------------------------
1605 void do_invulnerable_stuff(void)
1607 if (Players[Player_num].flags & PLAYER_FLAGS_INVULNERABLE) {
1608 if (GameTime - Players[Player_num].invulnerable_time > INVULNERABLE_TIME_MAX) {
1609 Players[Player_num].flags ^= PLAYER_FLAGS_INVULNERABLE;
1612 digi_play_sample( SOUND_INVULNERABILITY_OFF, F1_0);
1614 if (Game_mode & GM_MULTI)
1616 multi_send_play_sound(SOUND_INVULNERABILITY_OFF, F1_0);
1617 maybe_drop_net_powerup(POW_INVULNERABILITY);
1620 mprintf((0, " --- You have been DE-INVULNERABLEIZED! ---\n"));
1627 ubyte Last_afterburner_state = 0;
1628 fix Last_afterburner_charge = 0;
1630 #define AFTERBURNER_LOOP_START ((digi_sample_rate==SAMPLE_RATE_22K)?32027:(32027/2)) //20098
1631 #define AFTERBURNER_LOOP_END ((digi_sample_rate==SAMPLE_RATE_22K)?48452:(48452/2)) //25776
1635 //@@// ------------------------------------------------------------------------------------
1636 //@@void afterburner_shake(void)
1640 //@@ rx = (Ab_scale * fixmul(d_rand() - 16384, F1_0/8 + (((GameTime + 0x4000)*4) & 0x3fff)))/16;
1641 //@@ rz = (Ab_scale * fixmul(d_rand() - 16384, F1_0/2 + ((GameTime*4) & 0xffff)))/16;
1643 //@@ // -- mprintf((0, "AB: %8x %8x\n", rx, rz));
1644 //@@ ConsoleObject->mtype.phys_info.rotvel.x += rx;
1645 //@@ ConsoleObject->mtype.phys_info.rotvel.z += rz;
1649 // ------------------------------------------------------------------------------------
1651 extern void multi_send_sound_function (char,char);
1654 void do_afterburner_stuff(void)
1656 if (!(Players[Player_num].flags & PLAYER_FLAGS_AFTERBURNER))
1657 Afterburner_charge=0;
1659 if (Endlevel_sequence || Player_is_dead)
1661 digi_kill_sound_linked_to_object( Players[Player_num].objnum);
1663 multi_send_sound_function (0,0);
1667 if ((Controls.afterburner_state != Last_afterburner_state && Last_afterburner_charge) || (Last_afterburner_state && Last_afterburner_charge && !Afterburner_charge)) {
1669 if (Afterburner_charge && Controls.afterburner_state && (Players[Player_num].flags & PLAYER_FLAGS_AFTERBURNER)) {
1670 digi_link_sound_to_object3( SOUND_AFTERBURNER_IGNITE, Players[Player_num].objnum, 1, F1_0, i2f(256), AFTERBURNER_LOOP_START, AFTERBURNER_LOOP_END );
1672 if (Game_mode & GM_MULTI)
1673 multi_send_sound_function (3,SOUND_AFTERBURNER_IGNITE);
1676 digi_kill_sound_linked_to_object( Players[Player_num].objnum);
1677 digi_link_sound_to_object2( SOUND_AFTERBURNER_PLAY, Players[Player_num].objnum, 0, F1_0, i2f(256));
1679 if (Game_mode & GM_MULTI)
1680 multi_send_sound_function (0,0);
1682 mprintf((0,"Killing afterburner sound\n"));
1686 //@@if (Controls.afterburner_state && Afterburner_charge)
1687 //@@ afterburner_shake();
1689 Last_afterburner_state = Controls.afterburner_state;
1690 Last_afterburner_charge = Afterburner_charge;
1693 // -- // ------------------------------------------------------------------------------------
1694 // -- // if energy < F1_0/2, recharge up to F1_0/2
1695 // -- void recharge_energy_frame(void)
1697 // -- if (Players[Player_num].energy < Weapon_info[0].energy_usage) {
1698 // -- Players[Player_num].energy += FrameTime/4;
1700 // -- if (Players[Player_num].energy > Weapon_info[0].energy_usage)
1701 // -- Players[Player_num].energy = Weapon_info[0].energy_usage;
1705 // Amount to diminish guns towards normal, per second.
1706 #define DIMINISH_RATE 16 // gots to be a power of 2, else change the code in diminish_palette_towards_normal
1708 extern fix Flash_effect;
1710 //adds to rgb values for palette flash
1711 void PALETTE_FLASH_ADD(int _dr,int _dg,int _db)
1715 PaletteRedAdd += _dr;
1716 PaletteGreenAdd += _dg;
1717 PaletteBlueAdd += _db;
1719 // -- mprintf((0, "Palette add: %3i %3i %3i\n", PaletteRedAdd, PaletteGreenAdd, PaletteBlueAdd));
1724 maxval = MAX_PALETTE_ADD;
1726 if (PaletteRedAdd > maxval)
1727 PaletteRedAdd = maxval;
1729 if (PaletteGreenAdd > maxval)
1730 PaletteGreenAdd = maxval;
1732 if (PaletteBlueAdd > maxval)
1733 PaletteBlueAdd = maxval;
1735 if (PaletteRedAdd < -maxval)
1736 PaletteRedAdd = -maxval;
1738 if (PaletteGreenAdd < -maxval)
1739 PaletteGreenAdd = -maxval;
1741 if (PaletteBlueAdd < -maxval)
1742 PaletteBlueAdd = -maxval;
1745 fix Time_flash_last_played;
1748 void game_palette_step_up( int r, int g, int b );
1749 // ------------------------------------------------------------------------------------
1750 // Diminish palette effects towards normal.
1751 void diminish_palette_towards_normal(void)
1755 // Diminish at DIMINISH_RATE units/second.
1756 // For frame rates > DIMINISH_RATE Hz, use randomness to achieve this.
1757 if (FrameTime < F1_0/DIMINISH_RATE) {
1758 if (d_rand() < FrameTime*DIMINISH_RATE/2) // Note: d_rand() is in 0..32767, and 8 Hz means decrement every frame
1761 dec_amount = f2i(FrameTime*DIMINISH_RATE); // one second = DIMINISH_RATE counts
1762 if (dec_amount == 0)
1763 dec_amount++; // make sure we decrement by something
1769 // Part of hack system to force update of palette after exiting a menu.
1770 if (Time_flash_last_played) {
1772 PaletteRedAdd ^= 1; // Very Tricky! In gr_palette_step_up, if all stepups same as last time, won't do anything!
1775 if ((Time_flash_last_played + F1_0/8 < GameTime) || (Time_flash_last_played > GameTime)) {
1776 digi_play_sample( SOUND_CLOAK_OFF, Flash_effect/4);
1777 Time_flash_last_played = GameTime;
1780 Flash_effect -= FrameTime;
1781 if (Flash_effect < 0)
1784 if (force_do || (d_rand() > 4096 )) {
1785 if ( (Newdemo_state==ND_STATE_RECORDING) && (PaletteRedAdd || PaletteGreenAdd || PaletteBlueAdd) )
1786 newdemo_record_palette_effect(PaletteRedAdd, PaletteGreenAdd, PaletteBlueAdd);
1788 game_palette_step_up( PaletteRedAdd, PaletteGreenAdd, PaletteBlueAdd );
1795 if (PaletteRedAdd > 0 ) { PaletteRedAdd -= dec_amount; if (PaletteRedAdd < 0 ) PaletteRedAdd = 0; }
1796 if (PaletteRedAdd < 0 ) { PaletteRedAdd += dec_amount; if (PaletteRedAdd > 0 ) PaletteRedAdd = 0; }
1798 if (PaletteGreenAdd > 0 ) { PaletteGreenAdd -= dec_amount; if (PaletteGreenAdd < 0 ) PaletteGreenAdd = 0; }
1799 if (PaletteGreenAdd < 0 ) { PaletteGreenAdd += dec_amount; if (PaletteGreenAdd > 0 ) PaletteGreenAdd = 0; }
1801 if (PaletteBlueAdd > 0 ) { PaletteBlueAdd -= dec_amount; if (PaletteBlueAdd < 0 ) PaletteBlueAdd = 0; }
1802 if (PaletteBlueAdd < 0 ) { PaletteBlueAdd += dec_amount; if (PaletteBlueAdd > 0 ) PaletteBlueAdd = 0; }
1804 if ( (Newdemo_state==ND_STATE_RECORDING) && (PaletteRedAdd || PaletteGreenAdd || PaletteBlueAdd) )
1805 newdemo_record_palette_effect(PaletteRedAdd, PaletteGreenAdd, PaletteBlueAdd);
1807 game_palette_step_up( PaletteRedAdd, PaletteGreenAdd, PaletteBlueAdd );
1809 //mprintf(0, "%2i %2i %2i\n", PaletteRedAdd, PaletteGreenAdd, PaletteBlueAdd);
1812 int Redsave, Bluesave, Greensave;
1814 void palette_save(void)
1816 Redsave = PaletteRedAdd; Bluesave = PaletteBlueAdd; Greensave = PaletteGreenAdd;
1819 extern void gr_palette_step_up_vr( int r, int g, int b, int white, int black );
1821 void game_palette_step_up( int r, int g, int b )
1823 if ( VR_use_reg_code ) {
1825 // gr_palette_step_up_vr( r, g, b, VR_WHITE_INDEX, VR_BLACK_INDEX );
1828 gr_palette_step_up( r, g, b );
1832 void palette_restore(void)
1834 PaletteRedAdd = Redsave; PaletteBlueAdd = Bluesave; PaletteGreenAdd = Greensave;
1835 game_palette_step_up( PaletteRedAdd, PaletteGreenAdd, PaletteBlueAdd );
1837 // Forces flash effect to fixup palette next frame.
1838 Time_flash_last_played = 0;
1841 extern void dead_player_frame(void);
1844 // --------------------------------------------------------------------------------------------------
1845 int allowed_to_fire_laser(void)
1847 if (Player_is_dead) {
1848 Global_missile_firing_count = 0;
1852 // Make sure enough time has elapsed to fire laser, but if it looks like it will
1853 // be a long while before laser can be fired, then there must be some mistake!
1854 if (Next_laser_fire_time > GameTime)
1855 if (Next_laser_fire_time < GameTime + 2*F1_0)
1861 fix Next_flare_fire_time = 0;
1862 #define FLARE_BIG_DELAY (F1_0*2)
1864 int allowed_to_fire_flare(void)
1866 if (Next_flare_fire_time > GameTime)
1867 if (Next_flare_fire_time < GameTime + FLARE_BIG_DELAY) // In case time is bogus, never wait > 1 second.
1870 if (Players[Player_num].energy >= Weapon_info[FLARE_ID].energy_usage)
1871 Next_flare_fire_time = GameTime + F1_0/4;
1873 Next_flare_fire_time = GameTime + FLARE_BIG_DELAY;
1878 int allowed_to_fire_missile(void)
1880 // mprintf(0, "Next fire = %7.3f, Cur time = %7.3f\n", f2fl(Next_missile_fire_time), f2fl(GameTime));
1881 // Make sure enough time has elapsed to fire missile, but if it looks like it will
1882 // be a long while before missile can be fired, then there must be some mistake!
1883 if (Next_missile_fire_time > GameTime)
1884 if (Next_missile_fire_time < GameTime + 5*F1_0)
1890 void full_palette_save(void)
1893 apply_modified_palette();
1894 reset_palette_add();
1895 gr_palette_load( gr_palette );
1898 extern int Death_sequence_aborted;
1899 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) );
1906 char command_help[64], pixel_double_help[64], save_help[64], restore_help[64];
1909 m[ 0].type = NM_TYPE_TEXT; m[ 0].text = TXT_HELP_ESC;
1911 m[ 1].type = NM_TYPE_TEXT; m[ 1].text = TXT_HELP_ALT_F2;
1912 m[ 2].type = NM_TYPE_TEXT; m[ 2].text = TXT_HELP_ALT_F3;
1914 sprintf(save_help, "OPT-F2 (%c-s)\t Save Game", 133);
1915 sprintf(restore_help, "OPT-F3 (%c-o)\t Load Game", 133);
1916 m[ 1].type = NM_TYPE_TEXT; m[1].text = save_help;
1917 m[ 2].type = NM_TYPE_TEXT; m[2].text = restore_help;
1919 m[ 3].type = NM_TYPE_TEXT; m[ 3].text = TXT_HELP_F2;
1920 m[ 4].type = NM_TYPE_TEXT; m[ 4].text = TXT_HELP_F3;
1921 m[ 5].type = NM_TYPE_TEXT; m[ 5].text = TXT_HELP_F4;
1922 m[ 6].type = NM_TYPE_TEXT; m[ 6].text = TXT_HELP_F5;
1924 m[ 7].type = NM_TYPE_TEXT; m[ 7].text = TXT_HELP_PAUSE;
1926 m[ 7].type = NM_TYPE_TEXT; m[ 7].text = "Pause (F15)\t Pause";
1928 m[ 8].type = NM_TYPE_TEXT; m[ 8].text = TXT_HELP_MINUSPLUS;
1930 m[ 9].type = NM_TYPE_TEXT; m[ 9].text = TXT_HELP_PRTSCN;
1932 m[ 9].type = NM_TYPE_TEXT; m[ 9].text = "printscrn (F13)\t save screen shot";
1934 m[10].type = NM_TYPE_TEXT; m[10].text = TXT_HELP_1TO5;
1935 m[11].type = NM_TYPE_TEXT; m[11].text = TXT_HELP_6TO10;
1936 m[12].type = NM_TYPE_TEXT; m[12].text = "Shift-F1\t Cycle left window";
1937 m[13].type = NM_TYPE_TEXT; m[13].text = "Shift-F2\t Cycle right window";
1938 m[14].type = NM_TYPE_TEXT; m[14].text = "Shift-F4\t GuideBot menu";
1940 m[15].type = NM_TYPE_TEXT; m[15].text = "Alt-Shift-F4\t Rename GuideBot";
1942 m[15].type = NM_TYPE_TEXT; m[15].text = "Opt-Shift-F4\t Rename GuideBot";
1944 m[16].type = NM_TYPE_TEXT; m[16].text = "Shift-F5\t Drop primary";
1945 m[17].type = NM_TYPE_TEXT; m[17].text = "Shift-F6\t Drop secondary";
1946 m[18].type = NM_TYPE_TEXT; m[18].text = "Shift-F7\t Calibrate joystick";
1947 m[19].type = NM_TYPE_TEXT; m[19].text = "Shift-number\t GuideBot commands";
1950 sprintf(pixel_double_help, "%c-D\t Toggle Pixel Double Mode", 133);
1951 m[20].type = NM_TYPE_TEXT; m[20].text = pixel_double_help;
1952 m[21].type = NM_TYPE_TEXT; m[21].text = "";
1953 sprintf(command_help, "(Use %c-# for F#. i.e. %c-1 for F1)", 133, 133);
1954 m[22].type = NM_TYPE_TEXT; m[22].text = command_help;
1958 full_palette_save();
1960 newmenu_dotiny2( NULL, TXT_KEYS, nitems, m, NULL );
1965 //temp function until Matt cleans up game sequencing
1966 extern void temp_reset_stuff_on_level();
1968 //deal with rear view - switch it on, or off, or whatever
1969 void check_rear_view()
1972 #define LEAVE_TIME 0x1000 //how long until we decide key is down (Used to be 0x4000)
1974 static int leave_mode;
1975 static fix entry_time;
1977 if ( Controls.rear_view_down_count ) { //key/button has gone down
1981 if (Cockpit_mode==CM_REAR_VIEW) {
1982 select_cockpit(Cockpit_mode_save);
1983 Cockpit_mode_save = -1;
1985 if (Newdemo_state == ND_STATE_RECORDING)
1986 newdemo_record_restore_rearview();
1990 leave_mode = 0; //means wait for another key
1991 entry_time = timer_get_fixed_seconds();
1992 if (Cockpit_mode == CM_FULL_COCKPIT) {
1993 Cockpit_mode_save = Cockpit_mode;
1994 select_cockpit(CM_REAR_VIEW);
1996 if (Newdemo_state == ND_STATE_RECORDING)
1997 newdemo_record_rearview();
2001 if (Controls.rear_view_down_state) {
2003 if (leave_mode==0 && (timer_get_fixed_seconds()-entry_time)>LEAVE_TIME)
2008 //@@if (leave_mode==1 && Cockpit_mode==CM_REAR_VIEW) {
2010 if (leave_mode==1 && Rear_view) {
2012 if (Cockpit_mode==CM_REAR_VIEW) {
2013 select_cockpit(Cockpit_mode_save);
2014 Cockpit_mode_save = -1;
2016 if (Newdemo_state == ND_STATE_RECORDING)
2017 newdemo_record_restore_rearview();
2022 void reset_rear_view(void)
2025 if (Newdemo_state == ND_STATE_RECORDING)
2026 newdemo_record_restore_rearview();
2031 if (!(Cockpit_mode == CM_FULL_COCKPIT || Cockpit_mode == CM_STATUS_BAR || Cockpit_mode == CM_FULL_SCREEN)) {
2032 if (!(Cockpit_mode_save == CM_FULL_COCKPIT || Cockpit_mode_save == CM_STATUS_BAR || Cockpit_mode_save == CM_FULL_SCREEN))
2033 Cockpit_mode_save = CM_FULL_COCKPIT;
2034 select_cockpit(Cockpit_mode_save);
2035 Cockpit_mode_save = -1;
2041 int Config_menu_flag;
2045 int Cheats_enabled=0;
2047 extern int Laser_rapid_fire;
2048 extern void do_lunacy_on(), do_lunacy_off();
2050 extern int Physics_cheat_flag,Robots_kill_robots_cheat;
2051 extern char BounceCheat,HomingCheat,OldHomingState[20];
2052 extern char AcidCheatOn,old_IntMethod, Monster_mode;
2053 extern int Buddy_dude_cheat;
2055 //turns off active cheats
2056 void turn_cheats_off()
2062 Weapon_info[i].homing_flag=OldHomingState[i];
2067 Interpolation_method=old_IntMethod;
2070 Buddy_dude_cheat = 0;
2074 Laser_rapid_fire = 0;
2075 Physics_cheat_flag = 0;
2077 Robots_kill_robots_cheat=0;
2078 Robot_firing_enabled = 1;
2081 //turns off all cheats & resets cheater flag
2082 void game_disable_cheats()
2090 // ----------------------------------------------------------------------------
2092 void game_setup(void)
2094 //@@int demo_playing=0;
2095 //@@int multi_game=0;
2097 do_lunacy_on(); // Copy values for insane into copy buffer in ai.c
2098 do_lunacy_off(); // Restore true insane mode.
2101 last_drawn_cockpit[0] = -1; // Force cockpit to redraw next time a frame renders.
2102 last_drawn_cockpit[1] = -1; // Force cockpit to redraw next time a frame renders.
2103 Endlevel_sequence = 0;
2105 //@@if ( Newdemo_state == ND_STATE_PLAYBACK )
2106 //@@ demo_playing = 1;
2107 //@@if ( Game_mode & GM_MULTI )
2108 //@@ multi_game = 1;
2110 set_screen_mode(SCREEN_GAME);
2111 reset_palette_add();
2113 set_warn_func(game_show_warning);
2117 //digi_init_sounds();
2119 //keyd_repeat = 0; // Don't allow repeat in game
2120 keyd_repeat = 1; // Do allow repeat in game
2122 #if !defined(WINDOWS) && !defined(MACINTOSH)
2123 //_MARK_("start of game");
2127 if (Segments[ConsoleObject->segnum].segnum == -1) //segment no longer exists
2128 obj_relink( ConsoleObject-Objects, SEG_PTR_2_NUM(Cursegp) );
2130 if (!check_obj_seg(ConsoleObject))
2131 move_player_2_segment(Cursegp,Curside);
2134 Viewer = ConsoleObject;
2135 fly_init(ConsoleObject);
2140 FrameTime = 0; //make first frame zero
2143 if (Current_level_num == 0) { //not a real level
2144 init_player_stats_game();
2151 game_flush_inputs();
2157 extern char IWasKicked;
2161 // ------------------------------------------------------------------------------------
2162 //this function is the game. called when game mode selected. runs until
2163 //editor mode or exit selected
2166 game_setup(); // Replaces what was here earlier.
2167 // Good for Windows Sake.
2170 ProfilerSetStatus(1);
2173 if ( setjmp(LeaveGame)==0 ) {
2179 Config_menu_flag = 0;
2181 if ( ConsoleObject != &Objects[Players[Player_num].objnum] )
2183 mprintf ((0,"Player_num=%d objnum=%d",Player_num,Players[Player_num].objnum));
2184 //Assert( ConsoleObject == &Objects[Players[Player_num].objnum] );
2187 player_shields = Players[Player_num].shields;
2192 DoMessageStuff(&msg); // Do Windows event handling.
2193 if (_RedrawScreen) {
2194 _RedrawScreen = FALSE;
2195 load_palette(Current_level_palette,1,1);
2196 gr_palette_load(gr_palette);
2201 ExtGameStatus=GAMESTAT_RUNNING;
2202 GameLoop( 1, 1 ); // Do game loop with rendering and reading controls.
2204 //if the player is taking damage, give up guided missile control
2205 if (Players[Player_num].shields != player_shields)
2206 release_guided_missile(Player_num);
2208 //see if redbook song needs to be restarted
2209 songs_check_redbook_repeat(); // Handle RedBook Audio Repeating.
2211 if (Config_menu_flag) {
2212 int double_save = Scanline_double;
2214 //WIN(mouse_set_mode(0));
2215 if (!(Game_mode&GM_MULTI)) {palette_save(); reset_palette_add(); apply_modified_palette(); gr_palette_load( gr_palette ); }
2217 if (Scanline_double != double_save) init_cockpit();
2218 if (!(Game_mode&GM_MULTI)) palette_restore();
2219 //WIN(mouse_set_mode(1));
2223 int save_w=Game_window_w,save_h=Game_window_h;
2225 Screen_mode=-1; set_screen_mode(SCREEN_GAME);
2226 Game_window_w=save_w; Game_window_h=save_h;
2228 last_drawn_cockpit[0] = -1;
2229 last_drawn_cockpit[1] = -1;
2232 if ( (Function_mode != FMODE_GAME) && Auto_demo && (Newdemo_state != ND_STATE_NORMAL) ) {
2234 fmode = Function_mode;
2235 Function_mode = FMODE_GAME;
2237 apply_modified_palette();
2238 reset_palette_add();
2239 gr_palette_load( gr_palette );
2240 choice=nm_messagebox( NULL, 2, TXT_YES, TXT_NO, TXT_ABORT_AUTODEMO );
2242 Function_mode = fmode;
2245 newdemo_stop_playback();
2246 Function_mode = FMODE_MENU;
2248 Function_mode = FMODE_GAME;
2252 if ( (Function_mode != FMODE_GAME ) && (Newdemo_state != ND_STATE_PLAYBACK ) && (Function_mode!=FMODE_EDITOR)
2258 fmode = Function_mode;
2259 Function_mode = FMODE_GAME;
2261 apply_modified_palette();
2262 reset_palette_add();
2263 gr_palette_load( gr_palette );
2264 ExtGameStatus=GAMESTAT_ABORT_GAME;
2265 choice=nm_messagebox( NULL, 2, TXT_YES, TXT_NO, TXT_ABORT_GAME );
2267 Function_mode = fmode;
2269 Function_mode = FMODE_GAME;
2275 if (Function_mode != FMODE_GAME)
2276 longjmp(LeaveGame,0);
2279 if ( (keyd_time_when_last_pressed + (F1_0 * 60)) < timer_get_fixed_seconds() ) // idle in game for 1 minutes means exit
2280 longjmp(LeaveGame,0);
2286 ProfilerSetStatus(0);
2291 if ( (Newdemo_state == ND_STATE_RECORDING) || (Newdemo_state == ND_STATE_PAUSED) )
2292 newdemo_stop_recording();
2298 if ( Newdemo_state == ND_STATE_PLAYBACK )
2299 newdemo_stop_playback();
2301 if (Cockpit_mode_save!=-1)
2303 Cockpit_mode=Cockpit_mode_save;
2304 Cockpit_mode_save=-1;
2307 if (Function_mode != FMODE_EDITOR)
2308 gr_palette_fade_out(gr_palette,32,0); // Fade out before going to menu
2310 //@@ if ( (!demo_playing) && (!multi_game) && (Function_mode != FMODE_EDITOR)) {
2311 //@@ scores_maybe_add_player(Game_aborted);
2314 #if !defined(WINDOWS) && !defined(MACINTOSH)
2315 //_MARK_("end of game");
2318 clear_warn_func(game_show_warning); //don't use this func anymore
2320 game_disable_cheats();
2323 Function_mode = FMODE_EXIT; // get out of game in Apple OEM version
2327 //called at the end of the program
2331 if (dd_VR_offscreen_buffer) {
2332 if (dd_grd_backcanv != dd_VR_offscreen_buffer) {
2333 dd_gr_free_canvas(dd_VR_offscreen_buffer);
2335 dd_VR_offscreen_buffer = NULL;
2336 VR_offscreen_buffer = NULL;
2339 if (VR_offscreen_buffer) {
2340 gr_free_canvas(VR_offscreen_buffer);
2341 VR_offscreen_buffer = NULL;
2345 close_gauge_canvases();
2347 restore_effect_bitmap_icons();
2349 #if !defined(MACINTOSH) && !defined(WINDOWS)
2350 if (Game_cockpit_copy_code) {
2351 d_free(Game_cockpit_copy_code);
2352 Game_cockpit_copy_code = NULL;
2355 if (Game_cockpit_copy_code)
2356 Game_cockpit_copy_code = 0;
2359 if (background_bitmap.bm_data)
2360 d_free(background_bitmap.bm_data);
2362 clear_warn_func(game_show_warning); //don't use this func anymore
2366 dd_grs_canvas * get_current_game_screen()
2368 return &dd_VR_screen_pages[VR_current_page];
2373 grs_canvas * get_current_game_screen()
2375 return &VR_screen_pages[VR_current_page];
2380 extern void kconfig_center_headset();
2384 void speedtest_frame(void);
2385 int Debug_slowdown=0;
2389 extern void player_follow_path(object *objp);
2390 extern void check_create_player_path(void);
2394 extern int Do_appearance_effect;
2396 object *Missile_viewer=NULL;
2398 int Missile_view_enabled = 1;
2400 int Marker_viewer_num[2]={-1,-1};
2401 int Coop_view_player[2]={-1,-1};
2402 int Cockpit_3d_view[2]={CV_NONE,CV_NONE};
2404 //returns ptr to escort robot, or NULL
2405 object *find_escort()
2409 for (i=0; i<=Highest_object_index; i++)
2410 if (Objects[i].type == OBJ_ROBOT)
2411 if (Robot_info[Objects[i].id].companion)
2417 extern void process_super_mines_frame(void);
2418 extern void do_seismic_stuff(void);
2421 int Saving_movie_frames=0;
2422 int __Movie_frame_num=0;
2424 #define MAX_MOVIE_BUFFER_FRAMES 250
2425 #define MOVIE_FRAME_SIZE (320 * 200)
2427 ubyte *Movie_frame_buffer;
2428 int Movie_frame_counter;
2429 ubyte Movie_pal[768];
2430 char movie_path[50] = ".\\";
2432 grs_bitmap Movie_bm;
2434 void flush_movie_buffer()
2441 mprintf((0,"Flushing movie buffer..."));
2443 Movie_bm.bm_data = Movie_frame_buffer;
2445 for (f=0;f<Movie_frame_counter;f++) {
2446 sprintf(savename, "%sfrm%04d.pcx",movie_path,__Movie_frame_num);
2447 __Movie_frame_num++;
2448 pcx_write_bitmap(savename,&Movie_bm,Movie_pal);
2449 Movie_bm.bm_data += MOVIE_FRAME_SIZE;
2452 mprintf((0,"%3d/%3d\10\10\10\10\10\10\10",f,Movie_frame_counter));
2455 Movie_frame_counter=0;
2457 mprintf((0,"done \n"));
2462 void toggle_movie_saving()
2466 Saving_movie_frames = !Saving_movie_frames;
2468 if (Saving_movie_frames) {
2471 m[0].type=NM_TYPE_INPUT; m[0].text_len = 50; m[0].text = movie_path;
2472 exit = newmenu_do( NULL, "Directory for movie frames?" , 1, &(m[0]), NULL );
2475 Saving_movie_frames = 0;
2479 while (isspace(movie_path[strlen(movie_path)-1]))
2480 movie_path[strlen(movie_path)-1] = 0;
2481 if (movie_path[strlen(movie_path)-1]!='\\' && movie_path[strlen(movie_path)-1]!=':')
2482 strcat(movie_path,"\\");
2485 if (!Movie_frame_buffer) {
2486 Movie_frame_buffer = d_malloc(MAX_MOVIE_BUFFER_FRAMES * MOVIE_FRAME_SIZE);
2487 if (!Movie_frame_buffer) {
2489 Saving_movie_frames=0;
2492 Movie_frame_counter=0;
2494 Movie_bm.bm_x = Movie_bm.bm_y = 0;
2495 Movie_bm.bm_w = 320;
2496 Movie_bm.bm_h = 200;
2497 Movie_bm.bm_type = BM_LINEAR;
2498 Movie_bm.bm_flags = 0;
2499 Movie_bm.bm_rowsize = 320;
2500 Movie_bm.bm_handle = 0;
2502 gr_palette_read(Movie_pal); //get actual palette from the hardware
2504 if (Newdemo_state == ND_STATE_PLAYBACK)
2505 Newdemo_do_interpolate = 0;
2509 flush_movie_buffer();
2511 if (Newdemo_state == ND_STATE_PLAYBACK)
2512 Newdemo_do_interpolate = 1;
2517 void save_movie_frame()
2519 memcpy(Movie_frame_buffer+Movie_frame_counter*MOVIE_FRAME_SIZE,grd_curscreen->sc_canvas.cv_bitmap.bm_data,MOVIE_FRAME_SIZE);
2521 Movie_frame_counter++;
2523 if (Movie_frame_counter == MAX_MOVIE_BUFFER_FRAMES)
2524 flush_movie_buffer();
2530 extern int Level_shake_duration;
2532 //if water or fire level, make occasional sound
2533 void do_ambient_sounds()
2535 int has_water,has_lava;
2538 has_lava = (Segment2s[ConsoleObject->segnum].s2_flags & S2F_AMBIENT_LAVA);
2539 has_water = (Segment2s[ConsoleObject->segnum].s2_flags & S2F_AMBIENT_WATER);
2541 if (has_lava) { //has lava
2542 sound = SOUND_AMBIENT_LAVA;
2543 if (has_water && (d_rand() & 1)) //both, pick one
2544 sound = SOUND_AMBIENT_WATER;
2546 else if (has_water) //just water
2547 sound = SOUND_AMBIENT_WATER;
2551 if (((d_rand() << 3) < FrameTime)) { //play the sound
2552 fix volume = d_rand() + f1_0/2;
2553 digi_play_sample(sound,volume);
2557 // -- extern void lightning_frame(void);
2559 void game_render_frame();
2560 extern void omega_charge_frame(void);
2562 extern time_t t_current_time, t_saved_time;
2564 void flicker_lights();
2566 void GameLoop(int RenderFlag, int ReadControlsFlag )
2570 // Used to slow down frame rate for testing things.
2571 // RenderFlag = 1; // DEBUG
2572 if (Debug_slowdown) {
2575 for (h=0; h<Debug_slowdown; h++)
2576 for (i=0; i<1000; i++)
2583 static int desc_dead_countdown=100; /* used if player shouldn't be playing */
2585 if (desc_id_exit_num) { // are we supposed to be checking
2586 if (!(--desc_dead_countdown)) {// if so, at zero, then pull the plug
2587 char time_str[32], time_str2[32];
2589 _ctime(&t_saved_time, time_str);
2590 _ctime(&t_current_time, time_str2);
2592 Error ("EXPIRES %s. YOUR TIME %s.\n", time_str, time_str2);
2593 Error ("Loading overlay -- error number: %d\n", (int)desc_id_exit_num);
2600 if (FindArg("-invulnerability"))
2601 Players[Player_num].flags |= PLAYER_FLAGS_INVULNERABLE;
2605 update_player_stats();
2606 diminish_palette_towards_normal(); // Should leave palette effect up for as long as possible by putting right before render.
2607 do_afterburner_stuff();
2609 do_invulnerable_stuff();
2610 remove_obsolete_stuck_objects();
2612 do_final_boss_frame();
2613 // -- lightning_frame();
2614 // -- recharge_energy_frame();
2616 if ((Players[Player_num].flags & PLAYER_FLAGS_HEADLIGHT) && (Players[Player_num].flags & PLAYER_FLAGS_HEADLIGHT_ON)) {
2617 static int turned_off=0;
2618 Players[Player_num].energy -= (FrameTime*3/8);
2619 if (Players[Player_num].energy < i2f(10)) {
2621 Players[Player_num].flags &= ~PLAYER_FLAGS_HEADLIGHT_ON;
2624 if (Game_mode & GM_MULTI)
2625 multi_send_flags(Player_num);
2632 if (Players[Player_num].energy <= 0) {
2633 Players[Player_num].energy = 0;
2634 Players[Player_num].flags &= ~PLAYER_FLAGS_HEADLIGHT_ON;
2636 if (Game_mode & GM_MULTI)
2637 multi_send_flags(Player_num);
2644 check_create_player_path();
2645 player_follow_path(ConsoleObject);
2649 if (Game_mode & GM_MULTI)
2652 if (Netgame.PlayTimeAllowed && ThisLevelTime>=i2f((Netgame.PlayTimeAllowed*5*60)))
2653 multi_check_for_killgoal_winner();
2659 if (force_cockpit_redraw) { //screen need redrawing?
2661 force_cockpit_redraw=0;
2663 game_render_frame();
2664 //show_extra_views(); //missile view, buddy bot, etc.
2667 if (Saving_movie_frames)
2674 //mprintf(0,"Velocity %2.2f\n", f2fl(vm_vec_mag(&ConsoleObject->phys_info.velocity)));
2678 dead_player_frame();
2679 if (Newdemo_state != ND_STATE_PLAYBACK)
2680 do_controlcen_dead_frame();
2682 process_super_mines_frame();
2684 do_ambient_sounds();
2691 if (ReadControlsFlag)
2694 memset(&Controls, 0, sizeof(Controls));
2696 GameTime += FrameTime;
2698 if (f2i(GameTime)/10 != f2i(GameTime-FrameTime)/10)
2699 mprintf((0,"Gametime = %d secs\n",f2i(GameTime)));
2701 if (GameTime < 0 || GameTime > i2f(0x7fff - 600)) {
2702 GameTime = FrameTime; //wrap when goes negative, or gets within 10 minutes
2703 mprintf((0,"GameTime reset to 0\n"));
2707 if (FindArg("-checktime") != 0)
2708 if (GameTime >= i2f(600)) //wrap after 10 minutes
2709 GameTime = FrameTime;
2713 if ((Game_mode & GM_MULTI) && Netgame.PlayTimeAllowed)
2714 ThisLevelTime +=FrameTime;
2719 if (Endlevel_sequence) {
2720 do_endlevel_frame();
2721 powerup_grab_cheat_all();
2722 do_special_effects();
2723 return; //skip everything else
2726 if (Newdemo_state != ND_STATE_PLAYBACK)
2727 do_exploding_wall_frame();
2728 if ((Newdemo_state != ND_STATE_PLAYBACK) || (Newdemo_vcr_state != ND_STATE_PAUSED)) {
2729 do_special_effects();
2730 wall_frame_process();
2731 triggers_frame_process();
2735 if (Control_center_destroyed) {
2736 if (Newdemo_state==ND_STATE_RECORDING )
2737 newdemo_record_control_center_destroyed();
2742 if ( Newdemo_state == ND_STATE_PLAYBACK ) {
2743 newdemo_playback_one_frame();
2744 if ( Newdemo_state != ND_STATE_PLAYBACK ) {
2745 longjmp( LeaveGame, 0 ); // Go back to menu
2748 { // Note the link to above!
2750 Players[Player_num].homing_object_dist = -1; // Assume not being tracked. Laser_do_weapon_sequence modifies this.
2753 powerup_grab_cheat_all();
2755 if (Endlevel_sequence) //might have been started during move
2758 fuelcen_update_all();
2762 if (allowed_to_fire_laser())
2763 FireLaser(); // Fire Laser!
2765 if (Auto_fire_fusion_cannon_time) {
2766 if (Primary_weapon != FUSION_INDEX)
2767 Auto_fire_fusion_cannon_time = 0;
2768 else if (GameTime + FrameTime/2 >= Auto_fire_fusion_cannon_time) {
2769 Auto_fire_fusion_cannon_time = 0;
2770 Global_laser_firing_count = 1;
2772 vms_vector rand_vec;
2775 Global_laser_firing_count = 0;
2777 ConsoleObject->mtype.phys_info.rotvel.x += (d_rand() - 16384)/8;
2778 ConsoleObject->mtype.phys_info.rotvel.z += (d_rand() - 16384)/8;
2779 make_random_vector(&rand_vec);
2781 bump_amount = F1_0*4;
2783 if (Fusion_charge > F1_0*2)
2784 bump_amount = Fusion_charge*4;
2786 bump_one_object(ConsoleObject, &rand_vec, bump_amount);
2790 if (Global_laser_firing_count) {
2791 // Don't cap here, gets capped in Laser_create_new and is based on whether in multiplayer mode, MK, 3/27/95
2792 // if (Fusion_charge > F1_0*2)
2793 // Fusion_charge = F1_0*2;
2794 Global_laser_firing_count -= do_laser_firing_player(); //do_laser_firing(Players[Player_num].objnum, Primary_weapon);
2797 if (Global_laser_firing_count < 0)
2798 Global_laser_firing_count = 0;
2801 if (Do_appearance_effect) {
2802 create_player_appearance_effect(ConsoleObject);
2803 Do_appearance_effect = 0;
2805 if ((Game_mode & GM_MULTI) && Netgame.invul)
2807 Players[Player_num].flags |= PLAYER_FLAGS_INVULNERABLE;
2808 Players[Player_num].invulnerable_time = GameTime-i2f(27);
2815 omega_charge_frame();
2819 //!!hoard_light_pulse(); //do cool hoard light pulsing
2823 //!!extern int Goal_blue_segnum,Goal_red_segnum;
2824 //!!extern int Hoard_goal_eclip;
2826 //!!//do cool pulsing lights in hoard goals
2827 //!!hoard_light_pulse()
2829 //!! if (Game_mode & GM_HOARD) {
2833 //!! frame = Effects[Hoard_goal_eclip].frame_count;
2837 //!! if (frame >= Effects[Hoard_goal_eclip].vc.num_frames)
2840 //!! light = abs(frame - 5) * f1_0 / 5;
2842 //!! Segment2s[Goal_red_segnum].static_light = Segment2s[Goal_blue_segnum].static_light = light;
2847 ubyte Slide_segs[MAX_SEGMENTS];
2848 int Slide_segs_computed;
2850 void compute_slide_segs(void)
2852 int segnum, sidenum;
2854 for (segnum=0;segnum<=Highest_segment_index;segnum++) {
2855 Slide_segs[segnum] = 0;
2856 for (sidenum=0;sidenum<6;sidenum++) {
2857 int tmn = Segments[segnum].sides[sidenum].tmap_num;
2858 if (TmapInfo[tmn].slide_u != 0 || TmapInfo[tmn].slide_v != 0)
2859 Slide_segs[segnum] |= 1 << sidenum;
2863 Slide_segs_computed = 1;
2866 // -----------------------------------------------------------------------------
2867 void slide_textures(void)
2869 int segnum,sidenum,i;
2871 if (!Slide_segs_computed)
2872 compute_slide_segs();
2874 for (segnum=0;segnum<=Highest_segment_index;segnum++) {
2875 if (Slide_segs[segnum]) {
2876 for (sidenum=0;sidenum<6;sidenum++) {
2877 if (Slide_segs[segnum] & (1 << sidenum)) {
2878 int tmn = Segments[segnum].sides[sidenum].tmap_num;
2879 if (TmapInfo[tmn].slide_u != 0 || TmapInfo[tmn].slide_v != 0) {
2881 Segments[segnum].sides[sidenum].uvls[i].u += fixmul(FrameTime,TmapInfo[tmn].slide_u<<8);
2882 Segments[segnum].sides[sidenum].uvls[i].v += fixmul(FrameTime,TmapInfo[tmn].slide_v<<8);
2883 if (Segments[segnum].sides[sidenum].uvls[i].u > f2_0) {
2886 Segments[segnum].sides[sidenum].uvls[j].u -= f1_0;
2888 if (Segments[segnum].sides[sidenum].uvls[i].v > f2_0) {
2891 Segments[segnum].sides[sidenum].uvls[j].v -= f1_0;
2893 if (Segments[segnum].sides[sidenum].uvls[i].u < -f2_0) {
2896 Segments[segnum].sides[sidenum].uvls[j].u += f1_0;
2898 if (Segments[segnum].sides[sidenum].uvls[i].v < -f2_0) {
2901 Segments[segnum].sides[sidenum].uvls[j].v += f1_0;
2911 flickering_light Flickering_lights[MAX_FLICKERING_LIGHTS];
2913 int Num_flickering_lights=0;
2915 void flicker_lights()
2918 flickering_light *f;
2920 f = Flickering_lights;
2922 for (l=0;l<Num_flickering_lights;l++,f++) {
2923 segment *segp = &Segments[f->segnum];
2925 //make sure this is actually a light
2926 if (! (WALL_IS_DOORWAY(segp, f->sidenum) & WID_RENDER_FLAG))
2928 if (! (TmapInfo[segp->sides[f->sidenum].tmap_num].lighting | TmapInfo[segp->sides[f->sidenum].tmap_num2 & 0x3fff].lighting))
2931 if (f->timer == 0x80000000) //disabled
2934 if ((f->timer -= FrameTime) < 0) {
2936 while (f->timer < 0)
2937 f->timer += f->delay;
2939 f->mask = ((f->mask&0x80000000)?1:0) + (f->mask<<1);
2942 add_light(f->segnum,f->sidenum);
2944 subtract_light(f->segnum,f->sidenum);
2949 //returns ptr to flickering light structure, or NULL if can't find
2950 flickering_light *find_flicker(int segnum,int sidenum)
2953 flickering_light *f;
2955 //see if there's already an entry for this seg/side
2957 f = Flickering_lights;
2959 for (l=0;l<Num_flickering_lights;l++,f++)
2960 if (f->segnum == segnum && f->sidenum == sidenum) //found it!
2966 //turn flickering off (because light has been turned off)
2967 void disable_flicker(int segnum,int sidenum)
2969 flickering_light *f;
2971 if ((f=find_flicker(segnum,sidenum)) != NULL)
2972 f->timer = 0x80000000;
2975 //turn flickering off (because light has been turned on)
2976 void enable_flicker(int segnum,int sidenum)
2978 flickering_light *f;
2980 if ((f=find_flicker(segnum,sidenum)) != NULL)
2987 //returns 1 if ok, 0 if error
2988 int add_flicker(int segnum,int sidenum,fix delay,ulong mask)
2991 flickering_light *f;
2993 mprintf((0,"add_flicker: %d:%d %x %x\n",segnum,sidenum,delay,mask));
2995 //see if there's already an entry for this seg/side
2997 f = Flickering_lights;
2999 for (l=0;l<Num_flickering_lights;l++,f++)
3000 if (f->segnum == segnum && f->sidenum == sidenum) //found it!
3003 if (mask==0) { //clearing entry
3004 if (l == Num_flickering_lights)
3008 for (i=l;i<Num_flickering_lights-1;i++)
3009 Flickering_lights[i] = Flickering_lights[i+1];
3010 Num_flickering_lights--;
3015 if (l == Num_flickering_lights)
3016 if (Num_flickering_lights == MAX_FLICKERING_LIGHTS)
3019 Num_flickering_lights++;
3022 f->sidenum = sidenum;
3023 f->delay = f->timer = delay;
3031 // -----------------------------------------------------------------------------
3032 // Fire Laser: Registers a laser fire, and performs special stuff for the fusion
3037 Global_laser_firing_count += Weapon_info[Primary_weapon_to_weapon_info[Primary_weapon]].fire_count * (Controls.fire_primary_state || Controls.fire_primary_down_count);
3039 if ((Primary_weapon == FUSION_INDEX) && (Global_laser_firing_count)) {
3040 if ((Players[Player_num].energy < F1_0*2) && (Auto_fire_fusion_cannon_time == 0)) {
3041 Global_laser_firing_count = 0;
3043 if (Fusion_charge == 0)
3044 Players[Player_num].energy -= F1_0*2;
3046 Fusion_charge += FrameTime;
3047 Players[Player_num].energy -= FrameTime;
3049 if (Players[Player_num].energy <= 0) {
3050 Players[Player_num].energy = 0;
3051 Auto_fire_fusion_cannon_time = GameTime -1; // Fire now!
3053 Auto_fire_fusion_cannon_time = GameTime + FrameTime/2 + 1;
3054 // Fire the fusion cannon at this time in the future.
3056 if (Fusion_charge < F1_0*2)
3057 PALETTE_FLASH_ADD(Fusion_charge >> 11, 0, Fusion_charge >> 11);
3059 PALETTE_FLASH_ADD(Fusion_charge >> 11, Fusion_charge >> 11, 0);
3061 if (GameTime < Fusion_last_sound_time) //gametime has wrapped
3062 Fusion_next_sound_time = Fusion_last_sound_time = GameTime;
3064 if (Fusion_next_sound_time < GameTime) {
3065 if (Fusion_charge > F1_0*2) {
3066 digi_play_sample( 11, F1_0 );
3067 apply_damage_to_player(ConsoleObject, ConsoleObject, d_rand() * 4);
3069 create_awareness_event(ConsoleObject, PA_WEAPON_ROBOT_COLLISION);
3070 digi_play_sample( SOUND_FUSION_WARMUP, F1_0 );
3072 if (Game_mode & GM_MULTI)
3073 multi_send_play_sound(SOUND_FUSION_WARMUP, F1_0);
3076 Fusion_last_sound_time = GameTime;
3077 Fusion_next_sound_time = GameTime + F1_0/8 + d_rand()/4;
3085 // -------------------------------------------------------------------------------------------------------
3086 // If player is close enough to objnum, which ought to be a powerup, pick it up!
3087 // This could easily be made difficulty level dependent.
3088 void powerup_grab_cheat(object *player, int objnum)
3094 Assert(Objects[objnum].type == OBJ_POWERUP);
3096 powerup_size = Objects[objnum].size;
3097 player_size = player->size;
3099 dist = vm_vec_dist_quick(&Objects[objnum].pos, &player->pos);
3101 if ((dist < 2*(powerup_size + player_size)) && !(Objects[objnum].flags & OF_SHOULD_BE_DEAD)) {
3102 vms_vector collision_point;
3104 vm_vec_avg(&collision_point, &Objects[objnum].pos, &player->pos);
3105 collide_player_and_powerup(player, &Objects[objnum], &collision_point);
3109 // -------------------------------------------------------------------------------------------------------
3110 // Make it easier to pick up powerups.
3111 // For all powerups in this segment, pick them up at up to twice pickuppable distance based on dot product
3112 // from player to powerup and player's forward vector.
3113 // This has the effect of picking them up more easily left/right and up/down, but not making them disappear
3114 // way before the player gets there.
3115 void powerup_grab_cheat_all(void)
3120 segp = &Segments[ConsoleObject->segnum];
3121 objnum = segp->objects;
3123 while (objnum != -1) {
3124 if (Objects[objnum].type == OBJ_POWERUP)
3125 powerup_grab_cheat(ConsoleObject, objnum);
3126 objnum = Objects[objnum].next;
3131 int Last_level_path_created = -1;
3133 #ifdef SHOW_EXIT_PATH
3135 // ------------------------------------------------------------------------------------------------------------------
3136 // Create path for player from current segment to goal segment.
3137 // Return true if path created, else return false.
3138 int mark_player_path_to_segment(int segnum)
3141 object *objp = ConsoleObject;
3142 short player_path_length=0;
3143 int player_hide_index=-1;
3145 if (Last_level_path_created == Current_level_num) {
3149 Last_level_path_created = Current_level_num;
3151 if (create_path_points(objp, objp->segnum, segnum, Point_segs_free_ptr, &player_path_length, 100, 0, 0, -1) == -1) {
3152 mprintf((0, "Unable to form path of length %i for myself\n", 100));
3156 player_hide_index = Point_segs_free_ptr - Point_segs;
3157 Point_segs_free_ptr += player_path_length;
3159 if (Point_segs_free_ptr - Point_segs + MAX_PATH_LENGTH*2 > MAX_POINT_SEGS) {
3160 mprintf((1, "Can't create path. Not enough point_segs.\n"));
3161 ai_reset_all_paths();
3165 for (i=1; i<player_path_length; i++) {
3167 vms_vector seg_center;
3170 segnum = Point_segs[player_hide_index+i].segnum;
3171 mprintf((0, "%3i ", segnum));
3172 seg_center = Point_segs[player_hide_index+i].point;
3174 objnum = obj_create( OBJ_POWERUP, POW_ENERGY, segnum, &seg_center, &vmd_identity_matrix, Powerup_info[POW_ENERGY].size, CT_POWERUP, MT_NONE, RT_POWERUP);
3176 Int3(); // Unable to drop energy powerup for path
3180 obj = &Objects[objnum];
3181 obj->rtype.vclip_info.vclip_num = Powerup_info[obj->id].vclip_num;
3182 obj->rtype.vclip_info.frametime = Vclip[obj->rtype.vclip_info.vclip_num].frame_time;
3183 obj->rtype.vclip_info.framenum = 0;
3184 obj->lifeleft = F1_0*100 + d_rand() * 4;
3191 // Return true if it happened, else return false.
3192 int create_special_path(void)
3196 // ---------- Find exit doors ----------
3197 for (i=0; i<=Highest_segment_index; i++)
3198 for (j=0; j<MAX_SIDES_PER_SEGMENT; j++)
3199 if (Segments[i].children[j] == -2) {
3200 mprintf((0, "Exit at segment %i\n", i));
3201 return mark_player_path_to_segment(i);
3211 int Max_obj_count_mike = 0;
3213 // Shows current number of used objects.
3214 void show_free_objects(void)
3216 if (!(FrameCount & 8)) {
3220 mprintf((0, "Highest_object_index = %3i, MAX_OBJECTS = %3i, now used = ", Highest_object_index, MAX_OBJECTS));
3222 for (i=0; i<=Highest_object_index; i++)
3223 if (Objects[i].type != OBJ_NONE)
3226 mprintf((0, "%3i", count));
3228 if (count > Max_obj_count_mike) {
3229 Max_obj_count_mike = count;
3230 mprintf((0, " ***"));
3241 void game_win_init_cockpit_mask(int sram)
3243 if (dd_VR_offscreen_buffer && dd_VR_offscreen_buffer != dd_grd_backcanv) {
3244 dd_gr_free_canvas(dd_VR_offscreen_buffer);
3247 if (GRMODEINFO(paged) && !GRMODEINFO(dbuf)) {
3248 // Here we will make the VR_offscreen_buffer the 2nd page and hopefully
3249 // we can just flip it, saving a blt.
3252 else if (GRMODEINFO(dbuf)||GRMODEINFO(emul)) {
3253 // The offscreen buffer will be created. We will just blt this
3254 // to the screen (which may be blted to the primary surface)
3255 if ( grd_curscreen->sc_h < 200 ) {
3256 dd_VR_offscreen_buffer = dd_gr_create_canvas(grd_curscreen->sc_w, 200);
3257 VR_offscreen_buffer = &dd_VR_offscreen_buffer->canvas;
3259 DDFreeSurface(dd_VR_offscreen_buffer->lpdds);
3260 dd_VR_offscreen_buffer->lpdds = DDCreateSysMemSurface(grd_curscreen->sc_w, 200);
3261 dd_VR_offscreen_buffer->sram = 1;
3265 dd_VR_offscreen_buffer = dd_gr_create_canvas(grd_curscreen->sc_w, grd_curscreen->sc_h);
3266 VR_offscreen_buffer = &dd_VR_offscreen_buffer->canvas;
3268 DDFreeSurface(dd_VR_offscreen_buffer->lpdds);
3269 dd_VR_offscreen_buffer->lpdds = DDCreateSysMemSurface(grd_curscreen->sc_w, grd_curscreen->sc_h);
3270 dd_VR_offscreen_buffer->sram = 1;
3275 dd_gr_init_sub_canvas( &dd_VR_render_buffer[0], dd_VR_offscreen_buffer, 0, 0, grd_curscreen->sc_w, grd_curscreen->sc_h );
3276 dd_gr_init_sub_canvas( &dd_VR_render_buffer[1], dd_VR_offscreen_buffer, 0, 0, grd_curscreen->sc_w, grd_curscreen->sc_h );
3277 gr_init_sub_canvas( &VR_render_buffer[0], VR_offscreen_buffer, 0, 0, grd_curscreen->sc_w, grd_curscreen->sc_h );
3278 gr_init_sub_canvas( &VR_render_buffer[1], VR_offscreen_buffer, 0, 0, grd_curscreen->sc_w, grd_curscreen->sc_h );
3280 game_init_render_sub_buffers( 0, 0, grd_curscreen->sc_w, grd_curscreen->sc_h );
3283 //@@void game_win_init_cockpit_mask()
3285 //@@ char title_pal[768];
3286 //@@ dd_grs_canvas ccanv;
3288 //@@ LPDIRECTDRAWSURFACE dds;
3290 //@@ dds = DDCreateSurface(GRMODEINFO(w), GRMODEINFO(h), 1);
3291 //@@ Assert(dds != NULL);
3293 //@@ _lpDDSMask = dds;
3294 //@@ ccanv.lpdds = dds;
3295 //@@ dd_gr_reinit_canvas(&ccanv);
3297 //@@ dd_gr_set_current_canvas(&ccanv);
3298 //@@ DDGRLOCK(dd_grd_curcanv)
3300 //@@ if (W95DisplayMode == SM95_640x480x8) {
3301 //@@ pcx_error=pcx_read_bitmap( "MASKB.PCX", &grd_curcanv->cv_bitmap,
3302 //@@ grd_curcanv->cv_bitmap.bm_type,
3306 //@@ pcx_error=pcx_read_bitmap( "MASK.PCX", &grd_curcanv->cv_bitmap,
3307 //@@ grd_curcanv->cv_bitmap.bm_type,
3311 //@@ DDGRUNLOCK(dd_grd_curcanv);
3313 //@@ Assert(pcx_error == PCX_ERROR_NONE);
3314 //@@ Game_cockpit_copy_code = (ubyte *)(0xABADC0DE);