1
0
mirror of https://github.com/zenorogue/hyperrogue.git synced 2024-10-31 19:36:16 +00:00

refactored grid drawing

This commit is contained in:
Zeno Rogue 2023-03-16 14:40:26 +01:00
parent 999b26e818
commit 66671145a9

View File

@ -32,6 +32,7 @@ struct celldrawer {
void draw_wall(); void draw_wall();
void draw_boat(); void draw_boat();
void draw_grid(); void draw_grid();
void draw_grid_edge(int t, color_t col, int prec);
void draw_ceiling(); void draw_ceiling();
void draw_halfvine(); void draw_halfvine();
void draw_mirrorwall(); void draw_mirrorwall();
@ -829,6 +830,14 @@ EX int grid_prec() {
return prec; return prec;
} }
// should we draw t-th edge of c, or the opposite edge?
EX bool pick_for_grid(cell *c, int t) {
cell *c1 = c->move(t);
if(!c1) return false;
// removed: if(WDIM == 3 && bt::in() && !sn::in()) return !among(t, 5, 6, 8);
return c < c1 || isWarped(c->move(t)) || fake::split();
}
void celldrawer::draw_grid() { void celldrawer::draw_grid() {
int prec = grid_prec(); int prec = grid_prec();
@ -849,32 +858,44 @@ void celldrawer::draw_grid() {
vid.linewidth *= vid.multiplier_grid; vid.linewidth *= vid.multiplier_grid;
vid.linewidth *= cgi.scalefactor; vid.linewidth *= cgi.scalefactor;
// sphere: 0.3948 int maxt = c->type;
// sphere heptagonal: 0.5739 if(arb::apeirogon_hide_grid_edges && arb::is_apeirogonal(c)) maxt -= 2;
// sphere trihepta: 0.3467
// hyper trihepta: 0.2849 if(isWarped(c) && has_nice_dual()) {
// hyper heptagonal: 0.6150 if(pseudohept(c)) for(int t=0; t<c->type; t++) if(isWarped(c->move(t)))
// hyper: 0.3798 gridline(V, get_warp_corner(c, t%c->type), get_warp_corner(c, (t+1)%c->type), gridcolor(c, c->move(t)), prec);
return;
}
for(int t=0; t<maxt; t++)
if(pick_for_grid(c, t))
draw_grid_edge(t, gridcolor(c, c->move(t)), prec);
}
void celldrawer::draw_grid_edge(int t, color_t col, int prec) {
if(0);
#if MAXMDIM == 4 #if MAXMDIM == 4
else if(WDIM == 3) { if(WDIM == 3) {
int ofs = currentmap->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;
if(bt::in() && !sn::in() && !among(t, 5, 6, 8)) continue; // if(!bt::in() && c->move(t) < c) continue;
if(!bt::in() && c->move(t) < c) continue;
dynamicval<color_t> g(poly_outline, gridcolor(c, c->move(t))); dynamicval<color_t> g(poly_outline, col);
if(fat_edges && reg3::in()) { bool use_fat = fat_edges && (reg3::in() || euc::in(3));
if(!use_fat) {
queuepoly(V, cgi.shWireframe3D[ofs + t], 0);
return;
}
auto& ss = currentmap->get_cellshape(c); auto& ss = currentmap->get_cellshape(c);
for(int i=0; i<c->type; i++) if(c < c->move(i) || fake::split()) { auto& fa = ss.faces[t];
int face = isize(ss.faces[i]); int face = isize(fa);
for(int j=0; j<face; j++) { for(int j=0; j<face; j++) {
int jj = j == face-1 ? 0 : j+1; int jj = j == face-1 ? 0 : j+1;
int jjj = jj == face-1 ? 0 : jj+1; int jjj = jj == face-1 ? 0 : jj+1;
hyperpoint a = ss.faces[i][j]; hyperpoint a = fa[j];
hyperpoint b = ss.faces[i][jj]; hyperpoint b = fa[jj];
if(cgflags & qIDEAL) { if(cgflags & qIDEAL) {
ld mm = cgi.ultra_mirror_part; ld mm = cgi.ultra_mirror_part;
if((cgflags & qULTRA) && !reg3::ultra_mirror_in()) if((cgflags & qULTRA) && !reg3::ultra_mirror_in())
@ -885,34 +906,27 @@ void celldrawer::draw_grid() {
a = normalize(a); a = normalize(a);
b = normalize(b); b = normalize(b);
} }
gridline(V, a, b, gridcolor(c, c->move(t)), prec); gridline(V, a, b, col, prec);
if(reg3::ultra_mirror_in()) { if(reg3::ultra_mirror_in()) {
hyperpoint a = ss.faces[i][j]; hyperpoint a = fa[j];
hyperpoint b = ss.faces[i][jj]; hyperpoint b = fa[jj];
hyperpoint d = ss.faces[i][jjj]; hyperpoint d = fa[jjj];
auto& mm = cgi.ultra_mirror_part; auto& mm = cgi.ultra_mirror_part;
tie(a, d) = make_pair(normalize(lerp(a, b, mm)), normalize(lerp(d, b, mm))); tie(a, d) = make_pair(normalize(lerp(a, b, mm)), normalize(lerp(d, b, mm)));
gridline(V, a, d, stdgridcolor, prec); gridline(V, a, d, stdgridcolor, prec);
} }
} }
} return;
}
else {
queuepoly(V, cgi.shWireframe3D[ofs + t], 0);
}
}
} }
#endif #endif
#if CAP_BT #if CAP_BT
else if(bt::in() && WDIM == 2) { if(bt::in() && WDIM == 2) {
for(int t=0; t<c->type; t++) {
if(!c->move(t)|| c->move(t) < c) continue;
auto h0 = bt::get_corner_horo_coordinates(c, t); auto h0 = bt::get_corner_horo_coordinates(c, t);
auto h1 = bt::get_corner_horo_coordinates(c, t+1); auto h1 = bt::get_corner_horo_coordinates(c, t+1);
int steps = 12 * abs(h0[1] - h1[1]); int steps = 12 * abs(h0[1] - h1[1]);
if(!steps) { if(!steps) {
gridline(V, bt::get_horopoint(h0), bt::get_horopoint(h1), gridcolor(c, c->move(t)), prec); gridline(V, bt::get_horopoint(h0), bt::get_horopoint(h1), col, prec);
} }
else { else {
if(vid.linequality > 0) steps <<= vid.linequality; if(vid.linequality > 0) steps <<= vid.linequality;
@ -923,23 +937,13 @@ void celldrawer::draw_grid() {
} }
else { else {
for(int i=0; i<=steps; i++) curvepoint(bt::get_horopoint(h0 + i * step)); for(int i=0; i<=steps; i++) curvepoint(bt::get_horopoint(h0 + i * step));
queuecurve(V, gridcolor(c, c->move(t)), 0, PPR::LINE); queuecurve(V, col, 0, PPR::LINE);
}
} }
} }
return;
} }
#endif #endif
else if(isWarped(c) && has_nice_dual()) { gridline(V, get_corner_position(c, t%c->type), get_corner_position(c, (t+1)%c->type), col, prec);
if(pseudohept(c)) for(int t=0; t<c->type; t++) if(isWarped(c->move(t)))
gridline(V, get_warp_corner(c, t%c->type), get_warp_corner(c, (t+1)%c->type), gridcolor(c, c->move(t)), prec);
}
else {
int maxt = c->type;
if(arb::apeirogon_hide_grid_edges && arb::is_apeirogonal(c)) maxt -= 2;
for(int t=0; t<maxt; t++)
if(c->move(t) && (c->move(t) < c || isWarped(c->move(t)) || fake::split()))
gridline(V, get_corner_position(c, t%c->type), get_corner_position(c, (t+1)%c->type), gridcolor(c, c->move(t)), prec);
}
} }
void celldrawer::draw_halfvine() { void celldrawer::draw_halfvine() {