Use enumerated_array for unique_segment::sides

This commit is contained in:
Kp 2022-01-15 20:39:10 +00:00
parent ab9242fb67
commit 4a6a4c4646
13 changed files with 27 additions and 32 deletions

View file

@ -30,7 +30,7 @@ COPYRIGHT 1993-1998 PARALLAX SOFTWARE CORPORATION. ALL RIGHTS RESERVED.
void assign_light_to_side(unique_side &);
#ifdef dsx
static inline void assign_light_to_side(unique_segment &sp, const uint_fast32_t sidenum)
static inline void assign_light_to_side(unique_segment &sp, const sidenum_t sidenum)
{
assign_light_to_side(sp.sides[sidenum]);
}

View file

@ -70,7 +70,7 @@ struct eclip : public prohibit_void_ptr<eclip>
fix dest_size; //3d size of explosion
int sound_num; //what sound this makes
segnum_t segnum;
uint8_t sidenum; //what seg & side, for one-shot clips
sidenum_t sidenum; //what seg & side, for one-shot clips
};
extern unsigned Num_effects;

View file

@ -222,7 +222,7 @@ void wall_toggle(fvmwallptr &vmwallptr, vmsegptridx_t segnum, sidenum_t side);
void wall_frame_process();
//set the tmap_num or tmap_num2 field for a wall/door
void wall_set_tmap_num(const wclip &, vmsegptridx_t seg, unsigned side, vmsegptridx_t csegp, unsigned cside, unsigned frame_num);
void wall_set_tmap_num(const wclip &, vmsegptridx_t seg, sidenum_t side, vmsegptridx_t csegp, sidenum_t cside, unsigned frame_num);
void wclip_read(PHYSFS_File *, wclip &wc);
void wall_read(PHYSFS_File *fp, wall &w);
void wall_write(PHYSFS_File *fp, const wall &w, short version);

View file

@ -233,7 +233,7 @@ struct unique_segment
uint8_t slide_textures;
/* endif */
fix static_light;
std::array<unique_side, MAX_SIDES_PER_SEGMENT> sides;
enumerated_array<unique_side, MAX_SIDES_PER_SEGMENT, sidenum_t> sides;
};
struct segment : unique_segment, shared_segment
@ -339,7 +339,7 @@ namespace dsx {
struct delta_light : prohibit_void_ptr<delta_light>
{
segnum_t segnum;
uint8_t sidenum;
sidenum_t sidenum;
std::array<ubyte, 4> vert_light;
};

View file

@ -48,7 +48,7 @@ static fix get_light_intensity(const unique_side &s, const uint_fast32_t vert)
return s.uvls[vert].l;
}
static fix get_light_intensity(const unique_segment &segp, const uint_fast32_t sidenum, const uint_fast32_t vert)
static fix get_light_intensity(const unique_segment &segp, const sidenum_t sidenum, const uint_fast32_t vert)
{
Assert(sidenum <= MAX_SIDES_PER_SEGMENT);
return get_light_intensity(segp.sides[sidenum], vert);
@ -72,9 +72,8 @@ static void set_light_intensity(unique_side &s, const uint_fast32_t vert, const
Update_flags |= UF_WORLD_CHANGED;
}
static void set_light_intensity(unique_segment &segp, const uint_fast32_t sidenum, const uint_fast32_t vert, const fix intensity)
static void set_light_intensity(unique_segment &segp, const sidenum_t sidenum, const uint_fast32_t vert, const fix intensity)
{
Assert(sidenum <= MAX_SIDES_PER_SEGMENT);
set_light_intensity(segp.sides[sidenum], vert, intensity);
}
@ -133,7 +132,7 @@ static void apply_light_intensity(const csmusegment segp, const sidenum_t sidenu
// the associated intensity to segp. It calls apply_light_intensity to apply intensity/3
// to all neighbors. apply_light_intensity recursively calls itself to apply light to
// subsequent neighbors (and forming loops, see above).
static void propagate_light_intensity(const csmusegment segp, const unsigned sidenum)
static void propagate_light_intensity(const csmusegment segp, const sidenum_t sidenum)
{
fix intensity;

View file

@ -38,9 +38,6 @@ int AssignTexture(void)
const auto t1 = build_texture1_value(CurrentTexture);
Cursegp->unique_segment::sides[Curside].tmap_num = t1;
New_segment.unique_segment::sides[Curside].tmap_num = t1;
// propagate_light_intensity(Cursegp, Curside, CurrentTexture, 0);
Update_flags |= UF_WORLD_CHANGED;
return 1;

View file

@ -630,7 +630,7 @@ static void med_assign_uvs_to_side(const vmsegptridx_t con_seg, const sidenum_t
// Since we can attach any side of a segment to any side of another segment, and do so in each case in
// four different rotations (for a total of 6*6*4 = 144 ways), not having this nifty function will cause
// great confusion.
static std::pair<int, int> get_side_ids(const shared_segment &base_seg, const shared_segment &con_seg, int base_side, int con_side, const vertnum_t abs_id1, const vertnum_t abs_id2)
static std::pair<sidenum_t, sidenum_t> get_side_ids(const shared_segment &base_seg, const shared_segment &con_seg, sidenum_t base_side, sidenum_t con_side, const vertnum_t abs_id1, const vertnum_t abs_id2)
{
if (&base_seg == &con_seg)
return {base_side, con_side};
@ -680,7 +680,7 @@ static std::pair<int, int> get_side_ids(const shared_segment &base_seg, const sh
// The two vertices abs_id1 and abs_id2 are the only two vertices common to the two sides.
// If uv_only_flag is 1, then don't assign texture map ids, only update the uv coordinates
// If uv_only_flag is -1, then ONLY assign texture map ids, don't update the uv coordinates
static void propagate_tmaps_to_segment_side(const vcsegptridx_t base_seg, const int base_side, const vmsegptridx_t con_seg, const int con_side, const vertnum_t abs_id1, const vertnum_t abs_id2, const int uv_only_flag)
static void propagate_tmaps_to_segment_side(const vcsegptridx_t base_seg, const sidenum_t base_side, const vmsegptridx_t con_seg, const sidenum_t con_side, const vertnum_t abs_id1, const vertnum_t abs_id2, const int uv_only_flag)
{
Assert ((uv_only_flag == -1) || (uv_only_flag == 0) || (uv_only_flag == 1));
@ -780,7 +780,7 @@ int fix_bogus_uvs_on_side(void)
namespace {
static void fix_bogus_uvs_on_side1(const vmsegptridx_t sp, const unsigned sidenum, const int uvonly_flag)
static void fix_bogus_uvs_on_side1(const vmsegptridx_t sp, const sidenum_t sidenum, const int uvonly_flag)
{
auto &uvls = sp->unique_segment::sides[sidenum].uvls;
if (uvls[0].u == 0 && uvls[1].u == 0 && uvls[2].u == 0)
@ -794,7 +794,7 @@ static void fix_bogus_uvs_seg(const vmsegptridx_t segp)
for (const auto &&[idx, value] : enumerate(segp->children))
{
if (!IS_CHILD(value))
fix_bogus_uvs_on_side1(segp, idx, 1);
fix_bogus_uvs_on_side1(segp, static_cast<sidenum_t>(idx), 1);
}
}
@ -818,7 +818,7 @@ namespace {
// from that side in base_seg to the wall in con_seg. If the wall in base_seg is not present
// (ie, there is another segment connected through it), follow the connection through that
// segment to get the wall in the connected segment which shares the edge, and get tmap_num from there.
static void propagate_tmaps_to_segment_sides(const vcsegptridx_t base_seg, const sidenum_t base_side, const vmsegptridx_t con_seg, const int con_side, const int uv_only_flag)
static void propagate_tmaps_to_segment_sides(const vcsegptridx_t base_seg, const sidenum_t base_side, const vmsegptridx_t con_seg, const sidenum_t con_side, const int uv_only_flag)
{
int v;

View file

@ -1014,7 +1014,7 @@ static window_event_result collide_weapon_and_wall(
namespace {
static void collide_debris_and_wall(const vmobjptridx_t debris, const unique_segment &hitseg, const unsigned hitwall, const vms_vector &)
static void collide_debris_and_wall(const vmobjptridx_t debris, const unique_segment &hitseg, const sidenum_t hitwall, const vms_vector &)
{
auto &TmapInfo = LevelUniqueTmapInfoState.TmapInfo;
if (!PERSISTENT_DEBRIS || TmapInfo[get_texture_index(hitseg.sides[hitwall].tmap_num)].damage)

View file

@ -2153,7 +2153,8 @@ static void slide_textures(void)
{
if (const auto slide_seg = useg.slide_textures)
{
range_for (const int sidenum, xrange(6u)) {
for (const auto sidenum : MAX_SIDES_PER_SEGMENT)
{
if (slide_seg & (1 << sidenum))
{
auto &side = useg.sides[sidenum];

View file

@ -1680,9 +1680,8 @@ static void newdemo_record_oneframeevent_update(int wallupdate)
range_for (const auto &&wp, vcwallptr)
{
auto &w = *wp;
int side;
auto seg = &Segments[w.segnum];
side = w.sidenum;
const auto side = w.sidenum;
// actually this is kinda stupid: when playing ther same tmap will be put on front and back side of the wall ... for doors this is stupid so just record the front side which will do for doors just fine ...
auto &uside = seg->unique_segment::sides[side];
if (const auto tmap_num = uside.tmap_num; tmap_num != texture1_value::None)
@ -2820,7 +2819,7 @@ static int newdemo_read_frame_information(int rewrite)
case ND_EVENT_WALL_SET_TMAP_NUM1: {
uint16_t seg, cseg, tmap;
sbyte side,cside;
uint8_t side, cside;
nd_read_short(&seg);
nd_read_byte(&side);
@ -2837,13 +2836,13 @@ static int newdemo_read_frame_information(int rewrite)
break;
}
if ((Newdemo_vcr_state != ND_STATE_PAUSED) && (Newdemo_vcr_state != ND_STATE_REWINDING) && (Newdemo_vcr_state != ND_STATE_ONEFRAMEBACKWARD))
vmsegptr(seg)->unique_segment::sides[side].tmap_num = vmsegptr(cseg)->unique_segment::sides[cside].tmap_num = texture1_value{tmap};
vmsegptr(seg)->unique_segment::sides[(sidenum_t{side})].tmap_num = vmsegptr(cseg)->unique_segment::sides[(sidenum_t{cside})].tmap_num = texture1_value{tmap};
break;
}
case ND_EVENT_WALL_SET_TMAP_NUM2: {
uint16_t seg, cseg, tmap;
sbyte side,cside;
uint8_t side, cside;
nd_read_short(&seg);
nd_read_byte(&side);
@ -2861,8 +2860,8 @@ static int newdemo_read_frame_information(int rewrite)
}
if ((Newdemo_vcr_state != ND_STATE_PAUSED) && (Newdemo_vcr_state != ND_STATE_REWINDING) && (Newdemo_vcr_state != ND_STATE_ONEFRAMEBACKWARD)) {
unique_segment &s0 = *vmsegptr(seg);
auto &tmap_num2 = s0.sides[side].tmap_num2;
tmap_num2 = vmsegptr(cseg)->unique_segment::sides[cside].tmap_num2 = texture2_value{tmap};
auto &tmap_num2 = s0.sides[(sidenum_t{side})].tmap_num2;
tmap_num2 = vmsegptr(cseg)->unique_segment::sides[(sidenum_t{cside})].tmap_num2 = texture2_value{tmap};
}
break;
}

View file

@ -64,7 +64,7 @@ namespace dsx {
void delta_light_read(delta_light *dl, PHYSFS_File *fp)
{
dl->segnum = PHYSFSX_readShort(fp);
dl->sidenum = PHYSFSX_readByte(fp);
dl->sidenum = build_sidenum_from_untrusted(PHYSFSX_readByte(fp)).value_or(sidenum_t::WLEFT);
PHYSFSX_readByte(fp);
dl->vert_light[0] = PHYSFSX_readByte(fp);
dl->vert_light[1] = PHYSFSX_readByte(fp);

View file

@ -2412,11 +2412,10 @@ int state_restore_all_sub(const d_level_shared_destructible_light_state &LevelSh
// static_light should now be computed - now actually set tmap info
range_for (const auto &&segp, vmsegptridx)
{
range_for (const unsigned j, xrange(6u))
for (auto &&[uside, t1, t2] : zip(segp->unique_segment::sides, TempTmapNum[segp], TempTmapNum2[segp]))
{
auto &uside = segp->unique_segment::sides[j];
uside.tmap_num = TempTmapNum[segp][j];
uside.tmap_num2 = TempTmapNum2[segp][j];
uside.tmap_num = t1;
uside.tmap_num2 = t2;
}
}

View file

@ -263,7 +263,7 @@ void wall_init()
#endif
//set the tmap_num or tmap_num2 field for a wall/door
void wall_set_tmap_num(const wclip &anim, const vmsegptridx_t seg, const unsigned side, const vmsegptridx_t csegp, const unsigned cside, const unsigned frame_num)
void wall_set_tmap_num(const wclip &anim, const vmsegptridx_t seg, const sidenum_t side, const vmsegptridx_t csegp, const sidenum_t cside, const unsigned frame_num)
{
const auto newdemo_state = Newdemo_state;
if (newdemo_state == ND_STATE_PLAYBACK)