From 43e1c841f04e331cbc95b36eb72d2ed8184fb75e Mon Sep 17 00:00:00 2001 From: Kp Date: Sun, 9 Oct 2022 23:15:20 +0000 Subject: [PATCH] Pass polymodel& to polymodel_read --- common/main/fwd-robot.h | 2 +- common/main/polyobj.h | 2 +- d1x-rebirth/main/custom.cpp | 2 +- similar/main/bm.cpp | 16 +++++----- similar/main/polyobj.cpp | 61 ++++++++++++++++++------------------- similar/main/robot.cpp | 20 ++++++------ 6 files changed, 51 insertions(+), 52 deletions(-) diff --git a/common/main/fwd-robot.h b/common/main/fwd-robot.h index 5c973d666..f2ce57426 100644 --- a/common/main/fwd-robot.h +++ b/common/main/fwd-robot.h @@ -94,7 +94,7 @@ void calc_gun_point(const robot_info &, vms_vector &gun_point, const object_base * reads n robot_info structs from a PHYSFS_File */ void robot_info_read(PHYSFS_File *fp, robot_info &r); -void robot_set_angles(robot_info *r, polymodel *pm, enumerated_array, N_ANIM_STATES, robot_animation_state> &angs); +void robot_set_angles(robot_info &r, polymodel &pm, enumerated_array, N_ANIM_STATES, robot_animation_state> &angs); weapon_id_type get_robot_weapon(const robot_info &ri, const robot_gun_number gun_num); } diff --git a/common/main/polyobj.h b/common/main/polyobj.h index 62e66990a..da8417cb7 100644 --- a/common/main/polyobj.h +++ b/common/main/polyobj.h @@ -189,7 +189,7 @@ void free_model(polymodel &po); /* * reads a polymodel structure from a PHYSFS_File */ -extern void polymodel_read(polymodel *pm, PHYSFS_File *fp); +void polymodel_read(polymodel &pm, PHYSFS_File *fp); } #if 0 void polymodel_write(PHYSFS_File *fp, const polymodel &pm); diff --git a/d1x-rebirth/main/custom.cpp b/d1x-rebirth/main/custom.cpp index 46edd40cd..95a6bc174 100644 --- a/d1x-rebirth/main/custom.cpp +++ b/d1x-rebirth/main/custom.cpp @@ -551,7 +551,7 @@ static void load_hxm(const d_fname &hxmname) { auto &Polygon_models = LevelSharedPolygonModelState.Polygon_models; pm = &Polygon_models[repl_num]; - polymodel_read(pm, f); + polymodel_read(*pm, f); const auto model_data_size = pm->model_data_size; pm->model_data = std::make_unique(model_data_size); if (PHYSFS_read(f, pm->model_data, model_data_size, 1) < 1) diff --git a/similar/main/bm.cpp b/similar/main/bm.cpp index 30614b87f..18e505e33 100644 --- a/similar/main/bm.cpp +++ b/similar/main/bm.cpp @@ -213,7 +213,7 @@ void properties_read_cmp(d_level_shared_robot_info_state &LevelSharedRobotInfoSt { const auto &&r = partial_range(Polygon_models, N_polygon_models); range_for (auto &p, r) - polymodel_read(&p, fp); + polymodel_read(p, fp); range_for (auto &p, r) polygon_model_data_read(&p, fp); @@ -355,7 +355,7 @@ void bm_read_all(d_level_shared_robot_info_state &LevelSharedRobotInfoState, d_v { const auto &&r = partial_range(Polygon_models, N_polygon_models); range_for (auto &p, r) - polymodel_read(&p, fp); + polymodel_read(p, fp); range_for (auto &p, r) polygon_model_data_read(&p, fp); @@ -502,7 +502,7 @@ void bm_read_extra_robots(const char *fname, Mission::descent_version_type type) { const auto &&r = partial_range(Polygon_models, N_D2_POLYGON_MODELS.value, N_polygon_models); range_for (auto &p, r) - polymodel_read(&p, fp); + polymodel_read(p, fp); range_for (auto &p, r) polygon_model_data_read(&p, fp); @@ -585,7 +585,7 @@ void load_robot_replacements(const d_fname &level_name) Error("Polygon model (%u) out of range in (%s). Range = [0..%u].", i, static_cast(level_name), N_polygon_models - 1); free_model(Polygon_models[i]); - polymodel_read(&Polygon_models[i], fp); + polymodel_read(Polygon_models[i], fp); polygon_model_data_read(&Polygon_models[i], fp); Dying_modelnums[i] = PHYSFSX_readInt(fp); @@ -749,8 +749,8 @@ int load_exit_models() { exit_modelnum = LevelSharedPolygonModelState.N_polygon_models++; destroyed_exit_modelnum = LevelSharedPolygonModelState.N_polygon_models++; - polymodel_read(&Polygon_models[exit_modelnum], exit_hamfile); - polymodel_read(&Polygon_models[destroyed_exit_modelnum], exit_hamfile); + polymodel_read(Polygon_models[exit_modelnum], exit_hamfile); + polymodel_read(Polygon_models[destroyed_exit_modelnum], exit_hamfile); Polygon_models[exit_modelnum].first_texture = start_num; Polygon_models[destroyed_exit_modelnum].first_texture = start_num+3; @@ -796,8 +796,8 @@ int load_exit_models() PHYSFSX_fseek(exit_hamfile, offset, SEEK_SET); exit_modelnum = LevelSharedPolygonModelState.N_polygon_models++; destroyed_exit_modelnum = LevelSharedPolygonModelState.N_polygon_models++; - polymodel_read(&Polygon_models[exit_modelnum], exit_hamfile); - polymodel_read(&Polygon_models[destroyed_exit_modelnum], exit_hamfile); + polymodel_read(Polygon_models[exit_modelnum], exit_hamfile); + polymodel_read(Polygon_models[destroyed_exit_modelnum], exit_hamfile); Polygon_models[exit_modelnum].first_texture = start_num; Polygon_models[destroyed_exit_modelnum].first_texture = start_num+3; diff --git a/similar/main/polyobj.cpp b/similar/main/polyobj.cpp index 474d1ea2f..8b90dbb12 100644 --- a/similar/main/polyobj.cpp +++ b/similar/main/polyobj.cpp @@ -144,7 +144,7 @@ static void pof_read_ang(vms_angvec &ang, const std::span bufp, s //be filled in. //reads a binary file containing a 3d model -static polymodel *read_model_file(polymodel *pm,const char *filename,robot_info *r) +static void read_model_file(polymodel &pm, const char *const filename, robot_info *r) { short version; int len, next_chunk; @@ -181,10 +181,10 @@ static polymodel *read_model_file(polymodel *pm,const char *filename,robot_info case ID_OHDR: { //Object header vms_vector pmmin,pmmax; - pm->n_models = pof_read_int(model_buf, Pof_addr); - pm->rad = pof_read_int(model_buf, Pof_addr); + pm.n_models = pof_read_int(model_buf, Pof_addr); + pm.rad = pof_read_int(model_buf, Pof_addr); - Assert(pm->n_models <= MAX_SUBMODELS); + assert(pm.n_models <= MAX_SUBMODELS); pof_read_vec(pmmin, model_buf, Pof_addr); pof_read_vec(pmmax, model_buf, Pof_addr); @@ -199,15 +199,15 @@ static polymodel *read_model_file(polymodel *pm,const char *filename,robot_info Assert(n < MAX_SUBMODELS); - pm->submodel_parents[n] = pof_read_short(model_buf, Pof_addr); + pm.submodel_parents[n] = pof_read_short(model_buf, Pof_addr); - pof_read_vec(pm->submodel_norms[n], model_buf, Pof_addr); - pof_read_vec(pm->submodel_pnts[n], model_buf, Pof_addr); - pof_read_vec(pm->submodel_offsets[n], model_buf, Pof_addr); + pof_read_vec(pm.submodel_norms[n], model_buf, Pof_addr); + pof_read_vec(pm.submodel_pnts[n], model_buf, Pof_addr); + pof_read_vec(pm.submodel_offsets[n], model_buf, Pof_addr); - pm->submodel_rads[n] = pof_read_int(model_buf, Pof_addr); //radius + pm.submodel_rads[n] = pof_read_int(model_buf, Pof_addr); //radius - pm->submodel_ptrs[n] = pof_read_int(model_buf, Pof_addr); //offset + pm.submodel_ptrs[n] = pof_read_int(model_buf, Pof_addr); //offset break; @@ -263,12 +263,12 @@ static polymodel *read_model_file(polymodel *pm,const char *filename,robot_info Assert(n_frames == N_ANIM_STATES); - for (int m=0;mn_models;m++) + for (int m = 0; m < pm.n_models; ++m) range_for (auto &f, partial_range(anim_angs, n_frames)) pof_read_ang(f[m], model_buf, Pof_addr); - robot_set_angles(r,pm,anim_angs); + robot_set_angles(*r, pm, anim_angs); } else @@ -288,10 +288,10 @@ static polymodel *read_model_file(polymodel *pm,const char *filename,robot_info } case ID_IDTA: //Interpreter data - pm->model_data_size = len; - pm->model_data = std::make_unique(pm->model_data_size); + pm.model_data_size = len; + pm.model_data = std::make_unique(pm.model_data_size); - pof_cfread(pm->model_data.get(), len, model_buf, Pof_addr); + pof_cfread(pm.model_data.get(), len, model_buf, Pof_addr); break; @@ -308,8 +308,7 @@ static polymodel *read_model_file(polymodel *pm,const char *filename,robot_info align_polygon_model_data(pm); #endif if constexpr (words_bigendian) - swap_polygon_model_data(pm->model_data.get()); - return pm; + swap_polygon_model_data(pm.model_data.get()); } } @@ -504,16 +503,17 @@ static void assign_minmax(vms_vector &minv, vms_vector &maxv, const vms_vector & update_bounds<&vms_vector::z>(minv, maxv, v); } -static void polyobj_find_min_max(polymodel *pm) +static void polyobj_find_min_max(polymodel &pm) { - auto &big_mn = pm->mins; - auto &big_mx = pm->maxs; - for (int m=0;mn_models;m++) { - auto &mn = pm->submodel_mins[m]; - auto &mx = pm->submodel_maxs[m]; - const auto &ofs = pm->submodel_offsets[m]; + auto &big_mn = pm.mins; + auto &big_mx = pm.maxs; + for (int m = 0; m < pm.n_models; ++m) + { + auto &mn = pm.submodel_mins[m]; + auto &mx = pm.submodel_maxs[m]; + const auto &ofs = pm.submodel_offsets[m]; - auto data = reinterpret_cast(&pm->model_data[pm->submodel_ptrs[m]]); + auto data = reinterpret_cast(&pm.model_data[pm.submodel_ptrs[m]]); const auto type = *data++; @@ -560,9 +560,8 @@ int load_polygon_model(const char *filename,int n_textures,int first_texture,rob auto &Polygon_models = LevelSharedPolygonModelState.Polygon_models; auto &model = Polygon_models[n_models]; - read_model_file(&model, filename, r); - - polyobj_find_min_max(&model); + read_model_file(model, filename, r); + polyobj_find_min_max(model); const auto highest_texture_num = g3_init_polygon_model(std::span{model.model_data.get(), model.model_data_size}); @@ -615,10 +614,10 @@ ASSERT_SERIAL_UDT_MESSAGE_SIZE(polymodel, 12 + (10 * 4) + (10 * 3 * sizeof(vms_v /* * reads a polymodel structure from a PHYSFS_File */ -void polymodel_read(polymodel *pm, PHYSFS_File *fp) +void polymodel_read(polymodel &pm, PHYSFS_File *fp) { - pm->model_data.reset(); - PHYSFSX_serialize_read(fp, *pm); + pm.model_data.reset(); + PHYSFSX_serialize_read(fp, pm); } } diff --git a/similar/main/robot.cpp b/similar/main/robot.cpp index ed929249c..05bc55e50 100644 --- a/similar/main/robot.cpp +++ b/similar/main/robot.cpp @@ -124,32 +124,32 @@ static void set_robot_state(object_base &obj, const robot_animation_state state) //set the animation angles for this robot. Gun fields of robot info must //be filled in. -void robot_set_angles(robot_info *const r, polymodel *const pm, enumerated_array, N_ANIM_STATES, robot_animation_state> &angs) +void robot_set_angles(robot_info &r, polymodel &pm, enumerated_array, N_ANIM_STATES, robot_animation_state> &angs) { auto &Robot_joints = LevelSharedRobotJointState.Robot_joints; std::array gun_nums; //which gun each submodel is part of gun_nums[0] = robot_gun_number{UINT8_MAX}; //body never animates, at least for now { - auto &&gr = partial_range(gun_nums, 1u, pm->n_models); + auto &&gr = partial_range(gun_nums, 1u, pm.n_models); //assume part of body... - std::fill(gr.begin(), gr.end(), robot_gun_number{r->n_guns}); + std::fill(gr.begin(), gr.end(), robot_gun_number{r.n_guns}); } - for (auto [g, entry_m] : enumerate(partial_const_range(r->gun_submodels, r->n_guns))) + for (auto [g, entry_m] : enumerate(partial_const_range(r.gun_submodels, r.n_guns))) { - const std::size_t bound = std::min(std::size(gun_nums), std::size(pm->submodel_parents)); + const std::size_t bound = std::min(std::size(gun_nums), std::size(pm.submodel_parents)); auto m = entry_m; while (m != 0 && m < bound) { gun_nums[m] = g; //...unless we find it in a gun - m = pm->submodel_parents[m]; + m = pm.submodel_parents[m]; } } - const auto n_models = pm->n_models; + const auto n_models = pm.n_models; const auto &&gun_num_model_range = enumerate(partial_range(gun_nums, n_models)); - const unsigned n_guns = r->n_guns + 1; - for (auto &&[g, ras] : enumerate(partial_range(r->anim_states, n_guns))) + const unsigned n_guns = r.n_guns + 1; + for (auto &&[g, ras] : enumerate(partial_range(r.anim_states, n_guns))) { for (auto &&[state, as] : enumerate(ras)) { @@ -163,7 +163,7 @@ void robot_set_angles(robot_info *const r, polymodel *const pm, enumerated_array const auto N_robot_joints = LevelSharedRobotJointState.N_robot_joints ++; Robot_joints[N_robot_joints].jointnum = m; Robot_joints[N_robot_joints].angles = angs[state][m]; - r->anim_states[g][state].n_joints++; + r.anim_states[g][state].n_joints++; Assert(N_robot_joints < MAX_ROBOT_JOINTS); } }