From 1ffefa302903967a77d4e81e04db8c67bffdff9a Mon Sep 17 00:00:00 2001 From: Kp Date: Mon, 29 Jan 2018 01:56:40 +0000 Subject: [PATCH] Use partial_range for robot_get_anim_state --- common/include/partial_range.h | 5 +++++ common/main/robot.h | 4 +--- similar/main/ai.cpp | 18 ++++++------------ similar/main/robot.cpp | 17 ++++++----------- 4 files changed, 18 insertions(+), 26 deletions(-) diff --git a/common/include/partial_range.h b/common/include/partial_range.h index d5e9459453..3f725ab48f 100644 --- a/common/include/partial_range.h +++ b/common/include/partial_range.h @@ -94,6 +94,11 @@ class partial_range_t m_begin(partial_range_detail::adl_begin(t)), m_end(partial_range_detail::adl_end(t)) { } + template + partial_range_t(partial_range_t &&t) : + m_begin(t.begin()), m_end(t.end()) + { + } __attribute_warn_unused_result iterator begin() const { return m_begin; } __attribute_warn_unused_result diff --git a/common/main/robot.h b/common/main/robot.h index 1d10d49649..d8d71c9488 100644 --- a/common/main/robot.h +++ b/common/main/robot.h @@ -212,7 +212,6 @@ namespace dsx { //given an object and a gun number, return position in 3-space of gun //fills in gun_point void calc_gun_point(vms_vector &gun_point, const object_base &obj, unsigned gun_num); -} // Tells joint positions for a gun to be in a specified state. // A gun can have associated with it any number of joints. In order to tell whether a gun is a certain @@ -233,9 +232,8 @@ void calc_gun_point(vms_vector &gun_point, const object_base &obj, unsigned gun_ // On exit: // Returns number of joints in list. // jp_list_ptr is stuffed with a pointer to a static array of joint positions. This pointer is valid forever. -extern int robot_get_anim_state(const jointpos **jp_list_ptr,int robot_type,int gun_num,int state); +partial_range_t robot_get_anim_state(const array &, const array &, unsigned robot_type, unsigned gun_num, unsigned state); -namespace dsx { /* * reads n robot_info structs from a PHYSFS_File */ diff --git a/similar/main/ai.cpp b/similar/main/ai.cpp index b23ae37ce7..3d2c54aa4b 100644 --- a/similar/main/ai.cpp +++ b/similar/main/ai.cpp @@ -406,15 +406,11 @@ weapon_id_type get_robot_weapon(const robot_info &ri, const unsigned gun_num) return ri.weapon_type; } -} - static int ready_to_fire_weapon1(const ai_local &ailp, fix threshold) { return ailp.next_fire <= threshold; } -namespace dsx { - static int ready_to_fire_weapon2(const robot_info &robptr, const ai_local &ailp, fix threshold) { #if defined(DXX_BUILD_DESCENT_I) @@ -758,8 +754,7 @@ int player_is_visible_from_object(const vmobjptridx_t objp, vms_vector &pos, fix // Return 1 if animates, else return 0 static int do_silly_animation(object &objp) { - const jointpos *jp_list; - int robot_type, gun_num, robot_state, num_joint_positions; + int robot_type, gun_num, robot_state; polyobj_info *const pobj_info = &objp.rtype.pobj_info; auto &aip = objp.ctype.ai_info; int num_guns, at_goal; @@ -786,14 +781,13 @@ static int do_silly_animation(object &objp) at_goal = 1; for (gun_num=0; gun_num <= num_guns; gun_num++) { - int joint; - - num_joint_positions = robot_get_anim_state(&jp_list, robot_type, gun_num, robot_state); + const auto &&ras = robot_get_anim_state(Robot_info, Robot_joints, robot_type, gun_num, robot_state); auto &ail = aip.ail; - for (joint=0; jointanim_angles[jointnum]; if (jointnum >= Polygon_models[objp.rtype.pobj_info.model_num].n_models) { diff --git a/similar/main/robot.cpp b/similar/main/robot.cpp index d0c7cb024e..eae7f5f49e 100644 --- a/similar/main/robot.cpp +++ b/similar/main/robot.cpp @@ -92,18 +92,15 @@ void calc_gun_point(vms_vector &gun_point, const object_base &obj, unsigned gun_ vm_vec_add2(gun_point, obj.pos); } -} - //fills in ptr to list of joints, and returns the number of joints in list //takes the robot type (object id), gun number, and desired state -int robot_get_anim_state(const jointpos **jp_list_ptr,int robot_type,int gun_num,int state) +partial_range_t robot_get_anim_state(const array &robot_info, const array &robot_joints, const unsigned robot_type, const unsigned gun_num, const unsigned state) { - - Assert(gun_num <= Robot_info[robot_type].n_guns); - - *jp_list_ptr = &Robot_joints[Robot_info[robot_type].anim_states[gun_num][state].offset]; - - return Robot_info[robot_type].anim_states[gun_num][state].n_joints; + auto &rirt = robot_info[robot_type]; + assert(gun_num <= rirt.n_guns); + auto &as = rirt.anim_states[gun_num][state]; + const unsigned o = as.offset; + return partial_range(robot_joints, o, o + as.n_joints); } #ifndef NDEBUG @@ -137,8 +134,6 @@ static void set_robot_state(const vmobjptr_t obj,int state) } #endif -namespace dsx { - //set the animation angles for this robot. Gun fields of robot info must //be filled in. void robot_set_angles(robot_info *r,polymodel *pm,array, N_ANIM_STATES> &angs)