int DosShell() { int ok, w, h; grs_bitmap * save_bitmap; ok = 1; // Save the current graphics state. w = grd_curscreen->sc_canvas.cv_bitmap.bm_w; h = grd_curscreen->sc_canvas.cv_bitmap.bm_h; save_bitmap = gr_create_bitmap( w, h ); gr_bm_ubitblt(w, h, 0, 0, 0, 0, &(grd_curscreen->sc_canvas.cv_bitmap), save_bitmap ); // gr_set_mode( SM_ORIGINAL ); fflush(stdout); key_close(); #ifdef __MSDOS__ ok = spawnl(P_WAIT,getenv("COMSPEC"), NULL ); #endif key_init(); gr_set_mode(grd_curscreen->sc_mode); gr_bm_ubitblt(w, h, 0, 0, 0, 0, save_bitmap, &(grd_curscreen->sc_canvas.cv_bitmap)); gr_free_bitmap( save_bitmap ); //gr_pal_setblock( 0, 256, grd_curscreen->pal ); //gr_use_palette_table(); return ok; }
int DosShell() { int ok, w, h; grs_bitmap * save_bitmap; // Save the current graphics state. w = grd_curscreen->sc_canvas.cv_bitmap.bm_w; h = grd_curscreen->sc_canvas.cv_bitmap.bm_h; save_bitmap = gr_create_bitmap( w, h ); gr_bm_ubitblt(w, h, 0, 0, 0, 0, &(grd_curscreen->sc_canvas.cv_bitmap), save_bitmap ); gr_restore_mode(); printf( "\n\nType EXIT to return to Inferno" ); fflush(stdout); key_close(); ok = spawnl(P_WAIT,getenv("COMSPEC"), NULL ); key_init(); gr_set_mode(grd_curscreen->sc_mode); gr_bm_ubitblt(w, h, 0, 0, 0, 0, save_bitmap, &(grd_curscreen->sc_canvas.cv_bitmap)); gr_free_bitmap( save_bitmap ); //gr_pal_setblock( 0, 256, grd_curscreen->pal ); //gr_use_palette_table(); return 1; }
int gr_init(int mode) { int retcode; // Only do this function once! if (gr_installed==1) return -1; MALLOC(grd_curscreen,grs_screen, 1); memset(grd_curscreen, 0, sizeof(grs_screen)); ggiInit(); screenvis = ggiOpen(NULL); if ((retcode=gr_set_mode(mode))) return retcode; grd_curscreen->sc_canvas.cv_color = 0; grd_curscreen->sc_canvas.cv_drawmode = 0; grd_curscreen->sc_canvas.cv_font = NULL; grd_curscreen->sc_canvas.cv_font_fg_color = 0; grd_curscreen->sc_canvas.cv_font_bg_color = 0; gr_set_current_canvas( &grd_curscreen->sc_canvas ); gr_installed = 1; atexit(gr_close); return 0; }
int gr_init(int mode) { int retcode; // Only do this function once! if (gr_installed==1) return -1; MALLOC( grd_curscreen,grs_screen,1 ); memset( grd_curscreen, 0, sizeof(grs_screen)); //added 10/05/98 by Matt Mueller - make fullscreen mode optional if (FindArg("-fullscreen")) sdl_video_flags|=SDL_FULLSCREEN; //end addition -MM //added 05/19/99 Matt Mueller - make HW surface optional if (FindArg("-hwsurface")) sdl_video_flags|=SDL_HWSURFACE; //end addition -MM if (FindArg("-nosdlvidmodecheck")) checkvidmodeok=0; // Set the mode. if ((retcode=gr_set_mode(mode))) { return retcode; } grd_curscreen->sc_canvas.cv_color = 0; grd_curscreen->sc_canvas.cv_drawmode = 0; grd_curscreen->sc_canvas.cv_font = NULL; grd_curscreen->sc_canvas.cv_font_fg_color = 0; grd_curscreen->sc_canvas.cv_font_bg_color = 0; gr_set_current_canvas( &grd_curscreen->sc_canvas ); gr_installed = 1; // added on 980913 by adb to add cleanup atexit(gr_close); // end changes by adb return 0; }
static int main(int argc, char *argv[]) { if (!PHYSFSX_init(argc, argv)) return 1; con_init(); // Initialise the console setbuf(stdout, NULL); // unbuffered output via printf #ifdef _WIN32 freopen( "CON", "w", stdout ); freopen( "CON", "w", stderr ); #endif if (CGameArg.SysShowCmdHelp) { print_commandline_help(); return(0); } printf("\nType '%s -help' for a list of command-line options.\n\n", PROGNAME); PHYSFSX_listSearchPathContent(); if (!PHYSFSX_checkSupportedArchiveTypes()) return(0); #if defined(DXX_BUILD_DESCENT_I) if (! PHYSFSX_contfile_init("descent.hog", 1)) #define DXX_NAME_NUMBER "1" #define DXX_HOGFILE_NAMES "descent.hog" #elif defined(DXX_BUILD_DESCENT_II) if (! PHYSFSX_contfile_init("descent2.hog", 1) && ! PHYSFSX_contfile_init("d2demo.hog", 1)) #define DXX_NAME_NUMBER "2" #define DXX_HOGFILE_NAMES "descent2.hog or d2demo.hog" #endif { #if defined(__unix__) && !defined(__APPLE__) #define DXX_HOGFILE_PROGRAM_DATA_DIRECTORY \ "\t$HOME/.d" DXX_NAME_NUMBER "x-rebirth\n" \ "\t" SHAREPATH "\n" #else #define DXX_HOGFILE_PROGRAM_DATA_DIRECTORY \ "\tDirectory containing D" DXX_NAME_NUMBER "X\n" #endif #if (defined(__APPLE__) && defined(__MACH__)) || defined(macintosh) #define DXX_HOGFILE_APPLICATION_BUNDLE \ "\tIn 'Resources' inside the application bundle\n" #else #define DXX_HOGFILE_APPLICATION_BUNDLE "" #endif #define DXX_MISSING_HOGFILE_ERROR_TEXT \ "Could not find a valid hog file (" DXX_HOGFILE_NAMES ")\nPossible locations are:\n" \ DXX_HOGFILE_PROGRAM_DATA_DIRECTORY \ "\tIn a subdirectory called 'Data'\n" \ DXX_HOGFILE_APPLICATION_BUNDLE \ "Or use the -hogdir option to specify an alternate location." UserError(DXX_MISSING_HOGFILE_ERROR_TEXT); } #if defined(DXX_BUILD_DESCENT_I) switch (PHYSFSX_fsize("descent.hog")) { case D1_MAC_SHARE_MISSION_HOGSIZE: case D1_MAC_MISSION_HOGSIZE: MacHog = 1; // used for fonts and the Automap break; } #endif load_text(); //print out the banner title #if defined(DXX_BUILD_DESCENT_I) con_printf(CON_NORMAL, "%s %s", DESCENT_VERSION, g_descent_build_datetime); // D1X version con_printf(CON_NORMAL, "This is a MODIFIED version of Descent, based on %s.", BASED_VERSION); con_printf(CON_NORMAL, "%s\n%s",TXT_COPYRIGHT,TXT_TRADEMARK); con_printf(CON_NORMAL, "Copyright (C) 2005-2013 Christian Beckhaeuser"); #elif defined(DXX_BUILD_DESCENT_II) con_printf(CON_NORMAL, "%s%s %s", DESCENT_VERSION, PHYSFSX_exists(MISSION_DIR "d2x.hog",1) ? " Vertigo Enhanced" : "", g_descent_build_datetime); // D2X version con_printf(CON_NORMAL, "This is a MODIFIED version of Descent 2, based on %s.", BASED_VERSION); con_printf(CON_NORMAL, "%s\n%s",TXT_COPYRIGHT,TXT_TRADEMARK); con_printf(CON_NORMAL, "Copyright (C) 1999 Peter Hawkins, 2002 Bradley Bell, 2005-2013 Christian Beckhaeuser"); #endif if (CGameArg.DbgVerbose) con_puts(CON_VERBOSE, TXT_VERBOSE_1); ReadConfigFile(); PHYSFSX_addArchiveContent(); arch_init(); select_tmap(CGameArg.DbgTexMap); #if defined(DXX_BUILD_DESCENT_II) Lighting_on = 1; #endif con_printf(CON_VERBOSE, "Going into graphics mode..."); gr_set_mode(Game_screen_mode); // Load the palette stuff. Returns non-zero if error. con_printf(CON_DEBUG, "Initializing palette system..." ); #if defined(DXX_BUILD_DESCENT_I) gr_use_palette_table( "PALETTE.256" ); #elif defined(DXX_BUILD_DESCENT_II) gr_use_palette_table(D2_DEFAULT_PALETTE ); #endif con_printf(CON_DEBUG, "Initializing font system..." ); gamefont_init(); // must load after palette data loaded. #if defined(DXX_BUILD_DESCENT_II) con_printf( CON_DEBUG, "Initializing movie libraries..." ); init_movies(); //init movie libraries #endif show_titles(); set_screen_mode(SCREEN_MENU); #ifdef DEBUG_MEMORY_ALLOCATIONS /* Memdebug runs before global destructors, so it incorrectly * reports as leaked any allocations that would be freed by a global * destructor. This local will force the newmenu globals to be * reset before memdebug scans, which prevents memdebug falsely * reporting them as leaked. * * External tools, such as Valgrind, know to run global destructors * before checking for leaks, so this hack is only necessary when * memdebug is used. */ struct hack_free_global_backgrounds { ~hack_free_global_backgrounds() { newmenu_free_background(); } }; hack_free_global_backgrounds hack_free_global_background; #endif con_printf( CON_DEBUG, "\nDoing gamedata_init..." ); gamedata_init(); #if defined(DXX_BUILD_DESCENT_II) #if DXX_USE_EDITOR if (GameArg.EdiSaveHoardData) { save_hoard_data(); exit(1); } #endif #endif if (CGameArg.DbgNoRun) return(0); con_printf( CON_DEBUG, "\nInitializing texture caching system..." ); texmerge_init(); // 10 cache bitmaps #if defined(DXX_BUILD_DESCENT_II) piggy_init_pigfile("groupa.pig"); //get correct pigfile #endif con_printf( CON_DEBUG, "\nRunning game..." ); init_game(); get_local_player().callsign = {}; #if defined(DXX_BUILD_DESCENT_I) key_flush(); #elif defined(DXX_BUILD_DESCENT_II) // If built with editor, option to auto-load a level and quit game // to write certain data. #ifdef EDITOR if (!GameArg.EdiAutoLoad.empty()) { Players[0].callsign = "dummy"; } else #endif #endif { if (!CGameArg.SysPilot.empty()) { char filename[sizeof(PLAYER_DIRECTORY_TEXT) + CALLSIGN_LEN + 4]; /* Step over the literal PLAYER_DIRECTORY_TEXT when it is * present. Point at &filename[0] when * PLAYER_DIRECTORY_TEXT is absent. */ const auto b = &filename[-CGameArg.SysUsePlayersDir]; snprintf(filename, sizeof(filename), PLAYER_DIRECTORY_STRING("%.12s"), CGameArg.SysPilot.c_str()); /* The pilot name is never used after this. Clear it to * free the allocated memory, if any. */ CGameArg.SysPilot.clear(); auto p = b; for (const auto &facet = std::use_facet<std::ctype<char>>(std::locale::classic()); char &c = *p; ++p) { c = facet.tolower(static_cast<uint8_t>(c)); } auto j = p - filename; if (j < sizeof(filename) - 4 && (j <= 4 || strcmp(&filename[j - 4], ".plr"))) // if player hasn't specified .plr extension in argument, add it { strcpy(&filename[j], ".plr"); j += 4; } if(PHYSFSX_exists(filename,0)) { get_local_player().callsign.copy(b, std::distance(b, &filename[j - 4])); read_player_file(); WriteConfigFile(); } } } #if defined(DXX_BUILD_DESCENT_II) #if DXX_USE_EDITOR if (!GameArg.EdiAutoLoad.empty()) { /* Any number >= FILENAME_LEN works */ Level_names[0].copy_if(GameArg.EdiAutoLoad.c_str(), GameArg.EdiAutoLoad.size()); LoadLevel(1, 1); } else #endif #endif { Game_mode = GM_GAME_OVER; DoMenu(); } while (window_get_front()) // Send events to windows and the default handler event_process(); // Tidy up - avoids a crash on exit { window *wind; show_menus(); while ((wind = window_get_front())) window_close(wind); } WriteConfigFile(); show_order_form(); con_printf( CON_DEBUG, "\nCleanup..." ); close_game(); texmerge_close(); gamedata_close(); gamefont_close(); Current_mission.reset(); PHYSFSX_removeArchiveContent(); return(0); //presumably successful exit }
void modex_print_message(int x, int y, char *str) { #ifndef AUTOMAP_DIRECT_RENDER #ifndef AUTOMAP_NO_PAGING int i; for (i=0; i<2; i++ ) { gr_set_current_canvas(&Pages[i]); #else { gr_set_current_canvas(OffscreenPage); #endif #endif modex_printf(x, y, str, GFONT_MEDIUM_1); #ifndef AUTOMAP_DIRECT_RENDER } gr_set_current_canvas(&DrawingPages[current_page]); #endif } extern void GameLoop(int, int ); extern int set_segment_depths(int start_seg, ubyte *segbuf); u_int32_t automap_mode = SM(640,480); int automap_width = 640; int automap_height = 480; int automap_use_game_res=0; int nice_automap=0; void do_automap( int key_code ) { int done=0; vms_matrix tempm; vms_angvec tangles; int leave_mode=0; int first_time=1; // int pcx_error; int c; // char filename[] = "MAP.PCX"; fix entry_time; int pause_game=1; // Set to 1 if everything is paused during automap...No pause during net. fix t1, t2; control_info saved_control_info; grs_bitmap Automap_background; int Max_segments_away = 0; int SegmentLimit = 1; //added on 10/28/98 by adb to fix compile versions #if !defined (NDEBUG) || (!defined(AUTOMAP_NO_PAGING) && !defined(AUTOMAP_DIRECT_RENDER)) int i; #endif key_code = key_code; // disable warning... if ((Game_mode & GM_MULTI) && (Function_mode == FMODE_GAME) && (!Endlevel_sequence)) pause_game = 0; if (pause_game) stop_time(); create_name_canv(); Max_edges = min(MAX_EDGES_FROM_VERTS(Num_vertices),MAX_EDGES); //make maybe smaller than max //Edges = malloc( sizeof(Edge_info)*Max_edges); //if ( Edges == NULL ) { // mprintf((0, "Couldn't get %dK for automap!", sizeof(Edge_info)*Max_edges/1024)); // return; //} //DrawingListBright = malloc( sizeof(short)*Max_edges); //if ( DrawingListBright == NULL ) { // mprintf((0, "Couldn't get %dK for automap!", sizeof(short)*Max_edges/1024)); // return; //} mprintf( (0, "Num_vertices=%d, Max_edges=%d, (MAX:%d)\n", Num_vertices, Max_edges, MAX_EDGES )); mprintf( (0, "Allocated %d K for automap edge list\n", (sizeof(Edge_info)+sizeof(short))*Max_edges/1024 )); //edit 4/23/99 Matt Mueller - don't switch res unless we need to if (grd_curscreen->sc_mode != AUTOMAP_MODE) gr_set_mode( AUTOMAP_MODE ); else gr_set_current_canvas(NULL); //end edit -MM automap_width=grd_curscreen->sc_canvas.cv_bitmap.bm_w; automap_height=grd_curscreen->sc_canvas.cv_bitmap.bm_h; gr_palette_clear(); #ifndef AUTOMAP_DIRECT_RENDER gr_init_sub_canvas(&Pages[0],grd_curcanv,0,0,automap_width,automap_height); #ifndef AUTOMAP_NO_PAGING // NOTICE: should be 0,401! FIXME! gr_init_sub_canvas(&Pages[1],grd_curcanv,0,0,automap_width,automap_height); gr_init_sub_canvas(&DrawingPages[0],&Pages[0],0,0,automap_width,automap_height); gr_init_sub_canvas(&DrawingPages[1],&Pages[1],0,0,automap_width,automap_height); #else OffscreenPage = gr_create_canvas( automap_width,automap_height ); if (!OffscreenPage) { nm_messagebox("No memory for automap", 1, "Ok"); return; } gr_init_sub_canvas(&DrawingPages[0],OffscreenPage,0,0,automap_width,automap_height); #endif #endif gr_init_bitmap_data (&Automap_background); // pcx_error = pcx_read_bitmap(filename,&Automap_background,BM_LINEAR,NULL); // if ( pcx_error != PCX_ERROR_NONE ) { // printf("File %s - PCX error: %s",filename,pcx_errormsg(pcx_error)); // Error("File %s - PCX error: %s",filename,pcx_errormsg(pcx_error)); // return; // } #ifndef AUTOMAP_DIRECT_RENDER #ifndef AUTOMAP_NO_PAGING for (i=0; i<2; i++ ) { gr_set_current_canvas(&Pages[i]); #else { gr_set_current_canvas(OffscreenPage); #endif // gr_bitmap( 0, 0, &Automap_background ); // modex_printf( 40, 22,TXT_AUTOMAP,GFONT_BIG_1); // modex_printf( 70,353,TXT_TURN_SHIP,GFONT_SMALL); // modex_printf( 70,369,TXT_SLIDE_UPDOWN,GFONT_SMALL); // modex_printf( 70,385,TXT_VIEWING_DISTANCE,GFONT_SMALL); } #ifdef AUTOMAP_NO_PAGING //killed 05/17/99 Matt Mueller - this seems to merely copy undefined bytes around.. not needed //--killed-- gr_bm_ubitblt(automap_width,automap_height, 0, 0, 0, 0, &OffscreenPage->cv_bitmap,&Pages[0].cv_bitmap); //end kill -MM #endif gr_free_bitmap_data (&Automap_background); gr_set_current_canvas(&DrawingPages[current_page]); #endif automap_build_edge_list(); if ( ViewDist==0 ) ViewDist = ZOOM_DEFAULT; ViewMatrix = Objects[Players[Player_num].objnum].orient; tangles.p = PITCH_DEFAULT; tangles.h = 0; tangles.b = 0; done = 0; view_target = Objects[Players[Player_num].objnum].pos; t1 = entry_time = timer_get_fixed_seconds(); t2 = t1; //Fill in Automap_visited from Objects[Players[Player_num].objnum].segnum Max_segments_away = set_segment_depths(Objects[Players[Player_num].objnum].segnum, Automap_visited); SegmentLimit = Max_segments_away; adjust_segment_limit(SegmentLimit); while(!done) { if ( leave_mode==0 && Controls.automap_state && (timer_get_fixed_seconds()-entry_time)>LEAVE_TIME) leave_mode = 1; if ( !Controls.automap_state && (leave_mode==1) ) done=1; if (!pause_game) { ushort old_wiggle; saved_control_info = Controls; // Save controls so we can zero them memset(&Controls,0,sizeof(control_info)); // Clear everything... old_wiggle = ConsoleObject->mtype.phys_info.flags & PF_WIGGLE; // Save old wiggle ConsoleObject->mtype.phys_info.flags &= ~PF_WIGGLE; // Turn off wiggle #ifdef NETWORK if (multi_menu_poll()) done = 1; #endif // GameLoop( 0, 0 ); // Do game loop with no rendering and no reading controls. ConsoleObject->mtype.phys_info.flags |= old_wiggle; // Restore wiggle Controls = saved_control_info; } controls_read_all(); if ( Controls.automap_down_count ) { if (leave_mode==0) done = 1; c = 0; } while( (c=key_inkey()) ) { switch( c ) { #ifndef NDEBUG case KEY_BACKSP: Int3(); break; #endif case KEY_PRINT_SCREEN: save_screen_shot(1); break; case KEY_ESC: if (leave_mode==0) done = 1; break; case KEY_ALTED+KEY_F: // Alt+F shows full map, if cheats enabled if (Cheats_enabled) { uint t; t = Players[Player_num].flags; Players[Player_num].flags |= PLAYER_FLAGS_MAP_ALL_CHEAT; automap_build_edge_list(); Players[Player_num].flags=t; } break; #ifndef NDEBUG case KEY_DEBUGGED+KEY_F: { for (i=0; i<=Highest_segment_index; i++ ) Automap_visited[i] = 1; automap_build_edge_list(); Max_segments_away = set_segment_depths(Objects[Players[Player_num].objnum].segnum, Automap_visited); SegmentLimit = Max_segments_away; adjust_segment_limit(SegmentLimit); } break; #endif case KEY_MINUS: if (SegmentLimit > 1) { SegmentLimit--; adjust_segment_limit(SegmentLimit); } break; case KEY_EQUAL: if (SegmentLimit < Max_segments_away) { SegmentLimit++; adjust_segment_limit(SegmentLimit); } break; } } if ( Controls.fire_primary_down_count ) { // Reset orientation ViewDist = ZOOM_DEFAULT; tangles.p = PITCH_DEFAULT; tangles.h = 0; tangles.b = 0; view_target = Objects[Players[Player_num].objnum].pos; } ViewDist -= Controls.forward_thrust_time*ZOOM_SPEED_FACTOR; tangles.p += fixdiv( Controls.pitch_time, ROT_SPEED_DIVISOR ); tangles.h += fixdiv( Controls.heading_time, ROT_SPEED_DIVISOR ); tangles.b += fixdiv( Controls.bank_time, ROT_SPEED_DIVISOR*2 ); if ( Controls.vertical_thrust_time || Controls.sideways_thrust_time ) { vms_angvec tangles1; vms_vector old_vt; old_vt = view_target; tangles1 = tangles; vm_angles_2_matrix(&tempm,&tangles1); vm_matrix_x_matrix(&ViewMatrix,&Objects[Players[Player_num].objnum].orient,&tempm); vm_vec_scale_add2( &view_target, &ViewMatrix.uvec, Controls.vertical_thrust_time*SLIDE_SPEED ); vm_vec_scale_add2( &view_target, &ViewMatrix.rvec, Controls.sideways_thrust_time*SLIDE_SPEED ); if ( vm_vec_dist_quick( &view_target, &Objects[Players[Player_num].objnum].pos) > i2f(1000) ) { view_target = old_vt; } } vm_angles_2_matrix(&tempm,&tangles); vm_matrix_x_matrix(&ViewMatrix,&Objects[Players[Player_num].objnum].orient,&tempm); if ( ViewDist < ZOOM_MIN_VALUE ) ViewDist = ZOOM_MIN_VALUE; if ( ViewDist > ZOOM_MAX_VALUE ) ViewDist = ZOOM_MAX_VALUE; draw_automap(); if ( first_time ) { first_time = 0; gr_palette_load( gr_palette ); } t2 = timer_get_fixed_seconds(); while (t2-t1<F1_0/100){//ogl is fast enough that the automap can read the input too fast and you start to turn really slow. So delay a bit (and free up some cpu :) if (nice_automap) d_delay(1); t2 = timer_get_fixed_seconds(); } if (pause_game) FrameTime=t2-t1; t1 = t2; } //free(Edges); //free(DrawingListBright); gr_free_canvas(name_canv); name_canv=NULL; #ifdef AUTOMAP_NO_PAGING gr_free_canvas(OffscreenPage); OffscreenPage = NULL; #endif mprintf( (0, "Automap memory freed\n" )); game_flush_inputs(); if (pause_game) start_time(); } void adjust_segment_limit(int SegmentLimit) { int i,e1; Edge_info * e; mprintf(( 0, "Seglimit: %d\n", SegmentLimit )); for (i=0; i<=Highest_edge_index; i++ ) { e = &Edges[i]; e->flags |= EF_TOO_FAR; for (e1=0; e1<e->num_faces; e1++ ) { if ( Automap_visited[e->segnum[e1]] <= SegmentLimit ) { e->flags &= (~EF_TOO_FAR); break; } } } }
int main(int argc, char *argv[]) { mem_init(); #ifdef __LINUX__ error_init(NULL); #else error_init(msgbox_error); set_warn_func(msgbox_warning); #endif PHYSFSX_init(argc, argv); con_init(); // Initialise the console setbuf(stdout, NULL); // unbuffered output via printf #ifdef _WIN32 freopen( "CON", "w", stdout ); freopen( "CON", "w", stderr ); #endif if (GameArg.SysShowCmdHelp) { print_commandline_help(); return(0); } printf("\nType %s -help' for a list of command-line options.\n\n", PROGNAME); PHYSFSX_listSearchPathContent(); if (!PHYSFSX_checkSupportedArchiveTypes()) return(0); if (! PHYSFSX_contfile_init("descent2.hog", 1)) { if (! PHYSFSX_contfile_init("d2demo.hog", 1)) #define DXX_NAME_NUMBER "2" #define DXX_HOGFILE_NAMES "descent2.hog or d2demo.hog" #if defined(__unix__) && !defined(__APPLE__) #define DXX_HOGFILE_PROGRAM_DATA_DIRECTORY \ "\t$HOME/.d" DXX_NAME_NUMBER "x-rebirth\n" \ "\t" SHAREPATH "\n" #else #define DXX_HOGFILE_PROGRAM_DATA_DIRECTORY \ "\tDirectory containing D" DXX_NAME_NUMBER "X\n" #endif #if (defined(__APPLE__) && defined(__MACH__)) || defined(macintosh) #define DXX_HOGFILE_APPLICATION_BUNDLE \ "\tIn 'Resources' inside the application bundle\n" #else #define DXX_HOGFILE_APPLICATION_BUNDLE "" #endif #define DXX_MISSING_HOGFILE_ERROR_TEXT \ "Could not find a valid hog file (" DXX_HOGFILE_NAMES ")\nPossible locations are:\n" \ DXX_HOGFILE_PROGRAM_DATA_DIRECTORY \ "\tIn a subdirectory called 'Data'\n" \ DXX_HOGFILE_APPLICATION_BUNDLE \ "Or use the -hogdir option to specify an alternate location." Error(DXX_MISSING_HOGFILE_ERROR_TEXT); } load_text(); //print out the banner title con_printf(CON_NORMAL, "%s%s %s\n", DESCENT_VERSION, PHYSFSX_exists(MISSION_DIR "d2x.hog",1) ? " Vertigo Enhanced" : "", g_descent_build_datetime); // D2X version con_printf(CON_NORMAL, "This is a MODIFIED version of Descent 2, based on %s.\n", BASED_VERSION); con_printf(CON_NORMAL, "%s\n%s\n",TXT_COPYRIGHT,TXT_TRADEMARK); con_printf(CON_NORMAL, "Copyright (C) 1999 Peter Hawkins, 2002 Bradley Bell, 2005-2011 Christian Beckhaeuser\n\n"); if (GameArg.DbgVerbose) con_printf(CON_VERBOSE,"%s%s", TXT_VERBOSE_1, "\n"); ReadConfigFile(); PHYSFSX_addArchiveContent(); arch_init(); select_tmap(GameArg.DbgTexMap); Lighting_on = 1; con_printf(CON_VERBOSE, "Going into graphics mode...\n"); gr_set_mode(Game_screen_mode); // Load the palette stuff. Returns non-zero if error. con_printf(CON_DEBUG, "Initializing palette system...\n" ); gr_use_palette_table(D2_DEFAULT_PALETTE ); con_printf(CON_DEBUG, "Initializing font system...\n" ); gamefont_init(); // must load after palette data loaded. set_default_handler(standard_handler); con_printf( CON_DEBUG, "Initializing movie libraries...\n" ); init_movies(); //init movie libraries show_titles(); set_screen_mode(SCREEN_MENU); con_printf( CON_DEBUG, "\nDoing gamedata_init..." ); gamedata_init(); #ifdef EDITOR if (GameArg.EdiSaveHoardData) { save_hoard_data(); exit(1); } #endif if (GameArg.DbgNoRun) return(0); con_printf( CON_DEBUG, "\nInitializing texture caching system..." ); texmerge_init( 10 ); // 10 cache bitmaps piggy_init_pigfile("groupa.pig"); //get correct pigfile con_printf( CON_DEBUG, "\nRunning game...\n" ); init_game(); Players[Player_num].callsign[0] = '\0'; // If built with editor, option to auto-load a level and quit game // to write certain data. #ifdef EDITOR if (GameArg.EdiAutoLoad) { strcpy(Auto_file, GameArg.EdiAutoLoad); strcpy(Players[0].callsign, "dummy"); } else #endif { if(GameArg.SysPilot) { char filename[32] = ""; int j; if (GameArg.SysUsePlayersDir) strcpy(filename, "Players/"); strncat(filename, GameArg.SysPilot, 12); filename[8 + 12] = '\0'; // unfortunately strncat doesn't put the terminating 0 on the end if it reaches 'n' for (j = GameArg.SysUsePlayersDir? 8 : 0; filename[j] != '\0'; j++) { switch (filename[j]) { case ' ': filename[j] = '\0'; } } if(!strstr(filename,".plr")) // if player hasn't specified .plr extension in argument, add it strcat(filename,".plr"); if(PHYSFSX_exists(filename,0)) { strcpy(strstr(filename,".plr"),"\0"); strcpy(Players[Player_num].callsign, GameArg.SysUsePlayersDir? &filename[8] : filename); read_player_file(); WriteConfigFile(); } } } #ifdef EDITOR if (GameArg.EdiAutoLoad) { strcpy((char *)&Level_names[0], Auto_file); LoadLevel(1, 1); } else #endif { Game_mode = GM_GAME_OVER; DoMenu(); } setjmp(LeaveEvents); while (window_get_front()) // Send events to windows and the default handler event_process(); // Tidy up - avoids a crash on exit { window *wind; show_menus(); while ((wind = window_get_front())) window_close(wind); } WriteConfigFile(); show_order_form(); con_printf( CON_DEBUG, "\nCleanup...\n" ); close_game(); texmerge_close(); gamedata_close(); gamefont_close(); free_text(); args_exit(); newmenu_free_background(); free_mission(); PHYSFSX_removeArchiveContent(); return(0); //presumably successful exit }
int gr_init(int mode) { #ifdef RPI char sdl_driver[32]; char *sdl_driver_ret; #endif int retcode; // Only do this function once! if (gr_installed==1) return -1; #ifdef RPI // Initialize the broadcom host library // we have to call this before we can create an OpenGL ES context bcm_host_init(); // Check if we are running with SDL directfb driver ... sdl_driver_ret=SDL_VideoDriverName(sdl_driver,32); if (sdl_driver_ret) { if (strcmp(sdl_driver_ret,"x11")) { con_printf(CON_URGENT,"RPi: activating hack for console driver\n"); sdl_no_modeswitch=1; } } #endif #ifdef _WIN32 ogl_init_load_library(); #endif if (!GameCfg.WindowMode && !GameArg.SysWindow) sdl_video_flags|=SDL_FULLSCREEN; if (GameArg.SysNoBorders) sdl_video_flags|=SDL_NOFRAME; gr_set_attributes(); ogl_init_texture_list_internal(); CALLOC( grd_curscreen,grs_screen,1 ); grd_curscreen->sc_canvas.cv_bitmap.bm_data = NULL; // Set the mode. if ((retcode=gr_set_mode(mode))) return retcode; grd_curscreen->sc_canvas.cv_color = 0; grd_curscreen->sc_canvas.cv_fade_level = GR_FADE_OFF; grd_curscreen->sc_canvas.cv_blend_func = GR_BLEND_NORMAL; grd_curscreen->sc_canvas.cv_drawmode = 0; grd_curscreen->sc_canvas.cv_font = NULL; grd_curscreen->sc_canvas.cv_font_fg_color = 0; grd_curscreen->sc_canvas.cv_font_bg_color = 0; gr_set_current_canvas( &grd_curscreen->sc_canvas ); ogl_init_pixel_buffers(256, 128); // for gamefont_init gr_installed = 1; return 0; }
int main(int argc, char *argv[]) { mem_init(); #ifdef __LINUX__ error_init(NULL, NULL); #else error_init(msgbox_error, NULL); set_warn_func(msgbox_warning); #endif PHYSFSX_init(argc, argv); con_init(); // Initialise the console setbuf(stdout, NULL); // unbuffered output via printf #ifdef _WIN32 freopen( "CON", "w", stdout ); freopen( "CON", "w", stderr ); #endif if (GameArg.SysShowCmdHelp) { print_commandline_help(); set_exit_message(""); return(0); } printf("\nType %s -help' for a list of command-line options.\n\n", PROGNAME); PHYSFSX_listSearchPathContent(); if (!PHYSFSX_checkSupportedArchiveTypes()) return(0); if (! PHYSFSX_contfile_init("descent.hog", 1)) Error("Could not find a valid hog file (descent.hog)\nPossible locations are:\n" #if defined(__unix__) && !defined(__APPLE__) "\t$HOME/.d1x-rebirth\n" "\t" SHAREPATH "\n" #else "\tDirectory containing D1X\n" #endif "\tIn a subdirectory called 'Data'\n" #if (defined(__APPLE__) && defined(__MACH__)) || defined(macintosh) "\tIn 'Resources' inside the application bundle\n" #endif "Or use the -hogdir option to specify an alternate location."); switch (PHYSFSX_fsize("descent.hog")) { case D1_MAC_SHARE_MISSION_HOGSIZE: case D1_MAC_MISSION_HOGSIZE: MacHog = 1; // used for fonts and the Automap break; } load_text(); //print out the banner title con_printf(CON_NORMAL, "%s", DESCENT_VERSION); // D1X version con_printf(CON_NORMAL, " %s %s\n", __DATE__,__TIME__); con_printf(CON_NORMAL, "This is a MODIFIED version of Descent, based on %s.\n", BASED_VERSION); con_printf(CON_NORMAL, "%s\n%s\n",TXT_COPYRIGHT,TXT_TRADEMARK); con_printf(CON_NORMAL, "Copyright (C) 2005-2011 Christian Beckhaeuser\n\n"); if (GameArg.DbgVerbose) con_printf(CON_VERBOSE,"%s%s", TXT_VERBOSE_1, "\n"); ReadConfigFile(); PHYSFSX_addArchiveContent(); arch_init(); select_tmap(GameArg.DbgTexMap); con_printf(CON_VERBOSE, "Going into graphics mode...\n"); gr_set_mode(Game_screen_mode); // Load the palette stuff. Returns non-zero if error. con_printf(CON_DEBUG, "Initializing palette system...\n" ); gr_use_palette_table( "PALETTE.256" ); con_printf(CON_DEBUG, "Initializing font system...\n" ); gamefont_init(); // must load after palette data loaded. set_default_handler(standard_handler); show_titles(); set_screen_mode(SCREEN_MENU); con_printf( CON_DEBUG, "\nDoing gamedata_init..." ); gamedata_init(); if (GameArg.DbgNoRun) return(0); con_printf( CON_DEBUG, "\nInitializing texture caching system..." ); texmerge_init( 10 ); // 10 cache bitmaps con_printf( CON_DEBUG, "\nRunning game...\n" ); init_game(); Players[Player_num].callsign[0] = '\0'; key_flush(); if(GameArg.SysPilot) { char filename[32] = ""; int j; if (GameArg.SysUsePlayersDir) strcpy(filename, "Players/"); strncat(filename, GameArg.SysPilot, 12); filename[8 + 12] = '\0'; // unfortunately strncat doesn't put the terminating 0 on the end if it reaches 'n' for (j = GameArg.SysUsePlayersDir? 8 : 0; filename[j] != '\0'; j++) { switch (filename[j]) { case ' ': filename[j] = '\0'; } } if(!strstr(filename,".plr")) // if player hasn't specified .plr extension in argument, add it strcat(filename,".plr"); if(PHYSFSX_exists(filename,0)) { strcpy(strstr(filename,".plr"),"\0"); strcpy(Players[Player_num].callsign, GameArg.SysUsePlayersDir? &filename[8] : filename); read_player_file(); WriteConfigFile(); } } Game_mode = GM_GAME_OVER; DoMenu(); setjmp(LeaveEvents); while (window_get_front()) // Send events to windows and the default handler event_process(); // Tidy up - avoids a crash on exit { window *wind; show_menus(); while ((wind = window_get_front())) window_close(wind); } WriteConfigFile(); show_order_form(); con_printf( CON_DEBUG, "\nCleanup...\n" ); close_game(); texmerge_close(); gamedata_close(); gamefont_close(); free_text(); args_exit(); newmenu_free_background(); free_mission(); PHYSFSX_removeArchiveContent(); return(0); //presumably successful exit }
int gr_init(int mode) { int retcode,t,glt=0; // Only do this function once! if (gr_installed==1) return -1; #ifdef OGL_RUNTIME_LOAD ogl_init_load_library(); #endif #ifdef GR_SUPPORTS_FULLSCREEN_TOGGLE if (FindArg("-gl_voodoo")) { ogl_voodoohack=1; gr_toggle_fullscreen(); } if (FindArg("-fullscreen")) gr_toggle_fullscreen(); #endif if ((glt=FindArg("-gl_alttexmerge"))) ogl_alttexmerge=1; if ((t=FindArg("-gl_stdtexmerge"))) if (t>=glt)//allow overriding of earlier args ogl_alttexmerge=0; if ((glt=FindArg("-gl_16bittextures"))) ogl_rgba_format=GL_RGB5_A1; if ((glt=FindArg("-gl_mipmap"))) { GL_texmagfilt=GL_LINEAR; GL_texminfilt=GL_LINEAR_MIPMAP_NEAREST; } if ((glt=FindArg("-gl_trilinear"))) { GL_texmagfilt=GL_LINEAR; GL_texminfilt=GL_LINEAR_MIPMAP_LINEAR; } if ((t=FindArg("-gl_simple"))) { if (t>=glt) { //allow overriding of earlier args glt=t; GL_texmagfilt=GL_NEAREST; GL_texminfilt=GL_NEAREST; } } if ((t=FindArg("-gl_texmagfilt")) || (t=FindArg("-gl_texmagfilter"))) { if (t>=glt)//allow overriding of earlier args GL_texmagfilt=ogl_atotexfilti(Args[t+1],0); } if ((t=FindArg("-gl_texminfilt")) || (t=FindArg("-gl_texminfilter"))) { if (t>=glt)//allow overriding of earlier args GL_texminfilt=ogl_atotexfilti(Args[t+1],1); } GL_needmipmaps=ogl_testneedmipmaps(GL_texminfilt); if ((t=FindArg("-gl_anisotropy")) || (t=FindArg("-gl_anisotropic"))) { GL_texanisofilt=atof(Args[t+1]); } mprintf((0,"gr_init: texmagfilt:%x texminfilt:%x needmipmaps=%i anisotropic:%f\n",GL_texmagfilt,GL_texminfilt,GL_needmipmaps,GL_texanisofilt)); if ((t=FindArg("-gl_vidmem"))) { ogl_mem_target=atoi(Args[t+1])*1024*1024; } if ((t=FindArg("-gl_reticle"))) { gl_reticle=atoi(Args[t+1]); } //printf("ogl_mem_target=%i\n",ogl_mem_target); ogl_init();//platform specific initialization ogl_init_texture_list_internal(); MALLOC( grd_curscreen,grs_screen,1 ); memset( grd_curscreen, 0, sizeof(grs_screen)); grd_curscreen->sc_canvas.cv_bitmap.bm_data = NULL; // Set the mode. if ((retcode=gr_set_mode(mode))) { return retcode; } grd_curscreen->sc_canvas.cv_color = 0; grd_curscreen->sc_canvas.cv_drawmode = 0; grd_curscreen->sc_canvas.cv_font = NULL; grd_curscreen->sc_canvas.cv_font_fg_color = 0; grd_curscreen->sc_canvas.cv_font_bg_color = 0; gr_set_current_canvas( &grd_curscreen->sc_canvas ); gr_installed = 1; atexit(gr_close); return 0; }
int gr_init(void) { int org_gamma; int retcode; int mode = SM(320,200); // Only do this function once! if (gr_installed==1) return 3; #ifdef __DJGPP__ if (!__djgpp_nearptr_enable()) { printf("nearptr enable=%x\n", __dpmi_error); return 10; } #ifndef SAVEGR gr_video_memory = (unsigned char *)(__djgpp_conventional_base + 0xa0000); #else gr_video_memory=(unsigned char *)-1; #endif pVideoMode = (volatile ubyte *)(__djgpp_conventional_base+0x449); pNumColumns = (volatile ushort *)(__djgpp_conventional_base+0x44a); pNumRows = (volatile ubyte *)(__djgpp_conventional_base+0x484); pCharHeight = (volatile ushort *)(__djgpp_conventional_base+0x485); pCursorPos = (volatile ushort *)(__djgpp_conventional_base+0x450); pCursorType = (volatile ushort *)(__djgpp_conventional_base+0x460); pTextMemory = (volatile ushort *)(__djgpp_conventional_base+0xb8000); #endif #ifndef __DJGPP__ if (gr_init_A0000()) return 10; #endif // Save the current text screen mode if (gr_save_mode()==1) return 2; #ifndef NOGRAPH // Save the current palette, and fade it out to black. gr_palette_read( gr_pal_default ); gr_palette_faded_out = 0; org_gamma = gr_palette_get_gamma(); gr_palette_set_gamma( 0 ); gr_palette_fade_out( gr_pal_default, 32, 0 ); gr_palette_clear(); gr_palette_set_gamma( org_gamma ); gr_sync_display(); gr_sync_display(); #endif #ifdef __DJGPP__ #ifdef SAVEGR __djgpp_nearptr_disable(); #endif #endif MALLOC( grd_curscreen,grs_screen,1 ); memset( grd_curscreen, 0, sizeof(grs_screen)); // Set the mode. if ((retcode=gr_set_mode(mode))) { gr_restore_mode(); return retcode; } //JOHNgr_disable_default_palette_loading(); // Set all the screen, canvas, and bitmap variables that // aren't set by the gr_set_mode call: grd_curscreen->sc_canvas.cv_color = 0; grd_curscreen->sc_canvas.cv_drawmode = 0; grd_curscreen->sc_canvas.cv_font = NULL; grd_curscreen->sc_canvas.cv_font_fg_color = 0; grd_curscreen->sc_canvas.cv_font_bg_color = 0; gr_set_current_canvas( &grd_curscreen->sc_canvas ); #if 0 if (!dpmi_allocate_selector( &gr_fade_table, 256*GR_FADE_LEVELS, &gr_fade_table_selector )) Error( "Error allocating fade table selector!" ); if (!dpmi_allocate_selector( &gr_palette, 256*3, &gr_palette_selector )) Error( "Error allocating palette selector!" ); #endif // if (!dpmi_allocate_selector( &gr_inverse_table, 32*32*32, &gr_inverse_table_selector )) // Error( "Error allocating inverse table selector!" ); // Set flags indicating that this is installed. gr_installed = 1; #ifdef __GNUC__ atexit((void (*)) gr_close); #else atexit(gr_close); #endif return 0; }