Use enum class for materialization_center_number
This commit is contained in:
parent
0389955d7d
commit
3e02f99bcd
|
@ -155,7 +155,7 @@ struct d_level_shared_robotcenter_state
|
|||
{
|
||||
unsigned Num_robot_centers;
|
||||
// Original D1/D2 size: 20
|
||||
std::array<matcen_info, 128> RobotCenters;
|
||||
enumerated_array<matcen_info, 128, materialization_center_number> RobotCenters;
|
||||
};
|
||||
|
||||
extern d_level_shared_robotcenter_state LevelSharedRobotcenterState;
|
||||
|
|
|
@ -66,6 +66,8 @@ void delete_segment_from_group(vmsegptridx_t segment_num, unsigned group_num);
|
|||
|
||||
namespace dcx {
|
||||
|
||||
enum class materialization_center_number : uint8_t;
|
||||
|
||||
typedef uint_fast32_t sidenum_fast_t;
|
||||
|
||||
enum sidenum_t : uint8_t
|
||||
|
|
|
@ -82,6 +82,11 @@ enum class segment_special : uint8_t
|
|||
goal_red,
|
||||
};
|
||||
|
||||
enum class materialization_center_number : uint8_t
|
||||
{
|
||||
None = 0xff,
|
||||
};
|
||||
|
||||
struct shared_side
|
||||
{
|
||||
struct illegal_type;
|
||||
|
@ -189,7 +194,7 @@ struct shared_segment
|
|||
std::array<segnum_t, MAX_SIDES_PER_SEGMENT> children; // indices of 6 children segments, front, left, top, right, bottom, back
|
||||
std::array<vertnum_t, MAX_VERTICES_PER_SEGMENT> verts; // vertex ids of 4 front and 4 back vertices
|
||||
segment_special special; // what type of center this is
|
||||
int8_t matcen_num; // which center segment is associated with.
|
||||
materialization_center_number matcen_num; // which center segment is associated with.
|
||||
uint8_t station_idx;
|
||||
/* if DXX_BUILD_DESCENT_II */
|
||||
uint8_t s2_flags;
|
||||
|
|
|
@ -599,7 +599,7 @@ static int med_copy_group(const unsigned delta_flag, const vmsegptridx_t base_se
|
|||
shared_segment &s = *vmsegptr(gs);
|
||||
s.group = new_current_group;
|
||||
s.special = segment_special::nothing;
|
||||
s.matcen_num = -1;
|
||||
s.matcen_num = materialization_center_number::None;
|
||||
}
|
||||
|
||||
auto &vcvertptr = Vertices.vcptr;
|
||||
|
|
|
@ -1051,20 +1051,19 @@ int check_walls()
|
|||
{
|
||||
auto &RobotCenters = LevelSharedRobotcenterState.RobotCenters;
|
||||
std::array<count_wall, MAX_WALLS> CountedWalls;
|
||||
int matcen_num;
|
||||
|
||||
unsigned wall_count = 0;
|
||||
range_for (const auto &&segp, vmsegptridx)
|
||||
{
|
||||
if (segp->segnum != segment_none) {
|
||||
// Check fuelcenters
|
||||
matcen_num = segp->matcen_num;
|
||||
if (matcen_num == 0)
|
||||
if (RobotCenters[0].segnum != segp) {
|
||||
segp->matcen_num = -1;
|
||||
const auto matcen_num = segp->matcen_num;
|
||||
if (matcen_num == materialization_center_number{0u})
|
||||
if (RobotCenters[matcen_num].segnum != segp) {
|
||||
segp->matcen_num = materialization_center_number::None;
|
||||
}
|
||||
|
||||
if (matcen_num > -1)
|
||||
if (matcen_num != materialization_center_number::None)
|
||||
RobotCenters[matcen_num].segnum = segp;
|
||||
|
||||
for (auto &&[idx, s] : enumerate(segp->shared_segment::sides))
|
||||
|
|
|
@ -540,7 +540,7 @@ static void write_special(const shared_segment &seg, const unsigned bit_mask, PH
|
|||
if (bit_mask & (1 << MAX_SIDES_PER_SEGMENT))
|
||||
{
|
||||
PHYSFSX_writeU8(SaveFile, underlying_value(seg.special));
|
||||
PHYSFSX_writeU8(SaveFile, seg.matcen_num);
|
||||
PHYSFSX_writeU8(SaveFile, underlying_value(seg.matcen_num));
|
||||
PHYSFS_writeULE16(SaveFile, seg.station_idx);
|
||||
}
|
||||
}
|
||||
|
@ -604,7 +604,7 @@ int save_mine_data_compiled(PHYSFS_File *SaveFile)
|
|||
bit_mask |= (1 << sidenum);
|
||||
}
|
||||
|
||||
if (seg.s.special != segment_special::nothing || seg.s.matcen_num != 0 || seg.s.station_idx != station_none)
|
||||
if (seg.s.special != segment_special::nothing || seg.s.matcen_num != materialization_center_number::None || seg.s.station_idx != station_none)
|
||||
bit_mask |= (1 << MAX_SIDES_PER_SEGMENT);
|
||||
|
||||
if (New_file_format_save)
|
||||
|
|
|
@ -672,7 +672,7 @@ static int med_attach_segment_rotated(const vmsegptridx_t destseg, const csmuseg
|
|||
|
||||
nsp->segnum = segnum;
|
||||
static_cast<unique_segment &>(nsp).objects = object_none;
|
||||
nsp->matcen_num = -1;
|
||||
nsp->matcen_num = materialization_center_number::None;
|
||||
|
||||
// Copy group value.
|
||||
nsp->group = destseg->group;
|
||||
|
@ -1298,7 +1298,7 @@ void med_create_segment(const vmsegptridx_t sp,fix cx, fix cy, fix cz, fix lengt
|
|||
}
|
||||
|
||||
sp->group = -1;
|
||||
sp->matcen_num = -1;
|
||||
sp->matcen_num = materialization_center_number::None;
|
||||
|
||||
// Create relative-to-center vertices, which are the rotated points on the box defined by length, width, height
|
||||
sp->verts[0] = med_add_vertex(vertex{vm_vec_rotate({+width/2, +height/2, -length/2}, mp)});
|
||||
|
@ -1334,7 +1334,7 @@ void med_create_segment(const vmsegptridx_t sp,fix cx, fix cy, fix cz, fix lengt
|
|||
sp->special = segment_special::nothing;
|
||||
sp->station_idx = station_none;
|
||||
usp.static_light = 0;
|
||||
sp->matcen_num = -1;
|
||||
sp->matcen_num = materialization_center_number::None;
|
||||
|
||||
copy_tmaps_to_segment(sp, vcsegptr(&New_segment));
|
||||
|
||||
|
@ -1391,7 +1391,7 @@ void med_create_new_segment(const vms_vector &scale)
|
|||
sp->special = segment_special::nothing;
|
||||
sp->station_idx = station_none;
|
||||
usp.static_light = 0;
|
||||
sp->matcen_num = -1;
|
||||
sp->matcen_num = materialization_center_number::None;
|
||||
}
|
||||
|
||||
// -------------------------------------------------------------------------------
|
||||
|
|
|
@ -457,8 +457,8 @@ static void write_segment_text(fvcsegptridx &vcsegptridx, PHYSFS_File *my_file)
|
|||
PHYSFSX_printf(my_file, "Segment %4hu:", static_cast<uint16_t>(segp));
|
||||
if (segp->special != segment_special::nothing)
|
||||
PHYSFSX_printf(my_file, " special = %3i (%s), station_idx=%3i", underlying_value(segp->special), Special_names[segp->special], segp->station_idx);
|
||||
if (segp->matcen_num != -1)
|
||||
PHYSFSX_printf(my_file, " matcen = %3i", segp->matcen_num);
|
||||
if (segp->matcen_num != materialization_center_number::None)
|
||||
PHYSFSX_printf(my_file, " matcen = %3i", underlying_value(segp->matcen_num));
|
||||
PHYSFSX_puts_literal(my_file, "\n");
|
||||
}
|
||||
|
||||
|
@ -498,14 +498,14 @@ static void write_matcen_text(PHYSFS_File *my_file)
|
|||
auto &station = Station[fuelcen_num];
|
||||
if (station.Type != segment_special::robotmaker)
|
||||
{
|
||||
err_printf(my_file, "Error: Matcen %" PRIuFAST32 " corresponds to Station %i, which has type %i (%s).", i, fuelcen_num, underlying_value(station.Type), Special_names[station.Type]);
|
||||
err_printf(my_file, "Error: Matcen %i corresponds to Station %i, which has type %i (%s).", underlying_value(i), fuelcen_num, underlying_value(station.Type), Special_names[station.Type]);
|
||||
continue;
|
||||
}
|
||||
int trigger_count=0;
|
||||
|
||||
const auto segnum = station.segnum;
|
||||
PHYSFSX_printf(my_file, "FuelCenter[%02" PRIuFAST32 "].Segment = %04i ", i, segnum);
|
||||
PHYSFSX_printf(my_file, "Segment[%04i].matcen_num = %02i ", segnum, Segments[segnum].matcen_num);
|
||||
PHYSFSX_printf(my_file, "FuelCenter[%02i].Segment = %04i ", underlying_value(i), segnum);
|
||||
PHYSFSX_printf(my_file, "Segment[%04i].matcen_num = %02i ", segnum, underlying_value(Segments[segnum].matcen_num));
|
||||
|
||||
// Find trigger for this materialization center.
|
||||
range_for (auto &&t, vctrgptridx)
|
||||
|
@ -523,7 +523,7 @@ static void write_matcen_text(PHYSFS_File *my_file)
|
|||
PHYSFSX_puts_literal(my_file, "\n");
|
||||
|
||||
if (trigger_count == 0)
|
||||
err_printf(my_file, "Error: Matcen %" PRIuFAST32 " in segment %i has no trigger!", i, segnum);
|
||||
err_printf(my_file, "Error: Matcen %i in segment %i has no trigger!", underlying_value(i), segnum);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -107,7 +107,7 @@ static void reset_all_robot_centers()
|
|||
if (i.special == segment_special::robotmaker)
|
||||
{
|
||||
i.special = segment_special::nothing;
|
||||
i.matcen_num = -1;
|
||||
i.matcen_num = materialization_center_number::None;
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
@ -166,7 +166,7 @@ static void matcen_create(const vmsegptridx_t segp)
|
|||
station.Timer = -1;
|
||||
station.Flag = 0;
|
||||
|
||||
const auto next_robot_center_idx = LevelSharedRobotcenterState.Num_robot_centers++;
|
||||
const auto next_robot_center_idx = static_cast<materialization_center_number>(LevelSharedRobotcenterState.Num_robot_centers++);
|
||||
segp->matcen_num = next_robot_center_idx;
|
||||
auto &robotcenter = RobotCenters[next_robot_center_idx];
|
||||
robotcenter.fuelcen_num = next_fuelcenter_idx;
|
||||
|
@ -200,8 +200,7 @@ void trigger_matcen(const vmsegptridx_t segp)
|
|||
FuelCenter *robotcen;
|
||||
|
||||
assert(segp->special == segment_special::robotmaker);
|
||||
assert(segp->matcen_num < LevelUniqueFuelcenterState.Num_fuelcenters);
|
||||
Assert((segp->matcen_num >= 0) && (segp->matcen_num <= Highest_segment_index));
|
||||
assert(underlying_value(segp->matcen_num) < LevelUniqueFuelcenterState.Num_fuelcenters);
|
||||
|
||||
robotcen = &Station[RobotCenters[segp->matcen_num].fuelcen_num];
|
||||
|
||||
|
@ -272,7 +271,7 @@ Restart: ;
|
|||
{
|
||||
shared_segment &sfj = vmsegptr(fj.segnum);
|
||||
if (sfj.matcen_num > segp.matcen_num)
|
||||
--sfj.matcen_num;
|
||||
sfj.matcen_num = static_cast<materialization_center_number>(underlying_value(sfj.matcen_num) - 1);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -359,7 +358,6 @@ static void robotmaker_proc(const d_vclip_array &Vclip, fvmsegptridx &vmsegptrid
|
|||
auto &vcobjptr = Objects.vcptr;
|
||||
auto &vmobjptridx = Objects.vmptridx;
|
||||
auto &RobotCenters = LevelSharedRobotcenterState.RobotCenters;
|
||||
int matcen_num;
|
||||
fix top_time;
|
||||
|
||||
if (robotcen->Enabled == 0)
|
||||
|
@ -382,11 +380,10 @@ static void robotmaker_proc(const d_vclip_array &Vclip, fvmsegptridx &vmsegptrid
|
|||
}
|
||||
|
||||
const auto &&segp = vmsegptr(robotcen->segnum);
|
||||
matcen_num = segp->matcen_num;
|
||||
const auto matcen_num = segp->matcen_num;
|
||||
|
||||
if ( matcen_num == -1 ) {
|
||||
if (!RobotCenters.valid_index(matcen_num))
|
||||
return;
|
||||
}
|
||||
|
||||
matcen_info *mi = &RobotCenters[matcen_num];
|
||||
for (unsigned i = 0;; ++i)
|
||||
|
|
|
@ -76,13 +76,21 @@ static segment_special build_segment_special_from_untrusted(uint8_t untrusted)
|
|||
}
|
||||
}
|
||||
|
||||
static materialization_center_number build_materialization_center_number_from_untrusted(uint8_t untrusted)
|
||||
{
|
||||
if (decltype(d_level_shared_robotcenter_state::RobotCenters)::valid_index(untrusted))
|
||||
return materialization_center_number{untrusted};
|
||||
else
|
||||
return materialization_center_number::None;
|
||||
}
|
||||
|
||||
/*
|
||||
* reads a segment2 structure from a PHYSFS_File
|
||||
*/
|
||||
static void segment2_read(const msmusegment s2, PHYSFS_File *fp)
|
||||
{
|
||||
s2.s.special = build_segment_special_from_untrusted(PHYSFSX_readByte(fp));
|
||||
s2.s.matcen_num = PHYSFSX_readByte(fp);
|
||||
s2.s.matcen_num = build_materialization_center_number_from_untrusted(PHYSFSX_readByte(fp));
|
||||
/* station_idx is overwritten by the caller in some cases, but set
|
||||
* it here for compatibility with how the game previously worked */
|
||||
s2.s.station_idx = PHYSFSX_readByte(fp);
|
||||
|
@ -414,12 +422,12 @@ static void read_special(shared_segment &segp, const unsigned bit_mask, PHYSFS_F
|
|||
// Read ubyte Segments[segnum].special
|
||||
segp.special = build_segment_special_from_untrusted(PHYSFSX_readByte(LoadFile));
|
||||
// Read byte Segments[segnum].matcen_num
|
||||
segp.matcen_num = PHYSFSX_readByte(LoadFile);
|
||||
segp.matcen_num = build_materialization_center_number_from_untrusted(PHYSFSX_readByte(LoadFile));
|
||||
// Read short Segments[segnum].value
|
||||
segp.station_idx = PHYSFSX_readShort(LoadFile);
|
||||
} else {
|
||||
segp.special = segment_special::nothing;
|
||||
segp.matcen_num = -1;
|
||||
segp.matcen_num = materialization_center_number::None;
|
||||
segp.station_idx = station_none;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -71,7 +71,7 @@ void dl_index_read(dl_index *di, PHYSFS_File *fp)
|
|||
void segment2_write(const cscusegment s2, PHYSFS_File *fp)
|
||||
{
|
||||
PHYSFSX_writeU8(fp, underlying_value(s2.s.special));
|
||||
PHYSFSX_writeU8(fp, s2.s.matcen_num);
|
||||
PHYSFSX_writeU8(fp, underlying_value(s2.s.matcen_num));
|
||||
PHYSFSX_writeU8(fp, s2.s.station_idx);
|
||||
PHYSFSX_writeU8(fp, s2.s.s2_flags);
|
||||
PHYSFSX_writeFix(fp, s2.u.static_light);
|
||||
|
|
Loading…
Reference in a new issue