Skip to content

Commit

Permalink
Use partial_range for robot_get_anim_state
Browse files Browse the repository at this point in the history
  • Loading branch information
vLKp committed Jan 29, 2018
1 parent f175949 commit 1ffefa3
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 26 deletions.
5 changes: 5 additions & 0 deletions common/include/partial_range.h
Expand Up @@ -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 <typename T>
partial_range_t(partial_range_t<T> &&t) :
m_begin(t.begin()), m_end(t.end())
{
}
__attribute_warn_unused_result
iterator begin() const { return m_begin; }
__attribute_warn_unused_result
Expand Down
4 changes: 1 addition & 3 deletions common/main/robot.h
Expand Up @@ -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
Expand All @@ -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<const jointpos *> robot_get_anim_state(const array<robot_info, MAX_ROBOT_TYPES> &, const array<jointpos, MAX_ROBOT_JOINTS> &, unsigned robot_type, unsigned gun_num, unsigned state);

namespace dsx {
/*
* reads n robot_info structs from a PHYSFS_File
*/
Expand Down
18 changes: 6 additions & 12 deletions similar/main/ai.cpp
Expand Up @@ -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)
Expand Down Expand Up @@ -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;
Expand All @@ -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; joint<num_joint_positions; joint++) {
unsigned jointnum = jp_list[joint].jointnum;
const vms_angvec *jp = &jp_list[joint].angles;
range_for (auto &jr, ras)
{
unsigned jointnum = jr.jointnum;
const vms_angvec *jp = &jr.angles;
vms_angvec *pobjp = &pobj_info->anim_angles[jointnum];

if (jointnum >= Polygon_models[objp.rtype.pobj_info.model_num].n_models) {
Expand Down
17 changes: 6 additions & 11 deletions similar/main/robot.cpp
Expand Up @@ -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<const jointpos *> robot_get_anim_state(const array<robot_info, MAX_ROBOT_TYPES> &robot_info, const array<jointpos, MAX_ROBOT_JOINTS> &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
Expand Down Expand Up @@ -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<array<vms_angvec, MAX_SUBMODELS>, N_ANIM_STATES> &angs)
Expand Down

0 comments on commit 1ffefa3

Please sign in to comment.