From 342ba2cdac638a8837fe47bb41bb89bde41591b5 Mon Sep 17 00:00:00 2001 From: Taylor Richards Date: Mon, 10 Nov 2014 23:22:46 -0500 Subject: [PATCH] remove support for memory-mapped files specific conditions for use aren't met with retail install (with anims in VP archives) so there is not much point in keeping support for it --- include/animplay.h | 2 +- include/cfile.h | 4 - include/cfilearchive.h | 3 - src/anim/animplay.cpp | 24 +---- src/cfile/cfile.cpp | 148 +++----------------------- src/cfile/cfilearchive.cpp | 11 -- src/menuui/techmenu.cpp | 4 +- src/mission/missionmessage.cpp | 2 +- src/missionui/missioncmdbrief.cpp | 4 +- src/missionui/missionshipchoice.cpp | 6 +- src/missionui/missionweaponchoice.cpp | 7 +- 11 files changed, 32 insertions(+), 183 deletions(-) diff --git a/include/animplay.h b/include/animplay.h index 15d602f..55b1a81 100644 --- a/include/animplay.h +++ b/include/animplay.h @@ -136,7 +136,7 @@ int anim_stop_playing(anim_instance* anim_instance); int anim_show_next_frame(anim_instance *instance, float frametime); void anim_release_all_instances(int screen_id = 0); void anim_release_render_instance(anim_instance* instance); -anim *anim_load(const char *name, int file_mapped = 0); +anim *anim_load(const char *name); int anim_free(anim *ptr); int anim_playing(anim_instance *ai); int anim_write_frames_out(const char *filename); diff --git a/include/cfile.h b/include/cfile.h index a9a603a..4a3b1cb 100644 --- a/include/cfile.h +++ b/include/cfile.h @@ -409,7 +409,6 @@ typedef struct { // #define's for the type parameter in cfopen. #define CFILE_NORMAL 0 // open file normally -#define CFILE_MEMORY_MAPPED (1<<0) // open file as a memory-mapped file #define CF_SORT_NONE 0 #define CF_SORT_NAME 1 @@ -497,9 +496,6 @@ char *cfgets(char *buf, int n, CFILE *cfile); // cfeof() Tests for end-of-file on a stream int cfeof(CFILE *cfile); -// Return the data pointer associated with the CFILE structure (for memory mapped files) -void *cf_returndata(CFILE *cfile); - // get the 2 byte checksum of the passed filename - return 0 if operation failed, 1 if succeeded int cf_chksum_short(const char *filename, ushort *chksum, int max_size = -1, int cf_type = CF_TYPE_ANY ); diff --git a/include/cfilearchive.h b/include/cfilearchive.h index 22ceffc..9c9954c 100644 --- a/include/cfilearchive.h +++ b/include/cfilearchive.h @@ -61,9 +61,6 @@ typedef struct Cfile_block { int type; // CFILE_BLOCK_UNUSED, CFILE_BLOCK_USED int dir_type; // directory location FILE *fp; // File pointer if opening an individual file - void *data; // Pointer for memory-mapped file access. NULL if not mem-mapped. - HANDLE hInFile; // Handle from CreateFile() - HANDLE hMapFile; // Handle from CreateFileMapping() int lib_offset; int raw_position; int size; // for packed files diff --git a/src/anim/animplay.cpp b/src/anim/animplay.cpp index a9de1ed..089f741 100644 --- a/src/anim/animplay.cpp +++ b/src/anim/animplay.cpp @@ -874,22 +874,17 @@ void anim_read_header(anim *ptr, CFILE *fp) // of the animation can reference. Must be free'ed later with anim_free() // // input: name => filename of animation -// file_mapped => boolean, whether to use memory-mapped file or not. -// Memory-mapped files will page in the animation from disk -// as it is needed, but performance is not as good // // returns: pointer to anim that is loaded => sucess // NULL => failure // -anim *anim_load(const char *real_filename, int file_mapped) +anim *anim_load(const char *real_filename) { anim *ptr; CFILE *fp; int count,idx; char name[MAX_PATH_LEN]; -// file_mapped = 0; - SDL_assert ( real_filename != NULL ); SDL_strlcpy(name, real_filename, sizeof(name)); @@ -961,18 +956,9 @@ anim *anim_load(const char *real_filename, int file_mapped) ptr->cfile_ptr = NULL; - if ( file_mapped ) { - // Try mapping the file to memory - ptr->flags |= ANF_MEM_MAPPED; - ptr->cfile_ptr = cfopen(name, "rb", CFILE_MEMORY_MAPPED); - } - - // couldn't memory-map file... must be in a packfile, so stream manually - if ( file_mapped && !ptr->cfile_ptr ) { - ptr->flags &= ~ANF_MEM_MAPPED; - ptr->flags |= ANF_STREAMED; - ptr->cfile_ptr = cfopen(name, "rb"); - } + // NOTE: mapped files no longer supported!! + ptr->flags |= ANF_STREAMED; + ptr->cfile_ptr = cfopen(name, "rb"); ptr->cache = NULL; @@ -993,7 +979,7 @@ anim *anim_load(const char *real_filename, int file_mapped) cfseek(ptr->cfile_ptr, offset, CF_SEEK_SET); cfread(ptr->cache, ANI_STREAM_CACHE_SIZE, 1, ptr->cfile_ptr); } else { - ptr->data = (ubyte*)cf_returndata(ptr->cfile_ptr) + offset; + Int3(); } } else { // Not a memory mapped file (or streamed) diff --git a/src/cfile/cfile.cpp b/src/cfile/cfile.cpp index cc04c8a..a726bdb 100644 --- a/src/cfile/cfile.cpp +++ b/src/cfile/cfile.cpp @@ -311,7 +311,6 @@ CFILE Cfile_list[MAX_CFILE_BLOCKS]; int cfget_cfile_block(); CFILE *cf_open_fill_cfblock(FILE * fp, int type); CFILE *cf_open_packed_cfblock(FILE *fp, int type, int offset, int size); -CFILE *cf_open_mapped_fill_cfblock(HANDLE hFile, int type); void cf_chksum_long_init(); void cfile_close() @@ -609,8 +608,7 @@ void cf_create_directory( int dir_type ) // parameters: *filepath ==> name of file to open (may be path+name) // *mode ==> specifies how file should be opened (eg "rb" for read binary) // passing NULL to mode deletes the file if it exists and returns NULL -// type ==> one of: CFILE_NORMAL -// CFILE_MEMORY_MAPPED +// type ==> CFILE_NORMAL // dir_type => override extension check, value is one of CF_TYPE* #defines // // NOTE: type parameter is an optional parameter. The default value is CFILE_NORMAL @@ -631,24 +629,20 @@ CFILE *cfopen(const char *file_path, const char *mode, int type, int dir_type, b // Check that all the parameters make sense SDL_assert(file_path && strlen(file_path)); SDL_assert( mode != NULL ); - - // Can only open read-only binary files in memory mapped mode. - if ( (type & CFILE_MEMORY_MAPPED) && strcmp(mode,"rb") ) { - Int3(); - return NULL; - } //=========================================================== // If in write mode, just try to open the file straight off // the harddisk. No fancy packfile stuff here! if ( SDL_strchr(mode,'w') ) { - // For write-only files, require a full path or a path type #ifdef PLAT_UNIX - if ( strpbrk(file_path, "/") ) { + const char *toks = "/"; #else - if ( strpbrk(file_path,"/\\:") ) { + const char *toks = "/\\:"; #endif + + // For write-only files, require a full path or a path type + if ( strpbrk(file_path, toks) ) { // Full path given? SDL_strlcpy(longname, file_path, sizeof(longname)); } else { @@ -660,7 +654,6 @@ CFILE *cfopen(const char *file_path, const char *mode, int type, int dir_type, b cf_create_default_path_string( longname, dir_type, file_path ); } - SDL_assert( !(type & CFILE_MEMORY_MAPPED) ); // JOHN: TODO, you should create the path if it doesn't exist. @@ -681,41 +674,18 @@ CFILE *cfopen(const char *file_path, const char *mode, int type, int dir_type, b if ( cf_find_file_location( copy_file_path, dir_type, longname, &size, &offset, localize ) ) { - // Fount it, now create a cfile out of it - - if ( type & CFILE_MEMORY_MAPPED ) { - - // Can't open memory mapped files out of pack files - if ( offset == 0 ) { -#ifdef PLAT_UNIX - STUB_FUNCTION; -#else - HANDLE hFile; - - hFile = CreateFile((LPCWSTR)longname, GENERIC_READ, FILE_SHARE_READ, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL); - - if (hFile != INVALID_HANDLE_VALUE) { - return cf_open_mapped_fill_cfblock(hFile, dir_type); - } -#endif - } - - } else { + FILE *fp = fopen( longname, "rb" ); - FILE *fp = fopen( longname, "rb" ); - - if ( fp ) { - if ( offset ) { - // Found it in a pack file - return cf_open_packed_cfblock(fp, dir_type, offset, size ); - } else { - // Found it in a normal file - return cf_open_fill_cfblock(fp, dir_type); - } + if ( fp ) { + if ( offset ) { + // Found it in a pack file + return cf_open_packed_cfblock(fp, dir_type, offset, size ); + } else { + // Found it in a normal file + return cf_open_fill_cfblock(fp, dir_type); } } - } return NULL; @@ -757,7 +727,6 @@ int cfget_cfile_block() for ( i = 0; i < MAX_CFILE_BLOCKS; i++ ) { cb = &Cfile_block_list[i]; if ( cb->type == CFILE_BLOCK_UNUSED ) { - cb->data = NULL; cb->fp = NULL; cb->type = CFILE_BLOCK_USED; return i; @@ -786,21 +755,8 @@ int cfclose( CFILE * cfile ) cb = &Cfile_block_list[cfile->id]; result = 0; - if ( cb->data ) { - // close memory mapped file -#ifdef PLAT_UNIX - STUB_FUNCTION; -#else - result = UnmapViewOfFile((void*)cb->data); - SDL_assert(result); - result = CloseHandle(cb->hInFile); - SDL_assert(result); // Ensure file handle is closed properly - result = CloseHandle(cb->hMapFile); - SDL_assert(result); // Ensure file handle is closed properly -#endif - result = 0; - } else if ( cb->fp != NULL ) { + if (cb->fp != NULL) { SDL_assert(cb->fp != NULL); result = fclose(cb->fp); } else { @@ -834,7 +790,6 @@ CFILE *cf_open_fill_cfblock(FILE *fp, int type) cfp = &Cfile_list[cfile_block_index];; cfp->id = cfile_block_index; cfp->version = 0; - cfbp->data = NULL; cfbp->fp = fp; cfbp->dir_type = type; @@ -867,7 +822,6 @@ CFILE *cf_open_packed_cfblock(FILE *fp, int type, int offset, int size) cfp = &Cfile_list[cfile_block_index]; cfp->id = cfile_block_index; cfp->version = 0; - cfbp->data = NULL; cfbp->fp = fp; cfbp->dir_type = type; @@ -879,70 +833,11 @@ CFILE *cf_open_packed_cfblock(FILE *fp, int type, int offset, int size) } - -// cf_open_mapped_fill_cfblock() will fill up a Cfile_block element in the Cfile_block_list[] array -// for the case of a file being opened by cf_open_mapped(); -// -// returns: ptr CFILE structure. -// -CFILE *cf_open_mapped_fill_cfblock(HANDLE hFile, int type) -{ - int cfile_block_index; - - cfile_block_index = cfget_cfile_block(); - if ( cfile_block_index == -1 ) { - return NULL; - } - else { - CFILE *cfp; - Cfile_block *cfbp; - cfbp = &Cfile_block_list[cfile_block_index]; - - cfp = &Cfile_list[cfile_block_index]; - cfp->id = cfile_block_index; - cfbp->fp = NULL; - cfbp->hInFile = hFile; - cfbp->dir_type = type; - - cf_init_lowlevel_read_code(cfp,0 , 0 ); - -#ifdef PLAT_UNIX - STUB_FUNCTION; -#else - cfbp->hMapFile = CreateFileMapping(cfbp->hInFile, NULL, PAGE_READONLY, 0, 0, NULL); - if (cfbp->hMapFile == NULL) { - nprintf(("Error", "Could not create file-mapping object.\n")); - return NULL; - } - - cfbp->data = (ubyte*)MapViewOfFile(cfbp->hMapFile, FILE_MAP_READ, 0, 0, 0); - SDL_assert( cfbp->data != NULL ); -#endif - return cfp; - } -} - int cf_get_dir_type(CFILE *cfile) { return Cfile_block_list[cfile->id].dir_type; } -// cf_returndata() returns the data pointer for a memory-mapped file that is associated -// with the CFILE structure passed as a parameter -// -// - -void *cf_returndata(CFILE *cfile) -{ - SDL_assert(cfile != NULL); - Cfile_block *cb; - SDL_assert(cfile->id >= 0 && cfile->id < MAX_CFILE_BLOCKS); - cb = &Cfile_block_list[cfile->id]; - SDL_assert(cb->data != NULL); - return cb->data; -} - - // version number of opened file. Will be 0 unless you put something else here after you // open a file. Once set, you can use minimum version numbers with the read functions. @@ -1209,9 +1104,6 @@ int cfilelength( CFILE * cfile ) SDL_assert(cfile->id >= 0 && cfile->id < MAX_CFILE_BLOCKS); cb = &Cfile_block_list[cfile->id]; - // TODO: return length of memory mapped file - SDL_assert( !cb->data ); - SDL_assert(cb->fp != NULL); // cb->size gets set at cfopen @@ -1236,9 +1128,6 @@ int cfwrite(const void *buf, int elsize, int nelem, CFILE *cfile) int size = elsize * nelem; - // cfwrite() not supported for memory-mapped files - SDL_assert( !cb->data ); - SDL_assert(cb->fp != NULL); SDL_assert(cb->lib_offset == 0 ); int bytes_written = fwrite( buf, 1, size, cb->fp ); @@ -1270,9 +1159,6 @@ int cfputc(int c, CFILE *cfile) SDL_assert(cfile->id >= 0 && cfile->id < MAX_CFILE_BLOCKS); cb = &Cfile_block_list[cfile->id]; - // cfputc() not supported for memory-mapped files - SDL_assert( !cb->data ); - SDL_assert(cb->fp != NULL); result = fputc(c, cb->fp); @@ -1359,7 +1245,6 @@ int cfputs(const char *str, CFILE *cfile) int result = 0; // cfputs() not supported for memory-mapped files - SDL_assert( !cb->data ); SDL_assert(cb->fp != NULL); result = fputs(str, cb->fp); @@ -1599,9 +1484,6 @@ int cflush(CFILE *cfile) SDL_assert(cfile->id >= 0 && cfile->id < MAX_CFILE_BLOCKS); cb = &Cfile_block_list[cfile->id]; - // not supported for memory mapped files - SDL_assert( !cb->data ); - SDL_assert(cb->fp != NULL); return fflush(cb->fp); } diff --git a/src/cfile/cfilearchive.cpp b/src/cfile/cfilearchive.cpp index 78a844c..9fca15a 100644 --- a/src/cfile/cfilearchive.cpp +++ b/src/cfile/cfilearchive.cpp @@ -141,9 +141,6 @@ int cfeof(CFILE *cfile) int result = 0; - // cfeof() not supported for memory-mapped files - SDL_assert( !cb->data ); - SDL_assert(cb->fp != NULL); #if defined(CHECK_POSITION) && !defined(NDEBUG) @@ -172,9 +169,6 @@ int cftell( CFILE * cfile ) SDL_assert(cfile->id >= 0 && cfile->id < MAX_CFILE_BLOCKS); cb = &Cfile_block_list[cfile->id]; - // Doesn't work for memory mapped files - SDL_assert( !cb->data ); - SDL_assert(cb->fp != NULL); #if defined(CHECK_POSITION) && !defined(NDEBUG) @@ -199,9 +193,6 @@ int cfseek( CFILE *cfile, int offset, int where ) SDL_assert(cfile->id >= 0 && cfile->id < MAX_CFILE_BLOCKS); cb = &Cfile_block_list[cfile->id]; - - // TODO: seek to offset in memory mapped file - SDL_assert( !cb->data ); SDL_assert( cb->fp != NULL ); int goal_position; @@ -249,8 +240,6 @@ int cfread(void *buf, int elsize, int nelem, CFILE *cfile) Cfile_block *cb; cb = &Cfile_block_list[cfile->id]; - // cfread() not supported for memory-mapped files - SDL_assert( !cb->data ); SDL_assert(cb->fp != NULL); int size = elsize*nelem; diff --git a/src/menuui/techmenu.cpp b/src/menuui/techmenu.cpp index f069ec4..2c8ed05 100644 --- a/src/menuui/techmenu.cpp +++ b/src/menuui/techmenu.cpp @@ -1461,12 +1461,12 @@ int techroom_load_ani(anim **animpp, char *name) return 0; } - *animpp = anim_load(anim_filename, 1); + *animpp = anim_load(anim_filename); if ( *animpp ) { return 1; } else if (gr_screen.res == GR_1024) { // try to load low-res version if hi-res failed - *animpp = anim_load(name, 1); + *animpp = anim_load(name); if (*animpp) { return 1; } diff --git a/src/mission/missionmessage.cpp b/src/mission/missionmessage.cpp index 440c443..1d6edb1 100644 --- a/src/mission/missionmessage.cpp +++ b/src/mission/missionmessage.cpp @@ -1274,7 +1274,7 @@ void message_play_anim( message_q *q ) if ( (anim_info->anim_data != NULL) && !strstr(anim_info->anim_data->name, ani_name) ) message_mission_free_avi( m->avi_info.index ); - anim_info->anim_data = anim_load( ani_name, 0 ); + anim_info->anim_data = anim_load( ani_name ); if ( anim_info->anim_data == NULL ) { nprintf (("messaging", "Cannot load message avi %s. Will not play.\n", ani_name)); diff --git a/src/missionui/missioncmdbrief.cpp b/src/missionui/missioncmdbrief.cpp index a40a897..f90c12a 100644 --- a/src/missionui/missioncmdbrief.cpp +++ b/src/missionui/missioncmdbrief.cpp @@ -650,7 +650,7 @@ void cmd_brief_ani_wave_init(int index) break; } - Cur_cmd_brief->stage[index].anim = anim_load(name, 1); + Cur_cmd_brief->stage[index].anim = anim_load(name); if ( Cur_cmd_brief->stage[index].anim ) { break; } @@ -666,7 +666,7 @@ void cmd_brief_ani_wave_init(int index) // check to see if cb anim loaded, if not, try the default one if ( !Cur_cmd_brief->stage[index].anim ) { - Cur_cmd_brief->stage[index].anim = anim_load(NOX("CB_default"), 1); + Cur_cmd_brief->stage[index].anim = anim_load(NOX("CB_default")); } } diff --git a/src/missionui/missionshipchoice.cpp b/src/missionui/missionshipchoice.cpp index 47d5ac0..108a647 100644 --- a/src/missionui/missionshipchoice.cpp +++ b/src/missionui/missionshipchoice.cpp @@ -1901,11 +1901,11 @@ anim* ss_load_individual_animation(int ship_class) // GRR must add a .ANI at the end for detection SDL_strlcat(animation_filename, ".ani", sizeof(animation_filename)); - p_anim = anim_load(animation_filename, 1); + p_anim = anim_load(animation_filename); if (p_anim == NULL) { // failed loading hi-res, revert to low res SDL_strlcpy(animation_filename, Ship_info[ship_class].anim_filename, sizeof(animation_filename)); - p_anim = anim_load(animation_filename, 1); + p_anim = anim_load(animation_filename); mprintf(("Ship ANI: Can not find %s, using lowres version instead.\n", animation_filename)); } else { mprintf(("SHIP ANI: Found hires version of %s\n",animation_filename)); @@ -1923,7 +1923,7 @@ anim* ss_load_individual_animation(int ship_class) */ } else { SDL_strlcpy(animation_filename, Ship_info[ship_class].anim_filename, sizeof(animation_filename)); - p_anim = anim_load(animation_filename, 1); + p_anim = anim_load(animation_filename); } return p_anim; diff --git a/src/missionui/missionweaponchoice.cpp b/src/missionui/missionweaponchoice.cpp index 4665509..9bde593 100644 --- a/src/missionui/missionweaponchoice.cpp +++ b/src/missionui/missionweaponchoice.cpp @@ -1453,12 +1453,12 @@ void wl_load_anim(int weapon_class) // now check if file exists // GRR must add a .ANI at the end for detection SDL_strlcat(animation_filename,".ani", sizeof(animation_filename)); - icon->anim = anim_load(animation_filename, 1); + icon->anim = anim_load(animation_filename); if (icon->anim == NULL) { mprintf(("Weapon ANI: Can not find %s, using lowres version instead.\n",animation_filename)); SDL_strlcpy(animation_filename, Weapon_info[weapon_class].anim_filename, sizeof(animation_filename)); - icon->anim = anim_load(animation_filename, 1); + icon->anim = anim_load(animation_filename); } /* @@ -1474,8 +1474,7 @@ void wl_load_anim(int weapon_class) } else { SDL_strlcpy(animation_filename, Weapon_info[weapon_class].anim_filename, sizeof(animation_filename)); // load the compressed ship animation into memory - // NOTE: if last parm of load_anim is 1, the anim file is mapped to memory - icon->anim = anim_load(animation_filename, 1); + icon->anim = anim_load(animation_filename); } if ( icon->anim == NULL ) { -- 2.39.2