MCPcopy Create free account
hub / github.com/DescentDevelopers/Descent3 / bm_AllocLoadFileNoMemBitmap

Function bm_AllocLoadFileNoMemBitmap

bitmap/bitmain.cpp:865–916  ·  view source on GitHub ↗

Allocs and loads a bitmap but doesn't actually load texel data! Returns the handle of the loaded bitmap Returns -1 if something is wrong

Source from the content-addressed store, hash-verified

863// Returns the handle of the loaded bitmap
864// Returns -1 if something is wrong
865int bm_AllocLoadFileNoMemBitmap(const char *fname, int mipped, int format) {
866 if (!Bitmaps_initted) {
867 Int3();
868 mprintf(0, "Bitmaps not initted!!!\n");
869 return -1;
870 }
871
872 char name[BITMAP_NAME_LEN];
873 int n;
874 char *filename = (char *)fname;
875
876 // due to a bug in some people's tablefile editors, we got to make sure there is
877 // no path if there shouldn't be
878 if (!cfexist(filename)) {
879 // generate a possible new filename
880 char *end_ptr, *start_ptr;
881 start_ptr = (char *)fname;
882 end_ptr = start_ptr + strlen(start_ptr) - 1;
883 while ((end_ptr >= start_ptr) && (*end_ptr != '\\'))
884 end_ptr--;
885 if (end_ptr < start_ptr) {
886 mprintf(0, "Unable to find bitmap %s\n", fname);
887 return -1;
888 }
889 ASSERT(*end_ptr == '\\');
890 end_ptr++;
891 filename = end_ptr;
892 mprintf(0, "Couldn't find %s, so gonna try %s\n", fname, filename);
893 }
894
895 // Check to see if this bitmap is already in memory, if so, just return that
896 // bitmaps handle
897 if ((n = bm_TestName(filename)) != -1) {
898 GameBitmaps[n].used++;
899 mprintf(1, "Found duplicate bitmap %s.\n", GameBitmaps[n].name);
900 return n;
901 }
902
903 bm_ChangeEndName(filename, name);
904 if (strlen(name) > 33) {
905 mprintf(0, "ERROR!! This bitmaps name is too long, try shortening it and retry!\n");
906 return -1;
907 }
908 n = bm_AllocNoMemBitmap(1, 1);
909 strcpy(GameBitmaps[n].name, name);
910 if (mipped)
911 GameBitmaps[n].flags |= BF_WANTS_MIP;
912 if (format == BITMAP_FORMAT_4444)
913 GameBitmaps[n].flags |= BF_WANTS_4444;
914
915 return n; // We made it!
916}
917// Allocs and loads a bitmap from an open file
918// Returns the handle of the loaded bitmap
919// Returns -1 if something is wrong

Callers 1

LoadTextureImageFunction · 0.85

Calls 4

cfexistFunction · 0.85
bm_TestNameFunction · 0.85
bm_ChangeEndNameFunction · 0.85
bm_AllocNoMemBitmapFunction · 0.85

Tested by

no test coverage detected