void show_order_form() { if (CGameArg.SysNoTitles) return; #if defined(DXX_BUILD_DESCENT_I) show_first_found_title_screen( "warning.pcx", // D1 Registered "apple.pcx", // D1 Mac OEM Demo "order01.pcx" // D1 Demo ); #elif defined(DXX_BUILD_DESCENT_II) #if !DXX_USE_EDITOR key_flush(); const auto hiresmode = HIRESMODE; /* * If D2 registered, all checks fail and nothing is shown. */ const char *exit_screen = hiresmode ? "ordrd2ob.pcx" : "ordrd2o.pcx"; // OEM if ((PHYSFSX_exists(exit_screen, 1)) || // SHAREWARE, prefer mac if hires (exit_screen = hiresmode ? "orderd2b.pcx" : "orderd2.pcx", PHYSFSX_exists(exit_screen, 1)) || // SHAREWARE, have to rescale (exit_screen = hiresmode ? "orderd2.pcx" : "orderd2b.pcx", PHYSFSX_exists(exit_screen, 1)) || // D1 (exit_screen = hiresmode ? "warningb.pcx" : "warning.pcx", PHYSFSX_exists(exit_screen, 1)) ) show_title_screen(exit_screen,1,0); #endif #endif }
void key_got_focus() { if (!key_inited) return; key_flush(); }
int ui_play_events_fast( int NumberOfEvents, UI_EVENT * buffer ) { int i; if ( buffer == NULL ) return 1; EventBuffer = buffer; FrameCount = 0; ui_event_counter = 0; ui_number_of_events = NumberOfEvents; Record = 3; _disable(); keyd_last_released= 0; keyd_last_pressed= 0; //mprintf( 0, "Before: ", i ); for (i=0; i<256; i++ ) { //if (keyd_pressed[i]) mprintf( 0, "%d ", i ); SavedState[i] = keyd_pressed[i]; } //mprintf( 0, "\n" ); _enable(); key_flush(); return 0; }
// if text input mode is active, clear it void multi_msg_text_flush() { Multi_msg_text_enter = 0; Multi_msg_mode = MULTI_MSG_NONE; Multi_msg_stamp = -1; // keep eating keys for a short period of time and unset any used control bits Multi_msg_eat_stamp = timestamp(350); control_config_clear_used_status(); key_flush(); }
void key_init() { // Initialize queue Status1= *(ubyte*)0x417; Status2= *(ubyte*)0x418; keyd_time_when_last_pressed = timer_get_fixed_seconds(); keyd_buffer_type = 1; keyd_repeat = 1; key_data.in_key_handler = 0; key_data.E0Flag = 0; key_data.E1Flag = 0; // Clear the keyboard array key_flush(); if (Installed) return; Installed = 1; //--------------- lock everything for the virtal memory ---------------------------------- if (!dpmi_lock_region ((void near *)key_handler, (char *)key_handler_end - (char near *)key_handler)) { Error( "Can't lock keyboard handler!\n" ); } if (!dpmi_lock_region (&key_data, sizeof(keyboard))) { Error( "Can't lock keyboard handler's data!\n" ); } if (!dpmi_lock_region (&keyd_buffer_type, sizeof(char))) { Error( "Can't lock keyboard handler's data!\n" ); } if (!dpmi_lock_region (&keyd_repeat, sizeof(char))) { Error( "Can't lock keyboard handler's data!\n" ); } if (!dpmi_lock_region (&keyd_editor_mode, sizeof(char))) { Error( "Can't lock keyboard handler's data!\n" ); } if (!dpmi_lock_region (&keyd_last_pressed, sizeof(char))) { Error( "Can't lock keyboard handler's data!\n" ); } if (!dpmi_lock_region (&keyd_last_released, sizeof(char))) { Error( "Can't lock keyboard handler's data!\n" ); } if (!dpmi_lock_region (&keyd_pressed, sizeof(char)*256)) { Error( "Can't lock keyboard handler's data!\n" ); } if (!dpmi_lock_region (&keyd_time_when_last_pressed, sizeof(int))) { Error( "Can't lock keyboard handler's data!\n" ); } key_data.prev_int_9 = _dos_getvect( 9 ); _dos_setvect( 9, key_handler ); atexit( key_close ); }
void key_init() { Installed=1; keyd_time_when_last_pressed = timer_get_fixed_seconds(); keyd_buffer_type = 1; keyd_repeat = 1; // Clear the keyboard array key_flush(); atexit(key_close); }
void key_init() { // Initialize queue if (key_inited) return; key_inited = 1; INITIALIZE_CRITICAL_SECTION(key_lock); ENTER_CRITICAL_SECTION(key_lock); #ifdef SCP_UNIX FillSDLArray(); #endif keyd_time_when_last_pressed = timer_get_milliseconds(); keyd_buffer_type = 1; keyd_repeat = 1; // Clear the keyboard array key_flush(); // Clear key filter key_clear_filter(); LEAVE_CRITICAL_SECTION(key_lock); #ifdef _WIN32 #ifdef USE_DIRECTINPUT di_init(); #endif OSVERSIONINFO ver; ver.dwOSVersionInfoSize = sizeof(OSVERSIONINFO); GetVersionEx(&ver); if ( ver.dwPlatformId == VER_PLATFORM_WIN32_NT ) { Key_running_NT = 1; } else { Key_running_NT = 0; if ( key_numlock_is_on() ) { Key_numlock_was_on = 1; key_turn_off_numlock(); } } #endif atexit(key_close); }
void save_screen_shot(int automap_flag) { // fix t1; char message[100]; static int savenum=0; char savename[13]; unsigned char *buf; if (!ogl_readpixels_ok) { if (!automap_flag) hud_message(MSGC_GAME_FEEDBACK,"glReadPixels not supported on your configuration"); return; } stop_time(); //added/changed on 10/31/98 by Victor Rachels to fix overwrite each new game if ( savenum == 9999 ) savenum = 0; sprintf(savename,"scrn%04d.tga",savenum++); while(!access(savename,0)) { if ( savenum == 9999 ) savenum = 0; sprintf(savename,"scrn%04d.tga",savenum++); } sprintf( message, "%s '%s'", TXT_DUMPING_SCREEN, savename ); //end this section addition/change - Victor Rachels if (automap_flag) { // save_font = grd_curcanv->cv_font; // gr_set_curfont(GAME_FONT); // gr_set_fontcolor(gr_find_closest_color_current(0,31,0),-1); // gr_get_string_size(message,&w,&h,&aw); // modex_print_message(32, 2, message); } else { hud_message(MSGC_GAME_FEEDBACK,message); } buf = malloc(grd_curscreen->sc_w*grd_curscreen->sc_h*3); glReadBuffer(GL_FRONT); glReadPixels(0,0,grd_curscreen->sc_w,grd_curscreen->sc_h,GL_RGB,GL_UNSIGNED_BYTE,buf); write_bmp(savename,grd_curscreen->sc_w,grd_curscreen->sc_h,buf); free(buf); key_flush(); start_time(); }
int ui_play_events_realtime( int NumberOfEvents, UI_EVENT * buffer ) { int i; if ( buffer == NULL ) return 1; EventBuffer = buffer; FrameCount = 0; ui_event_counter = 0; ui_number_of_events = NumberOfEvents; Record = 2; _disable(); keyd_last_released= 0; keyd_last_pressed= 0; for (i=0; i<256; i++ ) SavedState[i] = keyd_pressed[i]; _enable(); key_flush(); return 0; }
void key_init() { int i; if (Installed) return; Installed=1; keyd_time_when_last_pressed = timer_get_fixed_seconds(); keyd_buffer_type = 1; keyd_repeat = 1; for(i=0; i<256; i++) key_text[i] = key_properties[i].key_text; // Clear the keyboard array key_flush(); atexit(key_close); }
void multi_pause_close(int end_mission) { if ( !Multi_paused ) return; // set the standalonest if (Game_mode & GM_STANDALONE_SERVER) { std_debug_set_standalone_state_string("Game play"); } else { // free the screen up if ( end_mission && (Multi_paused_screen_id >= 0) ) { gr_free_screen(Multi_paused_screen_id); Multi_paused_screen_id = -1; } if (Multi_paused_background >= 0) { bm_release(Multi_paused_background); Multi_paused_background = -1; } Multi_paused_window.destroy(); game_flush(); // unpause all the music audiostream_unpause_all(); } // unpause beam weapon sounds weapon_unpause_sounds(); // eat keys timestamp Multi_pause_eat = f2fl(timer_get_fixed_seconds()); // reset timestamps multi_reset_timestamps(); // clear out control config and keypress info control_config_clear_used_status(); key_flush(); Multi_paused = 0; }
static void credits_show_common(RAIIPHYSFS_File file, const int have_bin_file) { palette_array_t backdrop_palette; auto cr = make_unique<credits>(); *cr = {}; cr->file = std::move(file); cr->have_bin_file = have_bin_file; set_screen_mode(SCREEN_MENU); #if defined(DXX_BUILD_DESCENT_II) gr_use_palette_table( "credits.256" ); #endif cr->backdrop.bm_data=NULL; const auto pcx_error = pcx_read_bitmap(STARS_BACKGROUND, cr->backdrop,backdrop_palette); if (pcx_error != PCX_ERROR_NONE) { return; } songs_play_song( SONG_CREDITS, 1 ); gr_remap_bitmap_good(cr->backdrop,backdrop_palette, -1, -1); gr_set_current_canvas(NULL); show_fullscr(cr->backdrop); gr_palette_load( gr_palette ); key_flush(); credits *pcr = cr.get(); const auto wind = window_create(grd_curscreen->sc_canvas, 0, 0, SWIDTH, SHEIGHT, credits_handler, cr.release()); if (!wind) { d_event event = { EVENT_WINDOW_CLOSE }; credits_handler(NULL, event, pcr); return; } event_process_all(); }
// if we still want to eat keys int multi_pause_eat_keys() { // if the eat timestamp is negative, don't eat keys if(Multi_pause_eat < 0.0f){ return 0; } // if less than 1 second has passed, continue eating keys if((f2fl(timer_get_fixed_seconds()) - Multi_pause_eat) < 1.0f){ nprintf(("Network","PAUSE EATING KEYS\n")); control_config_clear_used_status(); key_flush(); return 1; } // otherwise, disable the timestamp Multi_pause_eat = -1.0f; return 0; }
//called to go to the next level (if there is one) //if secret_flag is true, advance to secret level, else next normal one // Return true if game over. int AdvanceLevel(int secret_flag) { Control_center_destroyed = 0; #ifdef EDITOR if (Current_level_num == 0) { return 1; //not a real level } #endif key_flush(); #ifdef NETWORK if (Game_mode & GM_MULTI) { int result; result = multi_endlevel(&secret_flag); // Wait for other players to reach this point if (result) // failed to sync { return (Current_level_num == Last_level); } } #endif key_flush(); if (Current_level_num == Last_level) { //player has finished the game! if ((Newdemo_state == ND_STATE_RECORDING) || (Newdemo_state == ND_STATE_PAUSED)) newdemo_stop_recording(); do_end_briefing_screens(Ending_text_filename); return 1; } else { Next_level_num = Current_level_num+1; //assume go to next normal level if (secret_flag) { //go to secret level instead int i; for (i=0;i<-Last_secret_level;i++) if (Secret_level_table[i]==Current_level_num) { Next_level_num = -(i+1); break; } Assert(i<-Last_secret_level); //couldn't find which secret level } if (Current_level_num < 0) { //on secret level, where to go? Assert(!secret_flag); //shouldn't be going to secret level Assert(Current_level_num<=-1 && Current_level_num>=Last_secret_level); Next_level_num = Secret_level_table[(-Current_level_num)-1]+1; } StartNewLevel(Next_level_num); } key_flush(); return 0; }
void credits_do_frame(float frametime) { int i, k, next, percent, bm1, bm2; int bx1, by1, bw1, bh1; int bx2, by2, bw2, bh2; // Use this id to trigger the start of music playing on the credits screen if ( timestamp_elapsed(Credits_music_begin_timestamp) ) { Credits_music_begin_timestamp = 0; credits_start_music(); } k = Ui_window.process(); switch (k) { case KEY_ESC: gameseq_post_event(GS_EVENT_MAIN_MENU); key_flush(); break; case KEY_CTRLED | KEY_UP: case KEY_SHIFTED | KEY_TAB: if ( !(Player->flags & PLAYER_FLAGS_IS_MULTI) ) { credits_screen_button_pressed(CUTSCENES_BUTTON); break; } // else, react like tab key. case KEY_CTRLED | KEY_DOWN: case KEY_TAB: credits_screen_button_pressed(TECH_DATABASE_BUTTON); break; default: break; } // end switch for (i=0; i<NUM_BUTTONS; i++){ if (Buttons[i][gr_screen.res].button.pressed()){ if (credits_screen_button_pressed(i)){ return; } } } gr_reset_clip(); GR_MAYBE_CLEAR_RES(Background_bitmap); if (Background_bitmap >= 0) { gr_set_bitmap(Background_bitmap); gr_bitmap(0, 0); } percent = (int) (100.0f - (CREDITS_ARTWORK_DISPLAY_TIME - Credits_counter) * 100.0f / CREDITS_ARTWORK_FADE_TIME); if (percent < 0){ percent = 0; } next = Credits_artwork_index + 1; if (next >= NUM_IMAGES){ next = 0; } if (Credits_bmps[Credits_artwork_index] < 0) { char buf[40]; if (gr_screen.res == GR_1024) { sprintf(buf, NOX("2_CrIm%.2d"), Credits_artwork_index); } else { sprintf(buf, NOX("CrIm%.2d"), Credits_artwork_index); } Credits_bmps[Credits_artwork_index] = bm_load(buf); } if (Credits_bmps[next] < 0) { char buf[40]; if (gr_screen.res == GR_1024) { sprintf(buf, NOX("2_CrIm%.2d"), Credits_artwork_index); } else { sprintf(buf, NOX("CrIm%.2d"), next); } Credits_bmps[next] = bm_load(buf); } bm1 = Credits_bmps[Credits_artwork_index]; bm2 = Credits_bmps[next]; if((bm1 != -1) && (bm2 != -1)){ Assert(percent >= 0 && percent <= 100); // get width and height bm_get_info(bm1, &bw1, &bh1, NULL, NULL, NULL); bm_get_info(bm2, &bw2, &bh2, NULL, NULL, NULL); // determine where to draw the coords bx1 = Credits_image_coords[gr_screen.res][CREDITS_X_COORD] + ((Credits_image_coords[gr_screen.res][CREDITS_W_COORD] - bw1)/2); by1 = Credits_image_coords[gr_screen.res][CREDITS_Y_COORD] + ((Credits_image_coords[gr_screen.res][CREDITS_H_COORD] - bh1)/2); bx2 = Credits_image_coords[gr_screen.res][CREDITS_X_COORD] + ((Credits_image_coords[gr_screen.res][CREDITS_W_COORD] - bw2)/2); by2 = Credits_image_coords[gr_screen.res][CREDITS_Y_COORD] + ((Credits_image_coords[gr_screen.res][CREDITS_H_COORD] - bh2)/2); gr_cross_fade(bm1, bm2, bx1, by1, bx2, by2, (float)percent / 100.0f); } /* if (CreditsWin01 != -1) { gr_set_bitmap(CreditsWin01); gr_bitmap(233, 5); } if (CreditsWin02 != -1) { gr_set_bitmap(CreditsWin02); gr_bitmap(616, 8); } if (CreditsWin03 != -1) { gr_set_bitmap(CreditsWin03); gr_bitmap(233, 299); } if (CreditsWin04 != -1) { gr_set_bitmap(CreditsWin04); gr_bitmap(215, 8); } */ Ui_window.draw(); for (i=TECH_DATABASE_BUTTON; i<=CREDITS_BUTTON; i++){ if (Buttons[i][gr_screen.res].button.button_down()){ break; } } if (i > CREDITS_BUTTON){ Buttons[CREDITS_BUTTON][gr_screen.res].button.draw_forced(2); } gr_set_clip(Credits_text_coords[gr_screen.res][CREDITS_X_COORD], Credits_text_coords[gr_screen.res][CREDITS_Y_COORD], Credits_text_coords[gr_screen.res][CREDITS_W_COORD], Credits_text_coords[gr_screen.res][CREDITS_H_COORD]); gr_set_font(FONT1); gr_set_color_fast(&Color_normal); int sy; if ( Credit_position > 0 ) { sy = fl2i(Credit_position+0.5f); } else { sy = fl2i(Credit_position-0.5f); } gr_string(0x8000, sy, Credit_text); int temp_time; temp_time = timer_get_milliseconds(); Credits_frametime = temp_time - Credits_last_time; Credits_last_time = temp_time; timestamp_inc(Credits_frametime / 1000.0f); float fl_frametime = i2fl(Credits_frametime) / 1000.f; if (keyd_pressed[KEY_LSHIFT]) { Credit_position -= fl_frametime * CREDITS_SCROLL_RATE * 4.0f; } else { Credit_position -= fl_frametime * CREDITS_SCROLL_RATE; } if (Credit_position < Credit_stop_pos){ Credit_position = Credit_start_pos; } Credits_counter += fl_frametime; while (Credits_counter >= CREDITS_ARTWORK_DISPLAY_TIME) { Credits_counter -= CREDITS_ARTWORK_DISPLAY_TIME; Credits_artwork_index = next; } gr_flip(); }
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 main (void) { char ascii; int c; setbuf( stdout, NULL ); key_init(); //timer_init( 0, NULL ); //keyd_buffer_type = 2; keyd_repeat = 0; printf( "\n\n\n\nThis tests the keyboard library.\n\n" ); printf( "Press any key to start...\n" ); printf( "You pressed: %c\n\n", key_getch() ); printf( "Press F1 to turn off buffering.\n" ); printf( " F2 to turn on buffering.\n" ); printf( " F4 to flush keyboard.\n" ); printf( " F5 to turn repeat off.\n"); printf( " F6 to turn repeat on.\n"); printf( " F7 to do an INT 3.\n" ); printf( " F10 to display some boxes.\n" ); printf( " The arrows to see fast multiple keystrokes.\n"); printf( " ESC to exit.\n\n" ); while( !keyd_pressed[KEY_ESC] ) { int i,j; for (i=0; i<256; i++ ) { if (keyd_pressed[i]) { j = key_to_ascii(i); if (j==255) vidmem[i*2] = 219; else vidmem[i*2] = j; } else vidmem[i*2] = 32; } if (keyd_pressed[KEY_F1]) keyd_buffer_type = 0; if (keyd_pressed[KEY_F2]) keyd_buffer_type = 1; if (keyd_pressed[KEY_F4]) key_flush(); if (keyd_pressed[KEY_F5]) { keyd_repeat = 0; printf( "Repeat off" ); } if (keyd_pressed[KEY_F6]) { keyd_repeat = 1; printf( "Repeat on" ); } // if (keyd_pressed[KEY_F7] ) // key_debug(); if (keyd_pressed[KEY_PAUSE]) putch( 254 ); if (key_checkch()) { c = key_getch(); ascii=key_to_ascii(c); if ( ascii==255 ) { printf("[%4X] ", c ); fflush( stdout ); } else putch( ascii ); if (c==1) break; } delay(100); } key_close(); //timer_close(); }
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 }
void credits_show() { int i, j, l, done; CFILE * file; char buffer[NUM_LINES][80]; grs_bitmap backdrop; ubyte backdrop_palette[768]; int pcx_error; int buffer_line = 0; fix last_time; fix time_delay = 4180 / f2fl(Scale_y); // ~ F1_0 / 12.9 int first_line_offset,extra_inc=0; int have_bin_file = 0; char * tempp; grs_point scale_pts[] = FULLSCREEN_SCALE_PTS; ubyte *fade_values = malloc(grd_curscreen->sc_h); for (i = 0; i < grd_curscreen->sc_h; ++i) { fade_values[i] = fade_values_200[(int)(((float)i / (float)grd_curscreen->sc_h) * 200)]; } set_screen_mode(SCREEN_MENU); // Clear out all tex buffer lines. for (i=0; i<NUM_LINES; i++ ) buffer[i][0] = 0; have_bin_file = 0; file = cfopen( "credits.tex", "rb" ); if (file == NULL) { file = cfopen("credits.txb", "rb"); if (file == NULL) Error("Missing CREDITS.TEX and CREDITS.TXB file\n"); have_bin_file = 1; } gr_use_palette_table( "credits.256" ); header_font = gr_init_font( "font1-1.fnt" ); title_font = gr_init_font( "font2-3.fnt" ); names_font = gr_init_font( "font2-2.fnt" ); backdrop.bm_data=NULL; pcx_error = pcx_read_bitmap("stars.pcx",&backdrop,BM_LINEAR,backdrop_palette); if (pcx_error != PCX_ERROR_NONE) { cfclose(file); return; } songs_play_song( SONG_CREDITS, 0 ); gr_remap_bitmap_good( &backdrop,backdrop_palette, -1, -1 ); gr_set_current_canvas(NULL); scale_bitmap(&backdrop,scale_pts); gr_palette_fade_in( gr_palette, 32, 0 ); vfx_set_palette_sub( gr_palette ); //gr_clear_canvas(BM_XRGB(0,0,0)); key_flush(); last_time = timer_get_fixed_seconds(); done = 0; first_line_offset = 0; while( 1 ) { int k; do { buffer_line = (buffer_line+1) % NUM_LINES; if (cfgets( buffer[buffer_line], 80, file )) { char *p; if (have_bin_file) { // is this a binary tbl file for (i = 0; i < strlen(buffer[buffer_line]) - 1; i++) { encode_rotate_left(&(buffer[buffer_line][i])); buffer[buffer_line][i] ^= BITMAP_TBL_XOR; encode_rotate_left(&(buffer[buffer_line][i])); } } p = strchr(&buffer[buffer_line][0],'\n'); if (p) *p = '\0'; } else { //fseek( file, 0, SEEK_SET); buffer[buffer_line][0] = 0; done++; } } while (extra_inc--); extra_inc = 0; for (i=0; i<ROW_SPACING; i++ ) { int y; y = first_line_offset - i; #ifndef OGLES gr_set_current_canvas(VR_offscreen_buffer); #endif scale_bitmap(&backdrop, scale_pts); for (j=0; j<NUM_LINES; j++ ) { char *s; l = (buffer_line + j + 1 ) % NUM_LINES; s = buffer[l]; if ( s[0] == '!' ) { s++; } else if ( s[0] == '$' ) { grd_curcanv->cv_font = header_font; s++; } else if ( s[0] == '*' ) { grd_curcanv->cv_font = title_font; s++; } else grd_curcanv->cv_font = names_font; gr_bitblt_fade_table = fade_values; tempp = strchr( s, '\t' ); if ( tempp ) { int w, h, aw; *tempp = 0; gr_get_string_size( s, &w, &h, &aw ); w *= f2fl(Scale_x); h *= f2fl(Scale_y); gr_scale_printf( (160-w)/2, y, Scale_factor, Scale_factor, s ); gr_get_string_size( &tempp[1], &w, &h, &aw ); w *= f2fl(Scale_x); h *= f2fl(Scale_y); gr_scale_printf( 160+((160-w)/2), y, Scale_factor, Scale_factor, &tempp[1] ); *tempp = '\t'; } else { gr_scale_printf( 0x8000, y, Scale_factor, Scale_factor, s ); } gr_bitblt_fade_table = NULL; if (buffer[l][0] == '!') y += ROW_SPACING/2; else y += ROW_SPACING; } #ifdef OGLES showRenderBuffer(); #else gr_bm_ubitblt(grd_curscreen->sc_w, grd_curscreen->sc_h, 0, 0, 0, 0, &(VR_offscreen_buffer->cv_bitmap), &(grd_curscreen->sc_canvas.cv_bitmap) ); #endif while( timer_get_fixed_seconds() < last_time+time_delay ); last_time = timer_get_fixed_seconds(); k = key_inkey(); #ifndef NDEBUG if (k == KEY_BACKSP) { Int3(); k=0; } #endif // { // fix ot = time_delay; // time_delay += (keyd_pressed[KEY_X] - keyd_pressed[KEY_Z])*100; // if (ot!=time_delay) { // mprintf( (0, "[%x] ", time_delay )); // } // } if (k == KEY_PRINT_SCREEN) { save_screen_shot(0); k = 0; } if ((k>0)||(done>NUM_LINES)) { gr_close_font(header_font); gr_close_font(title_font); gr_close_font(names_font); gr_palette_fade_out( gr_palette, 32, 0 ); gr_use_palette_table( "palette.256" ); free(backdrop.bm_data); cfclose(file); songs_play_song( SONG_TITLE, 1 ); return; } } if (buffer[(buffer_line + 1 ) % NUM_LINES][0] == '!') { first_line_offset -= ROW_SPACING-ROW_SPACING/2; if (first_line_offset <= -ROW_SPACING) { first_line_offset += ROW_SPACING; extra_inc++; } } } free(fade_values); }
void credits_do_frame(float frametime) { GR_DEBUG_SCOPE("Credits do frame"); int i, k, next, percent, bm1, bm2; int bx1, by1, bw1, bh1; int bx2, by2, bw2, bh2; // Use this id to trigger the start of music playing on the credits screen if ( timestamp_elapsed(Credits_music_begin_timestamp) ) { Credits_music_begin_timestamp = 0; credits_start_music(); } k = Ui_window.process(); switch (k) { case KEY_ESC: gameseq_post_event(GS_EVENT_MAIN_MENU); key_flush(); break; case KEY_CTRLED | KEY_UP: case KEY_SHIFTED | KEY_TAB: if ( !(Player->flags & PLAYER_FLAGS_IS_MULTI) ) { credits_screen_button_pressed(CUTSCENES_BUTTON); break; } // else, react like tab key. case KEY_CTRLED | KEY_DOWN: case KEY_TAB: credits_screen_button_pressed(TECH_DATABASE_BUTTON); break; default: break; } // end switch for (i=0; i<NUM_BUTTONS; i++){ if (Buttons[i][gr_screen.res].button.pressed()){ if (credits_screen_button_pressed(i)){ return; } } } gr_reset_clip(); GR_MAYBE_CLEAR_RES(Background_bitmap); if (Background_bitmap >= 0) { gr_set_bitmap(Background_bitmap); gr_bitmap(0, 0, GR_RESIZE_MENU); } percent = (int) (100.0f - (Credits_artwork_display_time - Credits_counter) * 100.0f / Credits_artwork_fade_time); if (percent < 0){ percent = 0; } next = Credits_artwork_index + 1; if (next >= Credits_num_images){ next = 0; } if (Credits_bmps[Credits_artwork_index] < 0) { char buf[40]; if (gr_screen.res == GR_1024) { sprintf(buf, NOX("2_CrIm%.2d"), Credits_artwork_index); } else { sprintf(buf, NOX("CrIm%.2d"), Credits_artwork_index); } Credits_bmps[Credits_artwork_index] = bm_load(buf); } if (Credits_bmps[next] < 0) { char buf[40]; if (gr_screen.res == GR_1024) { sprintf(buf, NOX("2_CrIm%.2d"), next); } else { sprintf(buf, NOX("CrIm%.2d"), next); } Credits_bmps[next] = bm_load(buf); } bm1 = Credits_bmps[Credits_artwork_index]; bm2 = Credits_bmps[next]; if((bm1 != -1) && (bm2 != -1)){ GR_DEBUG_SCOPE("Render credits bitmap"); Assert(percent >= 0 && percent <= 100); // get width and height bm_get_info(bm1, &bw1, &bh1, NULL, NULL, NULL); bm_get_info(bm2, &bw2, &bh2, NULL, NULL, NULL); // determine where to draw the coords bx1 = Credits_image_coords[gr_screen.res][CREDITS_X_COORD] + ((Credits_image_coords[gr_screen.res][CREDITS_W_COORD] - bw1)/2); by1 = Credits_image_coords[gr_screen.res][CREDITS_Y_COORD] + ((Credits_image_coords[gr_screen.res][CREDITS_H_COORD] - bh1)/2); bx2 = Credits_image_coords[gr_screen.res][CREDITS_X_COORD] + ((Credits_image_coords[gr_screen.res][CREDITS_W_COORD] - bw2)/2); by2 = Credits_image_coords[gr_screen.res][CREDITS_Y_COORD] + ((Credits_image_coords[gr_screen.res][CREDITS_H_COORD] - bh2)/2); auto alpha = (float)percent / 100.0f; gr_set_bitmap(bm1, GR_ALPHABLEND_FILTER, GR_BITBLT_MODE_NORMAL, 1.0f - alpha); gr_bitmap(bx1, by1, GR_RESIZE_MENU); gr_set_bitmap(bm2, GR_ALPHABLEND_FILTER, GR_BITBLT_MODE_NORMAL, alpha); gr_bitmap(bx2, by2, GR_RESIZE_MENU); } Ui_window.draw(); for (i=TECH_DATABASE_BUTTON; i<=CREDITS_BUTTON; i++){ if (Buttons[i][gr_screen.res].button.button_down()){ break; } } if (i > CREDITS_BUTTON){ Buttons[CREDITS_BUTTON][gr_screen.res].button.draw_forced(2); } gr_set_clip(Credits_text_coords[gr_screen.res][CREDITS_X_COORD], Credits_text_coords[gr_screen.res][CREDITS_Y_COORD], Credits_text_coords[gr_screen.res][CREDITS_W_COORD], Credits_text_coords[gr_screen.res][CREDITS_H_COORD], GR_RESIZE_MENU); font::set_font(font::FONT1); gr_set_color_fast(&Color_normal); int y_offset = 0; for (SCP_vector<SCP_string>::iterator iter = Credit_text_parts.begin(); iter != Credit_text_parts.end(); ++iter) { size_t currentPos = 0; size_t lineEnd; do { int height; int width; lineEnd = iter->find('\n', currentPos); auto length = lineEnd - currentPos; if (lineEnd == SCP_string::npos) { length = std::numeric_limits<size_t>::max(); } gr_get_string_size(&width, &height, iter->c_str() + currentPos, static_cast<int>(length)); // Check if the text part is actually visible if (Credit_position + y_offset + height > 0.0f) { float x = static_cast<float>((gr_screen.clip_width_unscaled - width) / 2); gr_string(x, Credit_position + y_offset, iter->c_str() + currentPos, GR_RESIZE_MENU, static_cast<int>(length)); } y_offset += height; currentPos = lineEnd + 1; } while (lineEnd < iter->length() && lineEnd != SCP_string::npos); } int temp_time; temp_time = timer_get_milliseconds(); Credits_frametime = temp_time - Credits_last_time; Credits_last_time = temp_time; timestamp_inc(i2f(Credits_frametime) / TIMESTAMP_FREQUENCY); float fl_frametime = i2fl(Credits_frametime) / 1000.f; if (keyd_pressed[KEY_LSHIFT]) { Credit_position -= fl_frametime * Credits_scroll_rate * 4.0f; } else { Credit_position -= fl_frametime * Credits_scroll_rate; } if (Credit_position < Credit_stop_pos){ Credit_position = Credit_start_pos; } Credits_counter += fl_frametime; while (Credits_counter >= Credits_artwork_display_time) { Credits_counter -= Credits_artwork_display_time; Credits_artwork_index = next; } gr_flip(); }
//if filename passed is NULL, show normal credits void credits_show(char *credits_filename) { credits *cr; window *wind; int i; int pcx_error; char * tempp; char filename[32]; ubyte backdrop_palette[768]; MALLOC(cr, credits, 1); if (!cr) return; cr->have_bin_file = 0; cr->buffer_line = 0; cr->first_line_offset = 0; cr->extra_inc = 0; cr->done = 0; cr->row = 0; // Clear out all tex buffer lines. for (i=0; i<NUM_LINES; i++ ) cr->buffer[i][0] = 0; sprintf(filename, "%s", CREDITS_FILE); cr->have_bin_file = 0; if (credits_filename) { strcpy(filename,credits_filename); cr->have_bin_file = 1; } cr->file = PHYSFSX_openReadBuffered( filename ); if (cr->file == NULL) { char nfile[32]; if (credits_filename) { d_free(cr); return; //ok to not find special filename } tempp = strchr(filename, '.'); *tempp = '\0'; sprintf(nfile, "%s.txb", filename); cr->file = PHYSFSX_openReadBuffered(nfile); if (cr->file == NULL) Error("Missing CREDITS.TEX and CREDITS.TXB file\n"); cr->have_bin_file = 1; } set_screen_mode(SCREEN_MENU); gr_use_palette_table( "credits.256" ); cr->backdrop.bm_data=NULL; pcx_error = pcx_read_bitmap(STARS_BACKGROUND,&cr->backdrop, BM_LINEAR,backdrop_palette); if (pcx_error != PCX_ERROR_NONE) { PHYSFS_close(cr->file); d_free(cr); return; } songs_play_song( SONG_CREDITS, 1 ); gr_remap_bitmap_good( &cr->backdrop,backdrop_palette, -1, -1 ); gr_set_current_canvas(NULL); show_fullscr(&cr->backdrop); gr_palette_load( gr_palette ); key_flush(); wind = window_create(&grd_curscreen->sc_canvas, 0, 0, SWIDTH, SHEIGHT, (int (*)(window *, d_event *, void *))credits_handler, cr); if (!wind) { d_event event = { EVENT_WINDOW_CLOSE }; credits_handler(NULL, &event, cr); return; } while (window_exists(wind)) event_process(); }