Skip to content

Commit 0a19616

Browse files
committed
Correct inconsistency in anim_load() regarding memory-mapped files.
In commit 735f5e1 randomtiger changed how anim_load() worked in seemingly-bizarre ways, for reasons unclear to me. In brief, a condition's logic was reversed, a three-value enum was created of which only one value was used, and as a result loose files passed to anim_load() (and only loose files) would be opened as "memory-mapped", one consequence of which is that they'd keep a cfile block open until the corresponding call to anim_free() (which means that, if a mission had enough different loose animations, the cfile block limit could be reached). Since files in packfiles behaved the same way they always had (namely, being loaded into memory and then closed, thereby not taking up a cfile block), apparently nobody noticed the difference, and this inconsistent code has stayed for the past 13-and-a-half years. This commit changes the condition after the one changed in the older commit so that they both match, then changes the enum so that the seemingly-meaningless third value is removed, and the other two values are swapped (and the default value of the file_mapped parameter to anim_load() changed) so that the original Volition behavior is restored.
1 parent 6da72bb commit 0a19616

File tree

2 files changed

+4
-5
lines changed

2 files changed

+4
-5
lines changed

code/anim/animplay.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -765,7 +765,7 @@ anim *anim_load(const char *real_filename, int cf_dir_type, int file_mapped)
765765
}
766766

767767
// couldn't memory-map file... must be in a packfile, so stream manually
768-
if ( file_mapped && !ptr->cfile_ptr ) {
768+
if ( file_mapped == PAGE_FROM_MEM && !ptr->cfile_ptr ) {
769769
ptr->flags &= ~ANF_MEM_MAPPED;
770770
ptr->flags |= ANF_STREAMED;
771771
ptr->cfile_ptr = cfopen(name, "rb", CFILE_NORMAL, cf_dir_type);

code/anim/animplay.h

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -40,9 +40,8 @@ typedef struct {
4040

4141
enum
4242
{
43-
PAGE_FROM_MEM = 0,
44-
PAGE_FROM_DISK = 1,
45-
PAGE_FROM_DISK_FORCED = 2
43+
PAGE_FROM_DISK = 0,
44+
PAGE_FROM_MEM = 1
4645
};
4746

4847
extern int Anim_paused;
@@ -59,7 +58,7 @@ int anim_stop_playing(anim_instance* anim_instance);
5958
int anim_show_next_frame(anim_instance *instance, float frametime);
6059
void anim_release_all_instances(int screen_id = 0);
6160
void anim_release_render_instance(anim_instance* instance);
62-
anim *anim_load(const char *name, int cf_dir_type = CF_TYPE_ANY, int file_mapped = PAGE_FROM_MEM);
61+
anim *anim_load(const char *name, int cf_dir_type = CF_TYPE_ANY, int file_mapped = PAGE_FROM_DISK);
6362
int anim_free(anim *ptr);
6463
int anim_playing(anim_instance *ai);
6564
int anim_write_frames_out(char *filename);

0 commit comments

Comments
 (0)