From ca913240d021e6f78c00e86c5b40bbce8994294e Mon Sep 17 00:00:00 2001 From: Kp Date: Sat, 31 Dec 2022 16:21:47 +0000 Subject: [PATCH] Return ranges::subrange from robot_get_anim_state --- common/main/backports-ranges.h | 2 +- common/main/robot.h | 3 ++- similar/main/ai.cpp | 4 +--- similar/main/robot.cpp | 2 +- 4 files changed, 5 insertions(+), 6 deletions(-) diff --git a/common/main/backports-ranges.h b/common/main/backports-ranges.h index 1bda0adba..0685a17a1 100644 --- a/common/main/backports-ranges.h +++ b/common/main/backports-ranges.h @@ -52,7 +52,7 @@ public: b(b), e(e) { } - subrange(auto &r) : + subrange(auto &&r) : b(std::ranges::begin(r)), e(std::ranges::end(r)) { } diff --git a/common/main/robot.h b/common/main/robot.h index b3f08ac24..5d364b519 100644 --- a/common/main/robot.h +++ b/common/main/robot.h @@ -30,6 +30,7 @@ COPYRIGHT 1993-1999 PARALLAX SOFTWARE CORPORATION. ALL RIGHTS RESERVED. #include "pack.h" #include "aistruct.h" +#include "backports-ranges.h" #include "weapon_id.h" #include "object.h" #include "fwd-partial_range.h" @@ -225,7 +226,7 @@ struct d_level_shared_robot_joint_state : ::dcx::d_level_shared_robot_joint_stat // 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. -partial_range_t robot_get_anim_state(const d_robot_info_array &, const std::array &, unsigned robot_type, robot_gun_number gun_num, robot_animation_state state); +ranges::subrange robot_get_anim_state(const d_robot_info_array &, const std::array &, unsigned robot_type, robot_gun_number gun_num, robot_animation_state state); /* * reads n robot_info structs from a PHYSFS_File diff --git a/similar/main/ai.cpp b/similar/main/ai.cpp index 9c2180de8..2b1b5b3ad 100644 --- a/similar/main/ai.cpp +++ b/similar/main/ai.cpp @@ -882,10 +882,8 @@ static int do_silly_animation(const d_robot_info_array &Robot_info, object &objp for (const uint8_t gun_num_idx : xrange(1u + num_guns)) { const auto gun_num = robot_gun_number{gun_num_idx}; - const auto &&ras = robot_get_anim_state(Robot_info, Robot_joints, robot_type, gun_num, robot_state); - auto &ail = aip.ail; - range_for (auto &jr, ras) + for (auto &jr : robot_get_anim_state(Robot_info, Robot_joints, robot_type, gun_num, robot_state)) { unsigned jointnum = jr.jointnum; auto &jp = jr.angles; diff --git a/similar/main/robot.cpp b/similar/main/robot.cpp index 6606691ef..c15a3aa33 100644 --- a/similar/main/robot.cpp +++ b/similar/main/robot.cpp @@ -84,7 +84,7 @@ void calc_gun_point(const robot_info &r, vms_vector &gun_point, const object_bas //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 -partial_range_t robot_get_anim_state(const d_robot_info_array &robot_info, const std::array &robot_joints, const unsigned robot_type, const robot_gun_number gun_num, const robot_animation_state state) +ranges::subrange robot_get_anim_state(const d_robot_info_array &robot_info, const std::array &robot_joints, const unsigned robot_type, const robot_gun_number gun_num, const robot_animation_state state) { auto &rirt = robot_info[robot_type]; auto &as = rirt.anim_states[gun_num][state];