Fold create_abs_vertex_lists into create_all_vertnum_lists

This commit is contained in:
Kp 2015-10-18 21:01:20 +00:00
parent af2d8f7deb
commit 6f94cc933c
3 changed files with 27 additions and 25 deletions

View file

@ -73,6 +73,11 @@ static inline side_vertnum_list_t get_side_verts(vcsegptr_t segnum,int sidenum)
}
struct vertex_array_list_t : array<int, 6> {};
struct vertex_vertnum_pair
{
int vertex, vertnum;
};
using vertex_vertnum_array_list = array<vertex_vertnum_pair, 6>;
#ifdef EDITOR
// Create all vertex lists (1 or 2) for faces on a side.
@ -118,13 +123,12 @@ static inline std::pair<uint_fast32_t, vertex_array_list_t> create_abs_vertex_li
// If there is one face, it has 4 vertices.
// If there are two faces, they both have three vertices, so face #0 is stored in vertices 0,1,2,
// face #1 is stored in vertices 3,4,5.
uint_fast32_t create_all_vertnum_lists(vertex_array_list_t &vertnums, vcsegptr_t segnum, const side *const sidep, uint_fast32_t sidenum);
void create_all_vertnum_lists(vertex_vertnum_array_list &vertnums, vcsegptr_t segnum, const side *const sidep, uint_fast32_t sidenum);
__attribute_warn_unused_result
static inline std::pair<uint_fast32_t, vertex_array_list_t> create_all_vertnum_lists(vcsegptr_t segnum, const side *const sidep, uint_fast32_t sidenum)
static inline vertex_vertnum_array_list create_all_vertnum_lists(vcsegptr_t segnum, const side *const sidep, uint_fast32_t sidenum)
{
vertex_array_list_t r;
auto n = create_all_vertnum_lists(r, segnum, sidep, sidenum);
return {n, r};
vertex_vertnum_array_list r;
return create_all_vertnum_lists(r, segnum, sidep, sidenum), r;
}
// Given a side, return the number of faces

View file

@ -1117,16 +1117,13 @@ fvi_hitpoint find_hitpoint_uv(const vms_vector &pnt, const vcsegptridx_t seg, co
//when do I return 0 & 1 for non-transparent walls?
const auto vx = create_abs_vertex_lists(seg, side, sidenum);
const auto &vertex_list = vx.second;
const auto vn = create_all_vertnum_lists(seg, side, sidenum);
const auto &vertnum_list = vn.second;
const auto &&vn = create_all_vertnum_lists(seg, side, sidenum);
//now the hard work.
//1. find what plane to project this wall onto to make it a 2d case
vms_vector normal_array = side->normals[facenum];
const auto &normal_array = side->normals[facenum];
auto fmax = [](const vms_vector &v, fix vms_vector::*a, fix vms_vector::*b) {
return abs(v.*a) > abs(v.*b) ? a : b;
};
@ -1137,13 +1134,13 @@ fvi_hitpoint find_hitpoint_uv(const vms_vector &pnt, const vcsegptridx_t seg, co
//2. compute u,v of intersection point
//vec from 1 -> 0
const vms_vector &vf1 = Vertices[vertex_list[facenum*3+1]];
const vms_vector &vf1 = Vertices[vn[facenum*3+1].vertex];
const vec2d p1{vf1.*ii, vf1.*jj};
const vms_vector &vf0 = Vertices[vertex_list[facenum*3+0]];
const vms_vector &vf0 = Vertices[vn[facenum*3+0].vertex];
const vec2d vec0{vf0.*ii - p1.i, vf0.*jj - p1.j};
//vec from 1 -> 2
const vms_vector &vf2 = Vertices[vertex_list[facenum*3+2]];
const vms_vector &vf2 = Vertices[vn[facenum*3+2].vertex];
const vec2d vec1{vf2.*ii - p1.i, vf2.*jj - p1.j};
//vec from 1 -> checkpoint
@ -1164,7 +1161,7 @@ fvi_hitpoint find_hitpoint_uv(const vms_vector &pnt, const vcsegptridx_t seg, co
array<uvl, 3> uvls;
for (i=0;i<3;i++)
uvls[i] = side->uvls[vertnum_list[facenum*3+i]];
uvls[i] = side->uvls[vn[facenum*3+i].vertnum];
auto p = [&uvls, k0, k1](fix uvl::*p) {
return uvls[1].*p + fixmul(k0,uvls[0].*p - uvls[1].*p) + fixmul(k1,uvls[2].*p - uvls[1].*p);

View file

@ -72,12 +72,16 @@ public:
}
};
class all_vertnum_lists_predicate
class all_vertnum_lists_predicate : public abs_vertex_lists_predicate
{
public:
int operator()(const uint_fast32_t vv) const
all_vertnum_lists_predicate(const vcsegptr_t segp, uint_fast32_t sidenum) :
abs_vertex_lists_predicate(segp, sidenum)
{
return vv;
}
vertex_vertnum_pair operator()(const uint_fast32_t vv) const
{
return {this->abs_vertex_lists_predicate::operator()(vv), static_cast<int>(vv)};
}
};
@ -164,8 +168,8 @@ static void create_vertex_list_from_invalid_side(const vcsegptr_t segp, const si
throw side::illegal_type(segp, sidep);
}
template <typename F>
static inline uint_fast32_t create_vertex_lists_by_predicate(vertex_array_list_t &va, const vcsegptr_t segp, const side *const sidep, const F &f)
template <typename T, typename F>
static inline uint_fast32_t create_vertex_lists_by_predicate(T &va, const vcsegptr_t segp, const side *const sidep, const F &f)
{
const auto f0 = f(0);
const auto f1 = f(1);
@ -235,10 +239,9 @@ uint_fast32_t create_all_vertex_lists(vertex_array_list_t &vertices, const vcseg
// If there is one face, it has 4 vertices.
// If there are two faces, they both have three vertices, so face #0 is stored in vertices 0,1,2,
// face #1 is stored in vertices 3,4,5.
uint_fast32_t create_all_vertnum_lists(vertex_array_list_t &vertnums, const vcsegptr_t segp, const side *const sidep, uint_fast32_t sidenum)
void create_all_vertnum_lists(vertex_vertnum_array_list &vertnums, const vcsegptr_t segp, const side *const sidep, uint_fast32_t sidenum)
{
(void)sidenum;
return create_vertex_lists_by_predicate(vertnums, segp, sidep, all_vertnum_lists_predicate());
create_vertex_lists_by_predicate(vertnums, segp, sidep, all_vertnum_lists_predicate(segp, sidenum));
}
// -----
@ -253,14 +256,12 @@ uint_fast32_t create_abs_vertex_lists(vertex_array_list_t &vertices, const vcseg
segmasks get_seg_masks(const vms_vector &checkp, const vcsegptr_t segnum, fix rad)
{
int sn,facebit,sidebit;
segmasks masks;
segmasks masks{};
const auto &seg = segnum;
//check point against each side of segment. return bitmask
masks.sidemask = masks.facemask = masks.centermask = 0;
for (sn=0,facebit=sidebit=1;sn<6;sn++,sidebit<<=1) {
auto s = &seg->sides[sn];
int side_pokes_out;