1
0
mirror of https://github.com/zenorogue/hyperrogue.git synced 2024-11-23 13:07:16 +00:00

redone hrmap::draw() function to keep DRY

This commit is contained in:
Zeno Rogue 2020-07-27 19:36:19 +02:00
parent 42446f1925
commit 67595a4ed3
15 changed files with 61 additions and 322 deletions

View File

@ -794,27 +794,6 @@ struct hrmap_arbi : hrmap {
return h1;
}
void draw() override {
dq::clear_all();
dq::enqueue(centerover->master, cview());
while(!dq::drawqueue.empty()) {
auto& p = dq::drawqueue.front();
heptagon *h = p.first;
shiftmatrix V = p.second;
dq::drawqueue.pop();
if(do_draw(h->c7, V)) drawcell(h->c7, V);
else continue;
for(int i=0; i<h->type; i++) {
shiftmatrix V1 = V * adj(h, i);
optimize_shift(V1);
dq::enqueue(h->move(i), V1);
}
}
}
transmatrix relative_matrix(heptagon *h2, heptagon *h1, const hyperpoint& hint) override {
return relative_matrix_recursive(h2, h1);
}

View File

@ -676,9 +676,9 @@ struct hrmap_archimedean : hrmap {
return hnew;
}
void draw() override {
void draw_at(cell *at, const shiftmatrix& where) override {
dq::clear_all();
dq::enqueue(centerover->master, cview());
dq::enqueue(at->master, where);
while(!dq::drawqueue.empty()) {
auto& p = dq::drawqueue.front();

View File

@ -176,27 +176,6 @@ struct hrmap_asonov : hrmap {
for(int a=0; a<S7; a++) if(h2 == h1->move(a)) return adjmatrix(a);
return coord_to_matrix(coords[h2], coords[h1]);
}
void draw() override {
dq::clear_all();
dq::enqueue_by_matrix(centerover->master, cview());
while(!dq::drawqueue.empty()) {
auto& p = dq::drawqueue.front();
heptagon *h = p.first;
shiftmatrix V = p.second;
dq::drawqueue.pop();
cell *c = h->c7;
if(!do_draw(c, V)) continue;
drawcell(c, V);
if(in_wallopt() && isWall3(c) && isize(dq::drawqueue) > 1000) continue;
for(int i=0; i<S7; i++)
dq::enqueue_by_matrix(h->cmove(i), V * adjmatrix(i));
}
}
};
EX hrmap *new_map() { return new hrmap_asonov; }

View File

@ -417,26 +417,6 @@ EX namespace bt {
return NULL;
}
void draw() override {
dq::clear_all();
dq::enqueue(centerover->master, cview());
while(!dq::drawqueue.empty()) {
auto& p = dq::drawqueue.front();
heptagon *h = p.first;
shiftmatrix V = p.second;
dq::drawqueue.pop();
cell *c = h->c7;
if(!do_draw(c, V)) continue;
drawcell(c, V);
for(int i=0; i<h->type; i++)
dq::enqueue(h->cmove(i), optimized_shift(V * adj(h, i)));
}
}
int updir_at(heptagon *h) {
if(geometry != gBinaryTiling) return updir();
else if(type_of(h) == 6) return bd_down;

View File

@ -42,9 +42,8 @@ struct hrmap {
transmatrix iadj(heptagon *h, int d) {
heptagon *h1 = h->cmove(d); return adj(h1, h->c.spin(d));
}
virtual void draw() {
printf("undrawable\n");
}
virtual void draw_all();
virtual void draw_at(cell *at, const shiftmatrix& where);
virtual vector<hyperpoint> get_vertices(cell*);
virtual void virtualRebase(heptagon*& base, transmatrix& at) {
@ -67,7 +66,7 @@ struct hrmap {
* (e.g. Euclidean and Crystal) also inherit from hrmap_standard
**/
struct hrmap_standard : hrmap {
void draw() override;
void draw_at(cell *at, const shiftmatrix& where) override;
transmatrix relative_matrix(heptagon *h2, heptagon *h1, const hyperpoint& hint) override;
transmatrix relative_matrix(cell *c2, cell *c1, const hyperpoint& hint) override;
heptagon *create_step(heptagon *h, int direction) override;

View File

@ -670,31 +670,9 @@ struct hrmap_crystal : hrmap_standard {
return hrmap_standard::adj(c, d);
}
void draw() override {
if(!crystal3()) { hrmap_standard::draw(); return; }
sphereflip = Id;
// for(int i=0; i<S6; i++) queuepoly(ggmatrix(cwt.at), shWall3D[i], 0xFF0000FF);
dq::clear_all();
dq::enqueue_by_matrix(centerover->master, cview());
while(!dq::drawqueue.empty()) {
auto& p = dq::drawqueue.front();
heptagon *h = p.first;
shiftmatrix V = p.second;
dq::drawqueue.pop();
cell *c = h->c7;
if(!do_draw(c, V)) continue;
drawcell(c, V);
if(in_wallopt() && isWall3(c) && isize(dq::drawqueue) > 1000) continue;
for(int d=0; d<S7; d++) {
dq::enqueue_by_matrix(h->move(d), optimized_shift(V * adj(h, d)));
}
}
void draw_at(cell *at, const shiftmatrix& where) override {
if(!crystal3()) { hrmap_standard::draw_at(at, where); return; }
else hrmap::draw_at(at, where);
}
virtual transmatrix relative_matrix(cell *h2, cell *h1, const hyperpoint& hint) override {

View File

@ -226,9 +226,9 @@ EX namespace euc {
else return hrmap_standard::adj(c, i);
}
void draw() override {
void draw_at(cell *at, const shiftmatrix& where) override {
dq::clear_all();
dq::enqueue_by_matrix(centerover->master, cview() * master_relative(centerover, true));
dq::enqueue_by_matrix(at->master, where * master_relative(centerover, true));
while(!dq::drawqueue.empty()) {
auto& p = dq::drawqueue.front();

View File

@ -182,13 +182,13 @@ EX namespace fake {
return relative_matrix(h2->c7, h1->c7, hint);
}
void draw() override {
void draw_at(cell *at, const shiftmatrix& where) override {
sphereflip = Id;
// for(int i=0; i<S6; i++) queuepoly(ggmatrix(cwt.at), shWall3D[i], 0xFF0000FF);
if(pmodel == mdDisk && WDIM == 2 && recursive_draw) {
draw_recursive(centerover, cview(), -1, -1, nullptr, 0);
draw_recursive(at, where, -1, -1, nullptr, 0);
return;
}
@ -253,7 +253,7 @@ EX namespace fake {
}
auto enqueue = (multiple && multiple_special_draw ? dq::enqueue_by_matrix_c : dq::enqueue_c);
enqueue(centerover, cview());
enqueue(at, where);
while(!dq::drawqueue_c.empty()) {
auto& p = dq::drawqueue_c.front();

View File

@ -1225,12 +1225,12 @@ EX namespace gp {
return T;
}
void draw() override {
void draw_at(cell *at, const shiftmatrix& where) override {
dq::clear_all();
auto enqueue = (quotient ? dq::enqueue_by_matrix_c : dq::enqueue_c);
enqueue(centerover, cview());
enqueue(at, where);
while(!dq::drawqueue_c.empty()) {
auto& p = dq::drawqueue_c.front();

View File

@ -4663,7 +4663,7 @@ EX void drawthemap() {
profile_start(1);
make_actual_view();
currentmap->draw();
currentmap->draw_all();
drawWormSegments();
drawBlizzards();
drawArrowTraps();
@ -4949,7 +4949,7 @@ EX void gamescreen(int _darken) {
View = subscreens::player_displays[0].view_matrix;
centerover = subscreens::player_displays[0].precise_center;
just_gmatrix = true;
currentmap->draw();
currentmap->draw_all();
just_gmatrix = false;
return;
}

View File

@ -1232,38 +1232,59 @@ EX bool drawcell_subs(cell *c, const shiftmatrix& V) {
return draw;
}
void hrmap_standard::draw() {
static ld shift = 0;
static bool in_multi = false;
if(sphere && pmodel == mdSpiral && !in_multi) {
/* todo other types? */
in_multi = true;
void hrmap::draw_all() {
if(sphere && pmodel == mdSpiral) {
if(models::ring_not_spiral) {
int qty = ceil(1. / pconf.sphere_spiral_multiplier);
if(qty > 100) qty = 100;
for(int i=-qty; i < qty; i++) {
shift = 2 * M_PI * i;
draw();
}
for(int i=-qty; i < qty; i++)
draw_at(centerover, cview(2 * M_PI * i));
}
else {
shift = 0;
draw();
draw_at(centerover, cview());
if(vid.use_smart_range) for(int i=1;; i++) {
int drawn = cells_drawn;
shift = 2 * M_PI * i;
draw();
shift = -2 * M_PI * i;
draw();
draw_at(centerover, cview(2 * M_PI * i));
draw_at(centerover, cview(-2 * M_PI * i));
if(drawn == cells_drawn) break;
}
}
in_multi = false;
shift = 0;
return;
}
else
draw_at(centerover, cview());
}
void hrmap::draw_at(cell *at, const shiftmatrix& where) {
dq::clear_all();
auto& enq = confusingGeometry() ? dq::enqueue_by_matrix_c : dq::enqueue_c;
enq(at, where);
while(!dq::drawqueue_c.empty()) {
auto& p = dq::drawqueue_c.front();
cell *c = p.first;
shiftmatrix V = p.second;
dq::drawqueue_c.pop();
if(!do_draw(c, V)) continue;
drawcell(c, V);
if(in_wallopt() && isWall3(c) && isize(dq::drawqueue) > 1000) continue;
if(reg3::ultra_mirror_in())
for(auto& T: cgi.ultra_mirrors)
enq(c, optimized_shift(V * T));
for(int i=0; i<c->type; i++) {
// note: need do cmove before c.spin
cell *c1 = c->cmove(i);
enq(c1, optimized_shift(V * adj(c, i)));
}
}
}
void hrmap_standard::draw_at(cell *at, const shiftmatrix& where) {
drawn_cells.clear();
drawn_cells.emplace_back(centerover->master, hsOrigin, cview(shift) * master_relative(centerover, true));
drawn_cells.emplace_back(at->master, hsOrigin, where * master_relative(at, true));
for(int i=0; i<isize(drawn_cells); i++) {
// prevent reallocation due to insertion
if(drawn_cells.capacity() < drawn_cells.size() + 16)

View File

@ -343,35 +343,6 @@ struct hrmap_kite : hrmap {
origin = newtile(pKite, 0);
}
void draw() override {
dq::clear_all();
dq::enqueue(centerover->master, cview());
while(!dq::drawqueue.empty()) {
auto& p = dq::drawqueue.front();
heptagon *h = p.first;
shiftmatrix V = p.second;
dq::drawqueue.pop();
cell *c = h->c7;
if(!do_draw(c, V)) continue;
drawcell(c, V);
for(int i=0; i<c->type; i++)
dq::enqueue(c->cmove(i)->master, optimized_shift(V * adj(c, i)));
/*
ld err = hdist(where[h->c7->cmove(i)->master] * C0, where[h] * M * C0);
if(err > -.01)
println(hlog,
" for ", make_tuple(getshape(h), i, getshape(h->c7->cmove(i)->master), h->c7->c.spin(i)),
" error = ", format("%f", float(err)),
" source = ", s0+source[{h->c7, h->c7->cmove(i)}]
);
*/
}
}
~hrmap_kite() {
clearfrom(origin);
}

View File

@ -458,31 +458,6 @@ EX namespace sn {
while(coords[h1].second != coords[h2].second) front = front * adj(h1, up), back = iadj(h2, up) * back, h1 = h1->cmove(up), h2 = h2->cmove(up);
return front * back;
}
void draw() override {
dq::clear_all();
dq::enqueue(centerover->master, cview());
while(!dq::drawqueue.empty()) {
auto& p = dq::drawqueue.front();
heptagon *h = p.first;
shiftmatrix V = p.second;
dq::drawqueue.pop();
cell *c = h->c7;
if(!do_draw(c, V)) continue;
drawcell(c, V);
if(in_wallopt() && isWall3(c) && isize(dq::drawqueue) > 1000) continue;
for(int i=0; i<S7; i++) {
// note: need do cmove before c.spin
heptagon *h1 = h->cmove(i);
dq::enqueue(h1, V * adjmatrix(i, h->c.spin(i)));
}
}
}
};
EX pair<heptagon*,heptagon*> getcoord(heptagon *h) {
@ -937,38 +912,8 @@ EX namespace nilv {
for(int a=0; a<3; a++) p[a] = szgmod(p[a], nilperiod[a]);
return nisot::translate(mvec_to_point(p));
}
void draw() override {
dq::clear_all();
dq::enqueue_by_matrix(centerover->master, cview());
while(!dq::drawqueue.empty()) {
auto& p = dq::drawqueue.front();
heptagon *h = p.first;
shiftmatrix V = p.second;
dq::drawqueue.pop();
cell *c = h->c7;
if(!do_draw(c, V)) continue;
drawcell(c, V);
if(in_wallopt() && isWall3(c) && isize(dq::drawqueue) > 1000) continue;
if(0) for(int t=0; t<c->type; t++) {
if(!c->move(t)) continue;
dynamicval<color_t> g(poly_outline, darkena((0x142968*t) & 0xFFFFFF, 0, 255) );
queuepoly(V, cgi.shWireframe3D[t], 0);
}
for(int i=0; i<S7; i++) {
// note: need do cmove before c.spin
heptagon *h1 = h->cmove(i);
dq::enqueue_by_matrix(h1, V * adjmatrix(i));
}
}
}
};
EX mvec get_coord(heptagon *h) { return ((hrmap_nil*)currentmap)->coords[h]; }
EX heptagon *get_heptagon_at(mvec m) { return ((hrmap_nil*)currentmap)->get_at(m); }
@ -1278,33 +1223,6 @@ EX namespace hybrid {
virtual transmatrix spin_to(cell *c, int d, ld bonus) override { if(d >= c->type-2) return Id; c = get_where(c).first; return in_underlying([&] { return currentmap->spin_to(c, d, bonus); }); }
virtual transmatrix spin_from(cell *c, int d, ld bonus) override { if(d >= c->type-2) return Id; c = get_where(c).first; return in_underlying([&] { return currentmap->spin_from(c, d, bonus); }); }
void draw() override {
cell* start = centerover;
dq::clear_all();
dq::enqueue_by_matrix_c(start, cview());
while(!dq::drawqueue_c.empty()) {
auto& p = dq::drawqueue_c.front();
cell *c = get<0>(p);
shiftmatrix V = get<1>(p);
dq::drawqueue_c.pop();
if(!do_draw(c, V)) continue;
drawcell(c, V);
if(in_wallopt() && isWall3(c) && isize(dq::drawqueue) > 1000) continue;
for(int i=0; i<c->type; i++) {
cell *c1 = c->cmove(i);
shiftmatrix V1 = V * adj(c, i);
optimize_shift(V1);
dq::enqueue_by_matrix_c(c1, V1);
}
}
}
};
hrmap_hybrid* hmap() { return (hrmap_hybrid*) currentmap; }
@ -2122,7 +2040,7 @@ EX namespace rots {
std::unordered_map<int, transmatrix> saved_matrices;
transmatrix adj(cell *c1, int i) override {
transmatrix adj(cell *c1, int i) override {
if(i == c1->type-2) return uzpush(-cgi.plevel) * spin(-2*cgi.plevel);
if(i == c1->type-1) return uzpush(+cgi.plevel) * spin(+2*cgi.plevel);
cell *c2 = c1->cmove(i);

View File

@ -292,7 +292,6 @@ EX namespace reg3 {
heptagon *getOrigin() override { return allh[0]; }
void draw() override;
transmatrix relative_matrix(heptagon *h2, heptagon *h1, const hyperpoint& hint) override;
void initialize(int cell_count);
@ -316,34 +315,6 @@ EX namespace reg3 {
}
}
void hrmap_quotient3::draw() {
sphereflip = Id;
// for(int i=0; i<S6; i++) queuepoly(ggmatrix(cwt.at), shWall3D[i], 0xFF0000FF);
dq::clear_all();
dq::enqueue_by_matrix(centerover->master, cview());
while(!dq::drawqueue.empty()) {
auto& p = dq::drawqueue.front();
heptagon *h = p.first;
shiftmatrix V = p.second;
dq::drawqueue.pop();
cell *c = h->c7;
if(!do_draw(c, V)) continue;
drawcell(c, V);
if(in_wallopt() && isWall3(c) && isize(dq::drawqueue) > 1000) continue;
if(ultra_mirror_in())
for(auto& T: cgi.ultra_mirrors)
dq::enqueue_by_matrix(h, optimized_shift(V * T));
for(int d=0; d<S7; d++)
dq::enqueue_by_matrix(h->move(d), optimized_shift(V * tmatrices[h->fieldval][d]));
}
}
transmatrix hrmap_quotient3::relative_matrix(heptagon *h2, heptagon *h1, const hyperpoint& hint) {
if(h1 == h2) return Id;
int d = hr::celldistance(h2->c7, h1->c7);
@ -918,37 +889,6 @@ EX namespace reg3 {
}
}
void draw() override {
sphereflip = Id;
dq::clear_all();
auto& enq = (ultra_mirror_in() ? dq::enqueue_by_matrix : dq::enqueue);
enq(centerover->master, cview());
while(!dq::drawqueue.empty()) {
auto& p = dq::drawqueue.front();
heptagon *h = p.first;
shiftmatrix V = p.second;
dq::drawqueue.pop();
cell *c = h->c7;
if(!do_draw(c, V)) continue;
drawcell(c, V);
if(in_wallopt() && isWall3(c) && isize(dq::drawqueue) > 1000) continue;
if(sightranges[geometry] == 0) return;
if(ultra_mirror_in())
for(auto& T: cgi.ultra_mirrors)
dq::enqueue_by_matrix(h, optimized_shift(V * T));
for(int i=0; i<S7; i++) if(h->move(i)) {
enq(h->move(i), optimized_shift(V * adj(h, i)));
}
}
}
transmatrix adj(heptagon *h, int d) override {
#if CAP_FIELD
if(quotient_map) return quotient_map->adj(h, d);
@ -1264,32 +1204,6 @@ EX namespace reg3 {
clearfrom(origin);
}
void draw() override {
sphereflip = Id;
// for(int i=0; i<S6; i++) queuepoly(ggmatrix(cwt.at), shWall3D[i], 0xFF0000FF);
dq::clear_all();
dq::enqueue(centerover->master, cview());
while(!dq::drawqueue.empty()) {
auto& p = dq::drawqueue.front();
heptagon *h = p.first;
shiftmatrix V = p.second;
dq::drawqueue.pop();
cell *c = h->c7;
if(!do_draw(c, V)) continue;
drawcell(c, V);
if(in_wallopt() && isWall3(c) && isize(dq::drawqueue) > 1000) continue;
for(int i=0; i<S7; i++) if(h->move(i)) {
dq::enqueue(h->move(i), optimized_shift(V * adj(h, i)));
}
}
}
transmatrix adj(heptagon *h, int d) override {
return quotient_map->adj(h, d);
}

View File

@ -168,7 +168,7 @@ struct hrmap_spherical : hrmap_standard {
swap(gmatrix, gmatrix0);
just_gmatrix = true;
dynamicval<cell*> cco(centerover, gamestart());
draw();
draw_all();
just_gmatrix = false;
swap(gmatrix, gmatrix0);
#if CAP_GP