diff --git a/common/include/editor/editor.h b/common/include/editor/editor.h index 3500adb9e..05d0d34bf 100644 --- a/common/include/editor/editor.h +++ b/common/include/editor/editor.h @@ -221,7 +221,7 @@ namespace dsx { // 0 = successful attach // 1 = No room in Segments[]. // 2 = No room in Vertices[]. -int med_attach_segment(vmsegptridx_t destseg, vmsegptr_t newseg, int destside, int newside); +int med_attach_segment(vmsegptridx_t destseg, csmusegment newseg, unsigned destside, unsigned newside); // Delete a segment. // Deletes a segment from the global array Segments. @@ -352,7 +352,7 @@ void assign_default_uvs_to_side(vmsegptridx_t segp, unsigned side); void med_assign_uvs_to_side(vmsegptridx_t con_seg, unsigned con_common_side, vcsegptr_t base_seg, unsigned base_common_side, unsigned abs_id1, unsigned abs_id2); // Create coordinate axes in orientation of specified segment, stores vertices at *vp. -void create_coordinate_axes_from_segment(vmsegptr_t sp, std::array &vertnums); +void create_coordinate_axes_from_segment(const shared_segment &sp, std::array &vertnums); // Set Vertex_active to number of occurrences of each vertex. // Set Num_vertices. @@ -543,8 +543,8 @@ namespace dsx { int place_object(vmsegptridx_t segp, const vms_vector &object_pos, short object_type, short object_id); // from ksegsize.c -void med_extract_up_vector_from_segment_side(vmsegptr_t sp, int sidenum, vms_vector &vp); -void med_extract_right_vector_from_segment_side(vmsegptr_t sp, int sidenum, vms_vector &vp); +void med_extract_up_vector_from_segment_side(const shared_segment &sp, int sidenum, vms_vector &vp); +void med_extract_right_vector_from_segment_side(const shared_segment &sp, int sidenum, vms_vector &vp); } #endif diff --git a/common/main/fuelcen.h b/common/main/fuelcen.h index 8526aecf9..e76db726a 100644 --- a/common/main/fuelcen.h +++ b/common/main/fuelcen.h @@ -64,7 +64,7 @@ void fuelcen_create( vmsegptridx_t segp); // a segment is loaded from disk. void fuelcen_activate(vmsegptridx_t segp); // Deletes a segment as a fuel center. -void fuelcen_delete(vmsegptr_t segp); +void fuelcen_delete(shared_segment &segp); // Create a matcen robot imobjptridx_t create_morph_robot(vmsegptridx_t segp, const vms_vector &object_pos, unsigned object_id); diff --git a/similar/editor/elight.cpp b/similar/editor/elight.cpp index e72f5c88d..ef851fb4e 100644 --- a/similar/editor/elight.cpp +++ b/similar/editor/elight.cpp @@ -101,7 +101,7 @@ static void add_light_intensity_all_verts(unique_side &s, const fix intensity) // Note that it is also possible to visit the original light-casting segment, for example // going from segment 0 to 2, then from 2 to 0. This is peculiar and probably not // desired, but not entirely invalid. 2 reflects some light back to 0. -static void apply_light_intensity(const vmsegptr_t segp, const unsigned sidenum, fix intensity, const unsigned depth) +static void apply_light_intensity(const csmusegment segp, const unsigned sidenum, fix intensity, const unsigned depth) { if (intensity == 0) return; @@ -110,7 +110,7 @@ static void apply_light_intensity(const vmsegptr_t segp, const unsigned sidenum, auto &vcwallptr = Walls.vcptr; const auto wid_result = WALL_IS_DOORWAY(GameBitmaps, Textures, vcwallptr, segp, sidenum); if (!(wid_result & WID_RENDPAST_FLAG)) { - add_light_intensity_all_verts(segp->unique_segment::sides[sidenum], intensity); + add_light_intensity_all_verts(segp.u.sides[sidenum], intensity); return; // we return because there is a wall here, and light does not shine through walls } @@ -119,7 +119,7 @@ static void apply_light_intensity(const vmsegptr_t segp, const unsigned sidenum, intensity /= 3; if (!intensity) return; - const auto &&csegp = vmsegptr(segp->children[sidenum]); + const csmusegment &&csegp = vmsegptr(segp.s.children[sidenum]); for (int s=0; sunique_segment::sides[sidenum]; + auto &us = segp.u.sides[sidenum]; auto &TmapInfo = LevelUniqueTmapInfoState.TmapInfo; texmap = us.tmap_num; intensity += TmapInfo[texmap].lighting; @@ -203,7 +203,7 @@ int LightCopyIntensity(void) { int intensity; - const vmsegptr_t segp = Cursegp; + unique_segment &segp = Cursegp; intensity = get_light_intensity(segp, Curside, Curvert); range_for (const int v, xrange(4u)) @@ -219,7 +219,7 @@ int LightCopyIntensitySegment(void) { int intensity; - const vmsegptr_t segp = Cursegp; + unique_segment &segp = Cursegp; intensity = get_light_intensity(segp, Curside, Curvert); for (int s=0; sverts[v]; + const auto vertex_ind = sp.verts[v]; if (SegSizeMode || is_free_vertex(vertex_ind)) scale_vert(sp, vertex_ind, vp, scale_factor); } @@ -144,7 +143,7 @@ static void scale_free_verts(const vmsegptr_t sp, const vms_vector &vp, int side // ----------------------------------------------------------------------------- // Make segment *sp bigger in dimension dimension by amount amount. -static void med_scale_segment_new(const vmsegptr_t sp, int dimension, fix amount) +static void med_scale_segment_new(const shared_segment &sp, const int dimension, const fix amount) { vms_matrix mat; @@ -182,12 +181,12 @@ static void med_scale_segment_new(const vmsegptr_t sp, int dimension, fix amount // ------------------------------------------------------------------------------------------ // Extract a vector from a segment. The vector goes from the start face to the end face. // The point on each face is the average of the four points forming the face. -static void extract_vector_from_segment_side(const vmsegptr_t sp, const unsigned side, vms_vector &vp, const unsigned vla, const unsigned vlb, const unsigned vra, const unsigned vrb) +static void extract_vector_from_segment_side(const shared_segment &sp, const unsigned side, vms_vector &vp, const unsigned vla, const unsigned vlb, const unsigned vra, const unsigned vrb) { auto &LevelSharedVertexState = LevelSharedSegmentState.get_vertex_state(); auto &Vertices = LevelSharedVertexState.get_vertices(); auto &sv = Side_to_verts[side]; - auto &verts = sp->verts; + auto &verts = sp.verts; auto &vcvertptr = Vertices.vcptr; const auto v1 = vm_vec_sub(vcvertptr(verts[sv[vra]]), vcvertptr(verts[sv[vla]])); const auto v2 = vm_vec_sub(vcvertptr(verts[sv[vrb]]), vcvertptr(verts[sv[vlb]])); @@ -199,7 +198,7 @@ static void extract_vector_from_segment_side(const vmsegptr_t sp, const unsigned // Extract the right vector from segment *sp, return in *vp. // The forward vector is defined to be the vector from the the center of the left face of the segment // to the center of the right face of the segment. -void med_extract_right_vector_from_segment_side(const vmsegptr_t sp, int sidenum, vms_vector &vp) +void med_extract_right_vector_from_segment_side(const shared_segment &sp, int sidenum, vms_vector &vp) { extract_vector_from_segment_side(sp, sidenum, vp, 3, 2, 0, 1); } @@ -208,7 +207,7 @@ void med_extract_right_vector_from_segment_side(const vmsegptr_t sp, int sidenum // Extract the up vector from segment *sp, return in *vp. // The forward vector is defined to be the vector from the the center of the bottom face of the segment // to the center of the top face of the segment. -void med_extract_up_vector_from_segment_side(const vmsegptr_t sp, int sidenum, vms_vector &vp) +void med_extract_up_vector_from_segment_side(const shared_segment &sp, int sidenum, vms_vector &vp) { extract_vector_from_segment_side(sp, sidenum, vp, 1, 2, 0, 3); } diff --git a/similar/editor/segment.cpp b/similar/editor/segment.cpp index 1c02fc9b4..7f41287fe 100644 --- a/similar/editor/segment.cpp +++ b/similar/editor/segment.cpp @@ -618,10 +618,9 @@ namespace dsx { // Copy texture map ids for each face in sseg to dseg. static void copy_tmap_ids(unique_segment &dseg, const unique_segment &sseg) { - range_for (const auto &&z, zip(sseg.sides, dseg.sides)) + for (auto &&[ss, ds] : zip(sseg.sides, dseg.sides)) { - auto &ds = std::get<1>(z); - ds.tmap_num = std::get<0>(z).tmap_num; + ds.tmap_num = ss.tmap_num; ds.tmap_num2 = 0; } } @@ -634,7 +633,7 @@ static void copy_tmap_ids(unique_segment &dseg, const unique_segment &sseg) // 2 = No room in Vertices[]. // 3 = newside != WFRONT -- for now, the new segment must be attached at its (own) front side // 4 = already a face attached on destseg:destside -static int med_attach_segment_rotated(const vmsegptridx_t destseg, const vmsegptr_t newseg, int destside, int newside,const vms_matrix &attmat) +static int med_attach_segment_rotated(const vmsegptridx_t destseg, const csmusegment newseg, const unsigned destside, const unsigned newside, const vms_matrix &attmat) { auto &LevelSharedVertexState = LevelSharedSegmentState.get_vertex_state(); auto &Vertices = LevelSharedVertexState.get_vertices(); @@ -710,7 +709,7 @@ static int med_attach_segment_rotated(const vmsegptridx_t destseg, const vmsegpt // Now rotate the free vertices in the segment std::array tvs; range_for (const unsigned v, xrange(4u)) - vm_vec_rotate(tvs[v], vcvertptr(newseg->verts[v + 4]), rotmat2); + vm_vec_rotate(tvs[v], vcvertptr(newseg.s.verts[v + 4]), rotmat2); // Now translate the new segment so that the center point of the attaching faces are the same. const auto &&vc1 = compute_center_point_on_side(vcvertptr, destseg, destside); @@ -750,7 +749,7 @@ static int med_attach_segment_rotated(const vmsegptridx_t destseg, const vmsegpt // 2 = No room in Vertices[]. // 3 = newside != WFRONT -- for now, the new segment must be attached at its (own) front side // 4 = already a face attached on side newside -int med_attach_segment(const vmsegptridx_t destseg, const vmsegptr_t newseg, int destside, int newside) +int med_attach_segment(const vmsegptridx_t destseg, const csmusegment newseg, const unsigned destside, const unsigned newside) { int rval; const auto ocursegp = Cursegp; @@ -1414,7 +1413,7 @@ void init_all_vertices(void) // ----------------------------------------------------------------------------- // Create coordinate axes in orientation of specified segment, stores vertices at *vp. -void create_coordinate_axes_from_segment(const vmsegptr_t sp, std::array &vertnums) +void create_coordinate_axes_from_segment(const shared_segment &sp, std::array &vertnums) { auto &LevelSharedVertexState = LevelSharedSegmentState.get_vertex_state(); auto &Vertices = LevelSharedVertexState.get_vertices(); diff --git a/similar/editor/seguvs.cpp b/similar/editor/seguvs.cpp index ab362914e..7baafe35b 100644 --- a/similar/editor/seguvs.cpp +++ b/similar/editor/seguvs.cpp @@ -155,12 +155,12 @@ static void set_average_light_at_vertex(int vnum) Update_flags |= UF_WORLD_CHANGED; } -static void set_average_light_on_side(const vmsegptr_t segp, int sidenum) +static void set_average_light_on_side(const shared_segment &segp, const unsigned sidenum) { - if (!IS_CHILD(segp->children[sidenum])) + if (!IS_CHILD(segp.children[sidenum])) range_for (const auto v, Side_to_verts[sidenum]) { - set_average_light_at_vertex(segp->verts[v]); + set_average_light_at_vertex(segp.verts[v]); } } diff --git a/similar/main/fuelcen.cpp b/similar/main/fuelcen.cpp index 4c974ca6a..2bd20f445 100644 --- a/similar/main/fuelcen.cpp +++ b/similar/main/fuelcen.cpp @@ -246,17 +246,17 @@ void trigger_matcen(const vmsegptridx_t segp) //------------------------------------------------------------ // Takes away a segment's fuel center properties. // Deletes the segment point entry in the FuelCenter list. -void fuelcen_delete(const vmsegptr_t segp) +void fuelcen_delete(shared_segment &segp) { auto &RobotCenters = LevelSharedRobotcenterState.RobotCenters; auto &Station = LevelUniqueFuelcenterState.Station; auto Num_fuelcenters = LevelUniqueFuelcenterState.Num_fuelcenters; Restart: ; - segp->special = 0; + segp.special = 0; for (uint_fast32_t i = 0; i < Num_fuelcenters; i++ ) { FuelCenter &fi = Station[i]; - if (vmsegptr(fi.segnum) == segp) + if (vmsegptr(fi.segnum) == &segp) { auto &Num_robot_centers = LevelSharedRobotcenterState.Num_robot_centers; @@ -267,14 +267,17 @@ Restart: ; con_printf(CON_URGENT, "%s:%u: error: Num_robot_centers=0 while deleting robot maker", __FILE__, __LINE__); return; } - const auto &&range = partial_range(RobotCenters, static_cast(segp->matcen_num), Num_robot_centers--); + const auto &&range = partial_range(RobotCenters, static_cast(segp.matcen_num), Num_robot_centers--); std::move(std::next(range.begin()), range.end(), range.begin()); range_for (auto &fj, partial_const_range(Station, Num_fuelcenters)) { if ( fj.Type == SEGMENT_IS_ROBOTMAKER ) - if ( Segments[fj.segnum].matcen_num > segp->matcen_num ) - Segments[fj.segnum].matcen_num--; + { + shared_segment &sfj = vmsegptr(fj.segnum); + if (sfj.matcen_num > segp.matcen_num) + --sfj.matcen_num; + } } }