2 THE COMPUTER CODE CONTAINED HEREIN IS THE SOLE PROPERTY OF PARALLAX
3 SOFTWARE CORPORATION ("PARALLAX"). PARALLAX, IN DISTRIBUTING THE CODE TO
4 END-USERS, AND SUBJECT TO ALL OF THE TERMS AND CONDITIONS HEREIN, GRANTS A
5 ROYALTY-FREE, PERPETUAL LICENSE TO SUCH END-USERS FOR USE BY SUCH END-USERS
6 IN USING, DISPLAYING, AND CREATING DERIVATIVE WORKS THEREOF, SO LONG AS
7 SUCH USE, DISPLAY OR CREATION IS FOR NON-COMMERCIAL, ROYALTY OR REVENUE
8 FREE PURPOSES. IN NO EVENT SHALL THE END-USER USE THE COMPUTER CODE
9 CONTAINED HEREIN FOR REVENUE-BEARING PURPOSES. THE END-USER UNDERSTANDS
10 AND AGREES TO THE TERMS HEREIN AND ACCEPTS THE SAME BY USE OF THIS FILE.
11 COPYRIGHT 1993-1999 PARALLAX SOFTWARE CORPORATION. ALL RIGHTS RESERVED.
19 char game_rcsid[] = "$Id: game.c,v 1.7 2001-01-31 16:31:13 bradleyb Exp $";
35 #include <StandardFile.h>
36 #include <Quickdraw.h>
47 #include "pa_enabl.h" //$$POLY_ACC
102 #if defined(POLY_ACC)
103 #include "poly_acc.h"
108 #include "cntrlcen.h"
112 #include "multibot.h"
115 #include "playsave.h"
119 int VGA_current_mode;
122 #include <profiler.h>
125 //#define TEST_TIMER 1 //if this is set, do checking on timer
127 #define SHOW_EXIT_PATH 1
130 #include "editor\editor.h"
135 #if __WATCOMC__ < 1000
136 #include <wsample.h> //should come after inferno.h to get mark setting
141 extern void ReadControls(void); // located in gamecntl.c
142 extern int Current_display_mode;
143 extern void do_final_boss_frame(void);
145 int Speedtest_on = 0;
148 int Mark_count = 0; // number of debugging marks set
149 int Speedtest_start_time;
150 int Speedtest_segnum;
151 int Speedtest_sidenum;
152 int Speedtest_frame_start;
153 int Speedtest_count=0; // number of times to do the debug test.
156 static fix last_timer_value=0;
159 #if defined(TIMER_TEST) && !defined(NDEBUG)
160 fix _timer_value,actual_last_timer_value,_last_frametime;
161 int stop_count,start_count;
162 int time_stopped,time_started;
166 ubyte * Game_cockpit_copy_code = NULL;
168 ubyte Game_cockpit_copy_code = 0;
169 ubyte Scanline_double = 1;
172 int VR_screen_mode = 0;
174 ubyte VR_screen_flags = 0; //see values in screens.h
175 ubyte VR_current_page = 0;
176 fix VR_eye_width = F1_0;
177 int VR_render_mode = VR_NONE;
178 int VR_low_res = 3; // Default to low res
180 int VR_sensitivity = 1; // 0 - 2
183 int VR_eye_offset = 0;
184 int VR_eye_switch = 0;
185 int VR_eye_offset_changed = 0;
186 int VR_use_reg_code = 0;
188 grs_canvas *VR_offscreen_buffer = NULL; // The offscreen data buffer
189 grs_canvas VR_render_buffer[2]; // Two offscreen buffers for left/right eyes.
190 grs_canvas VR_render_sub_buffer[2]; // Two sub buffers for left/right eyes.
191 grs_canvas VR_screen_pages[2]; // Two pages of VRAM if paging is available
192 grs_canvas VR_editor_canvas; // The canvas that the editor writes to.
195 //@@ LPDIRECTDRAWSURFACE _lpDDSMask = NULL;
196 dd_grs_canvas *dd_VR_offscreen_buffer = NULL;
197 dd_grs_canvas dd_VR_screen_pages[2];
198 dd_grs_canvas dd_VR_render_buffer[2];
199 dd_grs_canvas dd_VR_render_sub_buffer[2];
201 void game_win_init_cockpit_mask(int sram);
204 //do menus work in 640x480 or 320x200?
205 //PC version sets this in main(). Mac versios is always high-res, so set to 1 here
206 int MenuHiresAvailable = 1; //can we do highres menus?
207 int MenuHires = 1; //are we currently in highres menus?
209 int Debug_pause=0; //John's debugging pause system
211 int Cockpit_mode=CM_FULL_COCKPIT; //set game.h for values
213 int Cockpit_mode_save=-1; //set while in letterbox or rear view, or -1
214 int force_cockpit_redraw=0;
216 cvar_t r_framerate = {"r_framerate","0"};
218 int PaletteRedAdd, PaletteGreenAdd, PaletteBlueAdd;
220 // Toggle_var points at a variable which gets !ed on ctrl-alt-T press.
222 int *Toggle_var = &Dummy_var;
225 //flag for whether initial fade-in has been done
229 #ifndef NDEBUG //these only exist if debugging
231 int Game_double_buffer = 1; //double buffer by default
232 fix fixed_frametime=0; //if non-zero, set frametime to this
236 int Game_suspended=0; //if non-zero, nothing moves but player
239 fix Auto_fire_fusion_cannon_time = 0;
240 fix Fusion_charge = 0;
241 fix Fusion_next_sound_time = 0;
242 fix Fusion_last_sound_time = 0;
245 int Game_turbo_mode = 0;
247 int Game_mode = GM_GAME_OVER;
249 int Global_laser_firing_count = 0;
250 int Global_missile_firing_count = 0;
252 grs_bitmap background_bitmap;
256 #define BACKGROUND_NAME "statback.pcx"
258 // Function prototypes for GAME.C exclusively.
260 void GameLoop(int RenderFlag, int ReadControlsFlag);
261 void FireLaser(void);
262 void slide_textures(void);
263 void powerup_grab_cheat_all(void);
266 extern void multi_check_for_killgoal_winner();
267 extern void RestoreGameSurfaces();
271 void grow_window(void);
272 void shrink_window(void);
276 void fill_background();
279 void show_framerate(void);
280 void ftoa(char *string, fix f);
283 extern ubyte DefiningMarkerMessage;
284 extern char Marker_input[];
286 // ==============================================================================================
288 extern char john_head_on;
290 void load_background_bitmap()
295 if (background_bitmap.bm_data)
296 d_free(background_bitmap.bm_data);
298 background_bitmap.bm_data=NULL;
299 pcx_error = pcx_read_bitmap(john_head_on?"johnhead.pcx":BACKGROUND_NAME,&background_bitmap,BM_LINEAR,pal);
300 if (pcx_error != PCX_ERROR_NONE)
301 Error("File %s - PCX error: %s",BACKGROUND_NAME,pcx_errormsg(pcx_error));
302 gr_remap_bitmap_good( &background_bitmap, pal, -1, -1 );
306 //this is called once per game
309 atexit(close_game); //for cleanup
313 init_special_effects();
317 init_gauge_canvases();
319 init_exploding_walls();
321 load_background_bitmap();
323 Clear_window = 2; // do portal only window clear.
325 set_detail_level_parameters(Detail_level);
327 build_mission_list(0); // This also loads mission 0.
330 cvar_registervariable(&r_framerate);
335 void reset_palette_add()
340 //gr_palette_step_up( PaletteRedAdd, PaletteGreenAdd, PaletteBlueAdd );
345 void win_get_span_list(grs_bitmap *bm, int miny, int maxy)
351 int lspan=0, rspan=0, span=0;
355 //@@ fp = fopen("cockspan.dat", "w");
357 for (y = 0; y < miny; y++)
358 win_cockpit_mask[y].num = 0;
360 for (y = miny; y <= maxy; y++)
363 //@@ fprintf(fp, "line %d: ", y);
364 for (x = 0; x < bm->bm_w; x++)
366 offset = y*bm->bm_rowsize + x;
368 if (data[offset] == 255) {
371 case 0: // Start Mode
373 win_cockpit_mask[y].span[span].xmin = x;
375 //@@ fprintf(fp, "<%d,", lspan);
378 case 1: // Transparency mode
380 win_cockpit_mask[y].span[span].xmax = x;
383 case 2: // Switch from Draw mode to transparent
385 win_cockpit_mask[y].span[span].xmin = x;
386 //@@ fprintf(fp, "<%d,", lspan);
394 case 0: // Start mode
398 case 1: // Switching from transparent to Draw
401 win_cockpit_mask[y].span[span].xmax = x;
403 //@@ fprintf(fp, "%d> ", rspan);
412 //@@ fprintf(fp, "%d> ", rspan);
413 win_cockpit_mask[y].span[span].xmax = rspan;
416 win_cockpit_mask[y].num = span;
417 //@@ fprintf(fp, "\n");
420 win_cockpit_mask[y].num = 255;
425 void game_show_warning(char *s)
428 if (!((Game_mode & GM_MULTI) && (Function_mode == FMODE_GAME)))
431 nm_messagebox( TXT_WARNING, 1, TXT_OK, s );
433 if (!((Game_mode & GM_MULTI) && (Function_mode == FMODE_GAME)))
438 //these should be in gr.h
439 #define cv_w cv_bitmap.bm_w
440 #define cv_h cv_bitmap.bm_h
442 int Game_window_x = 0;
443 int Game_window_y = 0;
444 int Game_window_w = 0;
445 int Game_window_h = 0;
446 int max_window_w = 0;
447 int max_window_h = 0;
449 extern void newdemo_record_cockpit_change(int);
451 //initialize the various canvases on the game screen
452 //called every time the screen mode or cockpit changes
455 int minx, maxx, miny, maxy;
457 #if defined(POLY_ACC)
458 pa_flush(); // get rid of undrawn polys.
459 pa_clear_buffer(1, 0);
462 //Initialize the on-screen canvases
464 if (Newdemo_state==ND_STATE_RECORDING)
467 newdemo_record_cockpit_change(Cockpit_mode);
470 if ( VR_render_mode != VR_NONE )
471 Cockpit_mode = CM_FULL_SCREEN;
473 if (!(VR_screen_flags & VRF_ALLOW_COCKPIT) && (Cockpit_mode==CM_FULL_COCKPIT || Cockpit_mode==CM_STATUS_BAR || Cockpit_mode==CM_REAR_VIEW) )
474 Cockpit_mode = CM_FULL_SCREEN;
476 if ( Screen_mode == SCREEN_EDITOR )
477 Cockpit_mode = CM_FULL_SCREEN;
480 dd_gr_set_current_canvas(NULL),
481 gr_set_current_canvas(NULL)
483 gr_set_curfont( GAME_FONT );
485 #if !defined(MACINTOSH) && !defined(WINDOWS)
486 if (Game_cockpit_copy_code)
487 d_free(Game_cockpit_copy_code);
488 Game_cockpit_copy_code = NULL;
490 if (Game_cockpit_copy_code)
491 Game_cockpit_copy_code = 0;
495 //@@ if (_lpDDSMask) { DDFreeSurface(_lpDDSMask); _lpDDSMask = NULL; }
499 game_win_init_cockpit_mask(0);
502 switch( Cockpit_mode )
504 case CM_FULL_COCKPIT:
506 grs_bitmap *bm = &GameBitmaps[cockpit_bitmap[Cockpit_mode+(Current_display_mode?(Num_cockpits/2):0)].index];
508 PIGGY_PAGE_IN(cockpit_bitmap[Cockpit_mode+(Current_display_mode?(Num_cockpits/2):0)]);
511 dd_gr_set_current_canvas(NULL);
512 game_win_init_cockpit_mask(1);
513 dd_gr_set_current_canvas(dd_VR_offscreen_buffer);
515 gr_set_current_canvas(VR_offscreen_buffer)
518 WIN(DDGRLOCK(dd_grd_curcanv));
519 gr_bitmap( 0, 0, bm );
520 bm = &VR_offscreen_buffer->cv_bitmap;
521 bm->bm_flags = BM_FLAG_TRANSPARENT;
522 gr_ibitblt_find_hole_size ( bm, &minx, &miny, &maxx, &maxy );
523 WIN( win_get_span_list(bm, miny, maxy);
524 DDGRUNLOCK(dd_grd_curcanv)
528 #if 1 // def MACINTOSH
529 gr_ibitblt_create_mask( bm, minx, miny, maxx-minx+1, maxy-miny+1, VR_offscreen_buffer->cv_bitmap.bm_rowsize);
531 if ( Current_display_mode )
533 #if defined(POLY_ACC)
534 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 );
535 pa_clear_buffer(1, 0); // clear offscreen to reduce white flash.
537 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 );
540 Game_cockpit_copy_code = gr_ibitblt_create_mask( bm, minx, miny, maxx-minx+1, maxy-miny+1, VR_offscreen_buffer->cv_bitmap.bm_rowsize );
542 bm->bm_flags = 0; // Clear all flags for offscreen canvas
544 Game_cockpit_copy_code = (ubyte *)(1);
545 bm->bm_flags = 0; // Clear all flags for offscreen canvas
547 game_init_render_sub_buffers( 0, 0, maxx-minx+1, maxy-miny+1 );
553 max_window_h = grd_curscreen->sc_h;
555 if (Game_window_h > max_window_h || VR_screen_flags&VRF_ALLOW_COCKPIT)
556 Game_window_h = max_window_h;
558 if (Game_window_w > max_window_w || VR_screen_flags&VRF_ALLOW_COCKPIT)
559 Game_window_w = max_window_w;
561 Game_window_x = (max_window_w - Game_window_w)/2;
562 Game_window_y = (max_window_h - Game_window_h)/2;
564 game_init_render_sub_buffers( Game_window_x, Game_window_y, Game_window_w, Game_window_h );
569 max_window_h = grd_curscreen->sc_h - GameBitmaps[cockpit_bitmap[CM_STATUS_BAR+(Current_display_mode?(Num_cockpits/2):0)].index].bm_h;
571 if (Game_window_h > max_window_h)
572 Game_window_h = max_window_h;
574 if (Game_window_w > max_window_w)
575 Game_window_w = max_window_w;
577 Game_window_x = (max_window_w - Game_window_w)/2;
578 Game_window_y = (max_window_h - Game_window_h)/2;
580 game_init_render_sub_buffers( Game_window_x, Game_window_y, Game_window_w, Game_window_h );
586 x = 0; w = VR_render_buffer[0].cv_bitmap.bm_w; //VR_render_width;
587 h = (VR_render_buffer[0].cv_bitmap.bm_h * 7) / 10;
588 y = (VR_render_buffer[0].cv_bitmap.bm_h-h)/2;
590 game_init_render_sub_buffers( x, y, w, h );
597 dd_gr_set_current_canvas(NULL),
598 gr_set_current_canvas(NULL)
602 //selects a given cockpit (or lack of one). See types in game.h
603 void select_cockpit(int mode)
605 if (mode != Cockpit_mode) { //new mode
611 extern int last_drawn_cockpit[2];
613 //force cockpit redraw next time. call this if you've trashed the screen
616 force_cockpit_redraw=1;
617 last_drawn_cockpit[0] = -1;
618 last_drawn_cockpit[1] = -1;
621 // void HUD_clear_messages(); //Already declared in gauges.h
624 void VR_reset_params()
626 VR_eye_width = VR_SEPARATION;
627 VR_eye_offset = VR_PIXEL_SHIFT;
628 VR_eye_offset_changed = 2;
631 void game_init_render_sub_buffers( int x, int y, int w, int h )
634 dd_gr_init_sub_canvas( &dd_VR_render_sub_buffer[0], &dd_VR_render_buffer[0], x, y, w, h );
635 dd_gr_init_sub_canvas( &dd_VR_render_sub_buffer[1], &dd_VR_render_buffer[1], x, y, w, h );
637 dd_VR_render_sub_buffer[0].canvas.cv_bitmap.bm_x = 0;
638 dd_VR_render_sub_buffer[0].canvas.cv_bitmap.bm_y = 0;
639 dd_VR_render_sub_buffer[0].xoff = x;
640 dd_VR_render_sub_buffer[0].yoff = y;
641 dd_VR_render_sub_buffer[1].canvas.cv_bitmap.bm_x = 0;
642 dd_VR_render_sub_buffer[1].canvas.cv_bitmap.bm_y = 0;
643 dd_VR_render_sub_buffer[1].xoff = x;
644 dd_VR_render_sub_buffer[1].yoff = y;
647 if (Scanline_double) {
651 gr_init_sub_canvas( &VR_render_sub_buffer[0], &VR_render_buffer[0], x, y, w/2, (h/2)+1);
652 gr_init_sub_canvas( &VR_render_sub_buffer[1], &VR_render_buffer[1], x, y, w/2, (h/2)+1);
655 gr_init_sub_canvas( &VR_render_sub_buffer[0], &VR_render_buffer[0], x, y, w, h );
656 gr_init_sub_canvas( &VR_render_sub_buffer[1], &VR_render_buffer[1], x, y, w, h );
666 newBounds.right = x + w;
668 newBounds.bottom = y + h;
670 pa_set_context(kGamePlayDrawContextID, &newBounds); // must resize/create new context
676 VR_render_sub_buffer[0].cv_bitmap.bm_x = 0;
677 VR_render_sub_buffer[0].cv_bitmap.bm_y = 0;
678 VR_render_sub_buffer[1].cv_bitmap.bm_x = 0;
679 VR_render_sub_buffer[1].cv_bitmap.bm_y = 0;
685 // Sets up the canvases we will be rendering to (WIN95)
686 void game_init_render_buffers(int screen_mode, int render_w, int render_h, int render_method, int flags )
688 // Hack for switching to higher that 640x480 modes (DDraw doesn't allow
689 // creating surfaces greater than the current resolution
691 if (GRMODEINFO(rw) < render_w || GRMODEINFO(rh) < render_h) {
692 render_w = GRMODEINFO(rw);
693 render_h = GRMODEINFO(rh);
696 VR_screen_mode = screen_mode;
698 VR_screen_flags = flags;
701 VR_render_mode = render_method;
703 Game_window_w = render_w;
704 Game_window_h = render_h;
706 if (dd_VR_offscreen_buffer && dd_VR_offscreen_buffer != dd_grd_backcanv) {
707 dd_gr_free_canvas(dd_VR_offscreen_buffer);
710 if ( (VR_render_mode==VR_AREA_DET) || (VR_render_mode==VR_INTERLACED ) ) {
711 if ( render_h*2 < 200 ) {
712 Int3(); // Not Supported yet!!!
713 // VR_offscreen_buffer = gr_create_canvas( render_w, 200 );
716 Int3(); // Not Supported yet!!!
717 // VR_offscreen_buffer = gr_create_canvas( render_w, render_h*2 );
720 Int3(); // Not Supported yet!!!
721 // gr_init_sub_canvas( &VR_render_buffer[0], VR_offscreen_buffer, 0, 0, render_w, render_h );
722 // gr_init_sub_canvas( &VR_render_buffer[1], VR_offscreen_buffer, 0, render_h, render_w, render_h );
724 else if (GRMODEINFO(paged) && !GRMODEINFO(dbuf)) {
725 // Here we will make the VR_offscreen_buffer the 2nd page and hopefully
726 // we can just flip it, saving a blt.
728 dd_VR_offscreen_buffer = dd_grd_backcanv;
729 VR_offscreen_buffer = & dd_grd_backcanv->canvas;
731 else if (GRMODEINFO(dbuf)||GRMODEINFO(emul)) {
732 // The offscreen buffer will be created. We will just blt this
733 // to the screen (which may be blted to the primary surface)
734 if ( render_h < 200 ) {
735 dd_VR_offscreen_buffer = dd_gr_create_canvas(render_w, 200);
736 VR_offscreen_buffer = &dd_VR_offscreen_buffer->canvas;
739 dd_VR_offscreen_buffer = dd_gr_create_canvas(render_w, render_h);
740 VR_offscreen_buffer = &dd_VR_offscreen_buffer->canvas;
744 dd_gr_init_sub_canvas( &dd_VR_render_buffer[0], dd_VR_offscreen_buffer, 0, 0, render_w, render_h );
745 dd_gr_init_sub_canvas( &dd_VR_render_buffer[1], dd_VR_offscreen_buffer, 0, 0, render_w, render_h );
746 gr_init_sub_canvas( &VR_render_buffer[0], VR_offscreen_buffer, 0, 0, render_w, render_h );
747 gr_init_sub_canvas( &VR_render_buffer[1], VR_offscreen_buffer, 0, 0, render_w, render_h );
749 game_init_render_sub_buffers( 0, 0, render_w, render_h );
754 // Sets up the canvases we will be rendering to (NORMAL VERSION)
755 void game_init_render_buffers(int screen_mode, int render_w, int render_h, int render_method, int flags )
757 // if (vga_check_mode(screen_mode) != 0)
758 // Error("Cannot set requested video mode");
760 VR_screen_mode = screen_mode;
762 VR_screen_flags = flags;
766 VR_render_mode = render_method;
768 Game_window_w = render_w;
769 Game_window_h = render_h;
771 if (VR_offscreen_buffer) {
772 gr_free_canvas(VR_offscreen_buffer);
775 if ( (VR_render_mode==VR_AREA_DET) || (VR_render_mode==VR_INTERLACED ) ) {
776 if ( render_h*2 < 200 ) {
777 VR_offscreen_buffer = gr_create_canvas( render_w, 200 );
780 VR_offscreen_buffer = gr_create_canvas( render_w, render_h*2 );
783 gr_init_sub_canvas( &VR_render_buffer[0], VR_offscreen_buffer, 0, 0, render_w, render_h );
784 gr_init_sub_canvas( &VR_render_buffer[1], VR_offscreen_buffer, 0, render_h, render_w, render_h );
787 if ( render_h < 200 ) {
788 VR_offscreen_buffer = gr_create_canvas( render_w, 200 );
791 #if defined(POLY_ACC)
793 VR_offscreen_buffer = gr_create_canvas( render_w, render_h );
794 d_free(VR_offscreen_buffer->cv_bitmap.bm_data);
795 gr_init_canvas(VR_offscreen_buffer, pa_get_buffer_address(1), BM_LINEAR15, render_w, render_h);
797 if ( PAEnabled || gConfigInfo.mAcceleration ) {
798 Cockpit_mode=CM_FULL_SCREEN; // HACK HACK HACK HACK HACK!!!!
799 VR_offscreen_buffer = gr_create_canvas2(render_w, render_h, BM_LINEAR15);
801 VR_offscreen_buffer = gr_create_canvas( render_w, render_h );
804 VR_offscreen_buffer = gr_create_canvas( render_w, render_h );
809 VR_offscreen_buffer->cv_bitmap.bm_type = BM_OGL;
812 gr_init_sub_canvas( &VR_render_buffer[0], VR_offscreen_buffer, 0, 0, render_w, render_h );
813 gr_init_sub_canvas( &VR_render_buffer[1], VR_offscreen_buffer, 0, 0, render_w, render_h );
816 game_init_render_sub_buffers( 0, 0, render_w, render_h );
820 //called to get the screen in a mode compatible with popup menus.
821 //if we can't have popups over the game screen, switch to menu mode.
822 void set_popup_screen(void)
824 //WIN(LoadCursorWin(MOUSE_DEFAULT_CURSOR));
826 if (! (VR_screen_flags & VRF_COMPATIBLE_MENUS))
827 set_screen_mode(SCREEN_MENU); //must switch to menu mode
831 //called to change the screen mode. Parameter sm is the new mode, one of
832 //SMODE_GAME or SMODE_EDITOR. returns mode acutally set (could be other
833 //mode if cannot init requested mode)
834 int set_screen_mode(int sm)
836 WIN(static int force_mode_change=0);
837 WIN(static int saved_window_w);
838 WIN(static int saved_window_h);
841 if ( (sm==SCREEN_MENU) && (Screen_mode==SCREEN_EDITOR) ) {
842 gr_set_current_canvas( Canv_editor );
848 if ( Screen_mode == sm && W95DisplayMode == VR_screen_mode) {
849 dd_gr_set_current_canvas( &dd_VR_screen_pages[VR_current_page] );
853 if ( Screen_mode == sm && VGA_current_mode == VR_screen_mode) {
854 gr_set_current_canvas( &VR_screen_pages[VR_current_page] );
860 if ((Screen_mode == sm) && !((sm==SCREEN_GAME) && (grd_curscreen->sc_mode != VR_screen_mode) && (Screen_mode == SCREEN_GAME))) {
862 gr_set_current_canvas( &VR_screen_pages[VR_current_page] );
863 ogl_set_screen_mode();
874 switch( Screen_mode )
880 if (!(VR_screen_flags & VRF_COMPATIBLE_MENUS)) {
881 // HACK!!! Meant to save window size when switching from
882 // non-compat menu mode to menu mode.
883 saved_window_w = Game_window_w;
884 saved_window_h = Game_window_h;
885 force_mode_change = 1;
887 if (W95DisplayMode != SM95_640x480x8) {
888 //@@ piggy_bitmap_page_out_all_w(); // 2D GFX Flush cache.
889 DDSETDISPLAYMODE(SM95_640x480x8);
891 if (!gr_palette_faded_out) gr_palette_load(gr_palette);
894 dd_gr_init_sub_canvas(&dd_VR_screen_pages[0], dd_grd_screencanv,
896 dd_grd_screencanv->canvas.cv_bitmap.bm_w,
897 dd_grd_screencanv->canvas.cv_bitmap.bm_h);
898 dd_gr_init_sub_canvas(&dd_VR_screen_pages[1], dd_grd_screencanv,
900 dd_grd_screencanv->canvas.cv_bitmap.bm_w,
901 dd_grd_screencanv->canvas.cv_bitmap.bm_h);
909 MenuHires = MenuHiresAvailable; //do highres if we can
911 #if defined(POLY_ACC)
913 menu_mode = MenuHires?SM(640,480):SM(320,200);
915 menu_mode = PAEnabled?SM_640x480x15xPA:SM_640x480V;
918 menu_mode = MenuHires?SM(640,480):SM(320,200);
921 if (VGA_current_mode != menu_mode) {
922 if (gr_set_mode(menu_mode))
923 Error("Cannot set screen mode for menu");
924 if (!gr_palette_faded_out)
925 gr_palette_load(gr_palette);
928 gr_init_sub_canvas( &VR_screen_pages[0], &grd_curscreen->sc_canvas, 0, 0, grd_curscreen->sc_w, grd_curscreen->sc_h );
929 gr_init_sub_canvas( &VR_screen_pages[1], &grd_curscreen->sc_canvas, 0, 0, grd_curscreen->sc_w, grd_curscreen->sc_h );
931 FontHires = MenuHires;
941 if (force_mode_change || (W95DisplayMode != VR_screen_mode)) {
943 DDSETDISPLAYMODE(VR_screen_mode);
944 //@@ piggy_bitmap_page_out_all_w(); // 2D GFX Flush cache.
946 mprintf((0, "Reinitializing render buffers due to display mode change.\n"));
947 game_init_render_buffers(W95DisplayMode,
948 GRMODEINFO(rw), GRMODEINFO(rh),
949 VR_render_mode, VR_screen_flags);
954 if (VGA_current_mode != VR_screen_mode) {
955 if (gr_set_mode(VR_screen_mode)) {
956 Error("Cannot set desired screen mode for game!");
957 //we probably should do something else here, like select a standard mode
960 if ( (Config_control_type == 1) && (Function_mode == FMODE_GAME) )
967 if ( VR_render_mode == VR_NONE )
969 max_window_w = grd_curscreen->sc_w;
970 max_window_h = grd_curscreen->sc_h;
972 if (VR_screen_flags & VRF_ALLOW_COCKPIT) {
973 if (Cockpit_mode == CM_STATUS_BAR)
974 max_window_h = grd_curscreen->sc_h - GameBitmaps[cockpit_bitmap[CM_STATUS_BAR+(Current_display_mode?(Num_cockpits/2):0)].index].bm_h;
976 else if (Cockpit_mode != CM_LETTERBOX)
977 Cockpit_mode = CM_FULL_SCREEN;
979 if (Game_window_h==0 || Game_window_h > max_window_h || Game_window_w==0 || Game_window_w > max_window_w) {
980 Game_window_w = max_window_w;
981 Game_window_h = max_window_h;
986 Cockpit_mode = CM_FULL_SCREEN;
989 // Super hack. If we are switching from a 320x200 game to 640x480.
990 // and we were in a menumode when switching, we don't
991 // restore Game_window vals
992 if (force_mode_change && (W95DisplayMode == SM95_320x200x8X)) {
993 Game_window_w = saved_window_w;
994 Game_window_h = saved_window_h;
995 force_mode_change = 0;
1000 // Define screen pages for game mode
1001 // If we designate through screen_flags to use paging, then do so.
1003 dd_gr_init_sub_canvas( &dd_VR_screen_pages[0], dd_grd_screencanv, 0, 0, grd_curscreen->sc_w, grd_curscreen->sc_h ),
1004 gr_init_sub_canvas( &VR_screen_pages[0], &grd_curscreen->sc_canvas, 0, 0, grd_curscreen->sc_w, grd_curscreen->sc_h )
1007 if ( VR_screen_flags&VRF_USE_PAGING ) {
1009 dd_gr_init_sub_canvas( &dd_VR_screen_pages[1], dd_grd_backcanv, 0, 0, grd_curscreen->sc_w, grd_curscreen->sc_h ),
1010 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 )
1015 dd_gr_init_sub_canvas( &dd_VR_screen_pages[1], dd_grd_screencanv, 0, 0, grd_curscreen->sc_w, grd_curscreen->sc_h ),
1016 gr_init_sub_canvas( &VR_screen_pages[1], &grd_curscreen->sc_canvas, 0, 0, grd_curscreen->sc_w, grd_curscreen->sc_h )
1023 FontHires = (Current_display_mode != 0);
1026 FontHires = MenuHires = ((Current_display_mode != 0) && (Current_display_mode != 2));
1029 if ( VR_render_mode != VR_NONE ) {
1030 // for 640x480 or higher, use hires font.
1031 if ( grd_curscreen->sc_h > 400 )
1040 if (VGA_current_mode != SM_800x600V) {
1042 if ((gr_error=gr_set_mode(SM_800x600V))!=0) { //force into game scrren
1043 Warning("Cannot init editor screen (error=%d)",gr_error);
1047 gr_palette_load( gr_palette );
1049 gr_init_sub_canvas( &VR_editor_canvas, &grd_curscreen->sc_canvas, 0, 0, grd_curscreen->sc_w, grd_curscreen->sc_h );
1050 Canv_editor = &VR_editor_canvas;
1051 gr_init_sub_canvas( &VR_screen_pages[0], Canv_editor, 0, 0, Canv_editor->cv_w, Canv_editor->cv_h );
1052 gr_init_sub_canvas( &VR_screen_pages[1], Canv_editor, 0, 0, Canv_editor->cv_w, Canv_editor->cv_h );
1053 gr_set_current_canvas( Canv_editor );
1054 init_editor_screen(); //setup other editor stuff
1058 Error("Invalid screen mode %d",sm);
1061 VR_current_page = 0;
1064 dd_gr_set_current_canvas(&dd_VR_screen_pages[VR_current_page]),
1065 gr_set_current_canvas( &VR_screen_pages[VR_current_page] )
1068 if ( VR_screen_flags&VRF_USE_PAGING ) {
1071 gr_show_canvas( &VR_screen_pages[VR_current_page] )
1075 ogl_set_screen_mode();
1081 static int timer_paused=0;
1085 if (timer_paused==0) {
1087 time = timer_get_fixed_seconds();
1088 last_timer_value = time - last_timer_value;
1089 if (last_timer_value < 0) {
1090 #if defined(TIMER_TEST) && !defined(NDEBUG)
1091 Int3(); //get Matt!!!!
1093 last_timer_value = 0;
1095 #if defined(TIMER_TEST) && !defined(NDEBUG)
1096 time_stopped = time;
1101 #if defined(TIMER_TEST) && !defined(NDEBUG)
1109 Assert(timer_paused >= 0);
1110 if (timer_paused==0) {
1112 time = timer_get_fixed_seconds();
1113 #if defined(TIMER_TEST) && !defined(NDEBUG)
1114 if (last_timer_value < 0)
1115 Int3(); //get Matt!!!!
1118 last_timer_value = time - last_timer_value;
1119 #if defined(TIMER_TEST) && !defined(NDEBUG)
1120 time_started = time;
1124 #if defined(TIMER_TEST) && !defined(NDEBUG)
1129 MAC(extern ubyte joydefs_calibrating;)
1131 void game_flush_inputs()
1138 if ( (Function_mode != FMODE_MENU) && !joydefs_calibrating ) // only reset mouse when not in menu or not calibrating
1140 mouse_get_delta( &dx, &dy ); // Read mouse
1141 memset(&Controls,0,sizeof(control_info));
1146 last_timer_value = timer_get_fixed_seconds();
1151 extern int Saving_movie_frames;
1152 int Movie_fixed_frametime;
1154 #define Saving_movie_frames 0
1155 #define Movie_fixed_frametime 0
1158 static const int max_fps = 80;
1160 void calc_frame_time()
1162 fix timer_value,last_frametime = FrameTime;
1164 #if defined(TIMER_TEST) && !defined(NDEBUG)
1165 _last_frametime = last_frametime;
1168 timer_value = timer_get_fixed_seconds();
1169 FrameTime = timer_value - last_timer_value;
1172 timer_value = timer_get_fixed_seconds();
1173 FrameTime = timer_value - last_timer_value;
1174 if (FrameTime < f1_0/max_fps);
1178 } while (FrameTime < f1_0/max_fps);
1180 #if defined(TIMER_TEST) && !defined(NDEBUG)
1181 _timer_value = timer_value;
1185 if (!(((FrameTime > 0) && (FrameTime <= F1_0)) || (Function_mode == FMODE_EDITOR) || (Newdemo_state == ND_STATE_PLAYBACK))) {
1186 mprintf((1,"Bad FrameTime - value = %x\n",FrameTime));
1188 Int3(); // Call Mike or Matt or John! Your interrupts are probably trashed!
1189 // if ( !dpmi_virtual_memory )
1190 // Int3(); //Get MATT if hit this!
1194 #if defined(TIMER_TEST) && !defined(NDEBUG)
1195 actual_last_timer_value = last_timer_value;
1198 if ( Game_turbo_mode )
1201 // Limit frametime to be between 5 and 150 fps.
1202 RealFrameTime = FrameTime;
1203 if ( FrameTime < F1_0/150 ) FrameTime = F1_0/150;
1204 if ( FrameTime > F1_0/5 ) FrameTime = F1_0/5;
1206 last_timer_value = timer_value;
1208 if (FrameTime < 0) //if bogus frametime...
1209 FrameTime = last_frametime; //...then use time from last frame
1212 if (fixed_frametime) FrameTime = fixed_frametime;
1217 if ( Debug_pause ) {
1227 last_timer_value = timer_get_fixed_seconds();
1235 #if defined(TIMER_TEST) && !defined(NDEBUG)
1236 stop_count = start_count = 0;
1239 // Set value to determine whether homing missile can see target.
1240 // The lower frametime is, the more likely that it can see its target.
1241 if (FrameTime <= F1_0/64)
1242 Min_trackable_dot = MIN_TRACKABLE_DOT; // -- 3*(F1_0 - MIN_TRACKABLE_DOT)/4 + MIN_TRACKABLE_DOT;
1243 else if (FrameTime < F1_0/32)
1244 Min_trackable_dot = MIN_TRACKABLE_DOT + F1_0/64 - 2*FrameTime; // -- fixmul(F1_0 - MIN_TRACKABLE_DOT, F1_0-4*FrameTime) + MIN_TRACKABLE_DOT;
1245 else if (FrameTime < F1_0/4)
1246 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;
1248 Min_trackable_dot = MIN_TRACKABLE_DOT + F1_0/64 - F1_0/8;
1252 //--unused-- int Auto_flythrough=0; //if set, start flythough automatically
1254 void move_player_2_segment(segment *seg,int side)
1258 compute_segment_center(&ConsoleObject->pos,seg);
1259 compute_center_point_on_side(&vp,seg,side);
1260 vm_vec_sub2(&vp,&ConsoleObject->pos);
1261 vm_vector_2_matrix(&ConsoleObject->orient,&vp,NULL,NULL);
1263 obj_relink( ConsoleObject-Objects, SEG_PTR_2_NUM(seg) );
1268 void game_draw_time_left()
1270 char temp_string[30];
1274 gr_set_curfont( GAME_FONT ); //GAME_FONT
1275 gr_set_fontcolor(gr_getcolor(0,63,0), -1 );
1277 timevar=i2f (Netgame.PlayTimeAllowed*5*60);
1278 i=f2i(timevar-ThisLevelTime);
1281 sprintf( temp_string, "Time left: %d secs", i );
1284 gr_string(0, 32, temp_string );
1289 extern int Game_pause;
1292 void level_with_floor();
1294 void modex_clear_box(int x,int y,int w,int h)
1296 grs_canvas *temp_canv,*save_canv;
1298 save_canv = grd_curcanv;
1299 temp_canv = gr_create_canvas(w,h);
1300 gr_set_current_canvas(temp_canv);
1301 gr_clear_canvas(BM_XRGB(0,0,0));
1302 gr_set_current_canvas(save_canv);
1303 gr_bitmapm(x,y,&temp_canv->cv_bitmap);
1304 gr_free_canvas(temp_canv);
1308 extern void modex_printf(int x,int y,char *s,grs_font *font,int color);
1310 // mac routine to drop contents of screen to a pict file using copybits
1311 // save a PICT to a file
1314 void SavePictScreen(int multiplayer)
1317 int parid, i, count;
1318 char *pfilename, filename[50], buf[512], cwd[FILENAME_MAX];
1321 PicHandle pict_handle;
1322 static int multi_count = 0;
1323 StandardFileReply sf_reply;
1325 // dump the contents of the GameWindow into a picture using copybits
1327 pict_handle = OpenPicture(&GameWindow->portRect);
1328 if (pict_handle == NULL)
1331 CopyBits(&GameWindow->portBits, &GameWindow->portBits, &GameWindow->portRect, &GameWindow->portRect, srcBic, NULL);
1334 // get the cwd to restore with chdir when done -- this keeps the mac world sane
1335 if (!getcwd(cwd, FILENAME_MAX))
1337 // create the fsspec
1339 sprintf(filename, "screen%d", multi_count++);
1340 pfilename = c2pstr(filename);
1343 StandardPutFile("\pSave PICT as:", pfilename, &sf_reply);
1344 if (!sf_reply.sfGood)
1346 memcpy( &spec, &(sf_reply.sfFile), sizeof(FSSpec) );
1347 if (sf_reply.sfReplacing)
1349 err = FSpCreate( &spec, 'ttxt', 'PICT', smSystemScript );
1353 // parid = GetAppDirId();
1354 err = FSMakeFSSpec(0, 0, pfilename, &spec);
1359 err = FSpCreate(&spec, 'ttxt', 'PICT', smSystemScript);
1364 // write the PICT file
1365 if ( FSpOpenDF(&spec, fsRdWrPerm, &fd) )
1367 memset(buf, 0, sizeof(buf));
1369 if ( FSWrite(fd, &count, buf) )
1371 count = GetHandleSize((Handle)pict_handle);
1372 HLock((Handle)pict_handle);
1373 if ( FSWrite(fd, &count, *pict_handle) ) {
1379 HUnlock((Handle)pict_handle);
1380 DisposeHandle((Handle)pict_handle);
1388 //automap_flag is now unused, since we just check if the screen we're
1389 //writing to is modex
1390 //if called from automap, current canvas is set to visible screen
1392 void save_screen_shot(int automap_flag)
1394 #if defined(WINDOWS)
1395 mprintf((0, "Doing screen shot thing.\n"));
1396 win95_save_pcx_shot();
1398 #elif !defined(MACINTOSH)
1401 grs_canvas *screen_canv=&grd_curscreen->sc_canvas;
1402 grs_font *save_font;
1403 static int savenum=0;
1404 static int stereo_savenum=0;
1405 grs_canvas *temp_canv,*temp_canv2,*save_canv;
1406 char savename[FILENAME_LEN],savename2[FILENAME_LEN];
1414 // // Can't do screen shots in VR modes.
1415 // if ( VR_render_mode != VR_NONE )
1420 save_canv = grd_curcanv;
1422 if ( VR_render_mode != VR_NONE && !automap_flag && Function_mode==FMODE_GAME && Screen_mode==SCREEN_GAME)
1426 temp_canv = gr_create_canvas(VR_render_buffer[0].cv_bitmap.bm_w,VR_render_buffer[0].cv_bitmap.bm_h);
1427 gr_set_current_canvas(temp_canv);
1428 gr_ubitmap(0,0,&VR_render_buffer[0].cv_bitmap);
1430 temp_canv2 = gr_create_canvas(VR_render_buffer[1].cv_bitmap.bm_w,VR_render_buffer[1].cv_bitmap.bm_h);
1431 gr_set_current_canvas(temp_canv2);
1432 gr_ubitmap(0,0,&VR_render_buffer[1].cv_bitmap);
1435 temp_canv = gr_create_canvas(screen_canv->cv_bitmap.bm_w,screen_canv->cv_bitmap.bm_h);
1436 gr_set_current_canvas(temp_canv);
1437 gr_ubitmap(0,0,&screen_canv->cv_bitmap);
1440 gr_set_current_canvas(save_canv);
1442 if ( savenum > 99 ) savenum = 0;
1443 if ( stereo_savenum > 99 ) stereo_savenum = 0;
1446 sprintf(savename,"left%02d.pcx",stereo_savenum);
1447 sprintf(savename2,"right%02d.pcx",stereo_savenum);
1448 if (VR_eye_switch) {char t[FILENAME_LEN]; strcpy(t,savename); strcpy(savename,savename2); strcpy(savename2,t);}
1450 sprintf( message, "%s '%s' & '%s'", TXT_DUMPING_SCREEN, savename, savename2 );
1453 sprintf(savename,"screen%02d.pcx",savenum++);
1454 sprintf( message, "%s '%s'", TXT_DUMPING_SCREEN, savename );
1457 if (!automap_flag) //if from automap, curcanv is already visible canv
1458 gr_set_current_canvas(NULL);
1459 modex_flag = (grd_curcanv->cv_bitmap.bm_type==BM_MODEX);
1460 if (!automap_flag && modex_flag)
1461 gr_set_current_canvas(&VR_screen_pages[VR_current_page]);
1463 save_font = grd_curcanv->cv_font;
1464 gr_set_curfont(GAME_FONT);
1465 gr_set_fontcolor(gr_find_closest_color_current(0,31,0),-1);
1466 gr_get_string_size(message,&w,&h,&aw);
1471 //I changed how these coords were calculated for the high-res automap. -MT
1472 //x = (VR_screen_pages[VR_current_page].cv_w-w)/2;
1473 //y = (VR_screen_pages[VR_current_page].cv_h-h)/2;
1474 x = (grd_curcanv->cv_w-w)/2;
1475 y = (grd_curcanv->cv_h-h)/2;
1478 modex_clear_box(x-2,y-2,w+4,h+4);
1479 modex_printf(x, y, message,GAME_FONT,gr_find_closest_color_current(0,31,0));
1481 gr_setcolor(gr_find_closest_color_current(0,0,0));
1482 gr_rect(x-2,y-2,x+w+2,y+h+2);
1483 gr_printf(x,y,message);
1484 gr_set_curfont(save_font);
1486 t1 = timer_get_fixed_seconds() + F1_0;
1488 gr_palette_read(pal); //get actual palette from the hardware
1489 pcx_write_bitmap(savename,&temp_canv->cv_bitmap,pal);
1491 pcx_write_bitmap(savename2,&temp_canv2->cv_bitmap,pal);
1493 while ( timer_get_fixed_seconds() < t1 ); // Wait so that messag stays up at least 1 second.
1495 gr_set_current_canvas(screen_canv);
1497 if (grd_curcanv->cv_bitmap.bm_type!=BM_MODEX && !stereo)
1498 gr_ubitmap(0,0,&temp_canv->cv_bitmap);
1500 gr_free_canvas(temp_canv);
1502 gr_free_canvas(temp_canv2);
1504 gr_set_current_canvas(save_canv);
1510 grs_canvas *screen_canv = &grd_curscreen->sc_canvas;
1511 grs_canvas *temp_canv, *save_canv;
1513 // Can't do screen shots in VR modes.
1514 if ( VR_render_mode != VR_NONE )
1519 save_canv = grd_curcanv;
1520 temp_canv = gr_create_canvas( screen_canv->cv_bitmap.bm_w, screen_canv->cv_bitmap.bm_h );
1523 gr_set_current_canvas( temp_canv );
1524 gr_ubitmap( 0, 0, &screen_canv->cv_bitmap );
1525 gr_set_current_canvas( &VR_screen_pages[VR_current_page] );
1529 if (Game_mode & GM_MULTI)
1536 gr_set_current_canvas(screen_canv);
1538 // if (!automap_flag)
1539 gr_ubitmap( 0, 0, &temp_canv->cv_bitmap);
1541 gr_free_canvas(temp_canv);
1543 gr_set_current_canvas(save_canv);
1552 void fly_init(object *obj)
1554 obj->control_type = CT_FLYING;
1555 obj->movement_type = MT_PHYSICS;
1557 vm_vec_zero(&obj->mtype.phys_info.velocity);
1558 vm_vec_zero(&obj->mtype.phys_info.thrust);
1559 vm_vec_zero(&obj->mtype.phys_info.rotvel);
1560 vm_vec_zero(&obj->mtype.phys_info.rotthrust);
1563 //void morph_test(), morph_step();
1566 // ------------------------------------------------------------------------------------
1568 void test_anim_states();
1572 //put up the help message
1579 extern int been_in_editor;
1581 // ------------------------------------------------------------------------------------
1582 void do_cloak_stuff(void)
1585 for (i = 0; i < N_players; i++)
1586 if (Players[i].flags & PLAYER_FLAGS_CLOAKED) {
1587 // mprintf(0, "Cloak time left: %7.3f\n", f2fl(CLOAK_TIME_MAX - (GameTime - Players[Player_num].cloak_time)));
1588 if (GameTime - Players[i].cloak_time > CLOAK_TIME_MAX) {
1589 Players[i].flags &= ~PLAYER_FLAGS_CLOAKED;
1590 if (i == Player_num) {
1591 digi_play_sample( SOUND_CLOAK_OFF, F1_0);
1593 if (Game_mode & GM_MULTI)
1594 multi_send_play_sound(SOUND_CLOAK_OFF, F1_0);
1595 maybe_drop_net_powerup(POW_CLOAK);
1596 multi_send_decloak(); // For demo recording
1598 // mprintf((0, " --- You have been DE-CLOAKED! ---\n"));
1606 // ------------------------------------------------------------------------------------
1607 void do_invulnerable_stuff(void)
1609 if (Players[Player_num].flags & PLAYER_FLAGS_INVULNERABLE) {
1610 if (GameTime - Players[Player_num].invulnerable_time > INVULNERABLE_TIME_MAX) {
1611 Players[Player_num].flags ^= PLAYER_FLAGS_INVULNERABLE;
1614 digi_play_sample( SOUND_INVULNERABILITY_OFF, F1_0);
1616 if (Game_mode & GM_MULTI)
1618 multi_send_play_sound(SOUND_INVULNERABILITY_OFF, F1_0);
1619 maybe_drop_net_powerup(POW_INVULNERABILITY);
1622 mprintf((0, " --- You have been DE-INVULNERABLEIZED! ---\n"));
1629 ubyte Last_afterburner_state = 0;
1630 fix Last_afterburner_charge = 0;
1632 #define AFTERBURNER_LOOP_START ((digi_sample_rate==SAMPLE_RATE_22K)?32027:(32027/2)) //20098
1633 #define AFTERBURNER_LOOP_END ((digi_sample_rate==SAMPLE_RATE_22K)?48452:(48452/2)) //25776
1637 //@@// ------------------------------------------------------------------------------------
1638 //@@void afterburner_shake(void)
1642 //@@ rx = (Ab_scale * fixmul(d_rand() - 16384, F1_0/8 + (((GameTime + 0x4000)*4) & 0x3fff)))/16;
1643 //@@ rz = (Ab_scale * fixmul(d_rand() - 16384, F1_0/2 + ((GameTime*4) & 0xffff)))/16;
1645 //@@ // -- mprintf((0, "AB: %8x %8x\n", rx, rz));
1646 //@@ ConsoleObject->mtype.phys_info.rotvel.x += rx;
1647 //@@ ConsoleObject->mtype.phys_info.rotvel.z += rz;
1651 // ------------------------------------------------------------------------------------
1653 extern void multi_send_sound_function (char,char);
1656 void do_afterburner_stuff(void)
1658 if (!(Players[Player_num].flags & PLAYER_FLAGS_AFTERBURNER))
1659 Afterburner_charge=0;
1661 if (Endlevel_sequence || Player_is_dead)
1663 digi_kill_sound_linked_to_object( Players[Player_num].objnum);
1665 multi_send_sound_function (0,0);
1669 if ((Controls.afterburner_state != Last_afterburner_state && Last_afterburner_charge) || (Last_afterburner_state && Last_afterburner_charge && !Afterburner_charge)) {
1671 if (Afterburner_charge && Controls.afterburner_state && (Players[Player_num].flags & PLAYER_FLAGS_AFTERBURNER)) {
1672 digi_link_sound_to_object3( SOUND_AFTERBURNER_IGNITE, Players[Player_num].objnum, 1, F1_0, i2f(256), AFTERBURNER_LOOP_START, AFTERBURNER_LOOP_END );
1674 if (Game_mode & GM_MULTI)
1675 multi_send_sound_function (3,SOUND_AFTERBURNER_IGNITE);
1678 digi_kill_sound_linked_to_object( Players[Player_num].objnum);
1679 digi_link_sound_to_object2( SOUND_AFTERBURNER_PLAY, Players[Player_num].objnum, 0, F1_0, i2f(256));
1681 if (Game_mode & GM_MULTI)
1682 multi_send_sound_function (0,0);
1684 mprintf((0,"Killing afterburner sound\n"));
1688 //@@if (Controls.afterburner_state && Afterburner_charge)
1689 //@@ afterburner_shake();
1691 Last_afterburner_state = Controls.afterburner_state;
1692 Last_afterburner_charge = Afterburner_charge;
1695 // -- // ------------------------------------------------------------------------------------
1696 // -- // if energy < F1_0/2, recharge up to F1_0/2
1697 // -- void recharge_energy_frame(void)
1699 // -- if (Players[Player_num].energy < Weapon_info[0].energy_usage) {
1700 // -- Players[Player_num].energy += FrameTime/4;
1702 // -- if (Players[Player_num].energy > Weapon_info[0].energy_usage)
1703 // -- Players[Player_num].energy = Weapon_info[0].energy_usage;
1707 // Amount to diminish guns towards normal, per second.
1708 #define DIMINISH_RATE 16 // gots to be a power of 2, else change the code in diminish_palette_towards_normal
1710 extern fix Flash_effect;
1712 //adds to rgb values for palette flash
1713 void PALETTE_FLASH_ADD(int _dr,int _dg,int _db)
1717 PaletteRedAdd += _dr;
1718 PaletteGreenAdd += _dg;
1719 PaletteBlueAdd += _db;
1721 // -- mprintf((0, "Palette add: %3i %3i %3i\n", PaletteRedAdd, PaletteGreenAdd, PaletteBlueAdd));
1726 maxval = MAX_PALETTE_ADD;
1728 if (PaletteRedAdd > maxval)
1729 PaletteRedAdd = maxval;
1731 if (PaletteGreenAdd > maxval)
1732 PaletteGreenAdd = maxval;
1734 if (PaletteBlueAdd > maxval)
1735 PaletteBlueAdd = maxval;
1737 if (PaletteRedAdd < -maxval)
1738 PaletteRedAdd = -maxval;
1740 if (PaletteGreenAdd < -maxval)
1741 PaletteGreenAdd = -maxval;
1743 if (PaletteBlueAdd < -maxval)
1744 PaletteBlueAdd = -maxval;
1747 fix Time_flash_last_played;
1750 void game_palette_step_up( int r, int g, int b );
1751 // ------------------------------------------------------------------------------------
1752 // Diminish palette effects towards normal.
1753 void diminish_palette_towards_normal(void)
1757 // Diminish at DIMINISH_RATE units/second.
1758 // For frame rates > DIMINISH_RATE Hz, use randomness to achieve this.
1759 if (FrameTime < F1_0/DIMINISH_RATE) {
1760 if (d_rand() < FrameTime*DIMINISH_RATE/2) // Note: d_rand() is in 0..32767, and 8 Hz means decrement every frame
1763 dec_amount = f2i(FrameTime*DIMINISH_RATE); // one second = DIMINISH_RATE counts
1764 if (dec_amount == 0)
1765 dec_amount++; // make sure we decrement by something
1771 // Part of hack system to force update of palette after exiting a menu.
1772 if (Time_flash_last_played) {
1774 PaletteRedAdd ^= 1; // Very Tricky! In gr_palette_step_up, if all stepups same as last time, won't do anything!
1777 if ((Time_flash_last_played + F1_0/8 < GameTime) || (Time_flash_last_played > GameTime)) {
1778 digi_play_sample( SOUND_CLOAK_OFF, Flash_effect/4);
1779 Time_flash_last_played = GameTime;
1782 Flash_effect -= FrameTime;
1783 if (Flash_effect < 0)
1786 if (force_do || (d_rand() > 4096 )) {
1787 if ( (Newdemo_state==ND_STATE_RECORDING) && (PaletteRedAdd || PaletteGreenAdd || PaletteBlueAdd) )
1788 newdemo_record_palette_effect(PaletteRedAdd, PaletteGreenAdd, PaletteBlueAdd);
1790 game_palette_step_up( PaletteRedAdd, PaletteGreenAdd, PaletteBlueAdd );
1797 if (PaletteRedAdd > 0 ) { PaletteRedAdd -= dec_amount; if (PaletteRedAdd < 0 ) PaletteRedAdd = 0; }
1798 if (PaletteRedAdd < 0 ) { PaletteRedAdd += dec_amount; if (PaletteRedAdd > 0 ) PaletteRedAdd = 0; }
1800 if (PaletteGreenAdd > 0 ) { PaletteGreenAdd -= dec_amount; if (PaletteGreenAdd < 0 ) PaletteGreenAdd = 0; }
1801 if (PaletteGreenAdd < 0 ) { PaletteGreenAdd += dec_amount; if (PaletteGreenAdd > 0 ) PaletteGreenAdd = 0; }
1803 if (PaletteBlueAdd > 0 ) { PaletteBlueAdd -= dec_amount; if (PaletteBlueAdd < 0 ) PaletteBlueAdd = 0; }
1804 if (PaletteBlueAdd < 0 ) { PaletteBlueAdd += dec_amount; if (PaletteBlueAdd > 0 ) PaletteBlueAdd = 0; }
1806 if ( (Newdemo_state==ND_STATE_RECORDING) && (PaletteRedAdd || PaletteGreenAdd || PaletteBlueAdd) )
1807 newdemo_record_palette_effect(PaletteRedAdd, PaletteGreenAdd, PaletteBlueAdd);
1809 game_palette_step_up( PaletteRedAdd, PaletteGreenAdd, PaletteBlueAdd );
1811 //mprintf(0, "%2i %2i %2i\n", PaletteRedAdd, PaletteGreenAdd, PaletteBlueAdd);
1814 int Redsave, Bluesave, Greensave;
1816 void palette_save(void)
1818 Redsave = PaletteRedAdd; Bluesave = PaletteBlueAdd; Greensave = PaletteGreenAdd;
1821 extern void gr_palette_step_up_vr( int r, int g, int b, int white, int black );
1823 void game_palette_step_up( int r, int g, int b )
1825 if ( VR_use_reg_code ) {
1827 // gr_palette_step_up_vr( r, g, b, VR_WHITE_INDEX, VR_BLACK_INDEX );
1830 gr_palette_step_up( r, g, b );
1834 void palette_restore(void)
1836 PaletteRedAdd = Redsave; PaletteBlueAdd = Bluesave; PaletteGreenAdd = Greensave;
1837 game_palette_step_up( PaletteRedAdd, PaletteGreenAdd, PaletteBlueAdd );
1839 // Forces flash effect to fixup palette next frame.
1840 Time_flash_last_played = 0;
1843 extern void dead_player_frame(void);
1846 // --------------------------------------------------------------------------------------------------
1847 int allowed_to_fire_laser(void)
1849 if (Player_is_dead) {
1850 Global_missile_firing_count = 0;
1854 // Make sure enough time has elapsed to fire laser, but if it looks like it will
1855 // be a long while before laser can be fired, then there must be some mistake!
1856 if (Next_laser_fire_time > GameTime)
1857 if (Next_laser_fire_time < GameTime + 2*F1_0)
1863 fix Next_flare_fire_time = 0;
1864 #define FLARE_BIG_DELAY (F1_0*2)
1866 int allowed_to_fire_flare(void)
1868 if (Next_flare_fire_time > GameTime)
1869 if (Next_flare_fire_time < GameTime + FLARE_BIG_DELAY) // In case time is bogus, never wait > 1 second.
1872 if (Players[Player_num].energy >= Weapon_info[FLARE_ID].energy_usage)
1873 Next_flare_fire_time = GameTime + F1_0/4;
1875 Next_flare_fire_time = GameTime + FLARE_BIG_DELAY;
1880 int allowed_to_fire_missile(void)
1882 // mprintf(0, "Next fire = %7.3f, Cur time = %7.3f\n", f2fl(Next_missile_fire_time), f2fl(GameTime));
1883 // Make sure enough time has elapsed to fire missile, but if it looks like it will
1884 // be a long while before missile can be fired, then there must be some mistake!
1885 if (Next_missile_fire_time > GameTime)
1886 if (Next_missile_fire_time < GameTime + 5*F1_0)
1892 void full_palette_save(void)
1895 apply_modified_palette();
1896 reset_palette_add();
1897 gr_palette_load( gr_palette );
1900 extern int Death_sequence_aborted;
1901 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) );
1908 char command_help[64], pixel_double_help[64], save_help[64], restore_help[64];
1911 m[ 0].type = NM_TYPE_TEXT; m[ 0].text = TXT_HELP_ESC;
1913 m[ 1].type = NM_TYPE_TEXT; m[ 1].text = TXT_HELP_ALT_F2;
1914 m[ 2].type = NM_TYPE_TEXT; m[ 2].text = TXT_HELP_ALT_F3;
1916 sprintf(save_help, "OPT-F2 (%c-s)\t Save Game", 133);
1917 sprintf(restore_help, "OPT-F3 (%c-o)\t Load Game", 133);
1918 m[ 1].type = NM_TYPE_TEXT; m[1].text = save_help;
1919 m[ 2].type = NM_TYPE_TEXT; m[2].text = restore_help;
1921 m[ 3].type = NM_TYPE_TEXT; m[ 3].text = TXT_HELP_F2;
1922 m[ 4].type = NM_TYPE_TEXT; m[ 4].text = TXT_HELP_F3;
1923 m[ 5].type = NM_TYPE_TEXT; m[ 5].text = TXT_HELP_F4;
1924 m[ 6].type = NM_TYPE_TEXT; m[ 6].text = TXT_HELP_F5;
1926 m[ 7].type = NM_TYPE_TEXT; m[ 7].text = TXT_HELP_PAUSE;
1928 m[ 7].type = NM_TYPE_TEXT; m[ 7].text = "Pause (F15)\t Pause";
1930 m[ 8].type = NM_TYPE_TEXT; m[ 8].text = TXT_HELP_MINUSPLUS;
1932 m[ 9].type = NM_TYPE_TEXT; m[ 9].text = TXT_HELP_PRTSCN;
1934 m[ 9].type = NM_TYPE_TEXT; m[ 9].text = "printscrn (F13)\t save screen shot";
1936 m[10].type = NM_TYPE_TEXT; m[10].text = TXT_HELP_1TO5;
1937 m[11].type = NM_TYPE_TEXT; m[11].text = TXT_HELP_6TO10;
1938 m[12].type = NM_TYPE_TEXT; m[12].text = "Shift-F1\t Cycle left window";
1939 m[13].type = NM_TYPE_TEXT; m[13].text = "Shift-F2\t Cycle right window";
1940 m[14].type = NM_TYPE_TEXT; m[14].text = "Shift-F4\t GuideBot menu";
1942 m[15].type = NM_TYPE_TEXT; m[15].text = "Alt-Shift-F4\t Rename GuideBot";
1944 m[15].type = NM_TYPE_TEXT; m[15].text = "Opt-Shift-F4\t Rename GuideBot";
1946 m[16].type = NM_TYPE_TEXT; m[16].text = "Shift-F5\t Drop primary";
1947 m[17].type = NM_TYPE_TEXT; m[17].text = "Shift-F6\t Drop secondary";
1948 m[18].type = NM_TYPE_TEXT; m[18].text = "Shift-F7\t Calibrate joystick";
1949 m[19].type = NM_TYPE_TEXT; m[19].text = "Shift-number\t GuideBot commands";
1952 sprintf(pixel_double_help, "%c-D\t Toggle Pixel Double Mode", 133);
1953 m[20].type = NM_TYPE_TEXT; m[20].text = pixel_double_help;
1954 m[21].type = NM_TYPE_TEXT; m[21].text = "";
1955 sprintf(command_help, "(Use %c-# for F#. i.e. %c-1 for F1)", 133, 133);
1956 m[22].type = NM_TYPE_TEXT; m[22].text = command_help;
1960 full_palette_save();
1962 newmenu_dotiny2( NULL, TXT_KEYS, nitems, m, NULL );
1967 //temp function until Matt cleans up game sequencing
1968 extern void temp_reset_stuff_on_level();
1970 //deal with rear view - switch it on, or off, or whatever
1971 void check_rear_view()
1974 #define LEAVE_TIME 0x1000 //how long until we decide key is down (Used to be 0x4000)
1976 static int leave_mode;
1977 static fix entry_time;
1979 if ( Controls.rear_view_down_count ) { //key/button has gone down
1983 if (Cockpit_mode==CM_REAR_VIEW) {
1984 select_cockpit(Cockpit_mode_save);
1985 Cockpit_mode_save = -1;
1987 if (Newdemo_state == ND_STATE_RECORDING)
1988 newdemo_record_restore_rearview();
1992 leave_mode = 0; //means wait for another key
1993 entry_time = timer_get_fixed_seconds();
1994 if (Cockpit_mode == CM_FULL_COCKPIT) {
1995 Cockpit_mode_save = Cockpit_mode;
1996 select_cockpit(CM_REAR_VIEW);
1998 if (Newdemo_state == ND_STATE_RECORDING)
1999 newdemo_record_rearview();
2003 if (Controls.rear_view_down_state) {
2005 if (leave_mode==0 && (timer_get_fixed_seconds()-entry_time)>LEAVE_TIME)
2010 //@@if (leave_mode==1 && Cockpit_mode==CM_REAR_VIEW) {
2012 if (leave_mode==1 && Rear_view) {
2014 if (Cockpit_mode==CM_REAR_VIEW) {
2015 select_cockpit(Cockpit_mode_save);
2016 Cockpit_mode_save = -1;
2018 if (Newdemo_state == ND_STATE_RECORDING)
2019 newdemo_record_restore_rearview();
2024 void reset_rear_view(void)
2027 if (Newdemo_state == ND_STATE_RECORDING)
2028 newdemo_record_restore_rearview();
2033 if (!(Cockpit_mode == CM_FULL_COCKPIT || Cockpit_mode == CM_STATUS_BAR || Cockpit_mode == CM_FULL_SCREEN)) {
2034 if (!(Cockpit_mode_save == CM_FULL_COCKPIT || Cockpit_mode_save == CM_STATUS_BAR || Cockpit_mode_save == CM_FULL_SCREEN))
2035 Cockpit_mode_save = CM_FULL_COCKPIT;
2036 select_cockpit(Cockpit_mode_save);
2037 Cockpit_mode_save = -1;
2043 int Config_menu_flag;
2047 int Cheats_enabled=0;
2049 extern int Laser_rapid_fire;
2050 extern void do_lunacy_on(), do_lunacy_off();
2052 extern int Physics_cheat_flag,Robots_kill_robots_cheat;
2053 extern char BounceCheat,HomingCheat,OldHomingState[20];
2054 extern char AcidCheatOn,old_IntMethod, Monster_mode;
2055 extern int Buddy_dude_cheat;
2057 //turns off active cheats
2058 void turn_cheats_off()
2064 Weapon_info[i].homing_flag=OldHomingState[i];
2069 Interpolation_method=old_IntMethod;
2072 Buddy_dude_cheat = 0;
2076 Laser_rapid_fire = 0;
2077 Physics_cheat_flag = 0;
2079 Robots_kill_robots_cheat=0;
2080 Robot_firing_enabled = 1;
2083 //turns off all cheats & resets cheater flag
2084 void game_disable_cheats()
2092 // ----------------------------------------------------------------------------
2094 void game_setup(void)
2096 //@@int demo_playing=0;
2097 //@@int multi_game=0;
2099 do_lunacy_on(); // Copy values for insane into copy buffer in ai.c
2100 do_lunacy_off(); // Restore true insane mode.
2103 last_drawn_cockpit[0] = -1; // Force cockpit to redraw next time a frame renders.
2104 last_drawn_cockpit[1] = -1; // Force cockpit to redraw next time a frame renders.
2105 Endlevel_sequence = 0;
2107 //@@if ( Newdemo_state == ND_STATE_PLAYBACK )
2108 //@@ demo_playing = 1;
2109 //@@if ( Game_mode & GM_MULTI )
2110 //@@ multi_game = 1;
2112 set_screen_mode(SCREEN_GAME);
2113 reset_palette_add();
2115 set_warn_func(game_show_warning);
2119 //digi_init_sounds();
2121 //keyd_repeat = 0; // Don't allow repeat in game
2122 keyd_repeat = 1; // Do allow repeat in game
2124 #if !defined(WINDOWS) && !defined(MACINTOSH)
2125 //_MARK_("start of game");
2129 if (Segments[ConsoleObject->segnum].segnum == -1) //segment no longer exists
2130 obj_relink( ConsoleObject-Objects, SEG_PTR_2_NUM(Cursegp) );
2132 if (!check_obj_seg(ConsoleObject))
2133 move_player_2_segment(Cursegp,Curside);
2136 Viewer = ConsoleObject;
2137 fly_init(ConsoleObject);
2142 FrameTime = 0; //make first frame zero
2145 if (Current_level_num == 0) { //not a real level
2146 init_player_stats_game();
2153 game_flush_inputs();
2159 extern char IWasKicked;
2163 // ------------------------------------------------------------------------------------
2164 //this function is the game. called when game mode selected. runs until
2165 //editor mode or exit selected
2168 game_setup(); // Replaces what was here earlier.
2169 // Good for Windows Sake.
2172 ProfilerSetStatus(1);
2175 if ( setjmp(LeaveGame)==0 ) {
2181 Config_menu_flag = 0;
2183 if ( ConsoleObject != &Objects[Players[Player_num].objnum] )
2185 mprintf ((0,"Player_num=%d objnum=%d",Player_num,Players[Player_num].objnum));
2186 //Assert( ConsoleObject == &Objects[Players[Player_num].objnum] );
2189 player_shields = Players[Player_num].shields;
2194 DoMessageStuff(&msg); // Do Windows event handling.
2195 if (_RedrawScreen) {
2196 _RedrawScreen = FALSE;
2197 load_palette(Current_level_palette,1,1);
2198 gr_palette_load(gr_palette);
2203 ExtGameStatus=GAMESTAT_RUNNING;
2204 GameLoop( 1, 1 ); // Do game loop with rendering and reading controls.
2206 //if the player is taking damage, give up guided missile control
2207 if (Players[Player_num].shields != player_shields)
2208 release_guided_missile(Player_num);
2210 //see if redbook song needs to be restarted
2211 songs_check_redbook_repeat(); // Handle RedBook Audio Repeating.
2213 if (Config_menu_flag) {
2214 int double_save = Scanline_double;
2216 //WIN(mouse_set_mode(0));
2217 if (!(Game_mode&GM_MULTI)) {palette_save(); reset_palette_add(); apply_modified_palette(); gr_palette_load( gr_palette ); }
2219 if (Scanline_double != double_save) init_cockpit();
2220 if (!(Game_mode&GM_MULTI)) palette_restore();
2221 //WIN(mouse_set_mode(1));
2225 int save_w=Game_window_w,save_h=Game_window_h;
2227 Screen_mode=-1; set_screen_mode(SCREEN_GAME);
2228 Game_window_w=save_w; Game_window_h=save_h;
2230 last_drawn_cockpit[0] = -1;
2231 last_drawn_cockpit[1] = -1;
2234 if ( (Function_mode != FMODE_GAME) && Auto_demo && (Newdemo_state != ND_STATE_NORMAL) ) {
2236 fmode = Function_mode;
2237 Function_mode = FMODE_GAME;
2239 apply_modified_palette();
2240 reset_palette_add();
2241 gr_palette_load( gr_palette );
2242 choice=nm_messagebox( NULL, 2, TXT_YES, TXT_NO, TXT_ABORT_AUTODEMO );
2244 Function_mode = fmode;
2247 newdemo_stop_playback();
2248 Function_mode = FMODE_MENU;
2250 Function_mode = FMODE_GAME;
2254 if ( (Function_mode != FMODE_GAME ) && (Newdemo_state != ND_STATE_PLAYBACK ) && (Function_mode!=FMODE_EDITOR)
2260 fmode = Function_mode;
2261 Function_mode = FMODE_GAME;
2263 apply_modified_palette();
2264 reset_palette_add();
2265 gr_palette_load( gr_palette );
2266 ExtGameStatus=GAMESTAT_ABORT_GAME;
2267 choice=nm_messagebox( NULL, 2, TXT_YES, TXT_NO, TXT_ABORT_GAME );
2269 Function_mode = fmode;
2271 Function_mode = FMODE_GAME;
2277 if (Function_mode != FMODE_GAME)
2278 longjmp(LeaveGame,0);
2281 if ( (keyd_time_when_last_pressed + (F1_0 * 60)) < timer_get_fixed_seconds() ) // idle in game for 1 minutes means exit
2282 longjmp(LeaveGame,0);
2288 ProfilerSetStatus(0);
2293 if ( (Newdemo_state == ND_STATE_RECORDING) || (Newdemo_state == ND_STATE_PAUSED) )
2294 newdemo_stop_recording();
2300 if ( Newdemo_state == ND_STATE_PLAYBACK )
2301 newdemo_stop_playback();
2303 if (Cockpit_mode_save!=-1)
2305 Cockpit_mode=Cockpit_mode_save;
2306 Cockpit_mode_save=-1;
2309 if (Function_mode != FMODE_EDITOR)
2310 gr_palette_fade_out(gr_palette,32,0); // Fade out before going to menu
2312 //@@ if ( (!demo_playing) && (!multi_game) && (Function_mode != FMODE_EDITOR)) {
2313 //@@ scores_maybe_add_player(Game_aborted);
2316 #if !defined(WINDOWS) && !defined(MACINTOSH)
2317 //_MARK_("end of game");
2320 clear_warn_func(game_show_warning); //don't use this func anymore
2322 game_disable_cheats();
2325 Function_mode = FMODE_EXIT; // get out of game in Apple OEM version
2329 //called at the end of the program
2333 if (dd_VR_offscreen_buffer) {
2334 if (dd_grd_backcanv != dd_VR_offscreen_buffer) {
2335 dd_gr_free_canvas(dd_VR_offscreen_buffer);
2337 dd_VR_offscreen_buffer = NULL;
2338 VR_offscreen_buffer = NULL;
2341 if (VR_offscreen_buffer) {
2342 gr_free_canvas(VR_offscreen_buffer);
2343 VR_offscreen_buffer = NULL;
2347 close_gauge_canvases();
2349 restore_effect_bitmap_icons();
2351 #if !defined(MACINTOSH) && !defined(WINDOWS)
2352 if (Game_cockpit_copy_code) {
2353 d_free(Game_cockpit_copy_code);
2354 Game_cockpit_copy_code = NULL;
2357 if (Game_cockpit_copy_code)
2358 Game_cockpit_copy_code = 0;
2361 if (background_bitmap.bm_data)
2362 d_free(background_bitmap.bm_data);
2364 clear_warn_func(game_show_warning); //don't use this func anymore
2368 dd_grs_canvas * get_current_game_screen()
2370 return &dd_VR_screen_pages[VR_current_page];
2375 grs_canvas * get_current_game_screen()
2377 return &VR_screen_pages[VR_current_page];
2382 extern void kconfig_center_headset();
2386 void speedtest_frame(void);
2387 int Debug_slowdown=0;
2391 extern void player_follow_path(object *objp);
2392 extern void check_create_player_path(void);
2396 extern int Do_appearance_effect;
2398 object *Missile_viewer=NULL;
2400 int Missile_view_enabled = 1;
2402 int Marker_viewer_num[2]={-1,-1};
2403 int Coop_view_player[2]={-1,-1};
2404 int Cockpit_3d_view[2]={CV_NONE,CV_NONE};
2406 //returns ptr to escort robot, or NULL
2407 object *find_escort()
2411 for (i=0; i<=Highest_object_index; i++)
2412 if (Objects[i].type == OBJ_ROBOT)
2413 if (Robot_info[Objects[i].id].companion)
2419 extern void process_super_mines_frame(void);
2420 extern void do_seismic_stuff(void);
2423 int Saving_movie_frames=0;
2424 int __Movie_frame_num=0;
2426 #define MAX_MOVIE_BUFFER_FRAMES 250
2427 #define MOVIE_FRAME_SIZE (320 * 200)
2429 ubyte *Movie_frame_buffer;
2430 int Movie_frame_counter;
2431 ubyte Movie_pal[768];
2432 char movie_path[50] = ".\\";
2434 grs_bitmap Movie_bm;
2436 void flush_movie_buffer()
2443 mprintf((0,"Flushing movie buffer..."));
2445 Movie_bm.bm_data = Movie_frame_buffer;
2447 for (f=0;f<Movie_frame_counter;f++) {
2448 sprintf(savename, "%sfrm%04d.pcx",movie_path,__Movie_frame_num);
2449 __Movie_frame_num++;
2450 pcx_write_bitmap(savename,&Movie_bm,Movie_pal);
2451 Movie_bm.bm_data += MOVIE_FRAME_SIZE;
2454 mprintf((0,"%3d/%3d\10\10\10\10\10\10\10",f,Movie_frame_counter));
2457 Movie_frame_counter=0;
2459 mprintf((0,"done \n"));
2464 void toggle_movie_saving()
2468 Saving_movie_frames = !Saving_movie_frames;
2470 if (Saving_movie_frames) {
2473 m[0].type=NM_TYPE_INPUT; m[0].text_len = 50; m[0].text = movie_path;
2474 exit = newmenu_do( NULL, "Directory for movie frames?" , 1, &(m[0]), NULL );
2477 Saving_movie_frames = 0;
2481 while (isspace(movie_path[strlen(movie_path)-1]))
2482 movie_path[strlen(movie_path)-1] = 0;
2483 if (movie_path[strlen(movie_path)-1]!='\\' && movie_path[strlen(movie_path)-1]!=':')
2484 strcat(movie_path,"\\");
2487 if (!Movie_frame_buffer) {
2488 Movie_frame_buffer = d_malloc(MAX_MOVIE_BUFFER_FRAMES * MOVIE_FRAME_SIZE);
2489 if (!Movie_frame_buffer) {
2491 Saving_movie_frames=0;
2494 Movie_frame_counter=0;
2496 Movie_bm.bm_x = Movie_bm.bm_y = 0;
2497 Movie_bm.bm_w = 320;
2498 Movie_bm.bm_h = 200;
2499 Movie_bm.bm_type = BM_LINEAR;
2500 Movie_bm.bm_flags = 0;
2501 Movie_bm.bm_rowsize = 320;
2502 Movie_bm.bm_handle = 0;
2504 gr_palette_read(Movie_pal); //get actual palette from the hardware
2506 if (Newdemo_state == ND_STATE_PLAYBACK)
2507 Newdemo_do_interpolate = 0;
2511 flush_movie_buffer();
2513 if (Newdemo_state == ND_STATE_PLAYBACK)
2514 Newdemo_do_interpolate = 1;
2519 void save_movie_frame()
2521 memcpy(Movie_frame_buffer+Movie_frame_counter*MOVIE_FRAME_SIZE,grd_curscreen->sc_canvas.cv_bitmap.bm_data,MOVIE_FRAME_SIZE);
2523 Movie_frame_counter++;
2525 if (Movie_frame_counter == MAX_MOVIE_BUFFER_FRAMES)
2526 flush_movie_buffer();
2532 extern int Level_shake_duration;
2534 //if water or fire level, make occasional sound
2535 void do_ambient_sounds()
2537 int has_water,has_lava;
2540 has_lava = (Segment2s[ConsoleObject->segnum].s2_flags & S2F_AMBIENT_LAVA);
2541 has_water = (Segment2s[ConsoleObject->segnum].s2_flags & S2F_AMBIENT_WATER);
2543 if (has_lava) { //has lava
2544 sound = SOUND_AMBIENT_LAVA;
2545 if (has_water && (d_rand() & 1)) //both, pick one
2546 sound = SOUND_AMBIENT_WATER;
2548 else if (has_water) //just water
2549 sound = SOUND_AMBIENT_WATER;
2553 if (((d_rand() << 3) < FrameTime)) { //play the sound
2554 fix volume = d_rand() + f1_0/2;
2555 digi_play_sample(sound,volume);
2559 // -- extern void lightning_frame(void);
2561 void game_render_frame();
2562 extern void omega_charge_frame(void);
2564 extern time_t t_current_time, t_saved_time;
2566 void flicker_lights();
2568 void GameLoop(int RenderFlag, int ReadControlsFlag )
2572 // Used to slow down frame rate for testing things.
2573 // RenderFlag = 1; // DEBUG
2574 if (Debug_slowdown) {
2577 for (h=0; h<Debug_slowdown; h++)
2578 for (i=0; i<1000; i++)
2585 static int desc_dead_countdown=100; /* used if player shouldn't be playing */
2587 if (desc_id_exit_num) { // are we supposed to be checking
2588 if (!(--desc_dead_countdown)) {// if so, at zero, then pull the plug
2589 char time_str[32], time_str2[32];
2591 _ctime(&t_saved_time, time_str);
2592 _ctime(&t_current_time, time_str2);
2594 Error ("EXPIRES %s. YOUR TIME %s.\n", time_str, time_str2);
2595 Error ("Loading overlay -- error number: %d\n", (int)desc_id_exit_num);
2602 if (FindArg("-invulnerability"))
2603 Players[Player_num].flags |= PLAYER_FLAGS_INVULNERABLE;
2607 update_player_stats();
2608 diminish_palette_towards_normal(); // Should leave palette effect up for as long as possible by putting right before render.
2609 do_afterburner_stuff();
2611 do_invulnerable_stuff();
2612 remove_obsolete_stuck_objects();
2614 do_final_boss_frame();
2615 // -- lightning_frame();
2616 // -- recharge_energy_frame();
2618 if ((Players[Player_num].flags & PLAYER_FLAGS_HEADLIGHT) && (Players[Player_num].flags & PLAYER_FLAGS_HEADLIGHT_ON)) {
2619 static int turned_off=0;
2620 Players[Player_num].energy -= (FrameTime*3/8);
2621 if (Players[Player_num].energy < i2f(10)) {
2623 Players[Player_num].flags &= ~PLAYER_FLAGS_HEADLIGHT_ON;
2626 if (Game_mode & GM_MULTI)
2627 multi_send_flags(Player_num);
2634 if (Players[Player_num].energy <= 0) {
2635 Players[Player_num].energy = 0;
2636 Players[Player_num].flags &= ~PLAYER_FLAGS_HEADLIGHT_ON;
2638 if (Game_mode & GM_MULTI)
2639 multi_send_flags(Player_num);
2646 check_create_player_path();
2647 player_follow_path(ConsoleObject);
2651 if (Game_mode & GM_MULTI)
2654 if (Netgame.PlayTimeAllowed && ThisLevelTime>=i2f((Netgame.PlayTimeAllowed*5*60)))
2655 multi_check_for_killgoal_winner();
2661 if (force_cockpit_redraw) { //screen need redrawing?
2663 force_cockpit_redraw=0;
2665 game_render_frame();
2666 //show_extra_views(); //missile view, buddy bot, etc.
2669 if (Saving_movie_frames)
2676 //mprintf(0,"Velocity %2.2f\n", f2fl(vm_vec_mag(&ConsoleObject->phys_info.velocity)));
2680 dead_player_frame();
2681 if (Newdemo_state != ND_STATE_PLAYBACK)
2682 do_controlcen_dead_frame();
2684 process_super_mines_frame();
2686 do_ambient_sounds();
2693 if (ReadControlsFlag)
2696 memset(&Controls, 0, sizeof(Controls));
2698 GameTime += FrameTime;
2700 if (f2i(GameTime)/10 != f2i(GameTime-FrameTime)/10)
2701 mprintf((0,"Gametime = %d secs\n",f2i(GameTime)));
2703 if (GameTime < 0 || GameTime > i2f(0x7fff - 600)) {
2704 GameTime = FrameTime; //wrap when goes negative, or gets within 10 minutes
2705 mprintf((0,"GameTime reset to 0\n"));
2709 if (FindArg("-checktime") != 0)
2710 if (GameTime >= i2f(600)) //wrap after 10 minutes
2711 GameTime = FrameTime;
2715 if ((Game_mode & GM_MULTI) && Netgame.PlayTimeAllowed)
2716 ThisLevelTime +=FrameTime;
2721 if (Endlevel_sequence) {
2722 do_endlevel_frame();
2723 powerup_grab_cheat_all();
2724 do_special_effects();
2725 return; //skip everything else
2728 if (Newdemo_state != ND_STATE_PLAYBACK)
2729 do_exploding_wall_frame();
2730 if ((Newdemo_state != ND_STATE_PLAYBACK) || (Newdemo_vcr_state != ND_STATE_PAUSED)) {
2731 do_special_effects();
2732 wall_frame_process();
2733 triggers_frame_process();
2737 if (Control_center_destroyed) {
2738 if (Newdemo_state==ND_STATE_RECORDING )
2739 newdemo_record_control_center_destroyed();
2744 if ( Newdemo_state == ND_STATE_PLAYBACK ) {
2745 newdemo_playback_one_frame();
2746 if ( Newdemo_state != ND_STATE_PLAYBACK ) {
2747 longjmp( LeaveGame, 0 ); // Go back to menu
2750 { // Note the link to above!
2752 Players[Player_num].homing_object_dist = -1; // Assume not being tracked. Laser_do_weapon_sequence modifies this.
2755 powerup_grab_cheat_all();
2757 if (Endlevel_sequence) //might have been started during move
2760 fuelcen_update_all();
2764 if (allowed_to_fire_laser())
2765 FireLaser(); // Fire Laser!
2767 if (Auto_fire_fusion_cannon_time) {
2768 if (Primary_weapon != FUSION_INDEX)
2769 Auto_fire_fusion_cannon_time = 0;
2770 else if (GameTime + FrameTime/2 >= Auto_fire_fusion_cannon_time) {
2771 Auto_fire_fusion_cannon_time = 0;
2772 Global_laser_firing_count = 1;
2774 vms_vector rand_vec;
2777 Global_laser_firing_count = 0;
2779 ConsoleObject->mtype.phys_info.rotvel.x += (d_rand() - 16384)/8;
2780 ConsoleObject->mtype.phys_info.rotvel.z += (d_rand() - 16384)/8;
2781 make_random_vector(&rand_vec);
2783 bump_amount = F1_0*4;
2785 if (Fusion_charge > F1_0*2)
2786 bump_amount = Fusion_charge*4;
2788 bump_one_object(ConsoleObject, &rand_vec, bump_amount);
2792 if (Global_laser_firing_count) {
2793 // Don't cap here, gets capped in Laser_create_new and is based on whether in multiplayer mode, MK, 3/27/95
2794 // if (Fusion_charge > F1_0*2)
2795 // Fusion_charge = F1_0*2;
2796 Global_laser_firing_count -= do_laser_firing_player(); //do_laser_firing(Players[Player_num].objnum, Primary_weapon);
2799 if (Global_laser_firing_count < 0)
2800 Global_laser_firing_count = 0;
2803 if (Do_appearance_effect) {
2804 create_player_appearance_effect(ConsoleObject);
2805 Do_appearance_effect = 0;
2807 if ((Game_mode & GM_MULTI) && Netgame.invul)
2809 Players[Player_num].flags |= PLAYER_FLAGS_INVULNERABLE;
2810 Players[Player_num].invulnerable_time = GameTime-i2f(27);
2817 omega_charge_frame();
2821 //!!hoard_light_pulse(); //do cool hoard light pulsing
2825 //!!extern int Goal_blue_segnum,Goal_red_segnum;
2826 //!!extern int Hoard_goal_eclip;
2828 //!!//do cool pulsing lights in hoard goals
2829 //!!hoard_light_pulse()
2831 //!! if (Game_mode & GM_HOARD) {
2835 //!! frame = Effects[Hoard_goal_eclip].frame_count;
2839 //!! if (frame >= Effects[Hoard_goal_eclip].vc.num_frames)
2842 //!! light = abs(frame - 5) * f1_0 / 5;
2844 //!! Segment2s[Goal_red_segnum].static_light = Segment2s[Goal_blue_segnum].static_light = light;
2849 ubyte Slide_segs[MAX_SEGMENTS];
2850 int Slide_segs_computed;
2852 void compute_slide_segs(void)
2854 int segnum, sidenum;
2856 for (segnum=0;segnum<=Highest_segment_index;segnum++) {
2857 Slide_segs[segnum] = 0;
2858 for (sidenum=0;sidenum<6;sidenum++) {
2859 int tmn = Segments[segnum].sides[sidenum].tmap_num;
2860 if (TmapInfo[tmn].slide_u != 0 || TmapInfo[tmn].slide_v != 0)
2861 Slide_segs[segnum] |= 1 << sidenum;
2865 Slide_segs_computed = 1;
2868 // -----------------------------------------------------------------------------
2869 void slide_textures(void)
2871 int segnum,sidenum,i;
2873 if (!Slide_segs_computed)
2874 compute_slide_segs();
2876 for (segnum=0;segnum<=Highest_segment_index;segnum++) {
2877 if (Slide_segs[segnum]) {
2878 for (sidenum=0;sidenum<6;sidenum++) {
2879 if (Slide_segs[segnum] & (1 << sidenum)) {
2880 int tmn = Segments[segnum].sides[sidenum].tmap_num;
2881 if (TmapInfo[tmn].slide_u != 0 || TmapInfo[tmn].slide_v != 0) {
2883 Segments[segnum].sides[sidenum].uvls[i].u += fixmul(FrameTime,TmapInfo[tmn].slide_u<<8);
2884 Segments[segnum].sides[sidenum].uvls[i].v += fixmul(FrameTime,TmapInfo[tmn].slide_v<<8);
2885 if (Segments[segnum].sides[sidenum].uvls[i].u > f2_0) {
2888 Segments[segnum].sides[sidenum].uvls[j].u -= f1_0;
2890 if (Segments[segnum].sides[sidenum].uvls[i].v > f2_0) {
2893 Segments[segnum].sides[sidenum].uvls[j].v -= f1_0;
2895 if (Segments[segnum].sides[sidenum].uvls[i].u < -f2_0) {
2898 Segments[segnum].sides[sidenum].uvls[j].u += f1_0;
2900 if (Segments[segnum].sides[sidenum].uvls[i].v < -f2_0) {
2903 Segments[segnum].sides[sidenum].uvls[j].v += f1_0;
2913 flickering_light Flickering_lights[MAX_FLICKERING_LIGHTS];
2915 int Num_flickering_lights=0;
2917 void flicker_lights()
2920 flickering_light *f;
2922 f = Flickering_lights;
2924 for (l=0;l<Num_flickering_lights;l++,f++) {
2925 segment *segp = &Segments[f->segnum];
2927 //make sure this is actually a light
2928 if (! (WALL_IS_DOORWAY(segp, f->sidenum) & WID_RENDER_FLAG))
2930 if (! (TmapInfo[segp->sides[f->sidenum].tmap_num].lighting | TmapInfo[segp->sides[f->sidenum].tmap_num2 & 0x3fff].lighting))
2933 if (f->timer == 0x80000000) //disabled
2936 if ((f->timer -= FrameTime) < 0) {
2938 while (f->timer < 0)
2939 f->timer += f->delay;
2941 f->mask = ((f->mask&0x80000000)?1:0) + (f->mask<<1);
2944 add_light(f->segnum,f->sidenum);
2946 subtract_light(f->segnum,f->sidenum);
2951 //returns ptr to flickering light structure, or NULL if can't find
2952 flickering_light *find_flicker(int segnum,int sidenum)
2955 flickering_light *f;
2957 //see if there's already an entry for this seg/side
2959 f = Flickering_lights;
2961 for (l=0;l<Num_flickering_lights;l++,f++)
2962 if (f->segnum == segnum && f->sidenum == sidenum) //found it!
2968 //turn flickering off (because light has been turned off)
2969 void disable_flicker(int segnum,int sidenum)
2971 flickering_light *f;
2973 if ((f=find_flicker(segnum,sidenum)) != NULL)
2974 f->timer = 0x80000000;
2977 //turn flickering off (because light has been turned on)
2978 void enable_flicker(int segnum,int sidenum)
2980 flickering_light *f;
2982 if ((f=find_flicker(segnum,sidenum)) != NULL)
2989 //returns 1 if ok, 0 if error
2990 int add_flicker(int segnum,int sidenum,fix delay,ulong mask)
2993 flickering_light *f;
2995 mprintf((0,"add_flicker: %d:%d %x %x\n",segnum,sidenum,delay,mask));
2997 //see if there's already an entry for this seg/side
2999 f = Flickering_lights;
3001 for (l=0;l<Num_flickering_lights;l++,f++)
3002 if (f->segnum == segnum && f->sidenum == sidenum) //found it!
3005 if (mask==0) { //clearing entry
3006 if (l == Num_flickering_lights)
3010 for (i=l;i<Num_flickering_lights-1;i++)
3011 Flickering_lights[i] = Flickering_lights[i+1];
3012 Num_flickering_lights--;
3017 if (l == Num_flickering_lights)
3018 if (Num_flickering_lights == MAX_FLICKERING_LIGHTS)
3021 Num_flickering_lights++;
3024 f->sidenum = sidenum;
3025 f->delay = f->timer = delay;
3033 // -----------------------------------------------------------------------------
3034 // Fire Laser: Registers a laser fire, and performs special stuff for the fusion
3039 Global_laser_firing_count += Weapon_info[Primary_weapon_to_weapon_info[Primary_weapon]].fire_count * (Controls.fire_primary_state || Controls.fire_primary_down_count);
3041 if ((Primary_weapon == FUSION_INDEX) && (Global_laser_firing_count)) {
3042 if ((Players[Player_num].energy < F1_0*2) && (Auto_fire_fusion_cannon_time == 0)) {
3043 Global_laser_firing_count = 0;
3045 if (Fusion_charge == 0)
3046 Players[Player_num].energy -= F1_0*2;
3048 Fusion_charge += FrameTime;
3049 Players[Player_num].energy -= FrameTime;
3051 if (Players[Player_num].energy <= 0) {
3052 Players[Player_num].energy = 0;
3053 Auto_fire_fusion_cannon_time = GameTime -1; // Fire now!
3055 Auto_fire_fusion_cannon_time = GameTime + FrameTime/2 + 1;
3056 // Fire the fusion cannon at this time in the future.
3058 if (Fusion_charge < F1_0*2)
3059 PALETTE_FLASH_ADD(Fusion_charge >> 11, 0, Fusion_charge >> 11);
3061 PALETTE_FLASH_ADD(Fusion_charge >> 11, Fusion_charge >> 11, 0);
3063 if (GameTime < Fusion_last_sound_time) //gametime has wrapped
3064 Fusion_next_sound_time = Fusion_last_sound_time = GameTime;
3066 if (Fusion_next_sound_time < GameTime) {
3067 if (Fusion_charge > F1_0*2) {
3068 digi_play_sample( 11, F1_0 );
3069 apply_damage_to_player(ConsoleObject, ConsoleObject, d_rand() * 4);
3071 create_awareness_event(ConsoleObject, PA_WEAPON_ROBOT_COLLISION);
3072 digi_play_sample( SOUND_FUSION_WARMUP, F1_0 );
3074 if (Game_mode & GM_MULTI)
3075 multi_send_play_sound(SOUND_FUSION_WARMUP, F1_0);
3078 Fusion_last_sound_time = GameTime;
3079 Fusion_next_sound_time = GameTime + F1_0/8 + d_rand()/4;
3087 // -------------------------------------------------------------------------------------------------------
3088 // If player is close enough to objnum, which ought to be a powerup, pick it up!
3089 // This could easily be made difficulty level dependent.
3090 void powerup_grab_cheat(object *player, int objnum)
3096 Assert(Objects[objnum].type == OBJ_POWERUP);
3098 powerup_size = Objects[objnum].size;
3099 player_size = player->size;
3101 dist = vm_vec_dist_quick(&Objects[objnum].pos, &player->pos);
3103 if ((dist < 2*(powerup_size + player_size)) && !(Objects[objnum].flags & OF_SHOULD_BE_DEAD)) {
3104 vms_vector collision_point;
3106 vm_vec_avg(&collision_point, &Objects[objnum].pos, &player->pos);
3107 collide_player_and_powerup(player, &Objects[objnum], &collision_point);
3111 // -------------------------------------------------------------------------------------------------------
3112 // Make it easier to pick up powerups.
3113 // For all powerups in this segment, pick them up at up to twice pickuppable distance based on dot product
3114 // from player to powerup and player's forward vector.
3115 // This has the effect of picking them up more easily left/right and up/down, but not making them disappear
3116 // way before the player gets there.
3117 void powerup_grab_cheat_all(void)
3122 segp = &Segments[ConsoleObject->segnum];
3123 objnum = segp->objects;
3125 while (objnum != -1) {
3126 if (Objects[objnum].type == OBJ_POWERUP)
3127 powerup_grab_cheat(ConsoleObject, objnum);
3128 objnum = Objects[objnum].next;
3133 int Last_level_path_created = -1;
3135 #ifdef SHOW_EXIT_PATH
3137 // ------------------------------------------------------------------------------------------------------------------
3138 // Create path for player from current segment to goal segment.
3139 // Return true if path created, else return false.
3140 int mark_player_path_to_segment(int segnum)
3143 object *objp = ConsoleObject;
3144 short player_path_length=0;
3145 int player_hide_index=-1;
3147 if (Last_level_path_created == Current_level_num) {
3151 Last_level_path_created = Current_level_num;
3153 if (create_path_points(objp, objp->segnum, segnum, Point_segs_free_ptr, &player_path_length, 100, 0, 0, -1) == -1) {
3154 mprintf((0, "Unable to form path of length %i for myself\n", 100));
3158 player_hide_index = Point_segs_free_ptr - Point_segs;
3159 Point_segs_free_ptr += player_path_length;
3161 if (Point_segs_free_ptr - Point_segs + MAX_PATH_LENGTH*2 > MAX_POINT_SEGS) {
3162 mprintf((1, "Can't create path. Not enough point_segs.\n"));
3163 ai_reset_all_paths();
3167 for (i=1; i<player_path_length; i++) {
3169 vms_vector seg_center;
3172 segnum = Point_segs[player_hide_index+i].segnum;
3173 mprintf((0, "%3i ", segnum));
3174 seg_center = Point_segs[player_hide_index+i].point;
3176 objnum = obj_create( OBJ_POWERUP, POW_ENERGY, segnum, &seg_center, &vmd_identity_matrix, Powerup_info[POW_ENERGY].size, CT_POWERUP, MT_NONE, RT_POWERUP);
3178 Int3(); // Unable to drop energy powerup for path
3182 obj = &Objects[objnum];
3183 obj->rtype.vclip_info.vclip_num = Powerup_info[obj->id].vclip_num;
3184 obj->rtype.vclip_info.frametime = Vclip[obj->rtype.vclip_info.vclip_num].frame_time;
3185 obj->rtype.vclip_info.framenum = 0;
3186 obj->lifeleft = F1_0*100 + d_rand() * 4;
3193 // Return true if it happened, else return false.
3194 int create_special_path(void)
3198 // ---------- Find exit doors ----------
3199 for (i=0; i<=Highest_segment_index; i++)
3200 for (j=0; j<MAX_SIDES_PER_SEGMENT; j++)
3201 if (Segments[i].children[j] == -2) {
3202 mprintf((0, "Exit at segment %i\n", i));
3203 return mark_player_path_to_segment(i);
3213 int Max_obj_count_mike = 0;
3215 // Shows current number of used objects.
3216 void show_free_objects(void)
3218 if (!(FrameCount & 8)) {
3222 mprintf((0, "Highest_object_index = %3i, MAX_OBJECTS = %3i, now used = ", Highest_object_index, MAX_OBJECTS));
3224 for (i=0; i<=Highest_object_index; i++)
3225 if (Objects[i].type != OBJ_NONE)
3228 mprintf((0, "%3i", count));
3230 if (count > Max_obj_count_mike) {
3231 Max_obj_count_mike = count;
3232 mprintf((0, " ***"));
3243 void game_win_init_cockpit_mask(int sram)
3245 if (dd_VR_offscreen_buffer && dd_VR_offscreen_buffer != dd_grd_backcanv) {
3246 dd_gr_free_canvas(dd_VR_offscreen_buffer);
3249 if (GRMODEINFO(paged) && !GRMODEINFO(dbuf)) {
3250 // Here we will make the VR_offscreen_buffer the 2nd page and hopefully
3251 // we can just flip it, saving a blt.
3254 else if (GRMODEINFO(dbuf)||GRMODEINFO(emul)) {
3255 // The offscreen buffer will be created. We will just blt this
3256 // to the screen (which may be blted to the primary surface)
3257 if ( grd_curscreen->sc_h < 200 ) {
3258 dd_VR_offscreen_buffer = dd_gr_create_canvas(grd_curscreen->sc_w, 200);
3259 VR_offscreen_buffer = &dd_VR_offscreen_buffer->canvas;
3261 DDFreeSurface(dd_VR_offscreen_buffer->lpdds);
3262 dd_VR_offscreen_buffer->lpdds = DDCreateSysMemSurface(grd_curscreen->sc_w, 200);
3263 dd_VR_offscreen_buffer->sram = 1;
3267 dd_VR_offscreen_buffer = dd_gr_create_canvas(grd_curscreen->sc_w, grd_curscreen->sc_h);
3268 VR_offscreen_buffer = &dd_VR_offscreen_buffer->canvas;
3270 DDFreeSurface(dd_VR_offscreen_buffer->lpdds);
3271 dd_VR_offscreen_buffer->lpdds = DDCreateSysMemSurface(grd_curscreen->sc_w, grd_curscreen->sc_h);
3272 dd_VR_offscreen_buffer->sram = 1;
3277 dd_gr_init_sub_canvas( &dd_VR_render_buffer[0], dd_VR_offscreen_buffer, 0, 0, grd_curscreen->sc_w, grd_curscreen->sc_h );
3278 dd_gr_init_sub_canvas( &dd_VR_render_buffer[1], dd_VR_offscreen_buffer, 0, 0, grd_curscreen->sc_w, grd_curscreen->sc_h );
3279 gr_init_sub_canvas( &VR_render_buffer[0], VR_offscreen_buffer, 0, 0, grd_curscreen->sc_w, grd_curscreen->sc_h );
3280 gr_init_sub_canvas( &VR_render_buffer[1], VR_offscreen_buffer, 0, 0, grd_curscreen->sc_w, grd_curscreen->sc_h );
3282 game_init_render_sub_buffers( 0, 0, grd_curscreen->sc_w, grd_curscreen->sc_h );
3285 //@@void game_win_init_cockpit_mask()
3287 //@@ char title_pal[768];
3288 //@@ dd_grs_canvas ccanv;
3290 //@@ LPDIRECTDRAWSURFACE dds;
3292 //@@ dds = DDCreateSurface(GRMODEINFO(w), GRMODEINFO(h), 1);
3293 //@@ Assert(dds != NULL);
3295 //@@ _lpDDSMask = dds;
3296 //@@ ccanv.lpdds = dds;
3297 //@@ dd_gr_reinit_canvas(&ccanv);
3299 //@@ dd_gr_set_current_canvas(&ccanv);
3300 //@@ DDGRLOCK(dd_grd_curcanv)
3302 //@@ if (W95DisplayMode == SM95_640x480x8) {
3303 //@@ pcx_error=pcx_read_bitmap( "MASKB.PCX", &grd_curcanv->cv_bitmap,
3304 //@@ grd_curcanv->cv_bitmap.bm_type,
3308 //@@ pcx_error=pcx_read_bitmap( "MASK.PCX", &grd_curcanv->cv_bitmap,
3309 //@@ grd_curcanv->cv_bitmap.bm_type,
3313 //@@ DDGRUNLOCK(dd_grd_curcanv);
3315 //@@ Assert(pcx_error == PCX_ERROR_NONE);
3316 //@@ Game_cockpit_copy_code = (ubyte *)(0xABADC0DE);