refactored shvid_full and wall_offset as virtual functions

This commit is contained in:
Zeno Rogue 2021-07-09 10:09:31 +02:00
parent 09850d2f76
commit 9a319e2d2a
12 changed files with 98 additions and 109 deletions

View File

@ -774,6 +774,10 @@ struct hrmap_archimedean : hrmap {
return id;
}
int full_shvid(cell *c) override {
return id_of(c->master) + 20 * parent_index_of(c->master);
}
hyperpoint get_corner(cell *c, int cid, ld cf) override {
auto &ac = arcm::current_or_fake();
if(PURE) {

View File

@ -1485,6 +1485,7 @@ EX bool good_for_wall(cell *c) {
}
EX bool walls_not_implemented() {
if(WDIM == 3 && !PURE) return true;
if(sphere || quotient || nonisotropic || (kite::in() && !bt::in()) || experimental) return true;
return WDIM == 3 && (cgflags & qIDEAL);
}

View File

@ -64,7 +64,10 @@ struct hrmap {
virtual void find_cell_connection(cell *c, int d);
virtual int shvid(cell *c) { return 0; }
virtual int full_shvid(cell *c) { return shvid(c); }
virtual hyperpoint get_corner(cell *c, int cid, ld cf=3) { return C0; }
virtual int wall_offset(cell *c);
};
/** hrmaps which are based on regular non-Euclidean 2D tilings, possibly quotient

View File

@ -857,7 +857,7 @@ void celldrawer::draw_grid() {
if(0);
#if MAXMDIM == 4
else if(WDIM == 3) {
int ofs = wall_offset(c);
int ofs = currentmap->wall_offset(c);
for(int t=0; t<c->type; t++) {
if(!c->move(t)) continue;
if(bt::in() && !sn::in() && !among(t, 5, 6, 8)) continue;
@ -1666,7 +1666,7 @@ void celldrawer::draw_features() {
void celldrawer::draw_features_and_walls_3d() {
#if MAXMDIM >= 4
color_t dummy;
int ofs = wall_offset(c);
int ofs = currentmap->wall_offset(c);
if(isWall3(c, wcol)) {
if(!no_wall_rendering) {
color_t wcol2 = wcol;

View File

@ -1283,6 +1283,11 @@ EX namespace gp {
return gp::get_plainshape_id(c);
}
int full_shvid(cell *c) override {
gp::draw_li = gp::get_local_info(c);
return shvid(c);
}
hyperpoint get_corner(cell *c, int cid, ld cf) override {
if(UNTRUNCATED) {
cell *c1 = gp::get_mapped(c);

View File

@ -3963,14 +3963,64 @@ EX void gridline(const shiftmatrix& V, const hyperpoint h1, const hyperpoint h2,
gridline(V, h1, V, h2, col, prec);
}
EX int wall_offset(cell *c) {
if(hybri || WDIM == 2) return hybrid::wall_offset(c);
#if CAP_BT
if(kite::in() && kite::getshape(c->master) == kite::pKite) return 10;
#endif
if(reg3::in() && !PURE)
return reg3::get_wall_offset(c);
return 0;
int hrmap::wall_offset(cell *c) {
int id = currentmap->full_shvid(c);
if(isize(cgi.walloffsets) <= id) cgi.walloffsets.resize(id+1, {-1, nullptr});
auto &wop = cgi.walloffsets[id];
int &wo = wop.first;
if(!wop.second) wop.second = c;
if(wo == -1) {
cell *c1 = hybri ? hybrid::get_where(c).first : c;
wo = isize(cgi.shWall3D);
int won = wo + c->type + (WDIM == 2 ? 2 : 0);
if(!cgi.wallstart.empty()) cgi.wallstart.pop_back();
cgi.reserve_wall3d(won);
if(prod || WDIM == 2) for(int i=0; i<c1->type; i++) {
hyperpoint w;
auto f = [&] {
/* mirror image of C0 in the axis h1-h2 */
hyperpoint h1 = get_corner_position(c1, i);
hyperpoint h2 = get_corner_position(c1, i+1);
transmatrix T = gpushxto0(h1);
T = spintox(T * h2) * T;
w = T * C0;
w[1] = -w[1];
w = iso_inverse(T) * w;
};
if(prod) PIU(f());
else f();
cgi.walltester[wo + i] = w;
}
for(int i=0; i<c1->type; i++)
cgi.make_wall(wo + i, {hybrid::get_corner(c1, i, 0, -1), hybrid::get_corner(c1, i, 0, +1), hybrid::get_corner(c1, i, 1, +1), hybrid::get_corner(c1, i, 1, -1)});
for(int a: {0,1}) {
vector<hyperpoint> l;
int z = a ? 1 : -1;
hyperpoint ctr = zpush0(z * cgi.plevel/2);
for(int i=0; i<c1->type; i++)
if(prod || WDIM == 2)
l.push_back(hybrid::get_corner(c1, i, 0, z));
else {
l.push_back(ctr);
l.push_back(hybrid::get_corner(c1, i, 0, z));
l.push_back(hybrid::get_corner(c1, i+1, 1, z));
l.push_back(ctr);
l.push_back(hybrid::get_corner(c1, i, 1, z));
l.push_back(hybrid::get_corner(c1, i, 0, z));
}
if(a == 0) std::reverse(l.begin()+1, l.end());
cgi.make_wall(won-2+a, l);
}
cgi.wallstart.push_back(isize(cgi.raywall));
cgi.compute_cornerbonus();
cgi.extra_vertices();
}
return wo;
}
EX void queue_transparent_wall(const shiftmatrix& V, hpcshape& sh, color_t color) {
@ -4253,8 +4303,7 @@ void celldrawer::draw_fallanims() {
EX void queuecircleat1(cell *c, const shiftmatrix& V, double rad, color_t col) {
if(WDIM == 3) {
dynamicval<color_t> p(poly_outline, col);
// we must do hybrid::wall_offset in hybrid because the cached value is likely incorrect
int ofs = hybri ? hybrid::wall_offset(c) : wall_offset(c);
int ofs = currentmap->wall_offset(c);
for(int i=0; i<c->type; i++) {
queuepolyat(V, cgi.shWireframe3D[ofs + i], 0, PPR::SUPERLINE);
}

View File

@ -338,6 +338,13 @@ struct hrmap_kite : hrmap {
}
return gm * where;
}
virtual int wall_offset(cell *c) {
if(WDIM == 3)
return kite::getshape(c->master) == kite::pKite ? 10 : 0;
else
return hrmap::wall_offset(c);
}
hrmap_kite() {
make_graphrules();

View File

@ -173,7 +173,7 @@ EX namespace models {
spiral_multiplier = cld(cos_spiral, sin_spiral) * cld(spiral_cone_rad * mul / 2., 0);
}
if(euclid) {
euclidean_spin = pispin * iso_inverse(cview().T * master_relative(centerover, true));
euclidean_spin = pispin * iso_inverse(cview().T * currentmap->master_relative(centerover, true));
euclidean_spin = gpushxto0(euclidean_spin * C0) * euclidean_spin;
hyperpoint h = inverse(euclidean_spin) * (C0 + (euc::eumove(gp::loc{1,0})*C0 - C0) * vpconf.spiral_x + (euc::eumove(gp::loc{0,1})*C0 - C0) * vpconf.spiral_y);
spiral_multiplier = cld(0, 2 * M_PI) / cld(h[0], h[1]);

View File

@ -1355,88 +1355,6 @@ EX namespace hybrid {
}
}
EX int wall_offset(cell *c) {
if(GOLDBERG || INVERSE) {
/* a bit slow... */
cell *c1 = WDIM == 2 ? c : get_where(c).first;
gp::draw_li = WDIM == 2 ? gp::get_local_info(c1) : PIU(gp::get_local_info(c1));
}
auto ugeometry = hybri ? hybrid::underlying : geometry;
int id;
#if CAP_ARCM
if(ugeometry == gArchimedean)
id = arcm::id_of(c->master) + 20 * arcm::parent_index_of(c->master);
else
#endif
if(ugeometry == gArbitrary)
id = arb::id_of(c->master);
else
if(PURE && !kite::in() && !bt::in())
id = 0;
else
id = shvid(c);
if(isize(cgi.walloffsets) <= id) cgi.walloffsets.resize(id+1, {-1, nullptr});
auto &wop = cgi.walloffsets[id];
int &wo = wop.first;
if(!wop.second) wop.second = c;
if(wo == -1) {
cell *c1 = hybri ? hybrid::get_where(c).first : c;
wo = isize(cgi.shWall3D);
int won = wo + c->type + (WDIM == 2 ? 2 : 0);
if(!cgi.wallstart.empty()) cgi.wallstart.pop_back();
cgi.reserve_wall3d(won);
if(prod || WDIM == 2) for(int i=0; i<c1->type; i++) {
hyperpoint w;
auto f = [&] {
/* mirror image of C0 in the axis h1-h2 */
hyperpoint h1 = get_corner_position(c1, i);
hyperpoint h2 = get_corner_position(c1, i+1);
transmatrix T = gpushxto0(h1);
T = spintox(T * h2) * T;
w = T * C0;
w[1] = -w[1];
w = iso_inverse(T) * w;
};
if(prod)
((hrmap_hybrid*)currentmap)->in_underlying(f);
else
f();
cgi.walltester[wo + i] = w;
}
for(int i=0; i<c1->type; i++)
cgi.make_wall(wo + i, {hybrid::get_corner(c1, i, 0, -1), hybrid::get_corner(c1, i, 0, +1), hybrid::get_corner(c1, i, 1, +1), hybrid::get_corner(c1, i, 1, -1)});
for(int a: {0,1}) {
vector<hyperpoint> l;
int z = a ? 1 : -1;
hyperpoint ctr = zpush0(z * cgi.plevel/2);
for(int i=0; i<c1->type; i++)
if(prod || WDIM == 2)
l.push_back(hybrid::get_corner(c1, i, 0, z));
else {
l.push_back(ctr);
l.push_back(hybrid::get_corner(c1, i, 0, z));
l.push_back(hybrid::get_corner(c1, i+1, 1, z));
l.push_back(ctr);
l.push_back(hybrid::get_corner(c1, i, 1, z));
l.push_back(hybrid::get_corner(c1, i, 0, z));
}
if(a == 0) std::reverse(l.begin()+1, l.end());
cgi.make_wall(won-2+a, l);
}
cgi.wallstart.push_back(isize(cgi.raywall));
cgi.compute_cornerbonus();
cgi.extra_vertices();
}
return wo;
}
auto clear_samples = addHook(hooks_clearmemory, 40, [] () {
for(auto& c: cgis) for(auto& v: c.second.walloffsets)
v.second = nullptr;

View File

@ -2698,7 +2698,7 @@ EX namespace linepatterns {
if(S3 >= OINF)
gridlinef(V, C0, V, mid(C0, tC0(currentmap->adj(c, dir))), col, 2 + vid.linequality);
else
gridlinef(V, C0, V * master_relative(c, true) * currentmap->adj(c->master, dir), C0, col, 2 + vid.linequality);
gridlinef(V, C0, V * currentmap->master_relative(c, true) * currentmap->adj(c->master, dir), C0, col, 2 + vid.linequality);
}
}
)
@ -2716,7 +2716,7 @@ EX namespace linepatterns {
gridlinef(V, C0, V, mid(C0, tC0(inverse_shift(V, gmatrix[c2]))), col, 2 + vid.linequality);
}
else
gridlinef(V, C0, V*master_relative(c, true) * currentmap->adj(c->master,i), C0, col, 2 + vid.linequality);
gridlinef(V, C0, V*currentmap->master_relative(c, true) * currentmap->adj(c->master,i), C0, col, 2 + vid.linequality);
}
}
}
@ -2777,7 +2777,7 @@ EX namespace linepatterns {
linepattern patIrregularMaster("irregular master", 0x8438A400, [] { return IRREGULAR; },
ALLCELLS(
if(c->master->c7 != c) if(gmatrix.count(c->master->c7))
gridlinef(V, C0, V*master_relative(c, true), C0,
gridlinef(V, C0, V*currentmap->master_relative(c, true), C0,
darkena(backcolor ^ 0xFFFFFF, 0, col),
2 + vid.linequality);
)

View File

@ -312,7 +312,7 @@ void enable_raycaster() {
return "uWallstart[" + s + "]";
};
wall_offset(centerover); /* so raywall is not empty and deg is not zero */
currentmap->wall_offset(centerover); /* so raywall is not empty and deg is not zero */
deg = 0;
@ -1691,7 +1691,7 @@ struct raycast_map {
}
}
int wo = wall_offset(c);
int wo = currentmap->wall_offset(c);
if(wo >= irays) {
println(hlog, "wo=", wo, " irays = ", irays);
reset_raycaster();
@ -1706,11 +1706,12 @@ struct raycast_map {
connections[u][2] = (k+.5) / 1024.;
break;
}
if(wall_offset(c1) >= max_wall_offset)
println(hlog, "error: wall_offset exceeds ", max_wall_offset);
auto wo1 = currentmap->wall_offset(c1);
if(wo1 >= max_wall_offset)
println(hlog, "error: wall_offset ", wo1, " exceeds ", max_wall_offset);
if(c1->type >= max_celltype)
println(hlog, "error: type " + its(c1->type) + " exceeds ", max_celltype);
connections[u][3] = (wall_offset(c1) * 1. / max_wall_offset) + (c1->type + (WDIM == 2 ? 2 : 0) + .5) * 1. / max_wall_offset / max_celltype;
connections[u][3] = (wo1 * 1. / max_wall_offset) + (c1->type + (WDIM == 2 ? 2 : 0) + .5) * 1. / max_wall_offset / max_celltype;
}
if(WDIM == 2) for(int a: {0, 1}) {
celldrawer dd;
@ -1907,7 +1908,7 @@ EX void cast() {
}
if(o->uWallOffset != -1) {
glUniform1i(o->uWallOffset, wall_offset(cs));
glUniform1i(o->uWallOffset, currentmap->wall_offset(cs));
glUniform1i(o->uSides, cs->type + (WDIM == 2 ? 2 : 0));
}

View File

@ -659,22 +659,23 @@ EX namespace reg3 {
}
void make_subconnections();
int wall_offset(cell *c) override;
int shvid(cell *c) { return local_id[c].second; }
};
struct hrmap_quotient3 : hrmap_closed3 { };
#endif
EX int get_wall_offset(cell *c) {
auto m = (hrmap_closed3*) currentmap;
auto& wo = cgi.walloffsets[ m->local_id[c].second ];
int hrmap_closed3::wall_offset(cell *c) {
auto& wo = cgi.walloffsets[ local_id[c].second ];
if(wo.second == nullptr)
wo.second = c;
return wo.first;
}
EX const vector<hyperpoint>& get_face_vertices(cell *c, int d) {
auto m = (hrmap_closed3*) currentmap;
return cgi.subshapes[m->local_id[c].second].faces_local[d];
return cgi.subshapes[currentmap->shvid(c)].faces_local[d];
}
EX int get_face_vertex_count(cell *c, int d) {