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

Function PPic_GetBitmapHandle

Descent3/PilotPicsAPI.cpp:420–468  ·  view source on GitHub ↗

---------------------------------------------------------- PPic_GetBitmapHandle Purpose: Given a pilot id, it will return a handle to the bitmap for the pilot. MAKE SURE YOU FREE THE BITMAP WITH bm_FreeBitmap(). Returns -1 if it was an illegal pilot id. Returns BAD_BITMAP_HANDLE if it couldn't open the bitmap. ----------------------------------------------------------

Source from the content-addressed store, hash-verified

418// Returns BAD_BITMAP_HANDLE if it couldn't open the bitmap.
419// ----------------------------------------------------------
420int PPic_GetBitmapHandle(uint16_t pilot_id) {
421 if (!PilotPic_init)
422 return -1;
423
424 int oldoffset = cftell(PilotPic_database_index_handle);
425
426 int offset = PPic_GetOffsetByID(pilot_id);
427 if (offset == -1)
428 return -1;
429
430 // jump to the offset
431 // ------------------
432 cfseek(PilotPic_database_index_handle, offset, SEEK_SET);
433 if (cfeof(PilotPic_database_index_handle)) {
434 cfseek(PilotPic_database_index_handle, oldoffset, SEEK_SET);
435 return -1;
436 }
437
438 // read in the pilot name
439 // ----------------------
440 uint8_t name_size;
441 char name_buffer[PILOT_STRING_SIZE];
442 name_size = cf_ReadByte(PilotPic_database_index_handle);
443 if (cfeof(PilotPic_database_index_handle)) {
444 cfseek(PilotPic_database_index_handle, oldoffset, SEEK_SET);
445 return -1;
446 }
447 cf_ReadBytes((uint8_t *)name_buffer, name_size, PilotPic_database_index_handle);
448 name_buffer[name_size] = '\0';
449
450 // next read in pilot_id
451 uint16_t pid;
452 pid = (uint16_t)cf_ReadShort(PilotPic_database_index_handle);
453
454 // next read past the bitmap name
455 uint8_t bmp_size;
456 char bitmap_name[_MAX_PATH];
457 bmp_size = cf_ReadByte(PilotPic_database_index_handle);
458 cf_ReadBytes((uint8_t *)bitmap_name, bmp_size, PilotPic_database_index_handle);
459 bitmap_name[bmp_size] = '\0';
460
461 cfseek(PilotPic_database_index_handle, oldoffset, SEEK_SET);
462
463 int bm_handle = bm_AllocLoadFileBitmap(IGNORE_TABLE(bitmap_name), 0);
464 if (bm_handle <= BAD_BITMAP_HANDLE)
465 return BAD_BITMAP_HANDLE;
466
467 return bm_handle;
468}
469
470// ===============================================================================
471

Callers 1

Calls 8

cftellFunction · 0.85
PPic_GetOffsetByIDFunction · 0.85
cfseekFunction · 0.85
cfeofFunction · 0.85
cf_ReadByteFunction · 0.85
cf_ReadBytesFunction · 0.85
cf_ReadShortFunction · 0.85
bm_AllocLoadFileBitmapFunction · 0.85

Tested by

no test coverage detected