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.9 2002-02-13 10:45:05 bradleyb Exp $";
35 #include <StandardFile.h>
36 #include <Quickdraw.h>
47 #include "pa_enabl.h" //$$POLY_ACC
100 #include "controls.h"
104 #if defined(POLY_ACC)
105 #include "poly_acc.h"
110 #include "cntrlcen.h"
114 #include "multibot.h"
117 #include "playsave.h"
121 int VGA_current_mode;
124 #include <profiler.h>
127 //#define TEST_TIMER 1 //if this is set, do checking on timer
129 #define SHOW_EXIT_PATH 1
132 #include "editor/editor.h"
137 #if __WATCOMC__ < 1000
138 #include <wsample.h> //should come after inferno.h to get mark setting
143 extern void ReadControls(void); // located in gamecntl.c
144 extern int Current_display_mode;
145 extern void do_final_boss_frame(void);
147 int Speedtest_on = 0;
150 int Mark_count = 0; // number of debugging marks set
151 int Speedtest_start_time;
152 int Speedtest_segnum;
153 int Speedtest_sidenum;
154 int Speedtest_frame_start;
155 int Speedtest_count=0; // number of times to do the debug test.
158 static fix last_timer_value=0;
161 #if defined(TIMER_TEST) && !defined(NDEBUG)
162 fix _timer_value,actual_last_timer_value,_last_frametime;
163 int stop_count,start_count;
164 int time_stopped,time_started;
168 ubyte * Game_cockpit_copy_code = NULL;
170 ubyte Game_cockpit_copy_code = 0;
171 ubyte Scanline_double = 1;
174 int VR_screen_mode = 0;
176 ubyte VR_screen_flags = 0; //see values in screens.h
177 ubyte VR_current_page = 0;
178 fix VR_eye_width = F1_0;
179 int VR_render_mode = VR_NONE;
180 int VR_low_res = 3; // Default to low res
182 int VR_sensitivity = 1; // 0 - 2
185 int VR_eye_offset = 0;
186 int VR_eye_switch = 0;
187 int VR_eye_offset_changed = 0;
188 int VR_use_reg_code = 0;
190 grs_canvas *VR_offscreen_buffer = NULL; // The offscreen data buffer
191 grs_canvas VR_render_buffer[2]; // Two offscreen buffers for left/right eyes.
192 grs_canvas VR_render_sub_buffer[2]; // Two sub buffers for left/right eyes.
193 grs_canvas VR_screen_pages[2]; // Two pages of VRAM if paging is available
194 grs_canvas VR_editor_canvas; // The canvas that the editor writes to.
197 //@@ LPDIRECTDRAWSURFACE _lpDDSMask = NULL;
198 dd_grs_canvas *dd_VR_offscreen_buffer = NULL;
199 dd_grs_canvas dd_VR_screen_pages[2];
200 dd_grs_canvas dd_VR_render_buffer[2];
201 dd_grs_canvas dd_VR_render_sub_buffer[2];
203 void game_win_init_cockpit_mask(int sram);
206 //do menus work in 640x480 or 320x200?
207 //PC version sets this in main(). Mac versios is always high-res, so set to 1 here
208 int MenuHiresAvailable = 1; //can we do highres menus?
209 int MenuHires = 1; //are we currently in highres menus?
211 int Debug_pause=0; //John's debugging pause system
213 int Cockpit_mode=CM_FULL_COCKPIT; //set game.h for values
215 int Cockpit_mode_save=-1; //set while in letterbox or rear view, or -1
216 int force_cockpit_redraw=0;
218 cvar_t r_framerate = {"r_framerate","0"};
220 int PaletteRedAdd, PaletteGreenAdd, PaletteBlueAdd;
222 // Toggle_var points at a variable which gets !ed on ctrl-alt-T press.
224 int *Toggle_var = &Dummy_var;
227 //flag for whether initial fade-in has been done
231 #ifndef NDEBUG //these only exist if debugging
233 int Game_double_buffer = 1; //double buffer by default
234 fix fixed_frametime=0; //if non-zero, set frametime to this
238 int Game_suspended=0; //if non-zero, nothing moves but player
241 fix Auto_fire_fusion_cannon_time = 0;
242 fix Fusion_charge = 0;
243 fix Fusion_next_sound_time = 0;
244 fix Fusion_last_sound_time = 0;
247 int Game_turbo_mode = 0;
249 int Game_mode = GM_GAME_OVER;
251 int Global_laser_firing_count = 0;
252 int Global_missile_firing_count = 0;
254 grs_bitmap background_bitmap;
258 #define BACKGROUND_NAME "statback.pcx"
260 // Function prototypes for GAME.C exclusively.
262 void GameLoop(int RenderFlag, int ReadControlsFlag);
263 void FireLaser(void);
264 void slide_textures(void);
265 void powerup_grab_cheat_all(void);
268 extern void multi_check_for_killgoal_winner();
269 extern void RestoreGameSurfaces();
273 void grow_window(void);
274 void shrink_window(void);
278 void fill_background();
281 void show_framerate(void);
282 void ftoa(char *string, fix f);
285 extern ubyte DefiningMarkerMessage;
286 extern char Marker_input[];
288 // ==============================================================================================
290 extern char john_head_on;
292 void load_background_bitmap()
297 if (background_bitmap.bm_data)
298 d_free(background_bitmap.bm_data);
300 background_bitmap.bm_data=NULL;
301 pcx_error = pcx_read_bitmap(john_head_on?"johnhead.pcx":BACKGROUND_NAME,&background_bitmap,BM_LINEAR,pal);
302 if (pcx_error != PCX_ERROR_NONE)
303 Error("File %s - PCX error: %s",BACKGROUND_NAME,pcx_errormsg(pcx_error));
304 gr_remap_bitmap_good( &background_bitmap, pal, -1, -1 );
308 //this is called once per game
311 atexit(close_game); //for cleanup
315 init_special_effects();
319 init_gauge_canvases();
321 init_exploding_walls();
323 load_background_bitmap();
325 Clear_window = 2; // do portal only window clear.
327 set_detail_level_parameters(Detail_level);
329 build_mission_list(0); // This also loads mission 0.
332 cvar_registervariable(&r_framerate);
337 void reset_palette_add()
342 //gr_palette_step_up( PaletteRedAdd, PaletteGreenAdd, PaletteBlueAdd );
347 void win_get_span_list(grs_bitmap *bm, int miny, int maxy)
353 int lspan=0, rspan=0, span=0;
357 //@@ fp = fopen("cockspan.dat", "w");
359 for (y = 0; y < miny; y++)
360 win_cockpit_mask[y].num = 0;
362 for (y = miny; y <= maxy; y++)
365 //@@ fprintf(fp, "line %d: ", y);
366 for (x = 0; x < bm->bm_w; x++)
368 offset = y*bm->bm_rowsize + x;
370 if (data[offset] == 255) {
373 case 0: // Start Mode
375 win_cockpit_mask[y].span[span].xmin = x;
377 //@@ fprintf(fp, "<%d,", lspan);
380 case 1: // Transparency mode
382 win_cockpit_mask[y].span[span].xmax = x;
385 case 2: // Switch from Draw mode to transparent
387 win_cockpit_mask[y].span[span].xmin = x;
388 //@@ fprintf(fp, "<%d,", lspan);
396 case 0: // Start mode
400 case 1: // Switching from transparent to Draw
403 win_cockpit_mask[y].span[span].xmax = x;
405 //@@ fprintf(fp, "%d> ", rspan);
414 //@@ fprintf(fp, "%d> ", rspan);
415 win_cockpit_mask[y].span[span].xmax = rspan;
418 win_cockpit_mask[y].num = span;
419 //@@ fprintf(fp, "\n");
422 win_cockpit_mask[y].num = 255;
427 void game_show_warning(char *s)
430 if (!((Game_mode & GM_MULTI) && (Function_mode == FMODE_GAME)))
433 nm_messagebox( TXT_WARNING, 1, TXT_OK, s );
435 if (!((Game_mode & GM_MULTI) && (Function_mode == FMODE_GAME)))
440 //these should be in gr.h
441 #define cv_w cv_bitmap.bm_w
442 #define cv_h cv_bitmap.bm_h
444 int Game_window_x = 0;
445 int Game_window_y = 0;
446 int Game_window_w = 0;
447 int Game_window_h = 0;
448 int max_window_w = 0;
449 int max_window_h = 0;
451 extern void newdemo_record_cockpit_change(int);
453 //initialize the various canvases on the game screen
454 //called every time the screen mode or cockpit changes
457 int minx, maxx, miny, maxy;
459 #if defined(POLY_ACC)
460 pa_flush(); // get rid of undrawn polys.
461 pa_clear_buffer(1, 0);
464 //Initialize the on-screen canvases
466 if (Newdemo_state==ND_STATE_RECORDING)
469 newdemo_record_cockpit_change(Cockpit_mode);
472 if ( VR_render_mode != VR_NONE )
473 Cockpit_mode = CM_FULL_SCREEN;
475 if (!(VR_screen_flags & VRF_ALLOW_COCKPIT) && (Cockpit_mode==CM_FULL_COCKPIT || Cockpit_mode==CM_STATUS_BAR || Cockpit_mode==CM_REAR_VIEW) )
476 Cockpit_mode = CM_FULL_SCREEN;
478 if ( Screen_mode == SCREEN_EDITOR )
479 Cockpit_mode = CM_FULL_SCREEN;
482 dd_gr_set_current_canvas(NULL),
483 gr_set_current_canvas(NULL)
485 gr_set_curfont( GAME_FONT );
487 #if !defined(MACINTOSH) && !defined(WINDOWS)
488 if (Game_cockpit_copy_code)
489 d_free(Game_cockpit_copy_code);
490 Game_cockpit_copy_code = NULL;
492 if (Game_cockpit_copy_code)
493 Game_cockpit_copy_code = 0;
497 //@@ if (_lpDDSMask) { DDFreeSurface(_lpDDSMask); _lpDDSMask = NULL; }
501 game_win_init_cockpit_mask(0);
504 switch( Cockpit_mode )
506 case CM_FULL_COCKPIT:
508 grs_bitmap *bm = &GameBitmaps[cockpit_bitmap[Cockpit_mode+(Current_display_mode?(Num_cockpits/2):0)].index];
510 PIGGY_PAGE_IN(cockpit_bitmap[Cockpit_mode+(Current_display_mode?(Num_cockpits/2):0)]);
513 dd_gr_set_current_canvas(NULL);
514 game_win_init_cockpit_mask(1);
515 dd_gr_set_current_canvas(dd_VR_offscreen_buffer);
517 gr_set_current_canvas(VR_offscreen_buffer)
520 WIN(DDGRLOCK(dd_grd_curcanv));
521 gr_bitmap( 0, 0, bm );
522 bm = &VR_offscreen_buffer->cv_bitmap;
523 bm->bm_flags = BM_FLAG_TRANSPARENT;
524 gr_ibitblt_find_hole_size ( bm, &minx, &miny, &maxx, &maxy );
525 WIN( win_get_span_list(bm, miny, maxy);
526 DDGRUNLOCK(dd_grd_curcanv)
530 #if 1 // def MACINTOSH
531 gr_ibitblt_create_mask( bm, minx, miny, maxx-minx+1, maxy-miny+1, VR_offscreen_buffer->cv_bitmap.bm_rowsize);
533 if ( Current_display_mode )
535 #if defined(POLY_ACC)
536 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 );
537 pa_clear_buffer(1, 0); // clear offscreen to reduce white flash.
539 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 );
542 Game_cockpit_copy_code = gr_ibitblt_create_mask( bm, minx, miny, maxx-minx+1, maxy-miny+1, VR_offscreen_buffer->cv_bitmap.bm_rowsize );
544 bm->bm_flags = 0; // Clear all flags for offscreen canvas
546 Game_cockpit_copy_code = (ubyte *)(1);
547 bm->bm_flags = 0; // Clear all flags for offscreen canvas
549 game_init_render_sub_buffers( 0, 0, maxx-minx+1, maxy-miny+1 );
555 max_window_h = grd_curscreen->sc_h;
557 if (Game_window_h > max_window_h || VR_screen_flags&VRF_ALLOW_COCKPIT)
558 Game_window_h = max_window_h;
560 if (Game_window_w > max_window_w || VR_screen_flags&VRF_ALLOW_COCKPIT)
561 Game_window_w = max_window_w;
563 Game_window_x = (max_window_w - Game_window_w)/2;
564 Game_window_y = (max_window_h - Game_window_h)/2;
566 game_init_render_sub_buffers( Game_window_x, Game_window_y, Game_window_w, Game_window_h );
571 max_window_h = grd_curscreen->sc_h - GameBitmaps[cockpit_bitmap[CM_STATUS_BAR+(Current_display_mode?(Num_cockpits/2):0)].index].bm_h;
573 if (Game_window_h > max_window_h)
574 Game_window_h = max_window_h;
576 if (Game_window_w > max_window_w)
577 Game_window_w = max_window_w;
579 Game_window_x = (max_window_w - Game_window_w)/2;
580 Game_window_y = (max_window_h - Game_window_h)/2;
582 game_init_render_sub_buffers( Game_window_x, Game_window_y, Game_window_w, Game_window_h );
588 x = 0; w = VR_render_buffer[0].cv_bitmap.bm_w; //VR_render_width;
589 h = (VR_render_buffer[0].cv_bitmap.bm_h * 7) / 10;
590 y = (VR_render_buffer[0].cv_bitmap.bm_h-h)/2;
592 game_init_render_sub_buffers( x, y, w, h );
599 dd_gr_set_current_canvas(NULL),
600 gr_set_current_canvas(NULL)
604 //selects a given cockpit (or lack of one). See types in game.h
605 void select_cockpit(int mode)
607 if (mode != Cockpit_mode) { //new mode
613 extern int last_drawn_cockpit[2];
615 //force cockpit redraw next time. call this if you've trashed the screen
618 force_cockpit_redraw=1;
619 last_drawn_cockpit[0] = -1;
620 last_drawn_cockpit[1] = -1;
623 // void HUD_clear_messages(); //Already declared in gauges.h
626 void VR_reset_params()
628 VR_eye_width = VR_SEPARATION;
629 VR_eye_offset = VR_PIXEL_SHIFT;
630 VR_eye_offset_changed = 2;
633 void game_init_render_sub_buffers( int x, int y, int w, int h )
636 dd_gr_init_sub_canvas( &dd_VR_render_sub_buffer[0], &dd_VR_render_buffer[0], x, y, w, h );
637 dd_gr_init_sub_canvas( &dd_VR_render_sub_buffer[1], &dd_VR_render_buffer[1], x, y, w, h );
639 dd_VR_render_sub_buffer[0].canvas.cv_bitmap.bm_x = 0;
640 dd_VR_render_sub_buffer[0].canvas.cv_bitmap.bm_y = 0;
641 dd_VR_render_sub_buffer[0].xoff = x;
642 dd_VR_render_sub_buffer[0].yoff = y;
643 dd_VR_render_sub_buffer[1].canvas.cv_bitmap.bm_x = 0;
644 dd_VR_render_sub_buffer[1].canvas.cv_bitmap.bm_y = 0;
645 dd_VR_render_sub_buffer[1].xoff = x;
646 dd_VR_render_sub_buffer[1].yoff = y;
649 if (Scanline_double) {
653 gr_init_sub_canvas( &VR_render_sub_buffer[0], &VR_render_buffer[0], x, y, w/2, (h/2)+1);
654 gr_init_sub_canvas( &VR_render_sub_buffer[1], &VR_render_buffer[1], x, y, w/2, (h/2)+1);
657 gr_init_sub_canvas( &VR_render_sub_buffer[0], &VR_render_buffer[0], x, y, w, h );
658 gr_init_sub_canvas( &VR_render_sub_buffer[1], &VR_render_buffer[1], x, y, w, h );
668 newBounds.right = x + w;
670 newBounds.bottom = y + h;
672 pa_set_context(kGamePlayDrawContextID, &newBounds); // must resize/create new context
678 VR_render_sub_buffer[0].cv_bitmap.bm_x = 0;
679 VR_render_sub_buffer[0].cv_bitmap.bm_y = 0;
680 VR_render_sub_buffer[1].cv_bitmap.bm_x = 0;
681 VR_render_sub_buffer[1].cv_bitmap.bm_y = 0;
687 // Sets up the canvases we will be rendering to (WIN95)
688 void game_init_render_buffers(int screen_mode, int render_w, int render_h, int render_method, int flags )
690 // Hack for switching to higher that 640x480 modes (DDraw doesn't allow
691 // creating surfaces greater than the current resolution
693 if (GRMODEINFO(rw) < render_w || GRMODEINFO(rh) < render_h) {
694 render_w = GRMODEINFO(rw);
695 render_h = GRMODEINFO(rh);
698 VR_screen_mode = screen_mode;
700 VR_screen_flags = flags;
703 VR_render_mode = render_method;
705 Game_window_w = render_w;
706 Game_window_h = render_h;
708 if (dd_VR_offscreen_buffer && dd_VR_offscreen_buffer != dd_grd_backcanv) {
709 dd_gr_free_canvas(dd_VR_offscreen_buffer);
712 if ( (VR_render_mode==VR_AREA_DET) || (VR_render_mode==VR_INTERLACED ) ) {
713 if ( render_h*2 < 200 ) {
714 Int3(); // Not Supported yet!!!
715 // VR_offscreen_buffer = gr_create_canvas( render_w, 200 );
718 Int3(); // Not Supported yet!!!
719 // VR_offscreen_buffer = gr_create_canvas( render_w, render_h*2 );
722 Int3(); // Not Supported yet!!!
723 // gr_init_sub_canvas( &VR_render_buffer[0], VR_offscreen_buffer, 0, 0, render_w, render_h );
724 // gr_init_sub_canvas( &VR_render_buffer[1], VR_offscreen_buffer, 0, render_h, render_w, render_h );
726 else if (GRMODEINFO(paged) && !GRMODEINFO(dbuf)) {
727 // Here we will make the VR_offscreen_buffer the 2nd page and hopefully
728 // we can just flip it, saving a blt.
730 dd_VR_offscreen_buffer = dd_grd_backcanv;
731 VR_offscreen_buffer = & dd_grd_backcanv->canvas;
733 else if (GRMODEINFO(dbuf)||GRMODEINFO(emul)) {
734 // The offscreen buffer will be created. We will just blt this
735 // to the screen (which may be blted to the primary surface)
736 if ( render_h < 200 ) {
737 dd_VR_offscreen_buffer = dd_gr_create_canvas(render_w, 200);
738 VR_offscreen_buffer = &dd_VR_offscreen_buffer->canvas;
741 dd_VR_offscreen_buffer = dd_gr_create_canvas(render_w, render_h);
742 VR_offscreen_buffer = &dd_VR_offscreen_buffer->canvas;
746 dd_gr_init_sub_canvas( &dd_VR_render_buffer[0], dd_VR_offscreen_buffer, 0, 0, render_w, render_h );
747 dd_gr_init_sub_canvas( &dd_VR_render_buffer[1], dd_VR_offscreen_buffer, 0, 0, render_w, render_h );
748 gr_init_sub_canvas( &VR_render_buffer[0], VR_offscreen_buffer, 0, 0, render_w, render_h );
749 gr_init_sub_canvas( &VR_render_buffer[1], VR_offscreen_buffer, 0, 0, render_w, render_h );
751 game_init_render_sub_buffers( 0, 0, render_w, render_h );
756 // Sets up the canvases we will be rendering to (NORMAL VERSION)
757 void game_init_render_buffers(int screen_mode, int render_w, int render_h, int render_method, int flags )
759 // if (vga_check_mode(screen_mode) != 0)
760 // Error("Cannot set requested video mode");
762 VR_screen_mode = screen_mode;
764 VR_screen_flags = flags;
768 VR_render_mode = render_method;
770 Game_window_w = render_w;
771 Game_window_h = render_h;
773 if (VR_offscreen_buffer) {
774 gr_free_canvas(VR_offscreen_buffer);
777 if ( (VR_render_mode==VR_AREA_DET) || (VR_render_mode==VR_INTERLACED ) ) {
778 if ( render_h*2 < 200 ) {
779 VR_offscreen_buffer = gr_create_canvas( render_w, 200 );
782 VR_offscreen_buffer = gr_create_canvas( render_w, render_h*2 );
785 gr_init_sub_canvas( &VR_render_buffer[0], VR_offscreen_buffer, 0, 0, render_w, render_h );
786 gr_init_sub_canvas( &VR_render_buffer[1], VR_offscreen_buffer, 0, render_h, render_w, render_h );
789 if ( render_h < 200 ) {
790 VR_offscreen_buffer = gr_create_canvas( render_w, 200 );
793 #if defined(POLY_ACC)
795 VR_offscreen_buffer = gr_create_canvas( render_w, render_h );
796 d_free(VR_offscreen_buffer->cv_bitmap.bm_data);
797 gr_init_canvas(VR_offscreen_buffer, pa_get_buffer_address(1), BM_LINEAR15, render_w, render_h);
799 if ( PAEnabled || gConfigInfo.mAcceleration ) {
800 Cockpit_mode=CM_FULL_SCREEN; // HACK HACK HACK HACK HACK!!!!
801 VR_offscreen_buffer = gr_create_canvas2(render_w, render_h, BM_LINEAR15);
803 VR_offscreen_buffer = gr_create_canvas( render_w, render_h );
806 VR_offscreen_buffer = gr_create_canvas( render_w, render_h );
811 VR_offscreen_buffer->cv_bitmap.bm_type = BM_OGL;
814 gr_init_sub_canvas( &VR_render_buffer[0], VR_offscreen_buffer, 0, 0, render_w, render_h );
815 gr_init_sub_canvas( &VR_render_buffer[1], VR_offscreen_buffer, 0, 0, render_w, render_h );
818 game_init_render_sub_buffers( 0, 0, render_w, render_h );
822 //called to get the screen in a mode compatible with popup menus.
823 //if we can't have popups over the game screen, switch to menu mode.
824 void set_popup_screen(void)
826 //WIN(LoadCursorWin(MOUSE_DEFAULT_CURSOR));
828 if (! (VR_screen_flags & VRF_COMPATIBLE_MENUS))
829 set_screen_mode(SCREEN_MENU); //must switch to menu mode
833 //called to change the screen mode. Parameter sm is the new mode, one of
834 //SMODE_GAME or SMODE_EDITOR. returns mode acutally set (could be other
835 //mode if cannot init requested mode)
836 int set_screen_mode(int sm)
838 WIN(static int force_mode_change=0);
839 WIN(static int saved_window_w);
840 WIN(static int saved_window_h);
843 if ( (sm==SCREEN_MENU) && (Screen_mode==SCREEN_EDITOR) ) {
844 gr_set_current_canvas( Canv_editor );
850 if ( Screen_mode == sm && W95DisplayMode == VR_screen_mode) {
851 dd_gr_set_current_canvas( &dd_VR_screen_pages[VR_current_page] );
855 if ( Screen_mode == sm && VGA_current_mode == VR_screen_mode) {
856 gr_set_current_canvas( &VR_screen_pages[VR_current_page] );
862 if ((Screen_mode == sm) && !((sm==SCREEN_GAME) && (grd_curscreen->sc_mode != VR_screen_mode) && (Screen_mode == SCREEN_GAME))) {
864 gr_set_current_canvas( &VR_screen_pages[VR_current_page] );
865 ogl_set_screen_mode();
876 switch( Screen_mode )
882 if (!(VR_screen_flags & VRF_COMPATIBLE_MENUS)) {
883 // HACK!!! Meant to save window size when switching from
884 // non-compat menu mode to menu mode.
885 saved_window_w = Game_window_w;
886 saved_window_h = Game_window_h;
887 force_mode_change = 1;
889 if (W95DisplayMode != SM95_640x480x8) {
890 //@@ piggy_bitmap_page_out_all_w(); // 2D GFX Flush cache.
891 DDSETDISPLAYMODE(SM95_640x480x8);
893 if (!gr_palette_faded_out) gr_palette_load(gr_palette);
896 dd_gr_init_sub_canvas(&dd_VR_screen_pages[0], dd_grd_screencanv,
898 dd_grd_screencanv->canvas.cv_bitmap.bm_w,
899 dd_grd_screencanv->canvas.cv_bitmap.bm_h);
900 dd_gr_init_sub_canvas(&dd_VR_screen_pages[1], dd_grd_screencanv,
902 dd_grd_screencanv->canvas.cv_bitmap.bm_w,
903 dd_grd_screencanv->canvas.cv_bitmap.bm_h);
911 MenuHires = MenuHiresAvailable; //do highres if we can
913 #if defined(POLY_ACC)
915 menu_mode = MenuHires?SM(640,480):SM(320,200);
917 menu_mode = PAEnabled?SM_640x480x15xPA:SM_640x480V;
920 menu_mode = MenuHires?SM(640,480):SM(320,200);
923 if (VGA_current_mode != menu_mode) {
924 if (gr_set_mode(menu_mode))
925 Error("Cannot set screen mode for menu");
926 if (!gr_palette_faded_out)
927 gr_palette_load(gr_palette);
930 gr_init_sub_canvas( &VR_screen_pages[0], &grd_curscreen->sc_canvas, 0, 0, grd_curscreen->sc_w, grd_curscreen->sc_h );
931 gr_init_sub_canvas( &VR_screen_pages[1], &grd_curscreen->sc_canvas, 0, 0, grd_curscreen->sc_w, grd_curscreen->sc_h );
933 FontHires = MenuHires;
943 if (force_mode_change || (W95DisplayMode != VR_screen_mode)) {
945 DDSETDISPLAYMODE(VR_screen_mode);
946 //@@ piggy_bitmap_page_out_all_w(); // 2D GFX Flush cache.
948 mprintf((0, "Reinitializing render buffers due to display mode change.\n"));
949 game_init_render_buffers(W95DisplayMode,
950 GRMODEINFO(rw), GRMODEINFO(rh),
951 VR_render_mode, VR_screen_flags);
956 if (VGA_current_mode != VR_screen_mode) {
957 if (gr_set_mode(VR_screen_mode)) {
958 Error("Cannot set desired screen mode for game!");
959 //we probably should do something else here, like select a standard mode
962 if ( (Config_control_type == 1) && (Function_mode == FMODE_GAME) )
969 if ( VR_render_mode == VR_NONE )
971 max_window_w = grd_curscreen->sc_w;
972 max_window_h = grd_curscreen->sc_h;
974 if (VR_screen_flags & VRF_ALLOW_COCKPIT) {
975 if (Cockpit_mode == CM_STATUS_BAR)
976 max_window_h = grd_curscreen->sc_h - GameBitmaps[cockpit_bitmap[CM_STATUS_BAR+(Current_display_mode?(Num_cockpits/2):0)].index].bm_h;
978 else if (Cockpit_mode != CM_LETTERBOX)
979 Cockpit_mode = CM_FULL_SCREEN;
981 if (Game_window_h==0 || Game_window_h > max_window_h || Game_window_w==0 || Game_window_w > max_window_w) {
982 Game_window_w = max_window_w;
983 Game_window_h = max_window_h;
988 Cockpit_mode = CM_FULL_SCREEN;
991 // Super hack. If we are switching from a 320x200 game to 640x480.
992 // and we were in a menumode when switching, we don't
993 // restore Game_window vals
994 if (force_mode_change && (W95DisplayMode == SM95_320x200x8X)) {
995 Game_window_w = saved_window_w;
996 Game_window_h = saved_window_h;
997 force_mode_change = 0;
1002 // Define screen pages for game mode
1003 // If we designate through screen_flags to use paging, then do so.
1005 dd_gr_init_sub_canvas( &dd_VR_screen_pages[0], dd_grd_screencanv, 0, 0, grd_curscreen->sc_w, grd_curscreen->sc_h ),
1006 gr_init_sub_canvas( &VR_screen_pages[0], &grd_curscreen->sc_canvas, 0, 0, grd_curscreen->sc_w, grd_curscreen->sc_h )
1009 if ( VR_screen_flags&VRF_USE_PAGING ) {
1011 dd_gr_init_sub_canvas( &dd_VR_screen_pages[1], dd_grd_backcanv, 0, 0, grd_curscreen->sc_w, grd_curscreen->sc_h ),
1012 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 )
1017 dd_gr_init_sub_canvas( &dd_VR_screen_pages[1], dd_grd_screencanv, 0, 0, grd_curscreen->sc_w, grd_curscreen->sc_h ),
1018 gr_init_sub_canvas( &VR_screen_pages[1], &grd_curscreen->sc_canvas, 0, 0, grd_curscreen->sc_w, grd_curscreen->sc_h )
1025 FontHires = (Current_display_mode != 0);
1028 FontHires = MenuHires = ((Current_display_mode != 0) && (Current_display_mode != 2));
1031 if ( VR_render_mode != VR_NONE ) {
1032 // for 640x480 or higher, use hires font.
1033 if ( grd_curscreen->sc_h > 400 )
1042 if (grd_curscreen->sc_mode != SM(800,600)) {
1044 if ((gr_error=gr_set_mode(SM(800,600)))!=0) { //force into game scrren
1045 Warning("Cannot init editor screen (error=%d)",gr_error);
1049 gr_palette_load( gr_palette );
1051 gr_init_sub_canvas( &VR_editor_canvas, &grd_curscreen->sc_canvas, 0, 0, grd_curscreen->sc_w, grd_curscreen->sc_h );
1052 Canv_editor = &VR_editor_canvas;
1053 gr_init_sub_canvas( &VR_screen_pages[0], Canv_editor, 0, 0, Canv_editor->cv_w, Canv_editor->cv_h );
1054 gr_init_sub_canvas( &VR_screen_pages[1], Canv_editor, 0, 0, Canv_editor->cv_w, Canv_editor->cv_h );
1055 gr_set_current_canvas( Canv_editor );
1056 init_editor_screen(); //setup other editor stuff
1060 Error("Invalid screen mode %d",sm);
1063 VR_current_page = 0;
1066 dd_gr_set_current_canvas(&dd_VR_screen_pages[VR_current_page]),
1067 gr_set_current_canvas( &VR_screen_pages[VR_current_page] )
1070 if ( VR_screen_flags&VRF_USE_PAGING ) {
1073 gr_show_canvas( &VR_screen_pages[VR_current_page] )
1077 ogl_set_screen_mode();
1083 int arch_toggle_fullscreen_menu(void);
1085 int gr_toggle_fullscreen_menu(void){
1086 #ifdef GR_SUPPORTS_FULLSCREEN_MENU_TOGGLE
1088 i=arch_toggle_fullscreen_menu();
1090 generic_key_handler(KEY_PADENTER,0);
1099 static int timer_paused=0;
1103 if (timer_paused==0) {
1105 time = timer_get_fixed_seconds();
1106 last_timer_value = time - last_timer_value;
1107 if (last_timer_value < 0) {
1108 #if defined(TIMER_TEST) && !defined(NDEBUG)
1109 Int3(); //get Matt!!!!
1111 last_timer_value = 0;
1113 #if defined(TIMER_TEST) && !defined(NDEBUG)
1114 time_stopped = time;
1119 #if defined(TIMER_TEST) && !defined(NDEBUG)
1127 Assert(timer_paused >= 0);
1128 if (timer_paused==0) {
1130 time = timer_get_fixed_seconds();
1131 #if defined(TIMER_TEST) && !defined(NDEBUG)
1132 if (last_timer_value < 0)
1133 Int3(); //get Matt!!!!
1136 last_timer_value = time - last_timer_value;
1137 #if defined(TIMER_TEST) && !defined(NDEBUG)
1138 time_started = time;
1142 #if defined(TIMER_TEST) && !defined(NDEBUG)
1147 MAC(extern ubyte joydefs_calibrating;)
1149 void game_flush_inputs()
1156 if ( (Function_mode != FMODE_MENU) && !joydefs_calibrating ) // only reset mouse when not in menu or not calibrating
1158 mouse_get_delta( &dx, &dy ); // Read mouse
1159 memset(&Controls,0,sizeof(control_info));
1164 last_timer_value = timer_get_fixed_seconds();
1169 extern int Saving_movie_frames;
1170 int Movie_fixed_frametime;
1172 #define Saving_movie_frames 0
1173 #define Movie_fixed_frametime 0
1176 static const int max_fps = 80;
1178 void calc_frame_time()
1180 fix timer_value,last_frametime = FrameTime;
1182 #if defined(TIMER_TEST) && !defined(NDEBUG)
1183 _last_frametime = last_frametime;
1186 timer_value = timer_get_fixed_seconds();
1187 FrameTime = timer_value - last_timer_value;
1190 timer_value = timer_get_fixed_seconds();
1191 FrameTime = timer_value - last_timer_value;
1192 if (FrameTime < f1_0/max_fps);
1196 } while (FrameTime < f1_0/max_fps);
1198 #if defined(TIMER_TEST) && !defined(NDEBUG)
1199 _timer_value = timer_value;
1203 if (!(((FrameTime > 0) && (FrameTime <= F1_0)) || (Function_mode == FMODE_EDITOR) || (Newdemo_state == ND_STATE_PLAYBACK))) {
1204 mprintf((1,"Bad FrameTime - value = %x\n",FrameTime));
1206 Int3(); // Call Mike or Matt or John! Your interrupts are probably trashed!
1207 // if ( !dpmi_virtual_memory )
1208 // Int3(); //Get MATT if hit this!
1212 #if defined(TIMER_TEST) && !defined(NDEBUG)
1213 actual_last_timer_value = last_timer_value;
1216 if ( Game_turbo_mode )
1219 // Limit frametime to be between 5 and 150 fps.
1220 RealFrameTime = FrameTime;
1221 if ( FrameTime < F1_0/150 ) FrameTime = F1_0/150;
1222 if ( FrameTime > F1_0/5 ) FrameTime = F1_0/5;
1224 last_timer_value = timer_value;
1226 if (FrameTime < 0) //if bogus frametime...
1227 FrameTime = last_frametime; //...then use time from last frame
1230 if (fixed_frametime) FrameTime = fixed_frametime;
1235 if ( Debug_pause ) {
1245 last_timer_value = timer_get_fixed_seconds();
1253 #if defined(TIMER_TEST) && !defined(NDEBUG)
1254 stop_count = start_count = 0;
1257 // Set value to determine whether homing missile can see target.
1258 // The lower frametime is, the more likely that it can see its target.
1259 if (FrameTime <= F1_0/64)
1260 Min_trackable_dot = MIN_TRACKABLE_DOT; // -- 3*(F1_0 - MIN_TRACKABLE_DOT)/4 + MIN_TRACKABLE_DOT;
1261 else if (FrameTime < F1_0/32)
1262 Min_trackable_dot = MIN_TRACKABLE_DOT + F1_0/64 - 2*FrameTime; // -- fixmul(F1_0 - MIN_TRACKABLE_DOT, F1_0-4*FrameTime) + MIN_TRACKABLE_DOT;
1263 else if (FrameTime < F1_0/4)
1264 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;
1266 Min_trackable_dot = MIN_TRACKABLE_DOT + F1_0/64 - F1_0/8;
1270 //--unused-- int Auto_flythrough=0; //if set, start flythough automatically
1272 void move_player_2_segment(segment *seg,int side)
1276 compute_segment_center(&ConsoleObject->pos,seg);
1277 compute_center_point_on_side(&vp,seg,side);
1278 vm_vec_sub2(&vp,&ConsoleObject->pos);
1279 vm_vector_2_matrix(&ConsoleObject->orient,&vp,NULL,NULL);
1281 obj_relink( ConsoleObject-Objects, SEG_PTR_2_NUM(seg) );
1286 void game_draw_time_left()
1288 char temp_string[30];
1292 gr_set_curfont( GAME_FONT ); //GAME_FONT
1293 gr_set_fontcolor(gr_getcolor(0,63,0), -1 );
1295 timevar=i2f (Netgame.PlayTimeAllowed*5*60);
1296 i=f2i(timevar-ThisLevelTime);
1299 sprintf( temp_string, "Time left: %d secs", i );
1302 gr_string(0, 32, temp_string );
1307 extern int Game_pause;
1310 void level_with_floor();
1312 void modex_clear_box(int x,int y,int w,int h)
1314 grs_canvas *temp_canv,*save_canv;
1316 save_canv = grd_curcanv;
1317 temp_canv = gr_create_canvas(w,h);
1318 gr_set_current_canvas(temp_canv);
1319 gr_clear_canvas(BM_XRGB(0,0,0));
1320 gr_set_current_canvas(save_canv);
1321 gr_bitmapm(x,y,&temp_canv->cv_bitmap);
1322 gr_free_canvas(temp_canv);
1326 extern void modex_printf(int x,int y,char *s,grs_font *font,int color);
1328 // mac routine to drop contents of screen to a pict file using copybits
1329 // save a PICT to a file
1332 void SavePictScreen(int multiplayer)
1335 int parid, i, count;
1336 char *pfilename, filename[50], buf[512], cwd[FILENAME_MAX];
1339 PicHandle pict_handle;
1340 static int multi_count = 0;
1341 StandardFileReply sf_reply;
1343 // dump the contents of the GameWindow into a picture using copybits
1345 pict_handle = OpenPicture(&GameWindow->portRect);
1346 if (pict_handle == NULL)
1349 CopyBits(&GameWindow->portBits, &GameWindow->portBits, &GameWindow->portRect, &GameWindow->portRect, srcBic, NULL);
1352 // get the cwd to restore with chdir when done -- this keeps the mac world sane
1353 if (!getcwd(cwd, FILENAME_MAX))
1355 // create the fsspec
1357 sprintf(filename, "screen%d", multi_count++);
1358 pfilename = c2pstr(filename);
1361 StandardPutFile("\pSave PICT as:", pfilename, &sf_reply);
1362 if (!sf_reply.sfGood)
1364 memcpy( &spec, &(sf_reply.sfFile), sizeof(FSSpec) );
1365 if (sf_reply.sfReplacing)
1367 err = FSpCreate( &spec, 'ttxt', 'PICT', smSystemScript );
1371 // parid = GetAppDirId();
1372 err = FSMakeFSSpec(0, 0, pfilename, &spec);
1377 err = FSpCreate(&spec, 'ttxt', 'PICT', smSystemScript);
1382 // write the PICT file
1383 if ( FSpOpenDF(&spec, fsRdWrPerm, &fd) )
1385 memset(buf, 0, sizeof(buf));
1387 if ( FSWrite(fd, &count, buf) )
1389 count = GetHandleSize((Handle)pict_handle);
1390 HLock((Handle)pict_handle);
1391 if ( FSWrite(fd, &count, *pict_handle) ) {
1397 HUnlock((Handle)pict_handle);
1398 DisposeHandle((Handle)pict_handle);
1406 //automap_flag is now unused, since we just check if the screen we're
1407 //writing to is modex
1408 //if called from automap, current canvas is set to visible screen
1410 void save_screen_shot(int automap_flag)
1412 #if defined(WINDOWS)
1413 mprintf((0, "Doing screen shot thing.\n"));
1414 win95_save_pcx_shot();
1416 #elif !defined(MACINTOSH)
1419 grs_canvas *screen_canv=&grd_curscreen->sc_canvas;
1420 grs_font *save_font;
1421 static int savenum=0;
1422 static int stereo_savenum=0;
1423 grs_canvas *temp_canv,*temp_canv2,*save_canv;
1424 char savename[FILENAME_LEN],savename2[FILENAME_LEN];
1432 // // Can't do screen shots in VR modes.
1433 // if ( VR_render_mode != VR_NONE )
1438 save_canv = grd_curcanv;
1440 if ( VR_render_mode != VR_NONE && !automap_flag && Function_mode==FMODE_GAME && Screen_mode==SCREEN_GAME)
1444 temp_canv = gr_create_canvas(VR_render_buffer[0].cv_bitmap.bm_w,VR_render_buffer[0].cv_bitmap.bm_h);
1445 gr_set_current_canvas(temp_canv);
1446 gr_ubitmap(0,0,&VR_render_buffer[0].cv_bitmap);
1448 temp_canv2 = gr_create_canvas(VR_render_buffer[1].cv_bitmap.bm_w,VR_render_buffer[1].cv_bitmap.bm_h);
1449 gr_set_current_canvas(temp_canv2);
1450 gr_ubitmap(0,0,&VR_render_buffer[1].cv_bitmap);
1453 temp_canv = gr_create_canvas(screen_canv->cv_bitmap.bm_w,screen_canv->cv_bitmap.bm_h);
1454 gr_set_current_canvas(temp_canv);
1455 gr_ubitmap(0,0,&screen_canv->cv_bitmap);
1458 gr_set_current_canvas(save_canv);
1460 if ( savenum > 99 ) savenum = 0;
1461 if ( stereo_savenum > 99 ) stereo_savenum = 0;
1464 sprintf(savename,"left%02d.pcx",stereo_savenum);
1465 sprintf(savename2,"right%02d.pcx",stereo_savenum);
1466 if (VR_eye_switch) {char t[FILENAME_LEN]; strcpy(t,savename); strcpy(savename,savename2); strcpy(savename2,t);}
1468 sprintf( message, "%s '%s' & '%s'", TXT_DUMPING_SCREEN, savename, savename2 );
1471 sprintf(savename,"screen%02d.pcx",savenum++);
1472 sprintf( message, "%s '%s'", TXT_DUMPING_SCREEN, savename );
1475 if (!automap_flag) //if from automap, curcanv is already visible canv
1476 gr_set_current_canvas(NULL);
1477 modex_flag = (grd_curcanv->cv_bitmap.bm_type==BM_MODEX);
1478 if (!automap_flag && modex_flag)
1479 gr_set_current_canvas(&VR_screen_pages[VR_current_page]);
1481 save_font = grd_curcanv->cv_font;
1482 gr_set_curfont(GAME_FONT);
1483 gr_set_fontcolor(gr_find_closest_color_current(0,31,0),-1);
1484 gr_get_string_size(message,&w,&h,&aw);
1489 //I changed how these coords were calculated for the high-res automap. -MT
1490 //x = (VR_screen_pages[VR_current_page].cv_w-w)/2;
1491 //y = (VR_screen_pages[VR_current_page].cv_h-h)/2;
1492 x = (grd_curcanv->cv_w-w)/2;
1493 y = (grd_curcanv->cv_h-h)/2;
1496 modex_clear_box(x-2,y-2,w+4,h+4);
1497 modex_printf(x, y, message,GAME_FONT,gr_find_closest_color_current(0,31,0));
1499 gr_setcolor(gr_find_closest_color_current(0,0,0));
1500 gr_rect(x-2,y-2,x+w+2,y+h+2);
1501 gr_printf(x,y,message);
1502 gr_set_curfont(save_font);
1504 t1 = timer_get_fixed_seconds() + F1_0;
1506 gr_palette_read(pal); //get actual palette from the hardware
1507 pcx_write_bitmap(savename,&temp_canv->cv_bitmap,pal);
1509 pcx_write_bitmap(savename2,&temp_canv2->cv_bitmap,pal);
1511 while ( timer_get_fixed_seconds() < t1 ); // Wait so that messag stays up at least 1 second.
1513 gr_set_current_canvas(screen_canv);
1515 if (grd_curcanv->cv_bitmap.bm_type!=BM_MODEX && !stereo)
1516 gr_ubitmap(0,0,&temp_canv->cv_bitmap);
1518 gr_free_canvas(temp_canv);
1520 gr_free_canvas(temp_canv2);
1522 gr_set_current_canvas(save_canv);
1528 grs_canvas *screen_canv = &grd_curscreen->sc_canvas;
1529 grs_canvas *temp_canv, *save_canv;
1531 // Can't do screen shots in VR modes.
1532 if ( VR_render_mode != VR_NONE )
1537 save_canv = grd_curcanv;
1538 temp_canv = gr_create_canvas( screen_canv->cv_bitmap.bm_w, screen_canv->cv_bitmap.bm_h );
1541 gr_set_current_canvas( temp_canv );
1542 gr_ubitmap( 0, 0, &screen_canv->cv_bitmap );
1543 gr_set_current_canvas( &VR_screen_pages[VR_current_page] );
1547 if (Game_mode & GM_MULTI)
1554 gr_set_current_canvas(screen_canv);
1556 // if (!automap_flag)
1557 gr_ubitmap( 0, 0, &temp_canv->cv_bitmap);
1559 gr_free_canvas(temp_canv);
1561 gr_set_current_canvas(save_canv);
1570 void fly_init(object *obj)
1572 obj->control_type = CT_FLYING;
1573 obj->movement_type = MT_PHYSICS;
1575 vm_vec_zero(&obj->mtype.phys_info.velocity);
1576 vm_vec_zero(&obj->mtype.phys_info.thrust);
1577 vm_vec_zero(&obj->mtype.phys_info.rotvel);
1578 vm_vec_zero(&obj->mtype.phys_info.rotthrust);
1581 //void morph_test(), morph_step();
1584 // ------------------------------------------------------------------------------------
1586 void test_anim_states();
1590 //put up the help message
1597 extern int been_in_editor;
1599 // ------------------------------------------------------------------------------------
1600 void do_cloak_stuff(void)
1603 for (i = 0; i < N_players; i++)
1604 if (Players[i].flags & PLAYER_FLAGS_CLOAKED) {
1605 // mprintf(0, "Cloak time left: %7.3f\n", f2fl(CLOAK_TIME_MAX - (GameTime - Players[Player_num].cloak_time)));
1606 if (GameTime - Players[i].cloak_time > CLOAK_TIME_MAX) {
1607 Players[i].flags &= ~PLAYER_FLAGS_CLOAKED;
1608 if (i == Player_num) {
1609 digi_play_sample( SOUND_CLOAK_OFF, F1_0);
1611 if (Game_mode & GM_MULTI)
1612 multi_send_play_sound(SOUND_CLOAK_OFF, F1_0);
1613 maybe_drop_net_powerup(POW_CLOAK);
1614 multi_send_decloak(); // For demo recording
1616 // mprintf((0, " --- You have been DE-CLOAKED! ---\n"));
1624 // ------------------------------------------------------------------------------------
1625 void do_invulnerable_stuff(void)
1627 if (Players[Player_num].flags & PLAYER_FLAGS_INVULNERABLE) {
1628 if (GameTime - Players[Player_num].invulnerable_time > INVULNERABLE_TIME_MAX) {
1629 Players[Player_num].flags ^= PLAYER_FLAGS_INVULNERABLE;
1632 digi_play_sample( SOUND_INVULNERABILITY_OFF, F1_0);
1634 if (Game_mode & GM_MULTI)
1636 multi_send_play_sound(SOUND_INVULNERABILITY_OFF, F1_0);
1637 maybe_drop_net_powerup(POW_INVULNERABILITY);
1640 mprintf((0, " --- You have been DE-INVULNERABLEIZED! ---\n"));
1647 ubyte Last_afterburner_state = 0;
1648 fix Last_afterburner_charge = 0;
1650 #define AFTERBURNER_LOOP_START ((digi_sample_rate==SAMPLE_RATE_22K)?32027:(32027/2)) //20098
1651 #define AFTERBURNER_LOOP_END ((digi_sample_rate==SAMPLE_RATE_22K)?48452:(48452/2)) //25776
1655 //@@// ------------------------------------------------------------------------------------
1656 //@@void afterburner_shake(void)
1660 //@@ rx = (Ab_scale * fixmul(d_rand() - 16384, F1_0/8 + (((GameTime + 0x4000)*4) & 0x3fff)))/16;
1661 //@@ rz = (Ab_scale * fixmul(d_rand() - 16384, F1_0/2 + ((GameTime*4) & 0xffff)))/16;
1663 //@@ // -- mprintf((0, "AB: %8x %8x\n", rx, rz));
1664 //@@ ConsoleObject->mtype.phys_info.rotvel.x += rx;
1665 //@@ ConsoleObject->mtype.phys_info.rotvel.z += rz;
1669 // ------------------------------------------------------------------------------------
1671 extern void multi_send_sound_function (char,char);
1674 void do_afterburner_stuff(void)
1676 if (!(Players[Player_num].flags & PLAYER_FLAGS_AFTERBURNER))
1677 Afterburner_charge=0;
1679 if (Endlevel_sequence || Player_is_dead)
1681 digi_kill_sound_linked_to_object( Players[Player_num].objnum);
1683 multi_send_sound_function (0,0);
1687 if ((Controls.afterburner_state != Last_afterburner_state && Last_afterburner_charge) || (Last_afterburner_state && Last_afterburner_charge && !Afterburner_charge)) {
1689 if (Afterburner_charge && Controls.afterburner_state && (Players[Player_num].flags & PLAYER_FLAGS_AFTERBURNER)) {
1690 digi_link_sound_to_object3( SOUND_AFTERBURNER_IGNITE, Players[Player_num].objnum, 1, F1_0, i2f(256), AFTERBURNER_LOOP_START, AFTERBURNER_LOOP_END );
1692 if (Game_mode & GM_MULTI)
1693 multi_send_sound_function (3,SOUND_AFTERBURNER_IGNITE);
1696 digi_kill_sound_linked_to_object( Players[Player_num].objnum);
1697 digi_link_sound_to_object2( SOUND_AFTERBURNER_PLAY, Players[Player_num].objnum, 0, F1_0, i2f(256));
1699 if (Game_mode & GM_MULTI)
1700 multi_send_sound_function (0,0);
1702 mprintf((0,"Killing afterburner sound\n"));
1706 //@@if (Controls.afterburner_state && Afterburner_charge)
1707 //@@ afterburner_shake();
1709 Last_afterburner_state = Controls.afterburner_state;
1710 Last_afterburner_charge = Afterburner_charge;
1713 // -- // ------------------------------------------------------------------------------------
1714 // -- // if energy < F1_0/2, recharge up to F1_0/2
1715 // -- void recharge_energy_frame(void)
1717 // -- if (Players[Player_num].energy < Weapon_info[0].energy_usage) {
1718 // -- Players[Player_num].energy += FrameTime/4;
1720 // -- if (Players[Player_num].energy > Weapon_info[0].energy_usage)
1721 // -- Players[Player_num].energy = Weapon_info[0].energy_usage;
1725 // Amount to diminish guns towards normal, per second.
1726 #define DIMINISH_RATE 16 // gots to be a power of 2, else change the code in diminish_palette_towards_normal
1728 extern fix Flash_effect;
1730 //adds to rgb values for palette flash
1731 void PALETTE_FLASH_ADD(int _dr,int _dg,int _db)
1735 PaletteRedAdd += _dr;
1736 PaletteGreenAdd += _dg;
1737 PaletteBlueAdd += _db;
1739 // -- mprintf((0, "Palette add: %3i %3i %3i\n", PaletteRedAdd, PaletteGreenAdd, PaletteBlueAdd));
1744 maxval = MAX_PALETTE_ADD;
1746 if (PaletteRedAdd > maxval)
1747 PaletteRedAdd = maxval;
1749 if (PaletteGreenAdd > maxval)
1750 PaletteGreenAdd = maxval;
1752 if (PaletteBlueAdd > maxval)
1753 PaletteBlueAdd = maxval;
1755 if (PaletteRedAdd < -maxval)
1756 PaletteRedAdd = -maxval;
1758 if (PaletteGreenAdd < -maxval)
1759 PaletteGreenAdd = -maxval;
1761 if (PaletteBlueAdd < -maxval)
1762 PaletteBlueAdd = -maxval;
1765 fix Time_flash_last_played;
1768 void game_palette_step_up( int r, int g, int b );
1769 // ------------------------------------------------------------------------------------
1770 // Diminish palette effects towards normal.
1771 void diminish_palette_towards_normal(void)
1775 // Diminish at DIMINISH_RATE units/second.
1776 // For frame rates > DIMINISH_RATE Hz, use randomness to achieve this.
1777 if (FrameTime < F1_0/DIMINISH_RATE) {
1778 if (d_rand() < FrameTime*DIMINISH_RATE/2) // Note: d_rand() is in 0..32767, and 8 Hz means decrement every frame
1781 dec_amount = f2i(FrameTime*DIMINISH_RATE); // one second = DIMINISH_RATE counts
1782 if (dec_amount == 0)
1783 dec_amount++; // make sure we decrement by something
1789 // Part of hack system to force update of palette after exiting a menu.
1790 if (Time_flash_last_played) {
1792 PaletteRedAdd ^= 1; // Very Tricky! In gr_palette_step_up, if all stepups same as last time, won't do anything!
1795 if ((Time_flash_last_played + F1_0/8 < GameTime) || (Time_flash_last_played > GameTime)) {
1796 digi_play_sample( SOUND_CLOAK_OFF, Flash_effect/4);
1797 Time_flash_last_played = GameTime;
1800 Flash_effect -= FrameTime;
1801 if (Flash_effect < 0)
1804 if (force_do || (d_rand() > 4096 )) {
1805 if ( (Newdemo_state==ND_STATE_RECORDING) && (PaletteRedAdd || PaletteGreenAdd || PaletteBlueAdd) )
1806 newdemo_record_palette_effect(PaletteRedAdd, PaletteGreenAdd, PaletteBlueAdd);
1808 game_palette_step_up( PaletteRedAdd, PaletteGreenAdd, PaletteBlueAdd );
1815 if (PaletteRedAdd > 0 ) { PaletteRedAdd -= dec_amount; if (PaletteRedAdd < 0 ) PaletteRedAdd = 0; }
1816 if (PaletteRedAdd < 0 ) { PaletteRedAdd += dec_amount; if (PaletteRedAdd > 0 ) PaletteRedAdd = 0; }
1818 if (PaletteGreenAdd > 0 ) { PaletteGreenAdd -= dec_amount; if (PaletteGreenAdd < 0 ) PaletteGreenAdd = 0; }
1819 if (PaletteGreenAdd < 0 ) { PaletteGreenAdd += dec_amount; if (PaletteGreenAdd > 0 ) PaletteGreenAdd = 0; }
1821 if (PaletteBlueAdd > 0 ) { PaletteBlueAdd -= dec_amount; if (PaletteBlueAdd < 0 ) PaletteBlueAdd = 0; }
1822 if (PaletteBlueAdd < 0 ) { PaletteBlueAdd += dec_amount; if (PaletteBlueAdd > 0 ) PaletteBlueAdd = 0; }
1824 if ( (Newdemo_state==ND_STATE_RECORDING) && (PaletteRedAdd || PaletteGreenAdd || PaletteBlueAdd) )
1825 newdemo_record_palette_effect(PaletteRedAdd, PaletteGreenAdd, PaletteBlueAdd);
1827 game_palette_step_up( PaletteRedAdd, PaletteGreenAdd, PaletteBlueAdd );
1829 //mprintf(0, "%2i %2i %2i\n", PaletteRedAdd, PaletteGreenAdd, PaletteBlueAdd);
1832 int Redsave, Bluesave, Greensave;
1834 void palette_save(void)
1836 Redsave = PaletteRedAdd; Bluesave = PaletteBlueAdd; Greensave = PaletteGreenAdd;
1839 extern void gr_palette_step_up_vr( int r, int g, int b, int white, int black );
1841 void game_palette_step_up( int r, int g, int b )
1843 if ( VR_use_reg_code ) {
1845 // gr_palette_step_up_vr( r, g, b, VR_WHITE_INDEX, VR_BLACK_INDEX );
1848 gr_palette_step_up( r, g, b );
1852 void palette_restore(void)
1854 PaletteRedAdd = Redsave; PaletteBlueAdd = Bluesave; PaletteGreenAdd = Greensave;
1855 game_palette_step_up( PaletteRedAdd, PaletteGreenAdd, PaletteBlueAdd );
1857 // Forces flash effect to fixup palette next frame.
1858 Time_flash_last_played = 0;
1861 extern void dead_player_frame(void);
1864 // --------------------------------------------------------------------------------------------------
1865 int allowed_to_fire_laser(void)
1867 if (Player_is_dead) {
1868 Global_missile_firing_count = 0;
1872 // Make sure enough time has elapsed to fire laser, but if it looks like it will
1873 // be a long while before laser can be fired, then there must be some mistake!
1874 if (Next_laser_fire_time > GameTime)
1875 if (Next_laser_fire_time < GameTime + 2*F1_0)
1881 fix Next_flare_fire_time = 0;
1882 #define FLARE_BIG_DELAY (F1_0*2)
1884 int allowed_to_fire_flare(void)
1886 if (Next_flare_fire_time > GameTime)
1887 if (Next_flare_fire_time < GameTime + FLARE_BIG_DELAY) // In case time is bogus, never wait > 1 second.
1890 if (Players[Player_num].energy >= Weapon_info[FLARE_ID].energy_usage)
1891 Next_flare_fire_time = GameTime + F1_0/4;
1893 Next_flare_fire_time = GameTime + FLARE_BIG_DELAY;
1898 int allowed_to_fire_missile(void)
1900 // mprintf(0, "Next fire = %7.3f, Cur time = %7.3f\n", f2fl(Next_missile_fire_time), f2fl(GameTime));
1901 // Make sure enough time has elapsed to fire missile, but if it looks like it will
1902 // be a long while before missile can be fired, then there must be some mistake!
1903 if (Next_missile_fire_time > GameTime)
1904 if (Next_missile_fire_time < GameTime + 5*F1_0)
1910 void full_palette_save(void)
1913 apply_modified_palette();
1914 reset_palette_add();
1915 gr_palette_load( gr_palette );
1918 extern int Death_sequence_aborted;
1919 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) );
1926 char command_help[64], pixel_double_help[64], save_help[64], restore_help[64];
1929 m[ 0].type = NM_TYPE_TEXT; m[ 0].text = TXT_HELP_ESC;
1931 m[ 1].type = NM_TYPE_TEXT; m[ 1].text = TXT_HELP_ALT_F2;
1932 m[ 2].type = NM_TYPE_TEXT; m[ 2].text = TXT_HELP_ALT_F3;
1934 sprintf(save_help, "OPT-F2 (%c-s)\t Save Game", 133);
1935 sprintf(restore_help, "OPT-F3 (%c-o)\t Load Game", 133);
1936 m[ 1].type = NM_TYPE_TEXT; m[1].text = save_help;
1937 m[ 2].type = NM_TYPE_TEXT; m[2].text = restore_help;
1939 m[ 3].type = NM_TYPE_TEXT; m[ 3].text = TXT_HELP_F2;
1940 m[ 4].type = NM_TYPE_TEXT; m[ 4].text = TXT_HELP_F3;
1941 m[ 5].type = NM_TYPE_TEXT; m[ 5].text = TXT_HELP_F4;
1942 m[ 6].type = NM_TYPE_TEXT; m[ 6].text = TXT_HELP_F5;
1944 m[ 7].type = NM_TYPE_TEXT; m[ 7].text = TXT_HELP_PAUSE;
1946 m[ 7].type = NM_TYPE_TEXT; m[ 7].text = "Pause (F15)\t Pause";
1948 m[ 8].type = NM_TYPE_TEXT; m[ 8].text = TXT_HELP_MINUSPLUS;
1950 m[ 9].type = NM_TYPE_TEXT; m[ 9].text = TXT_HELP_PRTSCN;
1952 m[ 9].type = NM_TYPE_TEXT; m[ 9].text = "printscrn (F13)\t save screen shot";
1954 m[10].type = NM_TYPE_TEXT; m[10].text = TXT_HELP_1TO5;
1955 m[11].type = NM_TYPE_TEXT; m[11].text = TXT_HELP_6TO10;
1956 m[12].type = NM_TYPE_TEXT; m[12].text = "Shift-F1\t Cycle left window";
1957 m[13].type = NM_TYPE_TEXT; m[13].text = "Shift-F2\t Cycle right window";
1958 m[14].type = NM_TYPE_TEXT; m[14].text = "Shift-F4\t GuideBot menu";
1960 m[15].type = NM_TYPE_TEXT; m[15].text = "Alt-Shift-F4\t Rename GuideBot";
1962 m[15].type = NM_TYPE_TEXT; m[15].text = "Opt-Shift-F4\t Rename GuideBot";
1964 m[16].type = NM_TYPE_TEXT; m[16].text = "Shift-F5\t Drop primary";
1965 m[17].type = NM_TYPE_TEXT; m[17].text = "Shift-F6\t Drop secondary";
1966 m[18].type = NM_TYPE_TEXT; m[18].text = "Shift-F7\t Calibrate joystick";
1967 m[19].type = NM_TYPE_TEXT; m[19].text = "Shift-number\t GuideBot commands";
1970 sprintf(pixel_double_help, "%c-D\t Toggle Pixel Double Mode", 133);
1971 m[20].type = NM_TYPE_TEXT; m[20].text = pixel_double_help;
1972 m[21].type = NM_TYPE_TEXT; m[21].text = "";
1973 sprintf(command_help, "(Use %c-# for F#. i.e. %c-1 for F1)", 133, 133);
1974 m[22].type = NM_TYPE_TEXT; m[22].text = command_help;
1978 full_palette_save();
1980 newmenu_dotiny2( NULL, TXT_KEYS, nitems, m, NULL );
1985 //temp function until Matt cleans up game sequencing
1986 extern void temp_reset_stuff_on_level();
1988 //deal with rear view - switch it on, or off, or whatever
1989 void check_rear_view()
1992 #define LEAVE_TIME 0x1000 //how long until we decide key is down (Used to be 0x4000)
1994 static int leave_mode;
1995 static fix entry_time;
1997 if ( Controls.rear_view_down_count ) { //key/button has gone down
2001 if (Cockpit_mode==CM_REAR_VIEW) {
2002 select_cockpit(Cockpit_mode_save);
2003 Cockpit_mode_save = -1;
2005 if (Newdemo_state == ND_STATE_RECORDING)
2006 newdemo_record_restore_rearview();
2010 leave_mode = 0; //means wait for another key
2011 entry_time = timer_get_fixed_seconds();
2012 if (Cockpit_mode == CM_FULL_COCKPIT) {
2013 Cockpit_mode_save = Cockpit_mode;
2014 select_cockpit(CM_REAR_VIEW);
2016 if (Newdemo_state == ND_STATE_RECORDING)
2017 newdemo_record_rearview();
2021 if (Controls.rear_view_down_state) {
2023 if (leave_mode==0 && (timer_get_fixed_seconds()-entry_time)>LEAVE_TIME)
2028 //@@if (leave_mode==1 && Cockpit_mode==CM_REAR_VIEW) {
2030 if (leave_mode==1 && Rear_view) {
2032 if (Cockpit_mode==CM_REAR_VIEW) {
2033 select_cockpit(Cockpit_mode_save);
2034 Cockpit_mode_save = -1;
2036 if (Newdemo_state == ND_STATE_RECORDING)
2037 newdemo_record_restore_rearview();
2042 void reset_rear_view(void)
2045 if (Newdemo_state == ND_STATE_RECORDING)
2046 newdemo_record_restore_rearview();
2051 if (!(Cockpit_mode == CM_FULL_COCKPIT || Cockpit_mode == CM_STATUS_BAR || Cockpit_mode == CM_FULL_SCREEN)) {
2052 if (!(Cockpit_mode_save == CM_FULL_COCKPIT || Cockpit_mode_save == CM_STATUS_BAR || Cockpit_mode_save == CM_FULL_SCREEN))
2053 Cockpit_mode_save = CM_FULL_COCKPIT;
2054 select_cockpit(Cockpit_mode_save);
2055 Cockpit_mode_save = -1;
2061 int Config_menu_flag;
2065 int Cheats_enabled=0;
2067 extern int Laser_rapid_fire;
2068 extern void do_lunacy_on(), do_lunacy_off();
2070 extern int Physics_cheat_flag,Robots_kill_robots_cheat;
2071 extern char BounceCheat,HomingCheat,OldHomingState[20];
2072 extern char AcidCheatOn,old_IntMethod, Monster_mode;
2073 extern int Buddy_dude_cheat;
2075 //turns off active cheats
2076 void turn_cheats_off()
2082 Weapon_info[i].homing_flag=OldHomingState[i];
2087 Interpolation_method=old_IntMethod;
2090 Buddy_dude_cheat = 0;
2094 Laser_rapid_fire = 0;
2095 Physics_cheat_flag = 0;
2097 Robots_kill_robots_cheat=0;
2098 Robot_firing_enabled = 1;
2101 //turns off all cheats & resets cheater flag
2102 void game_disable_cheats()
2110 // ----------------------------------------------------------------------------
2112 void game_setup(void)
2114 //@@int demo_playing=0;
2115 //@@int multi_game=0;
2117 do_lunacy_on(); // Copy values for insane into copy buffer in ai.c
2118 do_lunacy_off(); // Restore true insane mode.
2121 last_drawn_cockpit[0] = -1; // Force cockpit to redraw next time a frame renders.
2122 last_drawn_cockpit[1] = -1; // Force cockpit to redraw next time a frame renders.
2123 Endlevel_sequence = 0;
2125 //@@if ( Newdemo_state == ND_STATE_PLAYBACK )
2126 //@@ demo_playing = 1;
2127 //@@if ( Game_mode & GM_MULTI )
2128 //@@ multi_game = 1;
2130 set_screen_mode(SCREEN_GAME);
2131 reset_palette_add();
2133 set_warn_func(game_show_warning);
2137 //digi_init_sounds();
2139 //keyd_repeat = 0; // Don't allow repeat in game
2140 keyd_repeat = 1; // Do allow repeat in game
2142 #if !defined(WINDOWS) && !defined(MACINTOSH)
2143 //_MARK_("start of game");
2147 if (Segments[ConsoleObject->segnum].segnum == -1) //segment no longer exists
2148 obj_relink( ConsoleObject-Objects, SEG_PTR_2_NUM(Cursegp) );
2150 if (!check_obj_seg(ConsoleObject))
2151 move_player_2_segment(Cursegp,Curside);
2154 Viewer = ConsoleObject;
2155 fly_init(ConsoleObject);
2160 FrameTime = 0; //make first frame zero
2163 if (Current_level_num == 0) { //not a real level
2164 init_player_stats_game();
2171 game_flush_inputs();
2177 extern char IWasKicked;
2181 // ------------------------------------------------------------------------------------
2182 //this function is the game. called when game mode selected. runs until
2183 //editor mode or exit selected
2186 game_setup(); // Replaces what was here earlier.
2187 // Good for Windows Sake.
2190 ProfilerSetStatus(1);
2193 if ( setjmp(LeaveGame)==0 ) {
2199 Config_menu_flag = 0;
2201 if ( ConsoleObject != &Objects[Players[Player_num].objnum] )
2203 mprintf ((0,"Player_num=%d objnum=%d",Player_num,Players[Player_num].objnum));
2204 //Assert( ConsoleObject == &Objects[Players[Player_num].objnum] );
2207 player_shields = Players[Player_num].shields;
2212 DoMessageStuff(&msg); // Do Windows event handling.
2213 if (_RedrawScreen) {
2214 _RedrawScreen = FALSE;
2215 load_palette(Current_level_palette,1,1);
2216 gr_palette_load(gr_palette);
2221 ExtGameStatus=GAMESTAT_RUNNING;
2222 GameLoop( 1, 1 ); // Do game loop with rendering and reading controls.
2224 //if the player is taking damage, give up guided missile control
2225 if (Players[Player_num].shields != player_shields)
2226 release_guided_missile(Player_num);
2228 //see if redbook song needs to be restarted
2229 songs_check_redbook_repeat(); // Handle RedBook Audio Repeating.
2231 if (Config_menu_flag) {
2232 int double_save = Scanline_double;
2234 //WIN(mouse_set_mode(0));
2235 if (!(Game_mode&GM_MULTI)) {palette_save(); reset_palette_add(); apply_modified_palette(); gr_palette_load( gr_palette ); }
2237 if (Scanline_double != double_save) init_cockpit();
2238 if (!(Game_mode&GM_MULTI)) palette_restore();
2239 //WIN(mouse_set_mode(1));
2243 int save_w=Game_window_w,save_h=Game_window_h;
2245 Screen_mode=-1; set_screen_mode(SCREEN_GAME);
2246 Game_window_w=save_w; Game_window_h=save_h;
2248 last_drawn_cockpit[0] = -1;
2249 last_drawn_cockpit[1] = -1;
2252 if ( (Function_mode != FMODE_GAME) && Auto_demo && (Newdemo_state != ND_STATE_NORMAL) ) {
2254 fmode = Function_mode;
2255 Function_mode = FMODE_GAME;
2257 apply_modified_palette();
2258 reset_palette_add();
2259 gr_palette_load( gr_palette );
2260 choice=nm_messagebox( NULL, 2, TXT_YES, TXT_NO, TXT_ABORT_AUTODEMO );
2262 Function_mode = fmode;
2265 newdemo_stop_playback();
2266 Function_mode = FMODE_MENU;
2268 Function_mode = FMODE_GAME;
2272 if ( (Function_mode != FMODE_GAME ) && (Newdemo_state != ND_STATE_PLAYBACK ) && (Function_mode!=FMODE_EDITOR)
2278 fmode = Function_mode;
2279 Function_mode = FMODE_GAME;
2281 apply_modified_palette();
2282 reset_palette_add();
2283 gr_palette_load( gr_palette );
2284 ExtGameStatus=GAMESTAT_ABORT_GAME;
2285 choice=nm_messagebox( NULL, 2, TXT_YES, TXT_NO, TXT_ABORT_GAME );
2287 Function_mode = fmode;
2289 Function_mode = FMODE_GAME;
2295 if (Function_mode != FMODE_GAME)
2296 longjmp(LeaveGame,0);
2299 if ( (keyd_time_when_last_pressed + (F1_0 * 60)) < timer_get_fixed_seconds() ) // idle in game for 1 minutes means exit
2300 longjmp(LeaveGame,0);
2306 ProfilerSetStatus(0);
2311 if ( (Newdemo_state == ND_STATE_RECORDING) || (Newdemo_state == ND_STATE_PAUSED) )
2312 newdemo_stop_recording();
2318 if ( Newdemo_state == ND_STATE_PLAYBACK )
2319 newdemo_stop_playback();
2321 if (Cockpit_mode_save!=-1)
2323 Cockpit_mode=Cockpit_mode_save;
2324 Cockpit_mode_save=-1;
2327 if (Function_mode != FMODE_EDITOR)
2328 gr_palette_fade_out(gr_palette,32,0); // Fade out before going to menu
2330 //@@ if ( (!demo_playing) && (!multi_game) && (Function_mode != FMODE_EDITOR)) {
2331 //@@ scores_maybe_add_player(Game_aborted);
2334 #if !defined(WINDOWS) && !defined(MACINTOSH)
2335 //_MARK_("end of game");
2338 clear_warn_func(game_show_warning); //don't use this func anymore
2340 game_disable_cheats();
2343 Function_mode = FMODE_EXIT; // get out of game in Apple OEM version
2347 //called at the end of the program
2351 if (dd_VR_offscreen_buffer) {
2352 if (dd_grd_backcanv != dd_VR_offscreen_buffer) {
2353 dd_gr_free_canvas(dd_VR_offscreen_buffer);
2355 dd_VR_offscreen_buffer = NULL;
2356 VR_offscreen_buffer = NULL;
2359 if (VR_offscreen_buffer) {
2360 gr_free_canvas(VR_offscreen_buffer);
2361 VR_offscreen_buffer = NULL;
2365 close_gauge_canvases();
2367 restore_effect_bitmap_icons();
2369 #if !defined(MACINTOSH) && !defined(WINDOWS)
2370 if (Game_cockpit_copy_code) {
2371 d_free(Game_cockpit_copy_code);
2372 Game_cockpit_copy_code = NULL;
2375 if (Game_cockpit_copy_code)
2376 Game_cockpit_copy_code = 0;
2379 if (background_bitmap.bm_data)
2380 d_free(background_bitmap.bm_data);
2382 clear_warn_func(game_show_warning); //don't use this func anymore
2386 dd_grs_canvas * get_current_game_screen()
2388 return &dd_VR_screen_pages[VR_current_page];
2393 grs_canvas * get_current_game_screen()
2395 return &VR_screen_pages[VR_current_page];
2400 extern void kconfig_center_headset();
2404 void speedtest_frame(void);
2405 int Debug_slowdown=0;
2409 extern void player_follow_path(object *objp);
2410 extern void check_create_player_path(void);
2414 extern int Do_appearance_effect;
2416 object *Missile_viewer=NULL;
2418 int Missile_view_enabled = 1;
2420 int Marker_viewer_num[2]={-1,-1};
2421 int Coop_view_player[2]={-1,-1};
2422 int Cockpit_3d_view[2]={CV_NONE,CV_NONE};
2424 //returns ptr to escort robot, or NULL
2425 object *find_escort()
2429 for (i=0; i<=Highest_object_index; i++)
2430 if (Objects[i].type == OBJ_ROBOT)
2431 if (Robot_info[Objects[i].id].companion)
2437 extern void process_super_mines_frame(void);
2438 extern void do_seismic_stuff(void);
2441 int Saving_movie_frames=0;
2442 int __Movie_frame_num=0;
2444 #define MAX_MOVIE_BUFFER_FRAMES 250
2445 #define MOVIE_FRAME_SIZE (320 * 200)
2447 ubyte *Movie_frame_buffer;
2448 int Movie_frame_counter;
2449 ubyte Movie_pal[768];
2450 char movie_path[50] = ".\\";
2452 grs_bitmap Movie_bm;
2454 void flush_movie_buffer()
2461 mprintf((0,"Flushing movie buffer..."));
2463 Movie_bm.bm_data = Movie_frame_buffer;
2465 for (f=0;f<Movie_frame_counter;f++) {
2466 sprintf(savename, "%sfrm%04d.pcx",movie_path,__Movie_frame_num);
2467 __Movie_frame_num++;
2468 pcx_write_bitmap(savename,&Movie_bm,Movie_pal);
2469 Movie_bm.bm_data += MOVIE_FRAME_SIZE;
2472 mprintf((0,"%3d/%3d\10\10\10\10\10\10\10",f,Movie_frame_counter));
2475 Movie_frame_counter=0;
2477 mprintf((0,"done \n"));
2482 void toggle_movie_saving()
2486 Saving_movie_frames = !Saving_movie_frames;
2488 if (Saving_movie_frames) {
2491 m[0].type=NM_TYPE_INPUT; m[0].text_len = 50; m[0].text = movie_path;
2492 exit = newmenu_do( NULL, "Directory for movie frames?" , 1, &(m[0]), NULL );
2495 Saving_movie_frames = 0;
2499 while (isspace(movie_path[strlen(movie_path)-1]))
2500 movie_path[strlen(movie_path)-1] = 0;
2501 if (movie_path[strlen(movie_path)-1]!='\\' && movie_path[strlen(movie_path)-1]!=':')
2502 strcat(movie_path,"\\");
2505 if (!Movie_frame_buffer) {
2506 Movie_frame_buffer = d_malloc(MAX_MOVIE_BUFFER_FRAMES * MOVIE_FRAME_SIZE);
2507 if (!Movie_frame_buffer) {
2509 Saving_movie_frames=0;
2512 Movie_frame_counter=0;
2514 Movie_bm.bm_x = Movie_bm.bm_y = 0;
2515 Movie_bm.bm_w = 320;
2516 Movie_bm.bm_h = 200;
2517 Movie_bm.bm_type = BM_LINEAR;
2518 Movie_bm.bm_flags = 0;
2519 Movie_bm.bm_rowsize = 320;
2520 Movie_bm.bm_handle = 0;
2522 gr_palette_read(Movie_pal); //get actual palette from the hardware
2524 if (Newdemo_state == ND_STATE_PLAYBACK)
2525 Newdemo_do_interpolate = 0;
2529 flush_movie_buffer();
2531 if (Newdemo_state == ND_STATE_PLAYBACK)
2532 Newdemo_do_interpolate = 1;
2537 void save_movie_frame()
2539 memcpy(Movie_frame_buffer+Movie_frame_counter*MOVIE_FRAME_SIZE,grd_curscreen->sc_canvas.cv_bitmap.bm_data,MOVIE_FRAME_SIZE);
2541 Movie_frame_counter++;
2543 if (Movie_frame_counter == MAX_MOVIE_BUFFER_FRAMES)
2544 flush_movie_buffer();
2550 extern int Level_shake_duration;
2552 //if water or fire level, make occasional sound
2553 void do_ambient_sounds()
2555 int has_water,has_lava;
2558 has_lava = (Segment2s[ConsoleObject->segnum].s2_flags & S2F_AMBIENT_LAVA);
2559 has_water = (Segment2s[ConsoleObject->segnum].s2_flags & S2F_AMBIENT_WATER);
2561 if (has_lava) { //has lava
2562 sound = SOUND_AMBIENT_LAVA;
2563 if (has_water && (d_rand() & 1)) //both, pick one
2564 sound = SOUND_AMBIENT_WATER;
2566 else if (has_water) //just water
2567 sound = SOUND_AMBIENT_WATER;
2571 if (((d_rand() << 3) < FrameTime)) { //play the sound
2572 fix volume = d_rand() + f1_0/2;
2573 digi_play_sample(sound,volume);
2577 // -- extern void lightning_frame(void);
2579 void game_render_frame();
2580 extern void omega_charge_frame(void);
2582 extern time_t t_current_time, t_saved_time;
2584 void flicker_lights();
2586 void GameLoop(int RenderFlag, int ReadControlsFlag )
2590 // Used to slow down frame rate for testing things.
2591 // RenderFlag = 1; // DEBUG
2592 if (Debug_slowdown) {
2595 for (h=0; h<Debug_slowdown; h++)
2596 for (i=0; i<1000; i++)
2603 static int desc_dead_countdown=100; /* used if player shouldn't be playing */
2605 if (desc_id_exit_num) { // are we supposed to be checking
2606 if (!(--desc_dead_countdown)) {// if so, at zero, then pull the plug
2607 char time_str[32], time_str2[32];
2609 _ctime(&t_saved_time, time_str);
2610 _ctime(&t_current_time, time_str2);
2612 Error ("EXPIRES %s. YOUR TIME %s.\n", time_str, time_str2);
2613 Error ("Loading overlay -- error number: %d\n", (int)desc_id_exit_num);
2620 if (FindArg("-invulnerability"))
2621 Players[Player_num].flags |= PLAYER_FLAGS_INVULNERABLE;
2625 update_player_stats();
2626 diminish_palette_towards_normal(); // Should leave palette effect up for as long as possible by putting right before render.
2627 do_afterburner_stuff();
2629 do_invulnerable_stuff();
2630 remove_obsolete_stuck_objects();
2632 do_final_boss_frame();
2633 // -- lightning_frame();
2634 // -- recharge_energy_frame();
2636 if ((Players[Player_num].flags & PLAYER_FLAGS_HEADLIGHT) && (Players[Player_num].flags & PLAYER_FLAGS_HEADLIGHT_ON)) {
2637 static int turned_off=0;
2638 Players[Player_num].energy -= (FrameTime*3/8);
2639 if (Players[Player_num].energy < i2f(10)) {
2641 Players[Player_num].flags &= ~PLAYER_FLAGS_HEADLIGHT_ON;
2644 if (Game_mode & GM_MULTI)
2645 multi_send_flags(Player_num);
2652 if (Players[Player_num].energy <= 0) {
2653 Players[Player_num].energy = 0;
2654 Players[Player_num].flags &= ~PLAYER_FLAGS_HEADLIGHT_ON;
2656 if (Game_mode & GM_MULTI)
2657 multi_send_flags(Player_num);
2664 check_create_player_path();
2665 player_follow_path(ConsoleObject);
2669 if (Game_mode & GM_MULTI)
2672 if (Netgame.PlayTimeAllowed && ThisLevelTime>=i2f((Netgame.PlayTimeAllowed*5*60)))
2673 multi_check_for_killgoal_winner();
2679 if (force_cockpit_redraw) { //screen need redrawing?
2681 force_cockpit_redraw=0;
2683 game_render_frame();
2684 //show_extra_views(); //missile view, buddy bot, etc.
2687 if (Saving_movie_frames)
2694 //mprintf(0,"Velocity %2.2f\n", f2fl(vm_vec_mag(&ConsoleObject->phys_info.velocity)));
2698 dead_player_frame();
2699 if (Newdemo_state != ND_STATE_PLAYBACK)
2700 do_controlcen_dead_frame();
2702 process_super_mines_frame();
2704 do_ambient_sounds();
2711 if (ReadControlsFlag)
2714 memset(&Controls, 0, sizeof(Controls));
2716 GameTime += FrameTime;
2718 if (f2i(GameTime)/10 != f2i(GameTime-FrameTime)/10)
2719 mprintf((0,"Gametime = %d secs\n",f2i(GameTime)));
2721 if (GameTime < 0 || GameTime > i2f(0x7fff - 600)) {
2722 GameTime = FrameTime; //wrap when goes negative, or gets within 10 minutes
2723 mprintf((0,"GameTime reset to 0\n"));
2727 if (FindArg("-checktime") != 0)
2728 if (GameTime >= i2f(600)) //wrap after 10 minutes
2729 GameTime = FrameTime;
2733 if ((Game_mode & GM_MULTI) && Netgame.PlayTimeAllowed)
2734 ThisLevelTime +=FrameTime;
2739 if (Endlevel_sequence) {
2740 do_endlevel_frame();
2741 powerup_grab_cheat_all();
2742 do_special_effects();
2743 return; //skip everything else
2746 if (Newdemo_state != ND_STATE_PLAYBACK)
2747 do_exploding_wall_frame();
2748 if ((Newdemo_state != ND_STATE_PLAYBACK) || (Newdemo_vcr_state != ND_STATE_PAUSED)) {
2749 do_special_effects();
2750 wall_frame_process();
2751 triggers_frame_process();
2755 if (Control_center_destroyed) {
2756 if (Newdemo_state==ND_STATE_RECORDING )
2757 newdemo_record_control_center_destroyed();
2762 if ( Newdemo_state == ND_STATE_PLAYBACK ) {
2763 newdemo_playback_one_frame();
2764 if ( Newdemo_state != ND_STATE_PLAYBACK ) {
2765 longjmp( LeaveGame, 0 ); // Go back to menu
2768 { // Note the link to above!
2770 Players[Player_num].homing_object_dist = -1; // Assume not being tracked. Laser_do_weapon_sequence modifies this.
2773 powerup_grab_cheat_all();
2775 if (Endlevel_sequence) //might have been started during move
2778 fuelcen_update_all();
2782 if (allowed_to_fire_laser())
2783 FireLaser(); // Fire Laser!
2785 if (Auto_fire_fusion_cannon_time) {
2786 if (Primary_weapon != FUSION_INDEX)
2787 Auto_fire_fusion_cannon_time = 0;
2788 else if (GameTime + FrameTime/2 >= Auto_fire_fusion_cannon_time) {
2789 Auto_fire_fusion_cannon_time = 0;
2790 Global_laser_firing_count = 1;
2792 vms_vector rand_vec;
2795 Global_laser_firing_count = 0;
2797 ConsoleObject->mtype.phys_info.rotvel.x += (d_rand() - 16384)/8;
2798 ConsoleObject->mtype.phys_info.rotvel.z += (d_rand() - 16384)/8;
2799 make_random_vector(&rand_vec);
2801 bump_amount = F1_0*4;
2803 if (Fusion_charge > F1_0*2)
2804 bump_amount = Fusion_charge*4;
2806 bump_one_object(ConsoleObject, &rand_vec, bump_amount);
2810 if (Global_laser_firing_count) {
2811 // Don't cap here, gets capped in Laser_create_new and is based on whether in multiplayer mode, MK, 3/27/95
2812 // if (Fusion_charge > F1_0*2)
2813 // Fusion_charge = F1_0*2;
2814 Global_laser_firing_count -= do_laser_firing_player(); //do_laser_firing(Players[Player_num].objnum, Primary_weapon);
2817 if (Global_laser_firing_count < 0)
2818 Global_laser_firing_count = 0;
2821 if (Do_appearance_effect) {
2822 create_player_appearance_effect(ConsoleObject);
2823 Do_appearance_effect = 0;
2825 if ((Game_mode & GM_MULTI) && Netgame.invul)
2827 Players[Player_num].flags |= PLAYER_FLAGS_INVULNERABLE;
2828 Players[Player_num].invulnerable_time = GameTime-i2f(27);
2835 omega_charge_frame();
2839 //!!hoard_light_pulse(); //do cool hoard light pulsing
2843 //!!extern int Goal_blue_segnum,Goal_red_segnum;
2844 //!!extern int Hoard_goal_eclip;
2846 //!!//do cool pulsing lights in hoard goals
2847 //!!hoard_light_pulse()
2849 //!! if (Game_mode & GM_HOARD) {
2853 //!! frame = Effects[Hoard_goal_eclip].frame_count;
2857 //!! if (frame >= Effects[Hoard_goal_eclip].vc.num_frames)
2860 //!! light = abs(frame - 5) * f1_0 / 5;
2862 //!! Segment2s[Goal_red_segnum].static_light = Segment2s[Goal_blue_segnum].static_light = light;
2867 ubyte Slide_segs[MAX_SEGMENTS];
2868 int Slide_segs_computed;
2870 void compute_slide_segs(void)
2872 int segnum, sidenum;
2874 for (segnum=0;segnum<=Highest_segment_index;segnum++) {
2875 Slide_segs[segnum] = 0;
2876 for (sidenum=0;sidenum<6;sidenum++) {
2877 int tmn = Segments[segnum].sides[sidenum].tmap_num;
2878 if (TmapInfo[tmn].slide_u != 0 || TmapInfo[tmn].slide_v != 0)
2879 Slide_segs[segnum] |= 1 << sidenum;
2883 Slide_segs_computed = 1;
2886 // -----------------------------------------------------------------------------
2887 void slide_textures(void)
2889 int segnum,sidenum,i;
2891 if (!Slide_segs_computed)
2892 compute_slide_segs();
2894 for (segnum=0;segnum<=Highest_segment_index;segnum++) {
2895 if (Slide_segs[segnum]) {
2896 for (sidenum=0;sidenum<6;sidenum++) {
2897 if (Slide_segs[segnum] & (1 << sidenum)) {
2898 int tmn = Segments[segnum].sides[sidenum].tmap_num;
2899 if (TmapInfo[tmn].slide_u != 0 || TmapInfo[tmn].slide_v != 0) {
2901 Segments[segnum].sides[sidenum].uvls[i].u += fixmul(FrameTime,TmapInfo[tmn].slide_u<<8);
2902 Segments[segnum].sides[sidenum].uvls[i].v += fixmul(FrameTime,TmapInfo[tmn].slide_v<<8);
2903 if (Segments[segnum].sides[sidenum].uvls[i].u > f2_0) {
2906 Segments[segnum].sides[sidenum].uvls[j].u -= f1_0;
2908 if (Segments[segnum].sides[sidenum].uvls[i].v > f2_0) {
2911 Segments[segnum].sides[sidenum].uvls[j].v -= f1_0;
2913 if (Segments[segnum].sides[sidenum].uvls[i].u < -f2_0) {
2916 Segments[segnum].sides[sidenum].uvls[j].u += f1_0;
2918 if (Segments[segnum].sides[sidenum].uvls[i].v < -f2_0) {
2921 Segments[segnum].sides[sidenum].uvls[j].v += f1_0;
2931 flickering_light Flickering_lights[MAX_FLICKERING_LIGHTS];
2933 int Num_flickering_lights=0;
2935 void flicker_lights()
2938 flickering_light *f;
2940 f = Flickering_lights;
2942 for (l=0;l<Num_flickering_lights;l++,f++) {
2943 segment *segp = &Segments[f->segnum];
2945 //make sure this is actually a light
2946 if (! (WALL_IS_DOORWAY(segp, f->sidenum) & WID_RENDER_FLAG))
2948 if (! (TmapInfo[segp->sides[f->sidenum].tmap_num].lighting | TmapInfo[segp->sides[f->sidenum].tmap_num2 & 0x3fff].lighting))
2951 if (f->timer == 0x80000000) //disabled
2954 if ((f->timer -= FrameTime) < 0) {
2956 while (f->timer < 0)
2957 f->timer += f->delay;
2959 f->mask = ((f->mask&0x80000000)?1:0) + (f->mask<<1);
2962 add_light(f->segnum,f->sidenum);
2964 subtract_light(f->segnum,f->sidenum);
2969 //returns ptr to flickering light structure, or NULL if can't find
2970 flickering_light *find_flicker(int segnum,int sidenum)
2973 flickering_light *f;
2975 //see if there's already an entry for this seg/side
2977 f = Flickering_lights;
2979 for (l=0;l<Num_flickering_lights;l++,f++)
2980 if (f->segnum == segnum && f->sidenum == sidenum) //found it!
2986 //turn flickering off (because light has been turned off)
2987 void disable_flicker(int segnum,int sidenum)
2989 flickering_light *f;
2991 if ((f=find_flicker(segnum,sidenum)) != NULL)
2992 f->timer = 0x80000000;
2995 //turn flickering off (because light has been turned on)
2996 void enable_flicker(int segnum,int sidenum)
2998 flickering_light *f;
3000 if ((f=find_flicker(segnum,sidenum)) != NULL)
3007 //returns 1 if ok, 0 if error
3008 int add_flicker(int segnum,int sidenum,fix delay,ulong mask)
3011 flickering_light *f;
3013 mprintf((0,"add_flicker: %d:%d %x %x\n",segnum,sidenum,delay,mask));
3015 //see if there's already an entry for this seg/side
3017 f = Flickering_lights;
3019 for (l=0;l<Num_flickering_lights;l++,f++)
3020 if (f->segnum == segnum && f->sidenum == sidenum) //found it!
3023 if (mask==0) { //clearing entry
3024 if (l == Num_flickering_lights)
3028 for (i=l;i<Num_flickering_lights-1;i++)
3029 Flickering_lights[i] = Flickering_lights[i+1];
3030 Num_flickering_lights--;
3035 if (l == Num_flickering_lights) {
3036 if (Num_flickering_lights == MAX_FLICKERING_LIGHTS)
3039 Num_flickering_lights++;
3043 f->sidenum = sidenum;
3044 f->delay = f->timer = delay;
3052 // -----------------------------------------------------------------------------
3053 // Fire Laser: Registers a laser fire, and performs special stuff for the fusion
3058 Global_laser_firing_count += Weapon_info[Primary_weapon_to_weapon_info[Primary_weapon]].fire_count * (Controls.fire_primary_state || Controls.fire_primary_down_count);
3060 if ((Primary_weapon == FUSION_INDEX) && (Global_laser_firing_count)) {
3061 if ((Players[Player_num].energy < F1_0*2) && (Auto_fire_fusion_cannon_time == 0)) {
3062 Global_laser_firing_count = 0;
3064 if (Fusion_charge == 0)
3065 Players[Player_num].energy -= F1_0*2;
3067 Fusion_charge += FrameTime;
3068 Players[Player_num].energy -= FrameTime;
3070 if (Players[Player_num].energy <= 0) {
3071 Players[Player_num].energy = 0;
3072 Auto_fire_fusion_cannon_time = GameTime -1; // Fire now!
3074 Auto_fire_fusion_cannon_time = GameTime + FrameTime/2 + 1;
3075 // Fire the fusion cannon at this time in the future.
3077 if (Fusion_charge < F1_0*2)
3078 PALETTE_FLASH_ADD(Fusion_charge >> 11, 0, Fusion_charge >> 11);
3080 PALETTE_FLASH_ADD(Fusion_charge >> 11, Fusion_charge >> 11, 0);
3082 if (GameTime < Fusion_last_sound_time) //gametime has wrapped
3083 Fusion_next_sound_time = Fusion_last_sound_time = GameTime;
3085 if (Fusion_next_sound_time < GameTime) {
3086 if (Fusion_charge > F1_0*2) {
3087 digi_play_sample( 11, F1_0 );
3088 apply_damage_to_player(ConsoleObject, ConsoleObject, d_rand() * 4);
3090 create_awareness_event(ConsoleObject, PA_WEAPON_ROBOT_COLLISION);
3091 digi_play_sample( SOUND_FUSION_WARMUP, F1_0 );
3093 if (Game_mode & GM_MULTI)
3094 multi_send_play_sound(SOUND_FUSION_WARMUP, F1_0);
3097 Fusion_last_sound_time = GameTime;
3098 Fusion_next_sound_time = GameTime + F1_0/8 + d_rand()/4;
3106 // -------------------------------------------------------------------------------------------------------
3107 // If player is close enough to objnum, which ought to be a powerup, pick it up!
3108 // This could easily be made difficulty level dependent.
3109 void powerup_grab_cheat(object *player, int objnum)
3115 Assert(Objects[objnum].type == OBJ_POWERUP);
3117 powerup_size = Objects[objnum].size;
3118 player_size = player->size;
3120 dist = vm_vec_dist_quick(&Objects[objnum].pos, &player->pos);
3122 if ((dist < 2*(powerup_size + player_size)) && !(Objects[objnum].flags & OF_SHOULD_BE_DEAD)) {
3123 vms_vector collision_point;
3125 vm_vec_avg(&collision_point, &Objects[objnum].pos, &player->pos);
3126 collide_player_and_powerup(player, &Objects[objnum], &collision_point);
3130 // -------------------------------------------------------------------------------------------------------
3131 // Make it easier to pick up powerups.
3132 // For all powerups in this segment, pick them up at up to twice pickuppable distance based on dot product
3133 // from player to powerup and player's forward vector.
3134 // This has the effect of picking them up more easily left/right and up/down, but not making them disappear
3135 // way before the player gets there.
3136 void powerup_grab_cheat_all(void)
3141 segp = &Segments[ConsoleObject->segnum];
3142 objnum = segp->objects;
3144 while (objnum != -1) {
3145 if (Objects[objnum].type == OBJ_POWERUP)
3146 powerup_grab_cheat(ConsoleObject, objnum);
3147 objnum = Objects[objnum].next;
3152 int Last_level_path_created = -1;
3154 #ifdef SHOW_EXIT_PATH
3156 // ------------------------------------------------------------------------------------------------------------------
3157 // Create path for player from current segment to goal segment.
3158 // Return true if path created, else return false.
3159 int mark_player_path_to_segment(int segnum)
3162 object *objp = ConsoleObject;
3163 short player_path_length=0;
3164 int player_hide_index=-1;
3166 if (Last_level_path_created == Current_level_num) {
3170 Last_level_path_created = Current_level_num;
3172 if (create_path_points(objp, objp->segnum, segnum, Point_segs_free_ptr, &player_path_length, 100, 0, 0, -1) == -1) {
3173 mprintf((0, "Unable to form path of length %i for myself\n", 100));
3177 player_hide_index = Point_segs_free_ptr - Point_segs;
3178 Point_segs_free_ptr += player_path_length;
3180 if (Point_segs_free_ptr - Point_segs + MAX_PATH_LENGTH*2 > MAX_POINT_SEGS) {
3181 mprintf((1, "Can't create path. Not enough point_segs.\n"));
3182 ai_reset_all_paths();
3186 for (i=1; i<player_path_length; i++) {
3188 vms_vector seg_center;
3191 segnum = Point_segs[player_hide_index+i].segnum;
3192 mprintf((0, "%3i ", segnum));
3193 seg_center = Point_segs[player_hide_index+i].point;
3195 objnum = obj_create( OBJ_POWERUP, POW_ENERGY, segnum, &seg_center, &vmd_identity_matrix, Powerup_info[POW_ENERGY].size, CT_POWERUP, MT_NONE, RT_POWERUP);
3197 Int3(); // Unable to drop energy powerup for path
3201 obj = &Objects[objnum];
3202 obj->rtype.vclip_info.vclip_num = Powerup_info[obj->id].vclip_num;
3203 obj->rtype.vclip_info.frametime = Vclip[obj->rtype.vclip_info.vclip_num].frame_time;
3204 obj->rtype.vclip_info.framenum = 0;
3205 obj->lifeleft = F1_0*100 + d_rand() * 4;
3212 // Return true if it happened, else return false.
3213 int create_special_path(void)
3217 // ---------- Find exit doors ----------
3218 for (i=0; i<=Highest_segment_index; i++)
3219 for (j=0; j<MAX_SIDES_PER_SEGMENT; j++)
3220 if (Segments[i].children[j] == -2) {
3221 mprintf((0, "Exit at segment %i\n", i));
3222 return mark_player_path_to_segment(i);
3232 int Max_obj_count_mike = 0;
3234 // Shows current number of used objects.
3235 void show_free_objects(void)
3237 if (!(FrameCount & 8)) {
3241 mprintf((0, "Highest_object_index = %3i, MAX_OBJECTS = %3i, now used = ", Highest_object_index, MAX_OBJECTS));
3243 for (i=0; i<=Highest_object_index; i++)
3244 if (Objects[i].type != OBJ_NONE)
3247 mprintf((0, "%3i", count));
3249 if (count > Max_obj_count_mike) {
3250 Max_obj_count_mike = count;
3251 mprintf((0, " ***"));
3262 void game_win_init_cockpit_mask(int sram)
3264 if (dd_VR_offscreen_buffer && dd_VR_offscreen_buffer != dd_grd_backcanv) {
3265 dd_gr_free_canvas(dd_VR_offscreen_buffer);
3268 if (GRMODEINFO(paged) && !GRMODEINFO(dbuf)) {
3269 // Here we will make the VR_offscreen_buffer the 2nd page and hopefully
3270 // we can just flip it, saving a blt.
3273 else if (GRMODEINFO(dbuf)||GRMODEINFO(emul)) {
3274 // The offscreen buffer will be created. We will just blt this
3275 // to the screen (which may be blted to the primary surface)
3276 if ( grd_curscreen->sc_h < 200 ) {
3277 dd_VR_offscreen_buffer = dd_gr_create_canvas(grd_curscreen->sc_w, 200);
3278 VR_offscreen_buffer = &dd_VR_offscreen_buffer->canvas;
3280 DDFreeSurface(dd_VR_offscreen_buffer->lpdds);
3281 dd_VR_offscreen_buffer->lpdds = DDCreateSysMemSurface(grd_curscreen->sc_w, 200);
3282 dd_VR_offscreen_buffer->sram = 1;
3286 dd_VR_offscreen_buffer = dd_gr_create_canvas(grd_curscreen->sc_w, grd_curscreen->sc_h);
3287 VR_offscreen_buffer = &dd_VR_offscreen_buffer->canvas;
3289 DDFreeSurface(dd_VR_offscreen_buffer->lpdds);
3290 dd_VR_offscreen_buffer->lpdds = DDCreateSysMemSurface(grd_curscreen->sc_w, grd_curscreen->sc_h);
3291 dd_VR_offscreen_buffer->sram = 1;
3296 dd_gr_init_sub_canvas( &dd_VR_render_buffer[0], dd_VR_offscreen_buffer, 0, 0, grd_curscreen->sc_w, grd_curscreen->sc_h );
3297 dd_gr_init_sub_canvas( &dd_VR_render_buffer[1], dd_VR_offscreen_buffer, 0, 0, grd_curscreen->sc_w, grd_curscreen->sc_h );
3298 gr_init_sub_canvas( &VR_render_buffer[0], VR_offscreen_buffer, 0, 0, grd_curscreen->sc_w, grd_curscreen->sc_h );
3299 gr_init_sub_canvas( &VR_render_buffer[1], VR_offscreen_buffer, 0, 0, grd_curscreen->sc_w, grd_curscreen->sc_h );
3301 game_init_render_sub_buffers( 0, 0, grd_curscreen->sc_w, grd_curscreen->sc_h );
3304 //@@void game_win_init_cockpit_mask()
3306 //@@ char title_pal[768];
3307 //@@ dd_grs_canvas ccanv;
3309 //@@ LPDIRECTDRAWSURFACE dds;
3311 //@@ dds = DDCreateSurface(GRMODEINFO(w), GRMODEINFO(h), 1);
3312 //@@ Assert(dds != NULL);
3314 //@@ _lpDDSMask = dds;
3315 //@@ ccanv.lpdds = dds;
3316 //@@ dd_gr_reinit_canvas(&ccanv);
3318 //@@ dd_gr_set_current_canvas(&ccanv);
3319 //@@ DDGRLOCK(dd_grd_curcanv)
3321 //@@ if (W95DisplayMode == SM95_640x480x8) {
3322 //@@ pcx_error=pcx_read_bitmap( "MASKB.PCX", &grd_curcanv->cv_bitmap,
3323 //@@ grd_curcanv->cv_bitmap.bm_type,
3327 //@@ pcx_error=pcx_read_bitmap( "MASK.PCX", &grd_curcanv->cv_bitmap,
3328 //@@ grd_curcanv->cv_bitmap.bm_type,
3332 //@@ DDGRUNLOCK(dd_grd_curcanv);
3334 //@@ Assert(pcx_error == PCX_ERROR_NONE);
3335 //@@ Game_cockpit_copy_code = (ubyte *)(0xABADC0DE);