From a3871cfefd80107c53af93c3d43d2d500cf04bf7 Mon Sep 17 00:00:00 2001 From: Kp Date: Sat, 31 Mar 2018 21:53:01 +0000 Subject: [PATCH] Tighten eclip::dest_bm_num handling Instead of testing for -1, test for any out-of-range value. --- common/main/effects.h | 2 +- d1x-rebirth/main/bmread.cpp | 2 +- d2x-rebirth/main/bmread.cpp | 4 ++-- similar/main/collide.cpp | 10 +++++----- similar/main/net_udp.cpp | 8 +++++--- similar/main/paging.cpp | 2 +- similar/main/wall.cpp | 6 ++++-- 7 files changed, 19 insertions(+), 15 deletions(-) diff --git a/common/main/effects.h b/common/main/effects.h index c2a1d0667..30ee4dfc1 100644 --- a/common/main/effects.h +++ b/common/main/effects.h @@ -60,7 +60,7 @@ struct eclip : public prohibit_void_ptr short changing_object_texture; //Which element of ObjBitmapPtrs array to replace. int flags; //see above int crit_clip; //use this clip instead of above one when mine critical - int dest_bm_num; //use this bitmap when monitor destroyed + unsigned dest_bm_num; //use this bitmap when monitor destroyed int dest_vclip; //what vclip to play when exploding int dest_eclip; //what eclip to play when exploding fix dest_size; //3d size of explosion diff --git a/d1x-rebirth/main/bmread.cpp b/d1x-rebirth/main/bmread.cpp index 4d69edcec..cd2c955bf 100644 --- a/d1x-rebirth/main/bmread.cpp +++ b/d1x-rebirth/main/bmread.cpp @@ -703,7 +703,7 @@ static void bm_read_eclip(const std::string &dest_bm, const char *const arg, int Effects[clip_num].dest_eclip = dest_eclip; } else { - Effects[clip_num].dest_bm_num = -1; + Effects[clip_num].dest_bm_num = ~0u; Effects[clip_num].dest_eclip = eclip_none; } diff --git a/d2x-rebirth/main/bmread.cpp b/d2x-rebirth/main/bmread.cpp index f5a6f67e0..2f8f0e604 100644 --- a/d2x-rebirth/main/bmread.cpp +++ b/d2x-rebirth/main/bmread.cpp @@ -681,7 +681,6 @@ static void set_texture_name(char *name) static void bm_read_eclip(int skip) { bitmap_index bitmap; - int dest_bm_num = 0; assert(clip_num < Effects.size()); @@ -690,6 +689,7 @@ static void bm_read_eclip(int skip) Effects[clip_num].flags = 0; + unsigned dest_bm_num = 0; //load the dest bitmap first, so that after this routine, the last-loaded //texture will be the monitor, so that lighting parameter will be applied //to the correct texture @@ -803,7 +803,7 @@ static void bm_read_eclip(int skip) Effects[clip_num].dest_eclip = dest_eclip; } else { - Effects[clip_num].dest_bm_num = -1; + Effects[clip_num].dest_bm_num = ~0u; Effects[clip_num].dest_eclip = eclip_none; } diff --git a/similar/main/collide.cpp b/similar/main/collide.cpp index aa28e757e..6c66c598b 100644 --- a/similar/main/collide.cpp +++ b/similar/main/collide.cpp @@ -540,14 +540,13 @@ static int effect_parent_is_guidebot(fvcobjptr &vcobjptr, const laser_parent &la namespace dsx { int check_effect_blowup(const vmsegptridx_t seg,int side,const vms_vector &pnt, const laser_parent &blower, int force_blowup_flag, int remote) { - int tm,db; + int tm; #if defined(DXX_BUILD_DESCENT_I) static constexpr std::integral_constant force_blowup_flag{}; #elif defined(DXX_BUILD_DESCENT_II) int trigger_check = 0, is_trigger = 0; auto wall_num = seg->sides[side].wall_num; - db=0; // If this wall has a trigger and the blower-upper is not the player or the buddy, abort! trigger_check = !(blower.parent_type == OBJ_PLAYER || effect_parent_is_guidebot(vcobjptr, blower)); @@ -565,12 +564,13 @@ int check_effect_blowup(const vmsegptridx_t seg,int side,const vms_vector &pnt, int tmf = tm&0xc000; //tm flags tm &= 0x3fff; //tm without flags - const int ec = TmapInfo[tm].eclip_num; + const auto ec = TmapInfo[tm].eclip_num; + unsigned db = 0; #if defined(DXX_BUILD_DESCENT_I) - if (ec!=-1 && (db=Effects[ec].dest_bm_num)!=-1 && !(Effects[ec].flags&EF_ONE_SHOT)) + if (ec != eclip_none && (db = Effects[ec].dest_bm_num) != ~0u && !(Effects[ec].flags & EF_ONE_SHOT)) #elif defined(DXX_BUILD_DESCENT_II) //check if it's an animation (monitor) or casts light - if ((ec!=-1 && ((db=Effects[ec].dest_bm_num)!=-1 && !(Effects[ec].flags&EF_ONE_SHOT))) || (ec==-1 && (TmapInfo[tm].destroyed!=-1))) + if ((ec != eclip_none && ((db = Effects[ec].dest_bm_num) != ~0u && !(Effects[ec].flags & EF_ONE_SHOT))) || (ec == eclip_none && (TmapInfo[tm].destroyed != -1))) #endif { const grs_bitmap *bm = &GameBitmaps[Textures[tm].index]; diff --git a/similar/main/net_udp.cpp b/similar/main/net_udp.cpp index b02b80bd8..c81c9fc2b 100644 --- a/similar/main/net_udp.cpp +++ b/similar/main/net_udp.cpp @@ -50,6 +50,7 @@ #include "physics.h" #include "hudmsg.h" #include "switch.h" +#include "textures.h" #include "automap.h" #include "event.h" #include "playsave.h" @@ -1794,7 +1795,7 @@ static void net_udp_process_monitor_vector(uint32_t vector) { if ( ((tm = j.tmap_num2) != 0) && ((ec = TmapInfo[tm&0x3fff].eclip_num) != -1) && - ((bm = Effects[ec].dest_bm_num) != -1) ) + (bm = Effects[ec].dest_bm_num) != ~0u) { if (vector & 1) { @@ -1851,7 +1852,8 @@ static int net_udp_create_monitor_vector(void) blown_bitmap_array blown_bitmaps; range_for (auto &i, partial_const_range(Effects, Num_effects)) { - if (i.dest_bm_num > 0) { + if (i.dest_bm_num < Textures.size()) + { blown_bitmaps.insert_unique(i.dest_bm_num); } } @@ -1864,7 +1866,7 @@ static int net_udp_create_monitor_vector(void) if ((tm = j.tmap_num2) != 0) { if ( ((ec = TmapInfo[tm&0x3fff].eclip_num) != -1) && - (Effects[ec].dest_bm_num != -1) ) + Effects[ec].dest_bm_num != ~0u) { monitor_num++; Assert(monitor_num < 32); diff --git a/similar/main/paging.cpp b/similar/main/paging.cpp index 74ffc24da..5892219aa 100644 --- a/similar/main/paging.cpp +++ b/similar/main/paging.cpp @@ -76,7 +76,7 @@ static void paging_touch_wall_effects( int tmap_num ) if ( i.changing_wall_texture == tmap_num ) { paging_touch_vclip(i.vc); - if (i.dest_bm_num > -1) + if (i.dest_bm_num < Textures.size()) PIGGY_PAGE_IN( Textures[i.dest_bm_num] ); //use this bitmap when monitor destroyed if ( i.dest_vclip > -1 ) paging_touch_vclip(Vclip[i.dest_vclip]); //what vclip to play when exploding diff --git a/similar/main/wall.cpp b/similar/main/wall.cpp index 067238c99..130b8f71b 100644 --- a/similar/main/wall.cpp +++ b/similar/main/wall.cpp @@ -1387,11 +1387,13 @@ static void bng_process_segment(const object &objp, fix damage, const vmsegptrid // Process only walls which have glass. if ((tm=segp->sides[sidenum].tmap_num2) != 0) { - int ec, db; + int ec; tm &= 0x3fff; //tm without flags - if ((((ec=TmapInfo[tm].eclip_num)!=-1) && ((db=Effects[ec].dest_bm_num)!=-1 && !(Effects[ec].flags&EF_ONE_SHOT))) || (ec==-1 && (TmapInfo[tm].destroyed!=-1))) { + if (((ec = TmapInfo[tm].eclip_num) != -1 && + (Effects[ec].dest_bm_num != ~0u && !(Effects[ec].flags & EF_ONE_SHOT))) || (ec == -1 && (TmapInfo[tm].destroyed != -1))) + { const auto &&pnt = compute_center_point_on_side(vcvertptr, segp, sidenum); dist = vm_vec_dist_quick(pnt, objp.pos); if (dist < damage/2) {