2 THE COMPUTER CODE CONTAINED HEREIN IS THE SOLE PROPERTY OF PARALLAX
3 SOFTWARE CORPORATION ("PARALLAX"). PARALLAX, IN DISTRIBUTING THE CODE TO
4 END-USERS, AND SUBJECT TO ALL OF THE TERMS AND CONDITIONS HEREIN, GRANTS A
5 ROYALTY-FREE, PERPETUAL LICENSE TO SUCH END-USERS FOR USE BY SUCH END-USERS
6 IN USING, DISPLAYING, AND CREATING DERIVATIVE WORKS THEREOF, SO LONG AS
7 SUCH USE, DISPLAY OR CREATION IS FOR NON-COMMERCIAL, ROYALTY OR REVENUE
8 FREE PURPOSES. IN NO EVENT SHALL THE END-USER USE THE COMPUTER CODE
9 CONTAINED HEREIN FOR REVENUE-BEARING PURPOSES. THE END-USER UNDERSTANDS
10 AND AGREES TO THE TERMS HEREIN AND ACCEPTS THE SAME BY USE OF THIS FILE.
11 COPYRIGHT 1993-1999 PARALLAX SOFTWARE CORPORATION. ALL RIGHTS RESERVED.
15 char game_rcsid[] = "$Id: game.c,v 1.2 2001-01-20 13:49:14 bradleyb Exp $";
32 #include <StandardFile.h>
33 #include <Quickdraw.h>
40 #include "pa_enabl.h" //$$POLY_ACC
101 #include "cntrlcen.h"
105 #include "multibot.h"
108 #include "playsave.h"
111 int VGA_current_mode;
114 #include <profiler.h>
117 //#define TEST_TIMER 1 //if this is set, do checking on timer
119 #define SHOW_EXIT_PATH 1
122 #include "editor\editor.h"
127 #if __WATCOMC__ < 1000
128 #include <wsample.h> //should come after inferno.h to get mark setting
133 extern void ReadControls(void); // located in gamecntl.c
134 extern int Current_display_mode;
135 extern void do_final_boss_frame(void);
137 int Speedtest_on = 0;
140 int Mark_count = 0; // number of debugging marks set
141 int Speedtest_start_time;
142 int Speedtest_segnum;
143 int Speedtest_sidenum;
144 int Speedtest_frame_start;
145 int Speedtest_count=0; // number of times to do the debug test.
148 static fix last_timer_value=0;
151 #if defined(TIMER_TEST) && !defined(NDEBUG)
152 fix _timer_value,actual_last_timer_value,_last_frametime;
153 int stop_count,start_count;
154 int time_stopped,time_started;
158 ubyte * Game_cockpit_copy_code = NULL;
160 ubyte Game_cockpit_copy_code = 0;
161 ubyte Scanline_double = 1;
164 int VR_screen_mode = 0;
166 ubyte VR_screen_flags = 0; //see values in screens.h
167 ubyte VR_current_page = 0;
168 fix VR_eye_width = F1_0;
169 int VR_render_mode = VR_NONE;
170 int VR_low_res = 3; // Default to low res
172 int VR_sensitivity = 1; // 0 - 2
175 int VR_eye_offset = 0;
176 int VR_eye_switch = 0;
177 int VR_eye_offset_changed = 0;
178 int VR_use_reg_code = 0;
180 grs_canvas *VR_offscreen_buffer = NULL; // The offscreen data buffer
181 grs_canvas VR_render_buffer[2]; // Two offscreen buffers for left/right eyes.
182 grs_canvas VR_render_sub_buffer[2]; // Two sub buffers for left/right eyes.
183 grs_canvas VR_screen_pages[2]; // Two pages of VRAM if paging is available
184 grs_canvas VR_editor_canvas; // The canvas that the editor writes to.
187 //@@ LPDIRECTDRAWSURFACE _lpDDSMask = NULL;
188 dd_grs_canvas *dd_VR_offscreen_buffer = NULL;
189 dd_grs_canvas dd_VR_screen_pages[2];
190 dd_grs_canvas dd_VR_render_buffer[2];
191 dd_grs_canvas dd_VR_render_sub_buffer[2];
193 void game_win_init_cockpit_mask(int sram);
196 //do menus work in 640x480 or 320x200?
197 //PC version sets this in main(). Mac versios is always high-res, so set to 1 here
198 int MenuHiresAvailable = 1; //can we do highres menus?
199 int MenuHires = 1; //are we currently in highres menus?
201 int Debug_pause=0; //John's debugging pause system
203 int Cockpit_mode=CM_FULL_COCKPIT; //set game.h for values
205 int Cockpit_mode_save=-1; //set while in letterbox or rear view, or -1
206 int force_cockpit_redraw=0;
208 cvar_t r_framerate = {"r_framerate","0"};
210 int PaletteRedAdd, PaletteGreenAdd, PaletteBlueAdd;
212 // Toggle_var points at a variable which gets !ed on ctrl-alt-T press.
214 int *Toggle_var = &Dummy_var;
217 //flag for whether initial fade-in has been done
221 #ifndef NDEBUG //these only exist if debugging
223 int Game_double_buffer = 1; //double buffer by default
224 fix fixed_frametime=0; //if non-zero, set frametime to this
228 int Game_suspended=0; //if non-zero, nothing moves but player
231 fix Auto_fire_fusion_cannon_time = 0;
232 fix Fusion_charge = 0;
233 fix Fusion_next_sound_time = 0;
234 fix Fusion_last_sound_time = 0;
237 int Game_turbo_mode = 0;
239 int Game_mode = GM_GAME_OVER;
241 int Global_laser_firing_count = 0;
242 int Global_missile_firing_count = 0;
244 grs_bitmap background_bitmap;
248 #define BACKGROUND_NAME "statback.pcx"
250 // Function prototypes for GAME.C exclusively.
252 void GameLoop(int RenderFlag, int ReadControlsFlag);
253 void FireLaser(void);
254 void slide_textures(void);
255 void powerup_grab_cheat_all(void);
258 extern void multi_check_for_killgoal_winner();
259 extern void RestoreGameSurfaces();
263 void grow_window(void);
264 void shrink_window(void);
268 void fill_background();
271 void show_framerate(void);
272 void ftoa(char *string, fix f);
275 extern ubyte DefiningMarkerMessage;
276 extern char Marker_input[];
278 // ==============================================================================================
280 extern char john_head_on;
282 void load_background_bitmap()
287 if (background_bitmap.bm_data)
288 d_free(background_bitmap.bm_data);
290 background_bitmap.bm_data=NULL;
291 pcx_error = pcx_read_bitmap(john_head_on?"johnhead.pcx":BACKGROUND_NAME,&background_bitmap,BM_LINEAR,pal);
292 if (pcx_error != PCX_ERROR_NONE)
293 Error("File %s - PCX error: %s",BACKGROUND_NAME,pcx_errormsg(pcx_error));
294 gr_remap_bitmap_good( &background_bitmap, pal, -1, -1 );
298 //this is called once per game
301 atexit(close_game); //for cleanup
305 init_special_effects();
309 init_gauge_canvases();
311 init_exploding_walls();
313 load_background_bitmap();
315 Clear_window = 2; // do portal only window clear.
317 set_detail_level_parameters(Detail_level);
319 build_mission_list(0); // This also loads mission 0.
322 cvar_registervariable(&r_framerate);
327 void reset_palette_add()
332 //gr_palette_step_up( PaletteRedAdd, PaletteGreenAdd, PaletteBlueAdd );
337 void win_get_span_list(grs_bitmap *bm, int miny, int maxy)
343 int lspan=0, rspan=0, span=0;
347 //@@ fp = fopen("cockspan.dat", "w");
349 for (y = 0; y < miny; y++)
350 win_cockpit_mask[y].num = 0;
352 for (y = miny; y <= maxy; y++)
355 //@@ fprintf(fp, "line %d: ", y);
356 for (x = 0; x < bm->bm_w; x++)
358 offset = y*bm->bm_rowsize + x;
360 if (data[offset] == 255) {
363 case 0: // Start Mode
365 win_cockpit_mask[y].span[span].xmin = x;
367 //@@ fprintf(fp, "<%d,", lspan);
370 case 1: // Transparency mode
372 win_cockpit_mask[y].span[span].xmax = x;
375 case 2: // Switch from Draw mode to transparent
377 win_cockpit_mask[y].span[span].xmin = x;
378 //@@ fprintf(fp, "<%d,", lspan);
386 case 0: // Start mode
390 case 1: // Switching from transparent to Draw
393 win_cockpit_mask[y].span[span].xmax = x;
395 //@@ fprintf(fp, "%d> ", rspan);
404 //@@ fprintf(fp, "%d> ", rspan);
405 win_cockpit_mask[y].span[span].xmax = rspan;
408 win_cockpit_mask[y].num = span;
409 //@@ fprintf(fp, "\n");
412 win_cockpit_mask[y].num = 255;
417 void game_show_warning(char *s)
420 if (!((Game_mode & GM_MULTI) && (Function_mode == FMODE_GAME)))
423 nm_messagebox( TXT_WARNING, 1, TXT_OK, s );
425 if (!((Game_mode & GM_MULTI) && (Function_mode == FMODE_GAME)))
430 //these should be in gr.h
431 #define cv_w cv_bitmap.bm_w
432 #define cv_h cv_bitmap.bm_h
434 int Game_window_x = 0;
435 int Game_window_y = 0;
436 int Game_window_w = 0;
437 int Game_window_h = 0;
438 int max_window_w = 0;
439 int max_window_h = 0;
441 extern void newdemo_record_cockpit_change(int);
443 //initialize the various canvases on the game screen
444 //called every time the screen mode or cockpit changes
447 int minx, maxx, miny, maxy;
449 #if defined(POLY_ACC)
450 pa_flush(); // get rid of undrawn polys.
451 pa_clear_buffer(1, 0);
454 //Initialize the on-screen canvases
456 if (Newdemo_state==ND_STATE_RECORDING)
459 newdemo_record_cockpit_change(Cockpit_mode);
462 if ( VR_render_mode != VR_NONE )
463 Cockpit_mode = CM_FULL_SCREEN;
465 if (!(VR_screen_flags & VRF_ALLOW_COCKPIT) && (Cockpit_mode==CM_FULL_COCKPIT || Cockpit_mode==CM_STATUS_BAR || Cockpit_mode==CM_REAR_VIEW) )
466 Cockpit_mode = CM_FULL_SCREEN;
468 if ( Screen_mode == SCREEN_EDITOR )
469 Cockpit_mode = CM_FULL_SCREEN;
472 dd_gr_set_current_canvas(NULL),
473 gr_set_current_canvas(NULL)
475 gr_set_curfont( GAME_FONT );
477 #if !defined(MACINTOSH) && !defined(WINDOWS)
478 if (Game_cockpit_copy_code)
479 d_free(Game_cockpit_copy_code);
480 Game_cockpit_copy_code = NULL;
482 if (Game_cockpit_copy_code)
483 Game_cockpit_copy_code = 0;
487 //@@ if (_lpDDSMask) { DDFreeSurface(_lpDDSMask); _lpDDSMask = NULL; }
491 game_win_init_cockpit_mask(0);
494 switch( Cockpit_mode )
496 case CM_FULL_COCKPIT:
498 grs_bitmap *bm = &GameBitmaps[cockpit_bitmap[Cockpit_mode+(Current_display_mode?(Num_cockpits/2):0)].index];
500 PIGGY_PAGE_IN(cockpit_bitmap[Cockpit_mode+(Current_display_mode?(Num_cockpits/2):0)]);
503 dd_gr_set_current_canvas(NULL);
504 game_win_init_cockpit_mask(1);
505 dd_gr_set_current_canvas(dd_VR_offscreen_buffer);
507 gr_set_current_canvas(VR_offscreen_buffer)
510 WIN(DDGRLOCK(dd_grd_curcanv));
511 gr_bitmap( 0, 0, bm );
512 bm = &VR_offscreen_buffer->cv_bitmap;
513 bm->bm_flags = BM_FLAG_TRANSPARENT;
514 gr_ibitblt_find_hole_size ( bm, &minx, &miny, &maxx, &maxy );
515 WIN( win_get_span_list(bm, miny, maxy);
516 DDGRUNLOCK(dd_grd_curcanv)
520 #if 1 // def MACINTOSH
521 gr_ibitblt_create_mask( bm, minx, miny, maxx-minx+1, maxy-miny+1, VR_offscreen_buffer->cv_bitmap.bm_rowsize);
523 if ( Current_display_mode )
525 #if defined(POLY_ACC)
526 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 );
527 pa_clear_buffer(1, 0); // clear offscreen to reduce white flash.
529 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 );
532 Game_cockpit_copy_code = gr_ibitblt_create_mask( bm, minx, miny, maxx-minx+1, maxy-miny+1, VR_offscreen_buffer->cv_bitmap.bm_rowsize );
534 bm->bm_flags = 0; // Clear all flags for offscreen canvas
536 Game_cockpit_copy_code = (ubyte *)(1);
537 bm->bm_flags = 0; // Clear all flags for offscreen canvas
539 game_init_render_sub_buffers( 0, 0, maxx-minx+1, maxy-miny+1 );
545 max_window_h = grd_curscreen->sc_h;
547 if (Game_window_h > max_window_h || VR_screen_flags&VRF_ALLOW_COCKPIT)
548 Game_window_h = max_window_h;
550 if (Game_window_w > max_window_w || VR_screen_flags&VRF_ALLOW_COCKPIT)
551 Game_window_w = max_window_w;
553 Game_window_x = (max_window_w - Game_window_w)/2;
554 Game_window_y = (max_window_h - Game_window_h)/2;
556 game_init_render_sub_buffers( Game_window_x, Game_window_y, Game_window_w, Game_window_h );
561 max_window_h = grd_curscreen->sc_h - GameBitmaps[cockpit_bitmap[CM_STATUS_BAR+(Current_display_mode?(Num_cockpits/2):0)].index].bm_h;
563 if (Game_window_h > max_window_h)
564 Game_window_h = max_window_h;
566 if (Game_window_w > max_window_w)
567 Game_window_w = max_window_w;
569 Game_window_x = (max_window_w - Game_window_w)/2;
570 Game_window_y = (max_window_h - Game_window_h)/2;
572 game_init_render_sub_buffers( Game_window_x, Game_window_y, Game_window_w, Game_window_h );
578 x = 0; w = VR_render_buffer[0].cv_bitmap.bm_w; //VR_render_width;
579 h = (VR_render_buffer[0].cv_bitmap.bm_h * 7) / 10;
580 y = (VR_render_buffer[0].cv_bitmap.bm_h-h)/2;
582 game_init_render_sub_buffers( x, y, w, h );
589 dd_gr_set_current_canvas(NULL),
590 gr_set_current_canvas(NULL)
594 //selects a given cockpit (or lack of one). See types in game.h
595 void select_cockpit(int mode)
597 if (mode != Cockpit_mode) { //new mode
603 extern int last_drawn_cockpit[2];
605 //force cockpit redraw next time. call this if you've trashed the screen
608 force_cockpit_redraw=1;
609 last_drawn_cockpit[0] = -1;
610 last_drawn_cockpit[1] = -1;
613 // void HUD_clear_messages(); //Already declared in gauges.h
616 void VR_reset_params()
618 VR_eye_width = VR_SEPARATION;
619 VR_eye_offset = VR_PIXEL_SHIFT;
620 VR_eye_offset_changed = 2;
623 void game_init_render_sub_buffers( int x, int y, int w, int h )
626 dd_gr_init_sub_canvas( &dd_VR_render_sub_buffer[0], &dd_VR_render_buffer[0], x, y, w, h );
627 dd_gr_init_sub_canvas( &dd_VR_render_sub_buffer[1], &dd_VR_render_buffer[1], x, y, w, h );
629 dd_VR_render_sub_buffer[0].canvas.cv_bitmap.bm_x = 0;
630 dd_VR_render_sub_buffer[0].canvas.cv_bitmap.bm_y = 0;
631 dd_VR_render_sub_buffer[0].xoff = x;
632 dd_VR_render_sub_buffer[0].yoff = y;
633 dd_VR_render_sub_buffer[1].canvas.cv_bitmap.bm_x = 0;
634 dd_VR_render_sub_buffer[1].canvas.cv_bitmap.bm_y = 0;
635 dd_VR_render_sub_buffer[1].xoff = x;
636 dd_VR_render_sub_buffer[1].yoff = y;
639 if (Scanline_double) {
643 gr_init_sub_canvas( &VR_render_sub_buffer[0], &VR_render_buffer[0], x, y, w/2, (h/2)+1);
644 gr_init_sub_canvas( &VR_render_sub_buffer[1], &VR_render_buffer[1], x, y, w/2, (h/2)+1);
647 gr_init_sub_canvas( &VR_render_sub_buffer[0], &VR_render_buffer[0], x, y, w, h );
648 gr_init_sub_canvas( &VR_render_sub_buffer[1], &VR_render_buffer[1], x, y, w, h );
658 newBounds.right = x + w;
660 newBounds.bottom = y + h;
662 pa_set_context(kGamePlayDrawContextID, &newBounds); // must resize/create new context
668 VR_render_sub_buffer[0].cv_bitmap.bm_x = 0;
669 VR_render_sub_buffer[0].cv_bitmap.bm_y = 0;
670 VR_render_sub_buffer[1].cv_bitmap.bm_x = 0;
671 VR_render_sub_buffer[1].cv_bitmap.bm_y = 0;
677 // Sets up the canvases we will be rendering to (WIN95)
678 void game_init_render_buffers(int screen_mode, int render_w, int render_h, int render_method, int flags )
680 // Hack for switching to higher that 640x480 modes (DDraw doesn't allow
681 // creating surfaces greater than the current resolution
683 if (GRMODEINFO(rw) < render_w || GRMODEINFO(rh) < render_h) {
684 render_w = GRMODEINFO(rw);
685 render_h = GRMODEINFO(rh);
688 VR_screen_mode = screen_mode;
690 VR_screen_flags = flags;
693 VR_render_mode = render_method;
695 Game_window_w = render_w;
696 Game_window_h = render_h;
698 if (dd_VR_offscreen_buffer && dd_VR_offscreen_buffer != dd_grd_backcanv) {
699 dd_gr_free_canvas(dd_VR_offscreen_buffer);
702 if ( (VR_render_mode==VR_AREA_DET) || (VR_render_mode==VR_INTERLACED ) ) {
703 if ( render_h*2 < 200 ) {
704 Int3(); // Not Supported yet!!!
705 // VR_offscreen_buffer = gr_create_canvas( render_w, 200 );
708 Int3(); // Not Supported yet!!!
709 // VR_offscreen_buffer = gr_create_canvas( render_w, render_h*2 );
712 Int3(); // Not Supported yet!!!
713 // gr_init_sub_canvas( &VR_render_buffer[0], VR_offscreen_buffer, 0, 0, render_w, render_h );
714 // gr_init_sub_canvas( &VR_render_buffer[1], VR_offscreen_buffer, 0, render_h, render_w, render_h );
716 else if (GRMODEINFO(paged) && !GRMODEINFO(dbuf)) {
717 // Here we will make the VR_offscreen_buffer the 2nd page and hopefully
718 // we can just flip it, saving a blt.
720 dd_VR_offscreen_buffer = dd_grd_backcanv;
721 VR_offscreen_buffer = & dd_grd_backcanv->canvas;
723 else if (GRMODEINFO(dbuf)||GRMODEINFO(emul)) {
724 // The offscreen buffer will be created. We will just blt this
725 // to the screen (which may be blted to the primary surface)
726 if ( render_h < 200 ) {
727 dd_VR_offscreen_buffer = dd_gr_create_canvas(render_w, 200);
728 VR_offscreen_buffer = &dd_VR_offscreen_buffer->canvas;
731 dd_VR_offscreen_buffer = dd_gr_create_canvas(render_w, render_h);
732 VR_offscreen_buffer = &dd_VR_offscreen_buffer->canvas;
736 dd_gr_init_sub_canvas( &dd_VR_render_buffer[0], dd_VR_offscreen_buffer, 0, 0, render_w, render_h );
737 dd_gr_init_sub_canvas( &dd_VR_render_buffer[1], dd_VR_offscreen_buffer, 0, 0, render_w, render_h );
738 gr_init_sub_canvas( &VR_render_buffer[0], VR_offscreen_buffer, 0, 0, render_w, render_h );
739 gr_init_sub_canvas( &VR_render_buffer[1], VR_offscreen_buffer, 0, 0, render_w, render_h );
741 game_init_render_sub_buffers( 0, 0, render_w, render_h );
746 // Sets up the canvases we will be rendering to (NORMAL VERSION)
747 void game_init_render_buffers(int screen_mode, int render_w, int render_h, int render_method, int flags )
749 // if (vga_check_mode(screen_mode) != 0)
750 // Error("Cannot set requested video mode");
752 VR_screen_mode = screen_mode;
754 VR_screen_flags = flags;
758 VR_render_mode = render_method;
760 Game_window_w = render_w;
761 Game_window_h = render_h;
763 if (VR_offscreen_buffer) {
764 gr_free_canvas(VR_offscreen_buffer);
767 if ( (VR_render_mode==VR_AREA_DET) || (VR_render_mode==VR_INTERLACED ) ) {
768 if ( render_h*2 < 200 ) {
769 VR_offscreen_buffer = gr_create_canvas( render_w, 200 );
772 VR_offscreen_buffer = gr_create_canvas( render_w, render_h*2 );
775 gr_init_sub_canvas( &VR_render_buffer[0], VR_offscreen_buffer, 0, 0, render_w, render_h );
776 gr_init_sub_canvas( &VR_render_buffer[1], VR_offscreen_buffer, 0, render_h, render_w, render_h );
779 if ( render_h < 200 ) {
780 VR_offscreen_buffer = gr_create_canvas( render_w, 200 );
783 #if defined(POLY_ACC)
785 VR_offscreen_buffer = gr_create_canvas( render_w, render_h );
786 d_free(VR_offscreen_buffer->cv_bitmap.bm_data);
787 gr_init_canvas(VR_offscreen_buffer, pa_get_buffer_address(1), BM_LINEAR15, render_w, render_h);
789 if ( PAEnabled || gConfigInfo.mAcceleration ) {
790 Cockpit_mode=CM_FULL_SCREEN; // HACK HACK HACK HACK HACK!!!!
791 VR_offscreen_buffer = gr_create_canvas2(render_w, render_h, BM_LINEAR15);
793 VR_offscreen_buffer = gr_create_canvas( render_w, render_h );
796 VR_offscreen_buffer = gr_create_canvas( render_w, render_h );
801 VR_offscreen_buffer->cv_bitmap.bm_type = BM_OGL;
804 gr_init_sub_canvas( &VR_render_buffer[0], VR_offscreen_buffer, 0, 0, render_w, render_h );
805 gr_init_sub_canvas( &VR_render_buffer[1], VR_offscreen_buffer, 0, 0, render_w, render_h );
808 game_init_render_sub_buffers( 0, 0, render_w, render_h );
812 //called to get the screen in a mode compatible with popup menus.
813 //if we can't have popups over the game screen, switch to menu mode.
814 void set_popup_screen(void)
816 //WIN(LoadCursorWin(MOUSE_DEFAULT_CURSOR));
818 if (! (VR_screen_flags & VRF_COMPATIBLE_MENUS))
819 set_screen_mode(SCREEN_MENU); //must switch to menu mode
823 //called to change the screen mode. Parameter sm is the new mode, one of
824 //SMODE_GAME or SMODE_EDITOR. returns mode acutally set (could be other
825 //mode if cannot init requested mode)
826 int set_screen_mode(int sm)
828 WIN(static int force_mode_change=0);
829 WIN(static int saved_window_w);
830 WIN(static int saved_window_h);
833 if ( (sm==SCREEN_MENU) && (Screen_mode==SCREEN_EDITOR) ) {
834 gr_set_current_canvas( Canv_editor );
840 if ( Screen_mode == sm && W95DisplayMode == VR_screen_mode) {
841 dd_gr_set_current_canvas( &dd_VR_screen_pages[VR_current_page] );
845 if ( Screen_mode == sm && VGA_current_mode == VR_screen_mode) {
846 gr_set_current_canvas( &VR_screen_pages[VR_current_page] );
852 if ((Screen_mode == sm) && !((sm==SCREEN_GAME) && (grd_curscreen->sc_mode != VR_screen_mode) && (Screen_mode == SCREEN_GAME))) {
854 gr_set_current_canvas( &VR_screen_pages[VR_current_page] );
855 ogl_set_screen_mode();
866 switch( Screen_mode )
872 if (!(VR_screen_flags & VRF_COMPATIBLE_MENUS)) {
873 // HACK!!! Meant to save window size when switching from
874 // non-compat menu mode to menu mode.
875 saved_window_w = Game_window_w;
876 saved_window_h = Game_window_h;
877 force_mode_change = 1;
879 if (W95DisplayMode != SM95_640x480x8) {
880 //@@ piggy_bitmap_page_out_all_w(); // 2D GFX Flush cache.
881 DDSETDISPLAYMODE(SM95_640x480x8);
883 if (!gr_palette_faded_out) gr_palette_load(gr_palette);
886 dd_gr_init_sub_canvas(&dd_VR_screen_pages[0], dd_grd_screencanv,
888 dd_grd_screencanv->canvas.cv_bitmap.bm_w,
889 dd_grd_screencanv->canvas.cv_bitmap.bm_h);
890 dd_gr_init_sub_canvas(&dd_VR_screen_pages[1], dd_grd_screencanv,
892 dd_grd_screencanv->canvas.cv_bitmap.bm_w,
893 dd_grd_screencanv->canvas.cv_bitmap.bm_h);
901 MenuHires = MenuHiresAvailable; //do highres if we can
903 #if defined(POLY_ACC)
905 menu_mode = MenuHires?SM(640,480):SM(320,200);
907 menu_mode = PAEnabled?SM_640x480x15xPA:SM_640x480V;
910 menu_mode = MenuHires?SM(640,480):SM(320,200);
913 if (VGA_current_mode != menu_mode) {
914 if (gr_set_mode(menu_mode))
915 Error("Cannot set screen mode for menu");
916 if (!gr_palette_faded_out)
917 gr_palette_load(gr_palette);
920 gr_init_sub_canvas( &VR_screen_pages[0], &grd_curscreen->sc_canvas, 0, 0, grd_curscreen->sc_w, grd_curscreen->sc_h );
921 gr_init_sub_canvas( &VR_screen_pages[1], &grd_curscreen->sc_canvas, 0, 0, grd_curscreen->sc_w, grd_curscreen->sc_h );
923 FontHires = MenuHires;
933 if (force_mode_change || (W95DisplayMode != VR_screen_mode)) {
935 DDSETDISPLAYMODE(VR_screen_mode);
936 //@@ piggy_bitmap_page_out_all_w(); // 2D GFX Flush cache.
938 mprintf((0, "Reinitializing render buffers due to display mode change.\n"));
939 game_init_render_buffers(W95DisplayMode,
940 GRMODEINFO(rw), GRMODEINFO(rh),
941 VR_render_mode, VR_screen_flags);
946 if (VGA_current_mode != VR_screen_mode) {
947 if (gr_set_mode(VR_screen_mode)) {
948 Error("Cannot set desired screen mode for game!");
949 //we probably should do something else here, like select a standard mode
952 if ( (Config_control_type == 1) && (Function_mode == FMODE_GAME) )
959 if ( VR_render_mode == VR_NONE )
961 max_window_w = grd_curscreen->sc_w;
962 max_window_h = grd_curscreen->sc_h;
964 if (VR_screen_flags & VRF_ALLOW_COCKPIT) {
965 if (Cockpit_mode == CM_STATUS_BAR)
966 max_window_h = grd_curscreen->sc_h - GameBitmaps[cockpit_bitmap[CM_STATUS_BAR+(Current_display_mode?(Num_cockpits/2):0)].index].bm_h;
968 else if (Cockpit_mode != CM_LETTERBOX)
969 Cockpit_mode = CM_FULL_SCREEN;
971 if (Game_window_h==0 || Game_window_h > max_window_h || Game_window_w==0 || Game_window_w > max_window_w) {
972 Game_window_w = max_window_w;
973 Game_window_h = max_window_h;
978 Cockpit_mode = CM_FULL_SCREEN;
981 // Super hack. If we are switching from a 320x200 game to 640x480.
982 // and we were in a menumode when switching, we don't
983 // restore Game_window vals
984 if (force_mode_change && (W95DisplayMode == SM95_320x200x8X)) {
985 Game_window_w = saved_window_w;
986 Game_window_h = saved_window_h;
987 force_mode_change = 0;
992 // Define screen pages for game mode
993 // If we designate through screen_flags to use paging, then do so.
995 dd_gr_init_sub_canvas( &dd_VR_screen_pages[0], dd_grd_screencanv, 0, 0, grd_curscreen->sc_w, grd_curscreen->sc_h ),
996 gr_init_sub_canvas( &VR_screen_pages[0], &grd_curscreen->sc_canvas, 0, 0, grd_curscreen->sc_w, grd_curscreen->sc_h )
999 if ( VR_screen_flags&VRF_USE_PAGING ) {
1001 dd_gr_init_sub_canvas( &dd_VR_screen_pages[1], dd_grd_backcanv, 0, 0, grd_curscreen->sc_w, grd_curscreen->sc_h ),
1002 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 )
1007 dd_gr_init_sub_canvas( &dd_VR_screen_pages[1], dd_grd_screencanv, 0, 0, grd_curscreen->sc_w, grd_curscreen->sc_h ),
1008 gr_init_sub_canvas( &VR_screen_pages[1], &grd_curscreen->sc_canvas, 0, 0, grd_curscreen->sc_w, grd_curscreen->sc_h )
1015 FontHires = (Current_display_mode != 0);
1018 FontHires = MenuHires = ((Current_display_mode != 0) && (Current_display_mode != 2));
1021 if ( VR_render_mode != VR_NONE ) {
1022 // for 640x480 or higher, use hires font.
1023 if ( grd_curscreen->sc_h > 400 )
1032 if (VGA_current_mode != SM_800x600V) {
1034 if ((gr_error=gr_set_mode(SM_800x600V))!=0) { //force into game scrren
1035 Warning("Cannot init editor screen (error=%d)",gr_error);
1039 gr_palette_load( gr_palette );
1041 gr_init_sub_canvas( &VR_editor_canvas, &grd_curscreen->sc_canvas, 0, 0, grd_curscreen->sc_w, grd_curscreen->sc_h );
1042 Canv_editor = &VR_editor_canvas;
1043 gr_init_sub_canvas( &VR_screen_pages[0], Canv_editor, 0, 0, Canv_editor->cv_w, Canv_editor->cv_h );
1044 gr_init_sub_canvas( &VR_screen_pages[1], Canv_editor, 0, 0, Canv_editor->cv_w, Canv_editor->cv_h );
1045 gr_set_current_canvas( Canv_editor );
1046 init_editor_screen(); //setup other editor stuff
1050 Error("Invalid screen mode %d",sm);
1053 VR_current_page = 0;
1056 dd_gr_set_current_canvas(&dd_VR_screen_pages[VR_current_page]),
1057 gr_set_current_canvas( &VR_screen_pages[VR_current_page] )
1060 if ( VR_screen_flags&VRF_USE_PAGING ) {
1063 gr_show_canvas( &VR_screen_pages[VR_current_page] )
1067 ogl_set_screen_mode();
1073 static int timer_paused=0;
1077 if (timer_paused==0) {
1079 time = timer_get_fixed_seconds();
1080 last_timer_value = time - last_timer_value;
1081 if (last_timer_value < 0) {
1082 #if defined(TIMER_TEST) && !defined(NDEBUG)
1083 Int3(); //get Matt!!!!
1085 last_timer_value = 0;
1087 #if defined(TIMER_TEST) && !defined(NDEBUG)
1088 time_stopped = time;
1093 #if defined(TIMER_TEST) && !defined(NDEBUG)
1101 Assert(timer_paused >= 0);
1102 if (timer_paused==0) {
1104 time = timer_get_fixed_seconds();
1105 #if defined(TIMER_TEST) && !defined(NDEBUG)
1106 if (last_timer_value < 0)
1107 Int3(); //get Matt!!!!
1110 last_timer_value = time - last_timer_value;
1111 #if defined(TIMER_TEST) && !defined(NDEBUG)
1112 time_started = time;
1116 #if defined(TIMER_TEST) && !defined(NDEBUG)
1121 MAC(extern ubyte joydefs_calibrating;)
1123 void game_flush_inputs()
1130 if ( (Function_mode != FMODE_MENU) && !joydefs_calibrating ) // only reset mouse when not in menu or not calibrating
1132 mouse_get_delta( &dx, &dy ); // Read mouse
1133 memset(&Controls,0,sizeof(control_info));
1138 last_timer_value = timer_get_fixed_seconds();
1143 extern int Saving_movie_frames;
1144 int Movie_fixed_frametime;
1146 #define Saving_movie_frames 0
1147 #define Movie_fixed_frametime 0
1150 void calc_frame_time()
1152 fix timer_value,last_frametime = FrameTime;
1154 #if defined(TIMER_TEST) && !defined(NDEBUG)
1155 _last_frametime = last_frametime;
1158 timer_value = timer_get_fixed_seconds();
1159 FrameTime = timer_value - last_timer_value;
1162 if (Saving_movie_frames || Movie_fixed_frametime) {
1163 if (FrameTime > f1_0/15)
1164 mprintf((0,"slow frame: %x\n",FrameTime));
1167 timer_value = timer_get_fixed_seconds();
1168 FrameTime = timer_value - last_timer_value;
1169 } while (FrameTime < f1_0/15);
1170 FrameTime = f1_0/15;
1174 #if defined(TIMER_TEST) && !defined(NDEBUG)
1175 _timer_value = timer_value;
1179 if (!(((FrameTime > 0) && (FrameTime <= F1_0)) || (Function_mode == FMODE_EDITOR) || (Newdemo_state == ND_STATE_PLAYBACK))) {
1180 mprintf((1,"Bad FrameTime - value = %x\n",FrameTime));
1182 Int3(); // Call Mike or Matt or John! Your interrupts are probably trashed!
1183 // if ( !dpmi_virtual_memory )
1184 // Int3(); //Get MATT if hit this!
1188 #if defined(TIMER_TEST) && !defined(NDEBUG)
1189 actual_last_timer_value = last_timer_value;
1192 if ( Game_turbo_mode )
1195 // Limit frametime to be between 5 and 150 fps.
1196 RealFrameTime = FrameTime;
1197 if ( FrameTime < F1_0/150 ) FrameTime = F1_0/150;
1198 if ( FrameTime > F1_0/5 ) FrameTime = F1_0/5;
1200 last_timer_value = timer_value;
1202 if (FrameTime < 0) //if bogus frametime...
1203 FrameTime = last_frametime; //...then use time from last frame
1206 if (fixed_frametime) FrameTime = fixed_frametime;
1211 if ( Debug_pause ) {
1221 last_timer_value = timer_get_fixed_seconds();
1229 #if defined(TIMER_TEST) && !defined(NDEBUG)
1230 stop_count = start_count = 0;
1233 // Set value to determine whether homing missile can see target.
1234 // The lower frametime is, the more likely that it can see its target.
1235 if (FrameTime <= F1_0/64)
1236 Min_trackable_dot = MIN_TRACKABLE_DOT; // -- 3*(F1_0 - MIN_TRACKABLE_DOT)/4 + MIN_TRACKABLE_DOT;
1237 else if (FrameTime < F1_0/32)
1238 Min_trackable_dot = MIN_TRACKABLE_DOT + F1_0/64 - 2*FrameTime; // -- fixmul(F1_0 - MIN_TRACKABLE_DOT, F1_0-4*FrameTime) + MIN_TRACKABLE_DOT;
1239 else if (FrameTime < F1_0/4)
1240 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;
1242 Min_trackable_dot = MIN_TRACKABLE_DOT + F1_0/64 - F1_0/8;
1246 //--unused-- int Auto_flythrough=0; //if set, start flythough automatically
1248 void move_player_2_segment(segment *seg,int side)
1252 compute_segment_center(&ConsoleObject->pos,seg);
1253 compute_center_point_on_side(&vp,seg,side);
1254 vm_vec_sub2(&vp,&ConsoleObject->pos);
1255 vm_vector_2_matrix(&ConsoleObject->orient,&vp,NULL,NULL);
1257 obj_relink( ConsoleObject-Objects, SEG_PTR_2_NUM(seg) );
1262 void game_draw_time_left()
1264 char temp_string[30];
1268 gr_set_curfont( GAME_FONT ); //GAME_FONT
1269 gr_set_fontcolor(gr_getcolor(0,63,0), -1 );
1271 timevar=i2f (Netgame.PlayTimeAllowed*5*60);
1272 i=f2i(timevar-ThisLevelTime);
1275 sprintf( temp_string, "Time left: %d secs", i );
1278 gr_string(0, 32, temp_string );
1283 extern int Game_pause;
1286 void level_with_floor();
1288 void modex_clear_box(int x,int y,int w,int h)
1290 grs_canvas *temp_canv,*save_canv;
1292 save_canv = grd_curcanv;
1293 temp_canv = gr_create_canvas(w,h);
1294 gr_set_current_canvas(temp_canv);
1295 gr_clear_canvas(BM_XRGB(0,0,0));
1296 gr_set_current_canvas(save_canv);
1297 gr_bitmapm(x,y,&temp_canv->cv_bitmap);
1298 gr_free_canvas(temp_canv);
1302 extern void modex_printf(int x,int y,char *s,grs_font *font,int color);
1304 // mac routine to drop contents of screen to a pict file using copybits
1305 // save a PICT to a file
1308 void SavePictScreen(int multiplayer)
1311 int parid, i, count;
1312 char *pfilename, filename[50], buf[512], cwd[FILENAME_MAX];
1315 PicHandle pict_handle;
1316 static int multi_count = 0;
1317 StandardFileReply sf_reply;
1319 // dump the contents of the GameWindow into a picture using copybits
1321 pict_handle = OpenPicture(&GameWindow->portRect);
1322 if (pict_handle == NULL)
1325 CopyBits(&GameWindow->portBits, &GameWindow->portBits, &GameWindow->portRect, &GameWindow->portRect, srcBic, NULL);
1328 // get the cwd to restore with chdir when done -- this keeps the mac world sane
1329 if (!getcwd(cwd, FILENAME_MAX))
1331 // create the fsspec
1333 sprintf(filename, "screen%d", multi_count++);
1334 pfilename = c2pstr(filename);
1337 StandardPutFile("\pSave PICT as:", pfilename, &sf_reply);
1338 if (!sf_reply.sfGood)
1340 memcpy( &spec, &(sf_reply.sfFile), sizeof(FSSpec) );
1341 if (sf_reply.sfReplacing)
1343 err = FSpCreate( &spec, 'ttxt', 'PICT', smSystemScript );
1347 // parid = GetAppDirId();
1348 err = FSMakeFSSpec(0, 0, pfilename, &spec);
1353 err = FSpCreate(&spec, 'ttxt', 'PICT', smSystemScript);
1358 // write the PICT file
1359 if ( FSpOpenDF(&spec, fsRdWrPerm, &fd) )
1361 memset(buf, 0, sizeof(buf));
1363 if ( FSWrite(fd, &count, buf) )
1365 count = GetHandleSize((Handle)pict_handle);
1366 HLock((Handle)pict_handle);
1367 if ( FSWrite(fd, &count, *pict_handle) ) {
1373 HUnlock((Handle)pict_handle);
1374 DisposeHandle((Handle)pict_handle);
1382 //automap_flag is now unused, since we just check if the screen we're
1383 //writing to is modex
1384 //if called from automap, current canvas is set to visible screen
1386 void save_screen_shot(int automap_flag)
1388 #if defined(WINDOWS)
1389 mprintf((0, "Doing screen shot thing.\n"));
1390 win95_save_pcx_shot();
1392 #elif !defined(MACINTOSH)
1395 grs_canvas *screen_canv=&grd_curscreen->sc_canvas;
1396 grs_font *save_font;
1397 static int savenum=0;
1398 static int stereo_savenum=0;
1399 grs_canvas *temp_canv,*temp_canv2,*save_canv;
1400 char savename[FILENAME_LEN],savename2[FILENAME_LEN];
1408 // // Can't do screen shots in VR modes.
1409 // if ( VR_render_mode != VR_NONE )
1414 save_canv = grd_curcanv;
1416 if ( VR_render_mode != VR_NONE && !automap_flag && Function_mode==FMODE_GAME && Screen_mode==SCREEN_GAME)
1420 temp_canv = gr_create_canvas(VR_render_buffer[0].cv_bitmap.bm_w,VR_render_buffer[0].cv_bitmap.bm_h);
1421 gr_set_current_canvas(temp_canv);
1422 gr_ubitmap(0,0,&VR_render_buffer[0].cv_bitmap);
1424 temp_canv2 = gr_create_canvas(VR_render_buffer[1].cv_bitmap.bm_w,VR_render_buffer[1].cv_bitmap.bm_h);
1425 gr_set_current_canvas(temp_canv2);
1426 gr_ubitmap(0,0,&VR_render_buffer[1].cv_bitmap);
1429 temp_canv = gr_create_canvas(screen_canv->cv_bitmap.bm_w,screen_canv->cv_bitmap.bm_h);
1430 gr_set_current_canvas(temp_canv);
1431 gr_ubitmap(0,0,&screen_canv->cv_bitmap);
1434 gr_set_current_canvas(save_canv);
1436 if ( savenum > 99 ) savenum = 0;
1437 if ( stereo_savenum > 99 ) stereo_savenum = 0;
1440 sprintf(savename,"left%02d.pcx",stereo_savenum);
1441 sprintf(savename2,"right%02d.pcx",stereo_savenum);
1442 if (VR_eye_switch) {char t[FILENAME_LEN]; strcpy(t,savename); strcpy(savename,savename2); strcpy(savename2,t);}
1444 sprintf( message, "%s '%s' & '%s'", TXT_DUMPING_SCREEN, savename, savename2 );
1447 sprintf(savename,"screen%02d.pcx",savenum++);
1448 sprintf( message, "%s '%s'", TXT_DUMPING_SCREEN, savename );
1451 if (!automap_flag) //if from automap, curcanv is already visible canv
1452 gr_set_current_canvas(NULL);
1453 modex_flag = (grd_curcanv->cv_bitmap.bm_type==BM_MODEX);
1454 if (!automap_flag && modex_flag)
1455 gr_set_current_canvas(&VR_screen_pages[VR_current_page]);
1457 save_font = grd_curcanv->cv_font;
1458 gr_set_curfont(GAME_FONT);
1459 gr_set_fontcolor(gr_find_closest_color_current(0,31,0),-1);
1460 gr_get_string_size(message,&w,&h,&aw);
1465 //I changed how these coords were calculated for the high-res automap. -MT
1466 //x = (VR_screen_pages[VR_current_page].cv_w-w)/2;
1467 //y = (VR_screen_pages[VR_current_page].cv_h-h)/2;
1468 x = (grd_curcanv->cv_w-w)/2;
1469 y = (grd_curcanv->cv_h-h)/2;
1472 modex_clear_box(x-2,y-2,w+4,h+4);
1473 modex_printf(x, y, message,GAME_FONT,gr_find_closest_color_current(0,31,0));
1475 gr_setcolor(gr_find_closest_color_current(0,0,0));
1476 gr_rect(x-2,y-2,x+w+2,y+h+2);
1477 gr_printf(x,y,message);
1478 gr_set_curfont(save_font);
1480 t1 = timer_get_fixed_seconds() + F1_0;
1482 gr_palette_read(pal); //get actual palette from the hardware
1483 pcx_write_bitmap(savename,&temp_canv->cv_bitmap,pal);
1485 pcx_write_bitmap(savename2,&temp_canv2->cv_bitmap,pal);
1487 while ( timer_get_fixed_seconds() < t1 ); // Wait so that messag stays up at least 1 second.
1489 gr_set_current_canvas(screen_canv);
1491 if (grd_curcanv->cv_bitmap.bm_type!=BM_MODEX && !stereo)
1492 gr_ubitmap(0,0,&temp_canv->cv_bitmap);
1494 gr_free_canvas(temp_canv);
1496 gr_free_canvas(temp_canv2);
1498 gr_set_current_canvas(save_canv);
1504 grs_canvas *screen_canv = &grd_curscreen->sc_canvas;
1505 grs_canvas *temp_canv, *save_canv;
1507 // Can't do screen shots in VR modes.
1508 if ( VR_render_mode != VR_NONE )
1513 save_canv = grd_curcanv;
1514 temp_canv = gr_create_canvas( screen_canv->cv_bitmap.bm_w, screen_canv->cv_bitmap.bm_h );
1517 gr_set_current_canvas( temp_canv );
1518 gr_ubitmap( 0, 0, &screen_canv->cv_bitmap );
1519 gr_set_current_canvas( &VR_screen_pages[VR_current_page] );
1523 if (Game_mode & GM_MULTI)
1530 gr_set_current_canvas(screen_canv);
1532 // if (!automap_flag)
1533 gr_ubitmap( 0, 0, &temp_canv->cv_bitmap);
1535 gr_free_canvas(temp_canv);
1537 gr_set_current_canvas(save_canv);
1546 void fly_init(object *obj)
1548 obj->control_type = CT_FLYING;
1549 obj->movement_type = MT_PHYSICS;
1551 vm_vec_zero(&obj->mtype.phys_info.velocity);
1552 vm_vec_zero(&obj->mtype.phys_info.thrust);
1553 vm_vec_zero(&obj->mtype.phys_info.rotvel);
1554 vm_vec_zero(&obj->mtype.phys_info.rotthrust);
1557 //void morph_test(), morph_step();
1560 // ------------------------------------------------------------------------------------
1562 void test_anim_states();
1566 //put up the help message
1573 extern int been_in_editor;
1575 // ------------------------------------------------------------------------------------
1576 void do_cloak_stuff(void)
1579 for (i = 0; i < N_players; i++)
1580 if (Players[i].flags & PLAYER_FLAGS_CLOAKED) {
1581 // mprintf(0, "Cloak time left: %7.3f\n", f2fl(CLOAK_TIME_MAX - (GameTime - Players[Player_num].cloak_time)));
1582 if (GameTime - Players[i].cloak_time > CLOAK_TIME_MAX) {
1583 Players[i].flags &= ~PLAYER_FLAGS_CLOAKED;
1584 if (i == Player_num) {
1585 digi_play_sample( SOUND_CLOAK_OFF, F1_0);
1587 if (Game_mode & GM_MULTI)
1588 multi_send_play_sound(SOUND_CLOAK_OFF, F1_0);
1589 maybe_drop_net_powerup(POW_CLOAK);
1590 multi_send_decloak(); // For demo recording
1592 // mprintf((0, " --- You have been DE-CLOAKED! ---\n"));
1600 // ------------------------------------------------------------------------------------
1601 void do_invulnerable_stuff(void)
1603 if (Players[Player_num].flags & PLAYER_FLAGS_INVULNERABLE) {
1604 if (GameTime - Players[Player_num].invulnerable_time > INVULNERABLE_TIME_MAX) {
1605 Players[Player_num].flags ^= PLAYER_FLAGS_INVULNERABLE;
1608 digi_play_sample( SOUND_INVULNERABILITY_OFF, F1_0);
1610 if (Game_mode & GM_MULTI)
1612 multi_send_play_sound(SOUND_INVULNERABILITY_OFF, F1_0);
1613 maybe_drop_net_powerup(POW_INVULNERABILITY);
1616 mprintf((0, " --- You have been DE-INVULNERABLEIZED! ---\n"));
1623 ubyte Last_afterburner_state = 0;
1624 fix Last_afterburner_charge = 0;
1626 #define AFTERBURNER_LOOP_START ((digi_sample_rate==SAMPLE_RATE_22K)?32027:(32027/2)) //20098
1627 #define AFTERBURNER_LOOP_END ((digi_sample_rate==SAMPLE_RATE_22K)?48452:(48452/2)) //25776
1631 //@@// ------------------------------------------------------------------------------------
1632 //@@void afterburner_shake(void)
1636 //@@ rx = (Ab_scale * fixmul(d_rand() - 16384, F1_0/8 + (((GameTime + 0x4000)*4) & 0x3fff)))/16;
1637 //@@ rz = (Ab_scale * fixmul(d_rand() - 16384, F1_0/2 + ((GameTime*4) & 0xffff)))/16;
1639 //@@ // -- mprintf((0, "AB: %8x %8x\n", rx, rz));
1640 //@@ ConsoleObject->mtype.phys_info.rotvel.x += rx;
1641 //@@ ConsoleObject->mtype.phys_info.rotvel.z += rz;
1645 // ------------------------------------------------------------------------------------
1647 extern void multi_send_sound_function (char,char);
1650 void do_afterburner_stuff(void)
1652 if (!(Players[Player_num].flags & PLAYER_FLAGS_AFTERBURNER))
1653 Afterburner_charge=0;
1655 if (Endlevel_sequence || Player_is_dead)
1657 digi_kill_sound_linked_to_object( Players[Player_num].objnum);
1659 multi_send_sound_function (0,0);
1663 if ((Controls.afterburner_state != Last_afterburner_state && Last_afterburner_charge) || (Last_afterburner_state && Last_afterburner_charge && !Afterburner_charge)) {
1665 if (Afterburner_charge && Controls.afterburner_state && (Players[Player_num].flags & PLAYER_FLAGS_AFTERBURNER)) {
1666 digi_link_sound_to_object3( SOUND_AFTERBURNER_IGNITE, Players[Player_num].objnum, 1, F1_0, i2f(256), AFTERBURNER_LOOP_START, AFTERBURNER_LOOP_END );
1668 if (Game_mode & GM_MULTI)
1669 multi_send_sound_function (3,SOUND_AFTERBURNER_IGNITE);
1672 digi_kill_sound_linked_to_object( Players[Player_num].objnum);
1673 digi_link_sound_to_object2( SOUND_AFTERBURNER_PLAY, Players[Player_num].objnum, 0, F1_0, i2f(256));
1675 if (Game_mode & GM_MULTI)
1676 multi_send_sound_function (0,0);
1678 mprintf((0,"Killing afterburner sound\n"));
1682 //@@if (Controls.afterburner_state && Afterburner_charge)
1683 //@@ afterburner_shake();
1685 Last_afterburner_state = Controls.afterburner_state;
1686 Last_afterburner_charge = Afterburner_charge;
1689 // -- // ------------------------------------------------------------------------------------
1690 // -- // if energy < F1_0/2, recharge up to F1_0/2
1691 // -- void recharge_energy_frame(void)
1693 // -- if (Players[Player_num].energy < Weapon_info[0].energy_usage) {
1694 // -- Players[Player_num].energy += FrameTime/4;
1696 // -- if (Players[Player_num].energy > Weapon_info[0].energy_usage)
1697 // -- Players[Player_num].energy = Weapon_info[0].energy_usage;
1701 // Amount to diminish guns towards normal, per second.
1702 #define DIMINISH_RATE 16 // gots to be a power of 2, else change the code in diminish_palette_towards_normal
1704 extern fix Flash_effect;
1706 //adds to rgb values for palette flash
1707 void PALETTE_FLASH_ADD(int _dr,int _dg,int _db)
1711 PaletteRedAdd += _dr;
1712 PaletteGreenAdd += _dg;
1713 PaletteBlueAdd += _db;
1715 // -- mprintf((0, "Palette add: %3i %3i %3i\n", PaletteRedAdd, PaletteGreenAdd, PaletteBlueAdd));
1720 maxval = MAX_PALETTE_ADD;
1722 if (PaletteRedAdd > maxval)
1723 PaletteRedAdd = maxval;
1725 if (PaletteGreenAdd > maxval)
1726 PaletteGreenAdd = maxval;
1728 if (PaletteBlueAdd > maxval)
1729 PaletteBlueAdd = maxval;
1731 if (PaletteRedAdd < -maxval)
1732 PaletteRedAdd = -maxval;
1734 if (PaletteGreenAdd < -maxval)
1735 PaletteGreenAdd = -maxval;
1737 if (PaletteBlueAdd < -maxval)
1738 PaletteBlueAdd = -maxval;
1741 fix Time_flash_last_played;
1744 void game_palette_step_up( int r, int g, int b );
1745 // ------------------------------------------------------------------------------------
1746 // Diminish palette effects towards normal.
1747 void diminish_palette_towards_normal(void)
1751 // Diminish at DIMINISH_RATE units/second.
1752 // For frame rates > DIMINISH_RATE Hz, use randomness to achieve this.
1753 if (FrameTime < F1_0/DIMINISH_RATE) {
1754 if (d_rand() < FrameTime*DIMINISH_RATE/2) // Note: d_rand() is in 0..32767, and 8 Hz means decrement every frame
1757 dec_amount = f2i(FrameTime*DIMINISH_RATE); // one second = DIMINISH_RATE counts
1758 if (dec_amount == 0)
1759 dec_amount++; // make sure we decrement by something
1765 // Part of hack system to force update of palette after exiting a menu.
1766 if (Time_flash_last_played) {
1768 PaletteRedAdd ^= 1; // Very Tricky! In gr_palette_step_up, if all stepups same as last time, won't do anything!
1771 if ((Time_flash_last_played + F1_0/8 < GameTime) || (Time_flash_last_played > GameTime)) {
1772 digi_play_sample( SOUND_CLOAK_OFF, Flash_effect/4);
1773 Time_flash_last_played = GameTime;
1776 Flash_effect -= FrameTime;
1777 if (Flash_effect < 0)
1780 if (force_do || (d_rand() > 4096 )) {
1781 if ( (Newdemo_state==ND_STATE_RECORDING) && (PaletteRedAdd || PaletteGreenAdd || PaletteBlueAdd) )
1782 newdemo_record_palette_effect(PaletteRedAdd, PaletteGreenAdd, PaletteBlueAdd);
1784 game_palette_step_up( PaletteRedAdd, PaletteGreenAdd, PaletteBlueAdd );
1791 if (PaletteRedAdd > 0 ) { PaletteRedAdd -= dec_amount; if (PaletteRedAdd < 0 ) PaletteRedAdd = 0; }
1792 if (PaletteRedAdd < 0 ) { PaletteRedAdd += dec_amount; if (PaletteRedAdd > 0 ) PaletteRedAdd = 0; }
1794 if (PaletteGreenAdd > 0 ) { PaletteGreenAdd -= dec_amount; if (PaletteGreenAdd < 0 ) PaletteGreenAdd = 0; }
1795 if (PaletteGreenAdd < 0 ) { PaletteGreenAdd += dec_amount; if (PaletteGreenAdd > 0 ) PaletteGreenAdd = 0; }
1797 if (PaletteBlueAdd > 0 ) { PaletteBlueAdd -= dec_amount; if (PaletteBlueAdd < 0 ) PaletteBlueAdd = 0; }
1798 if (PaletteBlueAdd < 0 ) { PaletteBlueAdd += dec_amount; if (PaletteBlueAdd > 0 ) PaletteBlueAdd = 0; }
1800 if ( (Newdemo_state==ND_STATE_RECORDING) && (PaletteRedAdd || PaletteGreenAdd || PaletteBlueAdd) )
1801 newdemo_record_palette_effect(PaletteRedAdd, PaletteGreenAdd, PaletteBlueAdd);
1803 game_palette_step_up( PaletteRedAdd, PaletteGreenAdd, PaletteBlueAdd );
1805 //mprintf(0, "%2i %2i %2i\n", PaletteRedAdd, PaletteGreenAdd, PaletteBlueAdd);
1808 int Redsave, Bluesave, Greensave;
1810 void palette_save(void)
1812 Redsave = PaletteRedAdd; Bluesave = PaletteBlueAdd; Greensave = PaletteGreenAdd;
1815 extern void gr_palette_step_up_vr( int r, int g, int b, int white, int black );
1817 void game_palette_step_up( int r, int g, int b )
1819 if ( VR_use_reg_code ) {
1821 // gr_palette_step_up_vr( r, g, b, VR_WHITE_INDEX, VR_BLACK_INDEX );
1824 gr_palette_step_up( r, g, b );
1828 void palette_restore(void)
1830 PaletteRedAdd = Redsave; PaletteBlueAdd = Bluesave; PaletteGreenAdd = Greensave;
1831 game_palette_step_up( PaletteRedAdd, PaletteGreenAdd, PaletteBlueAdd );
1833 // Forces flash effect to fixup palette next frame.
1834 Time_flash_last_played = 0;
1837 extern void dead_player_frame(void);
1840 // --------------------------------------------------------------------------------------------------
1841 int allowed_to_fire_laser(void)
1843 if (Player_is_dead) {
1844 Global_missile_firing_count = 0;
1848 // Make sure enough time has elapsed to fire laser, but if it looks like it will
1849 // be a long while before laser can be fired, then there must be some mistake!
1850 if (Next_laser_fire_time > GameTime)
1851 if (Next_laser_fire_time < GameTime + 2*F1_0)
1857 fix Next_flare_fire_time = 0;
1858 #define FLARE_BIG_DELAY (F1_0*2)
1860 int allowed_to_fire_flare(void)
1862 if (Next_flare_fire_time > GameTime)
1863 if (Next_flare_fire_time < GameTime + FLARE_BIG_DELAY) // In case time is bogus, never wait > 1 second.
1866 if (Players[Player_num].energy >= Weapon_info[FLARE_ID].energy_usage)
1867 Next_flare_fire_time = GameTime + F1_0/4;
1869 Next_flare_fire_time = GameTime + FLARE_BIG_DELAY;
1874 int allowed_to_fire_missile(void)
1876 // mprintf(0, "Next fire = %7.3f, Cur time = %7.3f\n", f2fl(Next_missile_fire_time), f2fl(GameTime));
1877 // Make sure enough time has elapsed to fire missile, but if it looks like it will
1878 // be a long while before missile can be fired, then there must be some mistake!
1879 if (Next_missile_fire_time > GameTime)
1880 if (Next_missile_fire_time < GameTime + 5*F1_0)
1886 void full_palette_save(void)
1889 apply_modified_palette();
1890 reset_palette_add();
1891 gr_palette_load( gr_palette );
1894 extern int Death_sequence_aborted;
1895 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) );
1902 char command_help[64], pixel_double_help[64], save_help[64], restore_help[64];
1905 m[ 0].type = NM_TYPE_TEXT; m[ 0].text = TXT_HELP_ESC;
1907 m[ 1].type = NM_TYPE_TEXT; m[ 1].text = TXT_HELP_ALT_F2;
1908 m[ 2].type = NM_TYPE_TEXT; m[ 2].text = TXT_HELP_ALT_F3;
1910 sprintf(save_help, "OPT-F2 (%c-s)\t Save Game", 133);
1911 sprintf(restore_help, "OPT-F3 (%c-o)\t Load Game", 133);
1912 m[ 1].type = NM_TYPE_TEXT; m[1].text = save_help;
1913 m[ 2].type = NM_TYPE_TEXT; m[2].text = restore_help;
1915 m[ 3].type = NM_TYPE_TEXT; m[ 3].text = TXT_HELP_F2;
1916 m[ 4].type = NM_TYPE_TEXT; m[ 4].text = TXT_HELP_F3;
1917 m[ 5].type = NM_TYPE_TEXT; m[ 5].text = TXT_HELP_F4;
1918 m[ 6].type = NM_TYPE_TEXT; m[ 6].text = TXT_HELP_F5;
1920 m[ 7].type = NM_TYPE_TEXT; m[ 7].text = TXT_HELP_PAUSE;
1922 m[ 7].type = NM_TYPE_TEXT; m[ 7].text = "Pause (F15)\t Pause";
1924 m[ 8].type = NM_TYPE_TEXT; m[ 8].text = TXT_HELP_MINUSPLUS;
1926 m[ 9].type = NM_TYPE_TEXT; m[ 9].text = TXT_HELP_PRTSCN;
1928 m[ 9].type = NM_TYPE_TEXT; m[ 9].text = "printscrn (F13)\t save screen shot";
1930 m[10].type = NM_TYPE_TEXT; m[10].text = TXT_HELP_1TO5;
1931 m[11].type = NM_TYPE_TEXT; m[11].text = TXT_HELP_6TO10;
1932 m[12].type = NM_TYPE_TEXT; m[12].text = "Shift-F1\t Cycle left window";
1933 m[13].type = NM_TYPE_TEXT; m[13].text = "Shift-F2\t Cycle right window";
1934 m[14].type = NM_TYPE_TEXT; m[14].text = "Shift-F4\t GuideBot menu";
1936 m[15].type = NM_TYPE_TEXT; m[15].text = "Alt-Shift-F4\t Rename GuideBot";
1938 m[15].type = NM_TYPE_TEXT; m[15].text = "Opt-Shift-F4\t Rename GuideBot";
1940 m[16].type = NM_TYPE_TEXT; m[16].text = "Shift-F5\t Drop primary";
1941 m[17].type = NM_TYPE_TEXT; m[17].text = "Shift-F6\t Drop secondary";
1942 m[18].type = NM_TYPE_TEXT; m[18].text = "Shift-F7\t Calibrate joystick";
1943 m[19].type = NM_TYPE_TEXT; m[19].text = "Shift-number\t GuideBot commands";
1946 sprintf(pixel_double_help, "%c-D\t Toggle Pixel Double Mode", 133);
1947 m[20].type = NM_TYPE_TEXT; m[20].text = pixel_double_help;
1948 m[21].type = NM_TYPE_TEXT; m[21].text = "";
1949 sprintf(command_help, "(Use %c-# for F#. i.e. %c-1 for F1)", 133, 133);
1950 m[22].type = NM_TYPE_TEXT; m[22].text = command_help;
1954 full_palette_save();
1956 newmenu_dotiny2( NULL, TXT_KEYS, nitems, m, NULL );
1961 //temp function until Matt cleans up game sequencing
1962 extern void temp_reset_stuff_on_level();
1964 //deal with rear view - switch it on, or off, or whatever
1965 void check_rear_view()
1968 #define LEAVE_TIME 0x1000 //how long until we decide key is down (Used to be 0x4000)
1970 static int leave_mode;
1971 static fix entry_time;
1973 if ( Controls.rear_view_down_count ) { //key/button has gone down
1977 if (Cockpit_mode==CM_REAR_VIEW) {
1978 select_cockpit(Cockpit_mode_save);
1979 Cockpit_mode_save = -1;
1981 if (Newdemo_state == ND_STATE_RECORDING)
1982 newdemo_record_restore_rearview();
1986 leave_mode = 0; //means wait for another key
1987 entry_time = timer_get_fixed_seconds();
1988 if (Cockpit_mode == CM_FULL_COCKPIT) {
1989 Cockpit_mode_save = Cockpit_mode;
1990 select_cockpit(CM_REAR_VIEW);
1992 if (Newdemo_state == ND_STATE_RECORDING)
1993 newdemo_record_rearview();
1997 if (Controls.rear_view_down_state) {
1999 if (leave_mode==0 && (timer_get_fixed_seconds()-entry_time)>LEAVE_TIME)
2004 //@@if (leave_mode==1 && Cockpit_mode==CM_REAR_VIEW) {
2006 if (leave_mode==1 && Rear_view) {
2008 if (Cockpit_mode==CM_REAR_VIEW) {
2009 select_cockpit(Cockpit_mode_save);
2010 Cockpit_mode_save = -1;
2012 if (Newdemo_state == ND_STATE_RECORDING)
2013 newdemo_record_restore_rearview();
2018 void reset_rear_view(void)
2021 if (Newdemo_state == ND_STATE_RECORDING)
2022 newdemo_record_restore_rearview();
2027 if (!(Cockpit_mode == CM_FULL_COCKPIT || Cockpit_mode == CM_STATUS_BAR || Cockpit_mode == CM_FULL_SCREEN)) {
2028 if (!(Cockpit_mode_save == CM_FULL_COCKPIT || Cockpit_mode_save == CM_STATUS_BAR || Cockpit_mode_save == CM_FULL_SCREEN))
2029 Cockpit_mode_save = CM_FULL_COCKPIT;
2030 select_cockpit(Cockpit_mode_save);
2031 Cockpit_mode_save = -1;
2037 int Config_menu_flag;
2041 int Cheats_enabled=0;
2043 extern int Laser_rapid_fire;
2044 extern void do_lunacy_on(), do_lunacy_off();
2046 extern int Physics_cheat_flag,Robots_kill_robots_cheat;
2047 extern char BounceCheat,HomingCheat,OldHomingState[20];
2048 extern char AcidCheatOn,old_IntMethod, Monster_mode;
2049 extern int Buddy_dude_cheat;
2051 //turns off active cheats
2052 void turn_cheats_off()
2058 Weapon_info[i].homing_flag=OldHomingState[i];
2063 Interpolation_method=old_IntMethod;
2066 Buddy_dude_cheat = 0;
2070 Laser_rapid_fire = 0;
2071 Physics_cheat_flag = 0;
2073 Robots_kill_robots_cheat=0;
2074 Robot_firing_enabled = 1;
2077 //turns off all cheats & resets cheater flag
2078 void game_disable_cheats()
2086 // ----------------------------------------------------------------------------
2088 void game_setup(void)
2090 //@@int demo_playing=0;
2091 //@@int multi_game=0;
2093 do_lunacy_on(); // Copy values for insane into copy buffer in ai.c
2094 do_lunacy_off(); // Restore true insane mode.
2097 last_drawn_cockpit[0] = -1; // Force cockpit to redraw next time a frame renders.
2098 last_drawn_cockpit[1] = -1; // Force cockpit to redraw next time a frame renders.
2099 Endlevel_sequence = 0;
2101 //@@if ( Newdemo_state == ND_STATE_PLAYBACK )
2102 //@@ demo_playing = 1;
2103 //@@if ( Game_mode & GM_MULTI )
2104 //@@ multi_game = 1;
2106 set_screen_mode(SCREEN_GAME);
2107 reset_palette_add();
2109 set_warn_func(game_show_warning);
2113 //digi_init_sounds();
2115 //keyd_repeat = 0; // Don't allow repeat in game
2116 keyd_repeat = 1; // Do allow repeat in game
2118 #if !defined(WINDOWS) && !defined(MACINTOSH)
2119 //_MARK_("start of game");
2123 if (Segments[ConsoleObject->segnum].segnum == -1) //segment no longer exists
2124 obj_relink( ConsoleObject-Objects, SEG_PTR_2_NUM(Cursegp) );
2126 if (!check_obj_seg(ConsoleObject))
2127 move_player_2_segment(Cursegp,Curside);
2130 Viewer = ConsoleObject;
2131 fly_init(ConsoleObject);
2136 FrameTime = 0; //make first frame zero
2139 if (Current_level_num == 0) { //not a real level
2140 init_player_stats_game();
2147 game_flush_inputs();
2153 extern char IWasKicked;
2157 // ------------------------------------------------------------------------------------
2158 //this function is the game. called when game mode selected. runs until
2159 //editor mode or exit selected
2162 game_setup(); // Replaces what was here earlier.
2163 // Good for Windows Sake.
2166 ProfilerSetStatus(1);
2169 if ( setjmp(LeaveGame)==0 ) {
2175 Config_menu_flag = 0;
2177 if ( ConsoleObject != &Objects[Players[Player_num].objnum] )
2179 mprintf ((0,"Player_num=%d objnum=%d",Player_num,Players[Player_num].objnum));
2180 //Assert( ConsoleObject == &Objects[Players[Player_num].objnum] );
2183 player_shields = Players[Player_num].shields;
2188 DoMessageStuff(&msg); // Do Windows event handling.
2189 if (_RedrawScreen) {
2190 _RedrawScreen = FALSE;
2191 load_palette(Current_level_palette,1,1);
2192 gr_palette_load(gr_palette);
2197 ExtGameStatus=GAMESTAT_RUNNING;
2198 GameLoop( 1, 1 ); // Do game loop with rendering and reading controls.
2200 //if the player is taking damage, give up guided missile control
2201 if (Players[Player_num].shields != player_shields)
2202 release_guided_missile(Player_num);
2204 //see if redbook song needs to be restarted
2205 songs_check_redbook_repeat(); // Handle RedBook Audio Repeating.
2207 if (Config_menu_flag) {
2208 int double_save = Scanline_double;
2210 //WIN(mouse_set_mode(0));
2211 if (!(Game_mode&GM_MULTI)) {palette_save(); reset_palette_add(); apply_modified_palette(); gr_palette_load( gr_palette ); }
2213 if (Scanline_double != double_save) init_cockpit();
2214 if (!(Game_mode&GM_MULTI)) palette_restore();
2215 //WIN(mouse_set_mode(1));
2219 int save_w=Game_window_w,save_h=Game_window_h;
2221 Screen_mode=-1; set_screen_mode(SCREEN_GAME);
2222 Game_window_w=save_w; Game_window_h=save_h;
2224 last_drawn_cockpit[0] = -1;
2225 last_drawn_cockpit[1] = -1;
2228 if ( (Function_mode != FMODE_GAME) && Auto_demo && (Newdemo_state != ND_STATE_NORMAL) ) {
2230 fmode = Function_mode;
2231 Function_mode = FMODE_GAME;
2233 apply_modified_palette();
2234 reset_palette_add();
2235 gr_palette_load( gr_palette );
2236 choice=nm_messagebox( NULL, 2, TXT_YES, TXT_NO, TXT_ABORT_AUTODEMO );
2238 Function_mode = fmode;
2241 newdemo_stop_playback();
2242 Function_mode = FMODE_MENU;
2244 Function_mode = FMODE_GAME;
2248 if ( (Function_mode != FMODE_GAME ) && (Newdemo_state != ND_STATE_PLAYBACK ) && (Function_mode!=FMODE_EDITOR)
2254 fmode = Function_mode;
2255 Function_mode = FMODE_GAME;
2257 apply_modified_palette();
2258 reset_palette_add();
2259 gr_palette_load( gr_palette );
2260 ExtGameStatus=GAMESTAT_ABORT_GAME;
2261 choice=nm_messagebox( NULL, 2, TXT_YES, TXT_NO, TXT_ABORT_GAME );
2263 Function_mode = fmode;
2265 Function_mode = FMODE_GAME;
2271 if (Function_mode != FMODE_GAME)
2272 longjmp(LeaveGame,0);
2275 if ( (keyd_time_when_last_pressed + (F1_0 * 60)) < timer_get_fixed_seconds() ) // idle in game for 1 minutes means exit
2276 longjmp(LeaveGame,0);
2282 ProfilerSetStatus(0);
2287 if ( (Newdemo_state == ND_STATE_RECORDING) || (Newdemo_state == ND_STATE_PAUSED) )
2288 newdemo_stop_recording();
2294 if ( Newdemo_state == ND_STATE_PLAYBACK )
2295 newdemo_stop_playback();
2297 if (Cockpit_mode_save!=-1)
2299 Cockpit_mode=Cockpit_mode_save;
2300 Cockpit_mode_save=-1;
2303 if (Function_mode != FMODE_EDITOR)
2304 gr_palette_fade_out(gr_palette,32,0); // Fade out before going to menu
2306 //@@ if ( (!demo_playing) && (!multi_game) && (Function_mode != FMODE_EDITOR)) {
2307 //@@ scores_maybe_add_player(Game_aborted);
2310 #if !defined(WINDOWS) && !defined(MACINTOSH)
2311 //_MARK_("end of game");
2314 clear_warn_func(game_show_warning); //don't use this func anymore
2316 game_disable_cheats();
2319 Function_mode = FMODE_EXIT; // get out of game in Apple OEM version
2323 //called at the end of the program
2327 if (dd_VR_offscreen_buffer) {
2328 if (dd_grd_backcanv != dd_VR_offscreen_buffer) {
2329 dd_gr_free_canvas(dd_VR_offscreen_buffer);
2331 dd_VR_offscreen_buffer = NULL;
2332 VR_offscreen_buffer = NULL;
2335 if (VR_offscreen_buffer) {
2336 gr_free_canvas(VR_offscreen_buffer);
2337 VR_offscreen_buffer = NULL;
2341 close_gauge_canvases();
2343 restore_effect_bitmap_icons();
2345 #if !defined(MACINTOSH) && !defined(WINDOWS)
2346 if (Game_cockpit_copy_code) {
2347 d_free(Game_cockpit_copy_code);
2348 Game_cockpit_copy_code = NULL;
2351 if (Game_cockpit_copy_code)
2352 Game_cockpit_copy_code = 0;
2355 if (background_bitmap.bm_data)
2356 d_free(background_bitmap.bm_data);
2358 clear_warn_func(game_show_warning); //don't use this func anymore
2362 dd_grs_canvas * get_current_game_screen()
2364 return &dd_VR_screen_pages[VR_current_page];
2369 grs_canvas * get_current_game_screen()
2371 return &VR_screen_pages[VR_current_page];
2376 extern void kconfig_center_headset();
2380 void speedtest_frame(void);
2381 int Debug_slowdown=0;
2385 extern void player_follow_path(object *objp);
2386 extern void check_create_player_path(void);
2390 extern int Do_appearance_effect;
2392 object *Missile_viewer=NULL;
2394 int Missile_view_enabled = 1;
2396 int Marker_viewer_num[2]={-1,-1};
2397 int Coop_view_player[2]={-1,-1};
2398 int Cockpit_3d_view[2]={CV_NONE,CV_NONE};
2400 //returns ptr to escort robot, or NULL
2401 object *find_escort()
2405 for (i=0; i<=Highest_object_index; i++)
2406 if (Objects[i].type == OBJ_ROBOT)
2407 if (Robot_info[Objects[i].id].companion)
2413 extern void process_super_mines_frame(void);
2414 extern void do_seismic_stuff(void);
2417 int Saving_movie_frames=0;
2418 int __Movie_frame_num=0;
2420 #define MAX_MOVIE_BUFFER_FRAMES 250
2421 #define MOVIE_FRAME_SIZE (320 * 200)
2423 ubyte *Movie_frame_buffer;
2424 int Movie_frame_counter;
2425 ubyte Movie_pal[768];
2426 char movie_path[50] = ".\\";
2428 grs_bitmap Movie_bm;
2430 void flush_movie_buffer()
2437 mprintf((0,"Flushing movie buffer..."));
2439 Movie_bm.bm_data = Movie_frame_buffer;
2441 for (f=0;f<Movie_frame_counter;f++) {
2442 sprintf(savename, "%sfrm%04d.pcx",movie_path,__Movie_frame_num);
2443 __Movie_frame_num++;
2444 pcx_write_bitmap(savename,&Movie_bm,Movie_pal);
2445 Movie_bm.bm_data += MOVIE_FRAME_SIZE;
2448 mprintf((0,"%3d/%3d\10\10\10\10\10\10\10",f,Movie_frame_counter));
2451 Movie_frame_counter=0;
2453 mprintf((0,"done \n"));
2458 void toggle_movie_saving()
2462 Saving_movie_frames = !Saving_movie_frames;
2464 if (Saving_movie_frames) {
2467 m[0].type=NM_TYPE_INPUT; m[0].text_len = 50; m[0].text = movie_path;
2468 exit = newmenu_do( NULL, "Directory for movie frames?" , 1, &(m[0]), NULL );
2471 Saving_movie_frames = 0;
2475 while (isspace(movie_path[strlen(movie_path)-1]))
2476 movie_path[strlen(movie_path)-1] = 0;
2477 if (movie_path[strlen(movie_path)-1]!='\\' && movie_path[strlen(movie_path)-1]!=':')
2478 strcat(movie_path,"\\");
2481 if (!Movie_frame_buffer) {
2482 Movie_frame_buffer = d_malloc(MAX_MOVIE_BUFFER_FRAMES * MOVIE_FRAME_SIZE);
2483 if (!Movie_frame_buffer) {
2485 Saving_movie_frames=0;
2488 Movie_frame_counter=0;
2490 Movie_bm.bm_x = Movie_bm.bm_y = 0;
2491 Movie_bm.bm_w = 320;
2492 Movie_bm.bm_h = 200;
2493 Movie_bm.bm_type = BM_LINEAR;
2494 Movie_bm.bm_flags = 0;
2495 Movie_bm.bm_rowsize = 320;
2496 Movie_bm.bm_handle = 0;
2498 gr_palette_read(Movie_pal); //get actual palette from the hardware
2500 if (Newdemo_state == ND_STATE_PLAYBACK)
2501 Newdemo_do_interpolate = 0;
2505 flush_movie_buffer();
2507 if (Newdemo_state == ND_STATE_PLAYBACK)
2508 Newdemo_do_interpolate = 1;
2513 void save_movie_frame()
2515 memcpy(Movie_frame_buffer+Movie_frame_counter*MOVIE_FRAME_SIZE,grd_curscreen->sc_canvas.cv_bitmap.bm_data,MOVIE_FRAME_SIZE);
2517 Movie_frame_counter++;
2519 if (Movie_frame_counter == MAX_MOVIE_BUFFER_FRAMES)
2520 flush_movie_buffer();
2526 extern int Level_shake_duration;
2528 //if water or fire level, make occasional sound
2529 void do_ambient_sounds()
2531 int has_water,has_lava;
2534 has_lava = (Segment2s[ConsoleObject->segnum].s2_flags & S2F_AMBIENT_LAVA);
2535 has_water = (Segment2s[ConsoleObject->segnum].s2_flags & S2F_AMBIENT_WATER);
2537 if (has_lava) { //has lava
2538 sound = SOUND_AMBIENT_LAVA;
2539 if (has_water && (d_rand() & 1)) //both, pick one
2540 sound = SOUND_AMBIENT_WATER;
2542 else if (has_water) //just water
2543 sound = SOUND_AMBIENT_WATER;
2547 if (((d_rand() << 3) < FrameTime)) { //play the sound
2548 fix volume = d_rand() + f1_0/2;
2549 digi_play_sample(sound,volume);
2553 // -- extern void lightning_frame(void);
2555 void game_render_frame();
2556 extern void omega_charge_frame(void);
2558 extern time_t t_current_time, t_saved_time;
2560 void flicker_lights();
2562 void GameLoop(int RenderFlag, int ReadControlsFlag )
2566 // Used to slow down frame rate for testing things.
2567 // RenderFlag = 1; // DEBUG
2568 if (Debug_slowdown) {
2571 for (h=0; h<Debug_slowdown; h++)
2572 for (i=0; i<1000; i++)
2579 static int desc_dead_countdown=100; /* used if player shouldn't be playing */
2581 if (desc_id_exit_num) { // are we supposed to be checking
2582 if (!(--desc_dead_countdown)) {// if so, at zero, then pull the plug
2583 char time_str[32], time_str2[32];
2585 _ctime(&t_saved_time, time_str);
2586 _ctime(&t_current_time, time_str2);
2588 Error ("EXPIRES %s. YOUR TIME %s.\n", time_str, time_str2);
2589 Error ("Loading overlay -- error number: %d\n", (int)desc_id_exit_num);
2596 if (args_find("-invulnerability"))
2597 Players[Player_num].flags |= PLAYER_FLAGS_INVULNERABLE;
2601 update_player_stats();
2602 diminish_palette_towards_normal(); // Should leave palette effect up for as long as possible by putting right before render.
2603 do_afterburner_stuff();
2605 do_invulnerable_stuff();
2606 remove_obsolete_stuck_objects();
2608 do_final_boss_frame();
2609 // -- lightning_frame();
2610 // -- recharge_energy_frame();
2612 if ((Players[Player_num].flags & PLAYER_FLAGS_HEADLIGHT) && (Players[Player_num].flags & PLAYER_FLAGS_HEADLIGHT_ON)) {
2613 static int turned_off=0;
2614 Players[Player_num].energy -= (FrameTime*3/8);
2615 if (Players[Player_num].energy < i2f(10)) {
2617 Players[Player_num].flags &= ~PLAYER_FLAGS_HEADLIGHT_ON;
2620 if (Game_mode & GM_MULTI)
2621 multi_send_flags(Player_num);
2628 if (Players[Player_num].energy <= 0) {
2629 Players[Player_num].energy = 0;
2630 Players[Player_num].flags &= ~PLAYER_FLAGS_HEADLIGHT_ON;
2632 if (Game_mode & GM_MULTI)
2633 multi_send_flags(Player_num);
2640 check_create_player_path();
2641 player_follow_path(ConsoleObject);
2645 if (Game_mode & GM_MULTI)
2648 if (Netgame.PlayTimeAllowed && ThisLevelTime>=i2f((Netgame.PlayTimeAllowed*5*60)))
2649 multi_check_for_killgoal_winner();
2655 if (force_cockpit_redraw) { //screen need redrawing?
2657 force_cockpit_redraw=0;
2659 game_render_frame();
2660 //show_extra_views(); //missile view, buddy bot, etc.
2663 if (Saving_movie_frames)
2670 //mprintf(0,"Velocity %2.2f\n", f2fl(vm_vec_mag(&ConsoleObject->phys_info.velocity)));
2674 dead_player_frame();
2675 if (Newdemo_state != ND_STATE_PLAYBACK)
2676 do_controlcen_dead_frame();
2678 process_super_mines_frame();
2680 do_ambient_sounds();
2687 if (ReadControlsFlag)
2690 memset(&Controls, 0, sizeof(Controls));
2692 GameTime += FrameTime;
2694 if (f2i(GameTime)/10 != f2i(GameTime-FrameTime)/10)
2695 mprintf((0,"Gametime = %d secs\n",f2i(GameTime)));
2697 if (GameTime < 0 || GameTime > i2f(0x7fff - 600)) {
2698 GameTime = FrameTime; //wrap when goes negative, or gets within 10 minutes
2699 mprintf((0,"GameTime reset to 0\n"));
2703 if (args_find("-checktime") != 0)
2704 if (GameTime >= i2f(600)) //wrap after 10 minutes
2705 GameTime = FrameTime;
2709 if ((Game_mode & GM_MULTI) && Netgame.PlayTimeAllowed)
2710 ThisLevelTime +=FrameTime;
2715 if (Endlevel_sequence) {
2716 do_endlevel_frame();
2717 powerup_grab_cheat_all();
2718 do_special_effects();
2719 return; //skip everything else
2722 if (Newdemo_state != ND_STATE_PLAYBACK)
2723 do_exploding_wall_frame();
2724 if ((Newdemo_state != ND_STATE_PLAYBACK) || (Newdemo_vcr_state != ND_STATE_PAUSED)) {
2725 do_special_effects();
2726 wall_frame_process();
2727 triggers_frame_process();
2731 if (Control_center_destroyed) {
2732 if (Newdemo_state==ND_STATE_RECORDING )
2733 newdemo_record_control_center_destroyed();
2738 if ( Newdemo_state == ND_STATE_PLAYBACK ) {
2739 newdemo_playback_one_frame();
2740 if ( Newdemo_state != ND_STATE_PLAYBACK ) {
2741 longjmp( LeaveGame, 0 ); // Go back to menu
2744 { // Note the link to above!
2746 Players[Player_num].homing_object_dist = -1; // Assume not being tracked. Laser_do_weapon_sequence modifies this.
2749 powerup_grab_cheat_all();
2751 if (Endlevel_sequence) //might have been started during move
2754 fuelcen_update_all();
2758 if (allowed_to_fire_laser())
2759 FireLaser(); // Fire Laser!
2761 if (Auto_fire_fusion_cannon_time) {
2762 if (Primary_weapon != FUSION_INDEX)
2763 Auto_fire_fusion_cannon_time = 0;
2764 else if (GameTime + FrameTime/2 >= Auto_fire_fusion_cannon_time) {
2765 Auto_fire_fusion_cannon_time = 0;
2766 Global_laser_firing_count = 1;
2768 vms_vector rand_vec;
2771 Global_laser_firing_count = 0;
2773 ConsoleObject->mtype.phys_info.rotvel.x += (d_rand() - 16384)/8;
2774 ConsoleObject->mtype.phys_info.rotvel.z += (d_rand() - 16384)/8;
2775 make_random_vector(&rand_vec);
2777 bump_amount = F1_0*4;
2779 if (Fusion_charge > F1_0*2)
2780 bump_amount = Fusion_charge*4;
2782 bump_one_object(ConsoleObject, &rand_vec, bump_amount);
2786 if (Global_laser_firing_count) {
2787 // Don't cap here, gets capped in Laser_create_new and is based on whether in multiplayer mode, MK, 3/27/95
2788 // if (Fusion_charge > F1_0*2)
2789 // Fusion_charge = F1_0*2;
2790 Global_laser_firing_count -= do_laser_firing_player(); //do_laser_firing(Players[Player_num].objnum, Primary_weapon);
2793 if (Global_laser_firing_count < 0)
2794 Global_laser_firing_count = 0;
2797 if (Do_appearance_effect) {
2798 create_player_appearance_effect(ConsoleObject);
2799 Do_appearance_effect = 0;
2801 if ((Game_mode & GM_MULTI) && Netgame.invul)
2803 Players[Player_num].flags |= PLAYER_FLAGS_INVULNERABLE;
2804 Players[Player_num].invulnerable_time = GameTime-i2f(27);
2811 omega_charge_frame();
2815 //!!hoard_light_pulse(); //do cool hoard light pulsing
2819 //!!extern int Goal_blue_segnum,Goal_red_segnum;
2820 //!!extern int Hoard_goal_eclip;
2822 //!!//do cool pulsing lights in hoard goals
2823 //!!hoard_light_pulse()
2825 //!! if (Game_mode & GM_HOARD) {
2829 //!! frame = Effects[Hoard_goal_eclip].frame_count;
2833 //!! if (frame >= Effects[Hoard_goal_eclip].vc.num_frames)
2836 //!! light = abs(frame - 5) * f1_0 / 5;
2838 //!! Segment2s[Goal_red_segnum].static_light = Segment2s[Goal_blue_segnum].static_light = light;
2843 ubyte Slide_segs[MAX_SEGMENTS];
2844 int Slide_segs_computed;
2846 void compute_slide_segs(void)
2848 int segnum, sidenum;
2850 for (segnum=0;segnum<=Highest_segment_index;segnum++) {
2851 Slide_segs[segnum] = 0;
2852 for (sidenum=0;sidenum<6;sidenum++) {
2853 int tmn = Segments[segnum].sides[sidenum].tmap_num;
2854 if (TmapInfo[tmn].slide_u != 0 || TmapInfo[tmn].slide_v != 0)
2855 Slide_segs[segnum] |= 1 << sidenum;
2859 Slide_segs_computed = 1;
2862 // -----------------------------------------------------------------------------
2863 void slide_textures(void)
2865 int segnum,sidenum,i;
2867 if (!Slide_segs_computed)
2868 compute_slide_segs();
2870 for (segnum=0;segnum<=Highest_segment_index;segnum++) {
2871 if (Slide_segs[segnum]) {
2872 for (sidenum=0;sidenum<6;sidenum++) {
2873 if (Slide_segs[segnum] & (1 << sidenum)) {
2874 int tmn = Segments[segnum].sides[sidenum].tmap_num;
2875 if (TmapInfo[tmn].slide_u != 0 || TmapInfo[tmn].slide_v != 0) {
2877 Segments[segnum].sides[sidenum].uvls[i].u += fixmul(FrameTime,TmapInfo[tmn].slide_u<<8);
2878 Segments[segnum].sides[sidenum].uvls[i].v += fixmul(FrameTime,TmapInfo[tmn].slide_v<<8);
2879 if (Segments[segnum].sides[sidenum].uvls[i].u > f2_0) {
2882 Segments[segnum].sides[sidenum].uvls[j].u -= f1_0;
2884 if (Segments[segnum].sides[sidenum].uvls[i].v > f2_0) {
2887 Segments[segnum].sides[sidenum].uvls[j].v -= f1_0;
2889 if (Segments[segnum].sides[sidenum].uvls[i].u < -f2_0) {
2892 Segments[segnum].sides[sidenum].uvls[j].u += f1_0;
2894 if (Segments[segnum].sides[sidenum].uvls[i].v < -f2_0) {
2897 Segments[segnum].sides[sidenum].uvls[j].v += f1_0;
2907 flickering_light Flickering_lights[MAX_FLICKERING_LIGHTS];
2909 int Num_flickering_lights=0;
2911 void flicker_lights()
2914 flickering_light *f;
2916 f = Flickering_lights;
2918 for (l=0;l<Num_flickering_lights;l++,f++) {
2919 segment *segp = &Segments[f->segnum];
2921 //make sure this is actually a light
2922 if (! (WALL_IS_DOORWAY(segp, f->sidenum) & WID_RENDER_FLAG))
2924 if (! (TmapInfo[segp->sides[f->sidenum].tmap_num].lighting | TmapInfo[segp->sides[f->sidenum].tmap_num2 & 0x3fff].lighting))
2927 if (f->timer == 0x80000000) //disabled
2930 if ((f->timer -= FrameTime) < 0) {
2932 while (f->timer < 0)
2933 f->timer += f->delay;
2935 f->mask = ((f->mask&0x80000000)?1:0) + (f->mask<<1);
2938 add_light(f->segnum,f->sidenum);
2940 subtract_light(f->segnum,f->sidenum);
2945 //returns ptr to flickering light structure, or NULL if can't find
2946 flickering_light *find_flicker(int segnum,int sidenum)
2949 flickering_light *f;
2951 //see if there's already an entry for this seg/side
2953 f = Flickering_lights;
2955 for (l=0;l<Num_flickering_lights;l++,f++)
2956 if (f->segnum == segnum && f->sidenum == sidenum) //found it!
2962 //turn flickering off (because light has been turned off)
2963 void disable_flicker(int segnum,int sidenum)
2965 flickering_light *f;
2967 if ((f=find_flicker(segnum,sidenum)) != NULL)
2968 f->timer = 0x80000000;
2971 //turn flickering off (because light has been turned on)
2972 void enable_flicker(int segnum,int sidenum)
2974 flickering_light *f;
2976 if ((f=find_flicker(segnum,sidenum)) != NULL)
2983 //returns 1 if ok, 0 if error
2984 int add_flicker(int segnum,int sidenum,fix delay,ulong mask)
2987 flickering_light *f;
2989 mprintf((0,"add_flicker: %d:%d %x %x\n",segnum,sidenum,delay,mask));
2991 //see if there's already an entry for this seg/side
2993 f = Flickering_lights;
2995 for (l=0;l<Num_flickering_lights;l++,f++)
2996 if (f->segnum == segnum && f->sidenum == sidenum) //found it!
2999 if (mask==0) { //clearing entry
3000 if (l == Num_flickering_lights)
3004 for (i=l;i<Num_flickering_lights-1;i++)
3005 Flickering_lights[i] = Flickering_lights[i+1];
3006 Num_flickering_lights--;
3011 if (l == Num_flickering_lights)
3012 if (Num_flickering_lights == MAX_FLICKERING_LIGHTS)
3015 Num_flickering_lights++;
3018 f->sidenum = sidenum;
3019 f->delay = f->timer = delay;
3027 // -----------------------------------------------------------------------------
3028 // Fire Laser: Registers a laser fire, and performs special stuff for the fusion
3033 Global_laser_firing_count += Weapon_info[Primary_weapon_to_weapon_info[Primary_weapon]].fire_count * (Controls.fire_primary_state || Controls.fire_primary_down_count);
3035 if ((Primary_weapon == FUSION_INDEX) && (Global_laser_firing_count)) {
3036 if ((Players[Player_num].energy < F1_0*2) && (Auto_fire_fusion_cannon_time == 0)) {
3037 Global_laser_firing_count = 0;
3039 if (Fusion_charge == 0)
3040 Players[Player_num].energy -= F1_0*2;
3042 Fusion_charge += FrameTime;
3043 Players[Player_num].energy -= FrameTime;
3045 if (Players[Player_num].energy <= 0) {
3046 Players[Player_num].energy = 0;
3047 Auto_fire_fusion_cannon_time = GameTime -1; // Fire now!
3049 Auto_fire_fusion_cannon_time = GameTime + FrameTime/2 + 1;
3050 // Fire the fusion cannon at this time in the future.
3052 if (Fusion_charge < F1_0*2)
3053 PALETTE_FLASH_ADD(Fusion_charge >> 11, 0, Fusion_charge >> 11);
3055 PALETTE_FLASH_ADD(Fusion_charge >> 11, Fusion_charge >> 11, 0);
3057 if (GameTime < Fusion_last_sound_time) //gametime has wrapped
3058 Fusion_next_sound_time = Fusion_last_sound_time = GameTime;
3060 if (Fusion_next_sound_time < GameTime) {
3061 if (Fusion_charge > F1_0*2) {
3062 digi_play_sample( 11, F1_0 );
3063 apply_damage_to_player(ConsoleObject, ConsoleObject, d_rand() * 4);
3065 create_awareness_event(ConsoleObject, PA_WEAPON_ROBOT_COLLISION);
3066 digi_play_sample( SOUND_FUSION_WARMUP, F1_0 );
3068 if (Game_mode & GM_MULTI)
3069 multi_send_play_sound(SOUND_FUSION_WARMUP, F1_0);
3072 Fusion_last_sound_time = GameTime;
3073 Fusion_next_sound_time = GameTime + F1_0/8 + d_rand()/4;
3081 // -------------------------------------------------------------------------------------------------------
3082 // If player is close enough to objnum, which ought to be a powerup, pick it up!
3083 // This could easily be made difficulty level dependent.
3084 void powerup_grab_cheat(object *player, int objnum)
3090 Assert(Objects[objnum].type == OBJ_POWERUP);
3092 powerup_size = Objects[objnum].size;
3093 player_size = player->size;
3095 dist = vm_vec_dist_quick(&Objects[objnum].pos, &player->pos);
3097 if ((dist < 2*(powerup_size + player_size)) && !(Objects[objnum].flags & OF_SHOULD_BE_DEAD)) {
3098 vms_vector collision_point;
3100 vm_vec_avg(&collision_point, &Objects[objnum].pos, &player->pos);
3101 collide_player_and_powerup(player, &Objects[objnum], &collision_point);
3105 // -------------------------------------------------------------------------------------------------------
3106 // Make it easier to pick up powerups.
3107 // For all powerups in this segment, pick them up at up to twice pickuppable distance based on dot product
3108 // from player to powerup and player's forward vector.
3109 // This has the effect of picking them up more easily left/right and up/down, but not making them disappear
3110 // way before the player gets there.
3111 void powerup_grab_cheat_all(void)
3116 segp = &Segments[ConsoleObject->segnum];
3117 objnum = segp->objects;
3119 while (objnum != -1) {
3120 if (Objects[objnum].type == OBJ_POWERUP)
3121 powerup_grab_cheat(ConsoleObject, objnum);
3122 objnum = Objects[objnum].next;
3127 int Last_level_path_created = -1;
3129 #ifdef SHOW_EXIT_PATH
3131 // ------------------------------------------------------------------------------------------------------------------
3132 // Create path for player from current segment to goal segment.
3133 // Return true if path created, else return false.
3134 int mark_player_path_to_segment(int segnum)
3137 object *objp = ConsoleObject;
3138 short player_path_length=0;
3139 int player_hide_index=-1;
3141 if (Last_level_path_created == Current_level_num) {
3145 Last_level_path_created = Current_level_num;
3147 if (create_path_points(objp, objp->segnum, segnum, Point_segs_free_ptr, &player_path_length, 100, 0, 0, -1) == -1) {
3148 mprintf((0, "Unable to form path of length %i for myself\n", 100));
3152 player_hide_index = Point_segs_free_ptr - Point_segs;
3153 Point_segs_free_ptr += player_path_length;
3155 if (Point_segs_free_ptr - Point_segs + MAX_PATH_LENGTH*2 > MAX_POINT_SEGS) {
3156 mprintf((1, "Can't create path. Not enough point_segs.\n"));
3157 ai_reset_all_paths();
3161 for (i=1; i<player_path_length; i++) {
3163 vms_vector seg_center;
3166 segnum = Point_segs[player_hide_index+i].segnum;
3167 mprintf((0, "%3i ", segnum));
3168 seg_center = Point_segs[player_hide_index+i].point;
3170 objnum = obj_create( OBJ_POWERUP, POW_ENERGY, segnum, &seg_center, &vmd_identity_matrix, Powerup_info[POW_ENERGY].size, CT_POWERUP, MT_NONE, RT_POWERUP);
3172 Int3(); // Unable to drop energy powerup for path
3176 obj = &Objects[objnum];
3177 obj->rtype.vclip_info.vclip_num = Powerup_info[obj->id].vclip_num;
3178 obj->rtype.vclip_info.frametime = Vclip[obj->rtype.vclip_info.vclip_num].frame_time;
3179 obj->rtype.vclip_info.framenum = 0;
3180 obj->lifeleft = F1_0*100 + d_rand() * 4;
3187 // Return true if it happened, else return false.
3188 int create_special_path(void)
3192 // ---------- Find exit doors ----------
3193 for (i=0; i<=Highest_segment_index; i++)
3194 for (j=0; j<MAX_SIDES_PER_SEGMENT; j++)
3195 if (Segments[i].children[j] == -2) {
3196 mprintf((0, "Exit at segment %i\n", i));
3197 return mark_player_path_to_segment(i);
3207 int Max_obj_count_mike = 0;
3209 // Shows current number of used objects.
3210 void show_free_objects(void)
3212 if (!(FrameCount & 8)) {
3216 mprintf((0, "Highest_object_index = %3i, MAX_OBJECTS = %3i, now used = ", Highest_object_index, MAX_OBJECTS));
3218 for (i=0; i<=Highest_object_index; i++)
3219 if (Objects[i].type != OBJ_NONE)
3222 mprintf((0, "%3i", count));
3224 if (count > Max_obj_count_mike) {
3225 Max_obj_count_mike = count;
3226 mprintf((0, " ***"));
3237 void game_win_init_cockpit_mask(int sram)
3239 if (dd_VR_offscreen_buffer && dd_VR_offscreen_buffer != dd_grd_backcanv) {
3240 dd_gr_free_canvas(dd_VR_offscreen_buffer);
3243 if (GRMODEINFO(paged) && !GRMODEINFO(dbuf)) {
3244 // Here we will make the VR_offscreen_buffer the 2nd page and hopefully
3245 // we can just flip it, saving a blt.
3248 else if (GRMODEINFO(dbuf)||GRMODEINFO(emul)) {
3249 // The offscreen buffer will be created. We will just blt this
3250 // to the screen (which may be blted to the primary surface)
3251 if ( grd_curscreen->sc_h < 200 ) {
3252 dd_VR_offscreen_buffer = dd_gr_create_canvas(grd_curscreen->sc_w, 200);
3253 VR_offscreen_buffer = &dd_VR_offscreen_buffer->canvas;
3255 DDFreeSurface(dd_VR_offscreen_buffer->lpdds);
3256 dd_VR_offscreen_buffer->lpdds = DDCreateSysMemSurface(grd_curscreen->sc_w, 200);
3257 dd_VR_offscreen_buffer->sram = 1;
3261 dd_VR_offscreen_buffer = dd_gr_create_canvas(grd_curscreen->sc_w, grd_curscreen->sc_h);
3262 VR_offscreen_buffer = &dd_VR_offscreen_buffer->canvas;
3264 DDFreeSurface(dd_VR_offscreen_buffer->lpdds);
3265 dd_VR_offscreen_buffer->lpdds = DDCreateSysMemSurface(grd_curscreen->sc_w, grd_curscreen->sc_h);
3266 dd_VR_offscreen_buffer->sram = 1;
3271 dd_gr_init_sub_canvas( &dd_VR_render_buffer[0], dd_VR_offscreen_buffer, 0, 0, grd_curscreen->sc_w, grd_curscreen->sc_h );
3272 dd_gr_init_sub_canvas( &dd_VR_render_buffer[1], dd_VR_offscreen_buffer, 0, 0, grd_curscreen->sc_w, grd_curscreen->sc_h );
3273 gr_init_sub_canvas( &VR_render_buffer[0], VR_offscreen_buffer, 0, 0, grd_curscreen->sc_w, grd_curscreen->sc_h );
3274 gr_init_sub_canvas( &VR_render_buffer[1], VR_offscreen_buffer, 0, 0, grd_curscreen->sc_w, grd_curscreen->sc_h );
3276 game_init_render_sub_buffers( 0, 0, grd_curscreen->sc_w, grd_curscreen->sc_h );
3279 //@@void game_win_init_cockpit_mask()
3281 //@@ char title_pal[768];
3282 //@@ dd_grs_canvas ccanv;
3284 //@@ LPDIRECTDRAWSURFACE dds;
3286 //@@ dds = DDCreateSurface(GRMODEINFO(w), GRMODEINFO(h), 1);
3287 //@@ Assert(dds != NULL);
3289 //@@ _lpDDSMask = dds;
3290 //@@ ccanv.lpdds = dds;
3291 //@@ dd_gr_reinit_canvas(&ccanv);
3293 //@@ dd_gr_set_current_canvas(&ccanv);
3294 //@@ DDGRLOCK(dd_grd_curcanv)
3296 //@@ if (W95DisplayMode == SM95_640x480x8) {
3297 //@@ pcx_error=pcx_read_bitmap( "MASKB.PCX", &grd_curcanv->cv_bitmap,
3298 //@@ grd_curcanv->cv_bitmap.bm_type,
3302 //@@ pcx_error=pcx_read_bitmap( "MASK.PCX", &grd_curcanv->cv_bitmap,
3303 //@@ grd_curcanv->cv_bitmap.bm_type,
3307 //@@ DDGRUNLOCK(dd_grd_curcanv);
3309 //@@ Assert(pcx_error == PCX_ERROR_NONE);
3310 //@@ Game_cockpit_copy_code = (ubyte *)(0xABADC0DE);