Skip to content

Commit

Permalink
chore: clean up some subscreen item animation code/replay errors
Browse files Browse the repository at this point in the history
  • Loading branch information
EmilyV99 committed Aug 20, 2023
1 parent 82b9954 commit 97be172
Show file tree
Hide file tree
Showing 10 changed files with 66 additions and 38 deletions.
18 changes: 16 additions & 2 deletions src/new_subscr.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,10 +34,11 @@ void magicgauge(BITMAP *dest,int32_t x,int32_t y, int32_t container, int32_t not
int32_t cap_tile, int32_t cap_cset, bool cap_mod, int32_t aftercap_tile, int32_t aftercap_cset, bool aftercap_mod, int32_t frames, int32_t speed, int32_t delay, bool unique_last, int32_t show);

int subscr_item_clk = 0;
bool subscr_itemless = false;
int btnitem_clks[4] = {0};
int btnitem_ids[4] = {0};

void reset_subscr_items()
void refresh_subscr_buttonitems()
{
for(int q = 0; q < 4; ++q)
{
Expand All @@ -46,7 +47,7 @@ void reset_subscr_items()
}
}

void update_subscr_items()
void animate_subscr_buttonitems()
{
int nullval = get_qr(qr_ITM_0_INVIS_ON_BTNS) ? 0 : -1;
int ids[] = {Awpn,Bwpn,Xwpn,Ywpn};
Expand All @@ -62,6 +63,17 @@ void update_subscr_items()
}
}

void refresh_subscr_items()
{
subscr_item_clk = 0;
subscr_itemless = false;
}

void kill_subscr_items()
{
subscr_itemless = true;
}

int32_t to_real_font(int32_t ss_font)
{
switch(ss_font)
Expand Down Expand Up @@ -1190,6 +1202,7 @@ byte SW_ButtonItem::getType() const
}
void SW_ButtonItem::draw(BITMAP* dest, int32_t xofs, int32_t yofs, SubscrPage& page) const
{
if(!show_subscreen_items) return;
if(flags&SUBSCR_BTNITM_TRANSP)
drawing_mode(DRAW_MODE_TRANS, NULL, 0, 0);

Expand Down Expand Up @@ -2186,6 +2199,7 @@ int32_t SW_ItemSlot::getDisplayItem() const
}
void SW_ItemSlot::draw(BITMAP* dest, int32_t xofs, int32_t yofs, SubscrPage& page) const
{
if(subscr_itemless) return;
#ifdef IS_PLAYER
if(flags&SUBSCR_CURITM_INVIS)
return;
Expand Down
1 change: 1 addition & 0 deletions src/new_subscr.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ struct PACKFILE;
#define NEG_OR_MASK(v,mask) (v < 0 ? v : (v&mask))

extern int subscr_item_clk;
extern bool subscr_itemless;

//Old subscreen stuff
struct subscreen_object
Expand Down
9 changes: 1 addition & 8 deletions src/subscr.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@ bool show_subscreen_dmap_dots=true;
bool show_subscreen_numbers=true;
bool show_subscreen_items=true;
bool show_subscreen_life=true;
bool new_sel=false;

extern sprite_list guys, items, Ewpns, Lwpns, chainlinks, decorations;
extern HeroClass Hero;
Expand Down Expand Up @@ -3396,7 +3395,7 @@ void minimaptitle(BITMAP *dest, int32_t x, int32_t y, FONT *tempfont, int32_t co
void put_passive_subscr(BITMAP *dest,int32_t x,int32_t y,bool showtime,int32_t pos2)
{
++subscr_item_clk;
update_subscr_items();
animate_subscr_buttonitems();
BITMAP *subscr = create_sub_bitmap(dest,x,y,256,passive_subscreen_height);

if(no_subscreen())
Expand Down Expand Up @@ -3766,12 +3765,6 @@ void putBmap(BITMAP *dest, int32_t x, int32_t y,bool showmap, bool showrooms, bo
}
}

void load_Sitems()
{
subscr_item_clk = 0;
new_sel=true;
}

void update_subscreens(int32_t dmap)
{
if(dmap<0)
Expand Down
7 changes: 4 additions & 3 deletions src/subscr.h
Original file line number Diff line number Diff line change
Expand Up @@ -167,16 +167,17 @@ const byte bmaptiles_bs[5][6] =
{40,41,42,43,43,44}
};

void reset_subscr_items();
void update_subscr_items();
void refresh_subscr_buttonitems();
void animate_subscr_buttonitems();
void refresh_subscr_items();
void kill_subscr_items();
int32_t stripspaces(char *source, char *target, int32_t stop);
void put_passive_subscr(BITMAP *dest,int32_t x,int32_t y,bool showtime,int32_t pos2);
void puttriframe(BITMAP *dest, int32_t x, int32_t y, int32_t triframecolor, int32_t numbercolor, int32_t triframetile, int32_t triframecset, int32_t triforcetile, int32_t triforcecset, bool showframe, bool showpieces, bool largepieces);
void puttriforce(BITMAP *dest, int32_t x, int32_t y, int32_t tile, int32_t cset, int32_t w, int32_t h, int32_t flip, bool overlay, bool trans, int32_t trinum);
void draw_block(BITMAP *dest,int32_t x,int32_t y,int32_t tile,int32_t cset,int32_t w,int32_t h);
void draw_block_flip(BITMAP *dest,int32_t x,int32_t y,int32_t tile,int32_t cset,int32_t w,int32_t h,int32_t flip,bool overlay,bool trans);
void putBmap(BITMAP *dest, int32_t x, int32_t y,bool showmap, bool showrooms, bool showhero, int32_t roomcolor, int32_t herocolor, bool large);
void load_Sitems();
void textout_styled_aligned_ex(BITMAP *bmp, const FONT *f, const char *s, int32_t x, int32_t y, int32_t textstyle, int32_t alignment, int32_t color, int32_t shadow, int32_t bg);
void textprintf_styled_aligned_ex(BITMAP *bmp, const FONT *f, int32_t x, int32_t y, int32_t textstyle, int32_t alignment, int32_t color, int32_t shadow, int32_t bg, const char *format, ...);
void update_subscreens(int32_t dmap=-1);
Expand Down
2 changes: 2 additions & 0 deletions src/zc/ending.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -212,6 +212,7 @@ void ending()
Lwpns.clear();
chainlinks.clear();
decorations.clear();
kill_subscr_items();

set_uformat(U_ASCII);
kill_sfx();
Expand Down Expand Up @@ -648,6 +649,7 @@ void ending_scripted()
guys.clear();
chainlinks.clear();
decorations.clear();
kill_subscr_items();
clear_bitmap(msg_txt_display_buf);
clear_bitmap(msg_bg_display_buf);
dismissmsg();
Expand Down
29 changes: 20 additions & 9 deletions src/zc/hero.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10214,7 +10214,10 @@ static void deselectbombsWPN(word& wpos, int32_t& BTNwpn, int32_t& directItemBTN
return;
}

auto temp = pg->movepos_legacy(SEL_VERIFY_LEFT, wpos, f1, f2, f3);
auto fp1 = ((f1&0xFF)==255) ? 255 : ((empty || (f1&0xFF)==(wpos&0xFF)) ? f1 : 255);
auto fp2 = ((f2&0xFF)==255) ? 255 : ((empty || (f2&0xFF)==(wpos&0xFF)) ? f2 : 255);
auto fp3 = ((f3&0xFF)==255) ? 255 : ((empty || (f3&0xFF)==(wpos&0xFF)) ? f3 : 255);
auto temp = pg->movepos_legacy(SEL_VERIFY_LEFT, wpos, fp1, fp2, fp3);
BTNwpn = pg->get_item_pos(temp>>8);
directItemBTN = NEG_OR_MASK(BTNwpn,0xFFF);
wpos = temp;
Expand Down Expand Up @@ -28617,10 +28620,13 @@ static void selectNextBTNWpn(int32_t type, word& wpos, int32_t& BTNwpn,
SubscrPage* pg = new_subscreen_active->get_page(pgn==255?new_subscreen_active->curpage:pgn);
if(!pg)
return;
auto ret = pg->movepos_legacy(type, wpos, f1, f2, f3);
BTNwpn = pg->get_item_pos(ret>>8);
directItemBTN = NEG_OR_MASK(BTNwpn,0xFFF);
wpos = ret;
auto fp1 = ((f1&0xFF)==255) ? 255 : ((empty || (f1&0xFF)==(wpos&0xFF)) ? f1 : 255);
auto fp2 = ((f2&0xFF)==255) ? 255 : ((empty || (f2&0xFF)==(wpos&0xFF)) ? f2 : 255);
auto fp3 = ((f3&0xFF)==255) ? 255 : ((empty || (f3&0xFF)==(wpos&0xFF)) ? f3 : 255);
auto ret = pg->movepos_legacy(type, wpos, fp1, fp2, fp3);
BTNwpn = pg->get_item_pos(ret>>8);
directItemBTN = NEG_OR_MASK(BTNwpn,0xFFF);
wpos = ret;
}
void selectNextAWpn(int32_t type)
{
Expand Down Expand Up @@ -28663,9 +28669,9 @@ static void verifyWpn(word& wpos, int32_t& BTNwpn, int32_t& directItemBTN, word
SubscrPage* pg = new_subscreen_active->get_page(pgn==255?new_subscreen_active->curpage:pgn);
if(!pg)
return;
auto fp1 = ((f1&0xFF)==255) ? 255 : ((empty || (f1&0xFF)==(wpos&0xFF)) ? f1>>8 : 255);
auto fp2 = ((f2&0xFF)==255) ? 255 : ((empty || (f2&0xFF)==(wpos&0xFF)) ? f2>>8 : 255);
auto fp3 = ((f3&0xFF)==255) ? 255 : ((empty || (f3&0xFF)==(wpos&0xFF)) ? f3>>8 : 255);
auto fp1 = ((f1&0xFF)==255) ? 255 : ((empty || (f1&0xFF)==(wpos&0xFF)) ? f1 : 255);
auto fp2 = ((f2&0xFF)==255) ? 255 : ((empty || (f2&0xFF)==(wpos&0xFF)) ? f2 : 255);
auto fp3 = ((f3&0xFF)==255) ? 255 : ((empty || (f3&0xFF)==(wpos&0xFF)) ? f3 : 255);
wpos = pg->movepos_legacy(SEL_VERIFY_RIGHT, wpos, fp1, fp2, fp3);
BTNwpn = pg->get_item_pos(wpos>>8);
directItemBTN = NEG_OR_MASK(BTNwpn,0xFFF);
Expand Down Expand Up @@ -29197,7 +29203,7 @@ void getitem(int32_t id, bool nosound, bool doRunPassive)

flushItemCache();
update_subscreens();
load_Sitems();
refresh_subscr_items();
verifyBothWeapons();
}

Expand Down Expand Up @@ -30012,6 +30018,8 @@ void HeroClass::getTriforce(int32_t id2)
Lwpns.clear();
chainlinks.clear();

kill_subscr_items();

//decorations.clear();
if(!COOLSCROLL)
{
Expand Down Expand Up @@ -30467,6 +30475,9 @@ void HeroClass::heroDeathAnimation()
Lwpns.clear();
chainlinks.clear();
decorations.clear();

kill_subscr_items();

Playing = false;

game->set_deaths(zc_min(game->get_deaths()+1,USHRT_MAX));
Expand Down
6 changes: 3 additions & 3 deletions src/zc/zc_subscr.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ void dosubscr()
int32_t miny;
bool showtime = game->should_show_time();
if(replay_version_check(0,19))
load_Sitems();
refresh_subscr_items();
else flushItemCache();

pause_sfx(WAV_BRANG);
Expand Down Expand Up @@ -154,14 +154,14 @@ void dosubscr()
{
if (!get_qr(qr_NO_L_R_BUTTON_INVENTORY_SWAP))
{
pg.cursor_pos = pg.movepos_legacy(SEL_LEFT, (pos<<8)|pg.getIndex(), -1, -1, -1, false, true);
pg.cursor_pos = pg.movepos_legacy(SEL_LEFT, (pos<<8)|pg.getIndex(), 255, 255, 255, false, true);
}
}
else if(rRbtn() )
{
if (!get_qr(qr_NO_L_R_BUTTON_INVENTORY_SWAP))
{
pg.cursor_pos = pg.movepos_legacy(SEL_RIGHT, (pos<<8)|pg.getIndex(), -1, -1, -1, false, true);
pg.cursor_pos = pg.movepos_legacy(SEL_RIGHT, (pos<<8)|pg.getIndex(), 255, 255, 255, false, true);
}
}
else if(rEx3btn() )
Expand Down
17 changes: 11 additions & 6 deletions src/zc/zc_sys.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2263,24 +2263,24 @@ void removeFromItemCache(int32_t itemclass)

void flushItemCache(bool justcost)
{
if(justcost && replay_version_check(0,19))
return;
itemcache_cost.clear();
if(!justcost)
itemcache.clear();
itemcache_cost.clear();
else if(replay_version_check(0,19))
return;

//also fix the active subscreen if items were deleted -DD
if(game != NULL)
{
verifyBothWeapons();
load_Sitems();
refresh_subscr_items();
}
}

// This is used often, so it should be as direct as possible.
int32_t _c_item_id_internal(int32_t itemtype, bool checkmagic, bool jinx_check)
{
bool use_cost_cache = replay_version_check(19);
bool use_cost_cache = true;//replay_version_check(19);
if(jinx_check)
{
if(!(HeroSwordClk() || HeroItemClk()))
Expand Down Expand Up @@ -2329,11 +2329,16 @@ int32_t _c_item_id_internal(int32_t itemtype, bool checkmagic, bool jinx_check)
if (use_cost_cache)
{
if (!checkmagic)
{
itemcache[itemtype] = result;
}
if (checkmagic || result < 0 || checkmagiccost(result))
itemcache_cost[itemtype] = result;
}
else itemcache[itemtype] = result;
else
{
itemcache[itemtype] = result;
}
}
return result;
}
Expand Down
13 changes: 7 additions & 6 deletions src/zc/zelda.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2170,7 +2170,7 @@ int32_t init_game()

update_subscreens();

load_Sitems();
refresh_subscr_items();

//load the previous weapons -DD

Expand Down Expand Up @@ -2223,9 +2223,9 @@ int32_t init_game()
Ywpn = pg.get_item_pos(ypos>>8);
directItemY = NEG_OR_MASK(Ywpn,0xFF);

update_subscr_items();
animate_subscr_buttonitems();

reset_subscr_items();
refresh_subscr_buttonitems();
}
else
{
Expand Down Expand Up @@ -2255,9 +2255,9 @@ int32_t init_game()
game->bwpn = bpos;
Bwpn = pg.get_item_pos(bpos>>8);
directItemB = NEG_OR_MASK(Bwpn,0xFF);
update_subscr_items();
animate_subscr_buttonitems();

reset_subscr_items();
refresh_subscr_buttonitems();
}
}
else if(new_subscreen_active)
Expand Down Expand Up @@ -5671,7 +5671,8 @@ void remove_installed_timers()
void delete_everything_else() //blarg.
{
delete_combo_aliases();
reset_subscr_items();
refresh_subscr_buttonitems();
kill_subscr_items();
}

void quit_game()
Expand Down
2 changes: 1 addition & 1 deletion src/zq/zq_subscr.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2150,7 +2150,7 @@ void update_subscr_dlg(bool start)
if(start)
{
subscreen_dlg[0].dp2=get_zc_font(font_lfont);
load_Sitems();
refresh_subscr_items();
curr_subscreen_object=0;

if(subscr_edit.pages.empty())
Expand Down

0 comments on commit 97be172

Please sign in to comment.