shadowshine57

shop_draw cached

Oct 31st, 2023 (edited)
1,172
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 2.80 KB | Source Code | 0 0
  1. // Shop draw function for each shelf slot, replaces GetItem_Draw inside of EnGirlA_Draw
  2. void shop_draw(z64_actor_t *actor, z64_game_t *game) {
  3.     EnGirlA *this = (EnGirlA *)actor;
  4.     model_t model = {
  5.         .object_id = 0x0000,
  6.         .graphic_id = 0x00,
  7.     };
  8.  
  9.     //See if there is cached data stored in the actor's isInitialized variable at 0x018C.
  10.     //Cached data is as follows:
  11.     //2 bytes: model object_id
  12.     //1 byte: model graphic_id
  13.     uint16_t object_id = (((uint8_t*)this)[0x018D] << 1) & ((uint8_t*)this)[0x018E];
  14.     uint8_t graphic_id = ((uint8_t*)this)[0x18F];    
  15.  
  16.     /*
  17.         SOLD OUT is given a get item ID of 0x53 for the slot,
  18.         which conflicts with the Gerudo Mask override if it's
  19.         shuffled and the override in the Gerudo Mask slot happens
  20.         to be progressive. To prevent the mask shop from filling up
  21.         with longshots or golden gauntlets, check the currently loaded
  22.         object ID for OBJECT_GI_SOLDOUT (0x148) before attempting to use
  23.         the override model.
  24.     */
  25.     // There is already cached model data, use it instead of doing lookups
  26.     if (object_id > 0 && graphic_id > 0 && graphic_id != 0xFF && game->obj_ctxt.objects[this->objBankIndex].id != 0x148) {      
  27.         model.object_id = object_id;
  28.         model.graphic_id = graphic_id;
  29.         draw_model(model, actor, game, 0.0);
  30.         return;
  31.     }
  32.  
  33.     // There is no cached data, check if there needs to be
  34.     if (this->getItemId && game->obj_ctxt.objects[this->objBankIndex].id != 0x148) {
  35.         // If the item isn't overridden then we don't want to do an unnecessary lookup, so we store -1 in graphic_id
  36.         if (graphic_id != -1) {
  37.             // Look up the override so we can either cache its model data, or cache that it doesn't exist
  38.             override_t override = lookup_override((z64_actor_t*) this, z64_game.scene_index, this->getItemId);
  39.             if (override.key.all) { // Override exists, cache the model data and load
  40.                 lookup_model_by_override(&model, override);
  41.                 if (model.object_id != 0x0000) {
  42.                     // Cache object_id and graphic_id
  43.                     ((uint8_t*)this)[0x18D] = (model.object_id >> 1);
  44.                     ((uint8_t*)this)[0x18E] = (model.object_id & 0xFF);
  45.                     ((uint8_t*)this)[0x18F] = model.graphic_id;
  46.                     draw_model(model, actor, game, 0.0);
  47.                 }
  48.                 return;
  49.             }
  50.             else { // Override does not exist
  51.                 ((uint8_t*)this)[0x18D] = 0;
  52.                 ((uint8_t*)this)[0x18E] = 0;
  53.                 ((uint8_t*)this)[0x18F] = 0xFF;
  54.             }
  55.         }
  56.     }
  57.  
  58.     // vanilla draw function if the slot is a regular shop item, shuffled or unshuffled
  59.     GetItem_Draw(game, this->giDrawId);
  60. }
Advertisement
Add Comment
Please, Sign In to add comment