1
0
mirror of https://github.com/zenorogue/hyperrogue.git synced 2024-12-24 01:00:25 +00:00
hyperrogue/fake.cpp

776 lines
22 KiB
C++
Raw Normal View History

2020-05-15 09:46:26 +00:00
#include "hyper.h"
// Fake non-Euclidean
namespace hr {
EX namespace fake {
EX ld scale;
2020-05-16 00:13:10 +00:00
EX bool multiple;
EX bool multiple_special_draw = true;
EX bool recursive_draw = false;
2020-05-15 09:46:26 +00:00
EX eGeometry underlying;
EX geometry_information *underlying_cgip;
EX hrmap *pmap;
EX geometry_information *pcgip;
EX eGeometry actual_geometry;
2020-07-03 13:06:33 +00:00
EX int ordered_mode = 0;
2020-05-15 09:46:26 +00:00
EX bool in() { return geometry == gFake; }
EX void on_dim_change() { pmap->on_dim_change(); }
2020-05-16 00:15:34 +00:00
/** like in() but takes slided arb into account */
EX bool split() { return in() || arb::in_slided(); }
2020-05-16 00:15:34 +00:00
EX bool available() {
if(in()) return true;
2020-06-03 13:11:20 +00:00
if(WDIM == 2 && standard_tiling() && (PURE || BITRUNCATED)) return true;
if(arcm::in() && PURE) return true;
2020-06-03 13:11:20 +00:00
if(WDIM == 2) return false;
2020-07-03 13:07:59 +00:00
if(among(geometry, gBitrunc3)) return false;
2022-05-10 06:53:58 +00:00
#if MAXMDIM >= 4
2021-07-13 13:12:03 +00:00
if(reg3::in() && !among(variation, eVariation::pure, eVariation::subcubes, eVariation::coxeter, eVariation::bch_oct)) return false;
2020-05-16 00:15:34 +00:00
return euc::in() || reg3::in();
2022-05-10 06:53:58 +00:00
#else
return euc::in();
#endif
2020-05-16 00:15:34 +00:00
}
2020-07-03 13:06:33 +00:00
map<cell*, ld> random_order;
2020-05-15 09:46:26 +00:00
// a dummy map that does nothing
struct hrmap_fake : hrmap {
hrmap *underlying_map;
template<class T> auto in_underlying(const T& t) -> decltype(t()) {
pcgip = cgip;
dynamicval<hrmap*> gpm(pmap, this);
dynamicval<eGeometry> gag(actual_geometry, geometry);
dynamicval<eGeometry> g(geometry, underlying);
dynamicval<geometry_information*> gc(cgip, underlying_cgip);
dynamicval<hrmap*> gu(currentmap, underlying_map);
return t();
}
heptagon *getOrigin() override { return in_underlying([this] { return underlying_map->getOrigin(); }); }
cell* gamestart() override { return in_underlying([this] { return underlying_map->gamestart(); }); }
2020-05-16 00:14:24 +00:00
hrmap_fake(hrmap *u) {
underlying_map = u;
for(hrmap*& m: allmaps) if(m == underlying_map) m = this;
if(currentmap == u) currentmap = this;
}
2021-06-12 21:25:59 +00:00
void find_cell_connection(cell *c, int d) override {
FPIU(createMov(c, d));
}
2020-05-15 09:46:26 +00:00
hrmap_fake() {
in_underlying([this] { initcells(); underlying_map = currentmap; });
for(hrmap*& m: allmaps) if(m == underlying_map) m = NULL;
}
2020-05-31 14:18:44 +00:00
~hrmap_fake() {
in_underlying([this] {
delete underlying_map;
});
}
2020-05-16 00:14:24 +00:00
2020-05-15 09:46:26 +00:00
heptagon *create_step(heptagon *parent, int d) override {
2021-08-05 09:56:12 +00:00
return FPIU(currentmap->create_step(parent, d));
}
2021-08-05 18:33:40 +00:00
hyperpoint get_corner(cell *c, int cid, ld cf=3) override {
2021-08-05 09:56:12 +00:00
if(arcm::in()) {
return underlying_map->get_corner(c, cid, cf);
}
hyperpoint h;
h = FPIU(currentmap->get_corner(c, cid, cf));
return befake(h);
2020-05-15 09:46:26 +00:00
}
transmatrix adj(cell *c, int d) override {
if(variation == eVariation::coxeter) {
array<int, 3> which;
in_underlying([&which, c, d] {
auto T = currentmap->adj(c, d);
auto& f1 = currentmap->get_cellshape(c).faces_local[d];
auto& f2 = currentmap->get_cellshape(c->move(d)).faces_local[c->c.spin(d)];
for(int i=0; i<3; i++) {
which[i] = -1;
for(int j=0; j<isize(f2); j++)
if(hdist(T * f2[j], f1[i]) < 1e-6)
which[i] = j;
}
});
auto& f1 = get_cellshape(c).faces_local[d];
auto& f2 = get_cellshape(c->move(d)).faces_local[c->c.spin(d)];
vector<ld> d1;
for(auto& v: f1) d1.push_back(hdist0(normalize(v)));
vector<hyperpoint> cf2(3);
for(int i=0; i<3; i++)
cf2[i] = f2[which[i]];
transmatrix F2, F1;
for(int i=0; i<3; i++) set_column(F2, i, cf2[i]);
for(int i=0; i<3; i++) set_column(F1, i, f1[i]);
auto dtang = [] (vector<hyperpoint> v) {
if(euclid) return (v[1] - v[0]) ^ (v[2] - v[0]);
transmatrix T = gpushxto0(normalize(v[0]));
hyperpoint h = iso_inverse(T) * ((T*v[1]) ^ (T*v[2]));
return h;
};
set_column(F2, 3, dtang(cf2));
set_column(F1, 3, dtang(f1));
transmatrix T = F1 * inverse(F2);
return T;
}
2020-05-15 09:46:26 +00:00
transmatrix S1, S2;
ld dist;
2022-05-10 06:53:58 +00:00
#if MAXMDIM >= 4
2021-07-13 00:34:24 +00:00
bool impure = reg3::in() && !PURE;
2022-05-10 06:53:58 +00:00
#else
bool impure = !PURE;
#endif
2021-07-13 00:34:24 +00:00
vector<int> mseq;
if(impure) {
mseq = FPIU ( currentmap->get_move_seq(c, d) );
if(mseq.empty()) {
auto& s1 = get_cellshape(c);
auto& s2 = get_cellshape(c->move(d));
return s1.from_cellcenter * s2.to_cellcenter;
}
if(isize(mseq) > 1)
throw hr_exception("fake adj not implemented for isize(mseq) > 1");
2021-07-13 00:10:34 +00:00
}
2021-07-13 00:34:24 +00:00
in_underlying([c, d, &S1, &S2, &dist, &impure, &mseq] {
2020-10-15 14:33:52 +00:00
#if CAP_ARCM
2020-05-31 14:18:44 +00:00
dynamicval<bool> u(arcm::use_gmatrix, false);
2020-10-15 14:33:52 +00:00
#endif
2021-07-13 00:10:34 +00:00
transmatrix T;
2021-07-13 00:34:24 +00:00
if(impure) {
T = currentmap->adj(c->master, mseq[0]);
2021-07-13 00:10:34 +00:00
}
else {
T = currentmap->adj(c, d);
}
2020-05-15 09:46:26 +00:00
S1 = rspintox(tC0(T));
transmatrix T1 = spintox(tC0(T)) * T;
dist = hdist0(tC0(T1));
S2 = xpush(-dist) * T1;
});
2021-07-13 00:34:24 +00:00
if(impure) {
2021-07-13 00:10:34 +00:00
auto& s1 = get_cellshape(c);
auto& s2 = get_cellshape(c->move(d));
S1 = s1.from_cellcenter * S1;
S2 = S2 * s2.to_cellcenter;
}
2020-10-15 14:33:52 +00:00
#if CAP_ARCM
2020-05-31 14:18:44 +00:00
if(arcm::in()) {
int t = arcm::id_of(c->master);
int t2 = arcm::id_of(c->move(d)->master);
auto& cof = arcm::current_or_fake();
cgi.adjcheck = cof.inradius[t/2] + cof.inradius[t2/2];
}
2020-10-15 14:33:52 +00:00
#else
if(0) ;
#endif
2020-05-31 14:18:44 +00:00
else if(WDIM == 2) {
2020-05-31 01:30:14 +00:00
ld dist;
in_underlying([c, d, &dist] {
dist = currentmap->spacedist(c, d);
2020-05-15 09:46:26 +00:00
});
2020-05-31 01:30:14 +00:00
auto& u = *underlying_cgip;
if(dist == u.tessf) cgi.adjcheck = cgi.tessf;
else if(dist == u.crossf) cgi.adjcheck = cgi.crossf;
else if(dist == u.hexhexdist) cgi.adjcheck = cgi.hexhexdist;
else cgi.adjcheck = dist * scale;
2020-05-15 09:46:26 +00:00
}
2020-07-03 13:07:59 +00:00
else if(underlying == gBitrunc3) {
ld x = (d % 7 < 3) ? 1 : sqrt(3)/2;
x *= scale;
cgi.adjcheck = 2 * atanh(x);
}
2020-05-15 09:46:26 +00:00
return S1 * xpush(cgi.adjcheck) * S2;
}
void draw_recursive(cell *c, const shiftmatrix& V, ld a0, ld a1, cell *parent, int depth) {
2020-05-15 09:46:26 +00:00
if(!do_draw(c, V)) return;
drawcell(c, V);
if(depth >= 15) return;
// queuestr(V, .2, fts(a0)+":"+fts(a1), 0xFFFFFFFF, 1);
ld d = hdist0(tC0(V));
if(false) {
curvepoint(spin(-a0) * xpush0(d));
curvepoint(spin(-a0) * xpush0(d+.2));
curvepoint(spin(-a1) * xpush0(d+.2));
curvepoint(spin(-a1) * xpush0(d));
curvepoint(spin(-a0) * xpush0(d));
queuecurve(shiftless(Id), 0xFF0000FF, 0, PPR::LINE);
2020-05-15 09:46:26 +00:00
}
indenter id(2);
for(int i=0; i<c->type; i++) if(c->move(i) && c->move(i) != parent) {
auto h0 = V * befake(FPIU(get_corner_position(c, i)));
auto h1 = V * befake(FPIU(get_corner_position(c, (i+1) % c->type)));
ld b0 = atan2(unshift(h0));
ld b1 = atan2(unshift(h1));
2020-05-15 09:46:26 +00:00
while(b1 < b0) b1 += 2 * M_PI;
if(a0 == -1) {
draw_recursive(c->move(i), optimized_shift(V * adj(c, i)), b0, b1, c, depth+1);
2020-05-15 09:46:26 +00:00
}
else {
if(b1 - b0 > M_PI) continue;
if(b0 < a0 - M_PI) b0 += 2 * M_PI;
if(b0 > a0 + M_PI) b0 -= 2 * M_PI;
if(b0 < a0) b0 = a0;
if(b1 > a1 + M_PI) b1 -= 2 * M_PI;
if(b1 < a1 - M_PI) b1 += 2 * M_PI;
if(b1 > a1) b1 = a1;
if(b0 > b1) continue;
draw_recursive(c->move(i), optimized_shift(V * adj(c, i)), b0, b1, c, depth+1);
2020-05-15 09:46:26 +00:00
}
}
}
transmatrix relative_matrixc(cell *h2, cell *h1, const hyperpoint& hint) override {
2020-05-31 14:18:44 +00:00
if(arcm::in()) return underlying_map->relative_matrix(h2, h1, hint);
2020-05-15 09:46:26 +00:00
if(h1 == h2) return Id;
for(int a=0; a<h1->type; a++) if(h1->move(a) == h2)
return adj(h1, a);
return Id;
}
transmatrix relative_matrixh(heptagon *h2, heptagon *h1, const hyperpoint& hint) override {
2020-05-31 14:18:44 +00:00
if(arcm::in()) return underlying_map->relative_matrix(h2, h1, hint);
2020-05-15 09:46:26 +00:00
return relative_matrix(h2->c7, h1->c7, hint);
}
void draw_at(cell *at, const shiftmatrix& where) override {
2020-05-15 09:46:26 +00:00
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(at, where, -1, -1, nullptr, 0);
2020-05-15 09:46:26 +00:00
return;
}
2020-07-03 13:06:33 +00:00
dq::clear_all();
2020-05-15 09:46:26 +00:00
2020-05-31 01:30:51 +00:00
int id = 0;
int limit = 100 * pow(1.2, sightrange_bonus);
if(WDIM == 3 || vid.use_smart_range)
limit = INT_MAX;
2020-07-03 13:06:33 +00:00
if(ordered_mode && !(multiple && multiple_special_draw)) {
using pct = pair<cell*, shiftmatrix>;
2020-07-03 13:06:33 +00:00
auto comparer = [] (pct& a1, pct& a2) {
if(ordered_mode > 2) {
auto val = [] (pct& a) {
if(!random_order.count(a.first))
random_order[a.first] = randd() * 2;
return random_order[a.first] + hdist0(tC0(a.second));
};
return val(a1) > val(a2);
}
return a1.second[LDIM][LDIM] > a2.second[LDIM][LDIM];
};
std::priority_queue<pct, std::vector<pct>, decltype(comparer)> myqueue(comparer);
auto enq = [&] (cell *c, const shiftmatrix& V) {
2020-07-03 13:06:33 +00:00
if(!c) return;
if(ordered_mode == 1 || ordered_mode == 3) {
if(dq::visited_c.count(c)) return;
dq::visited_c.insert(c);
}
myqueue.emplace(c, V);
};
enq(centerover, cview());
while(!myqueue.empty()) {
auto& p = myqueue.top();
id++;
cell *c = p.first;
shiftmatrix V = p.second;
2020-07-03 13:06:33 +00:00
myqueue.pop();
if(ordered_mode == 2 || ordered_mode == 4) {
if(dq::visited_c.count(c)) continue;
dq::visited_c.insert(c);
}
if(!do_draw(c, V)) continue;
drawcell(c, V);
if(in_wallopt() && isWall3(c) && isize(dq::drawqueue_c) > 1000) continue;
if(id > limit) continue;
for(int i=0; i<c->type; i++) if(c->move(i)) {
enq(c->move(i), optimized_shift(V * adj(c, i)));
2020-07-03 13:06:33 +00:00
}
}
return;
}
auto enqueue = (multiple && multiple_special_draw ? dq::enqueue_by_matrix_c : dq::enqueue_c);
enqueue(at, where);
2020-05-31 01:30:51 +00:00
2020-05-15 09:46:26 +00:00
while(!dq::drawqueue_c.empty()) {
auto& p = dq::drawqueue_c.front();
2020-05-31 01:30:51 +00:00
id++;
cell *c = p.first;
shiftmatrix V = p.second;
2020-05-15 09:46:26 +00:00
dq::drawqueue_c.pop();
if(!do_draw(c, V)) continue;
drawcell(c, V);
if(in_wallopt() && isWall3(c) && isize(dq::drawqueue_c) > 1000) continue;
2020-05-31 01:30:51 +00:00
if(id > limit) continue;
2020-05-15 09:46:26 +00:00
2020-05-31 01:30:14 +00:00
for(int i=0; i<c->type; i++) if(c->move(i)) {
enqueue(c->move(i), optimized_shift(V * adj(c, i)));
2020-05-15 09:46:26 +00:00
}
}
}
2020-05-31 14:18:44 +00:00
ld spin_angle(cell *c, int d) override {
return underlying_map->spin_angle(c,d);
}
2021-07-13 00:10:34 +00:00
int shvid(cell *c) override {
return FPIU( currentmap->shvid(c) );
}
subcellshape& get_cellshape(cell *c) override {
return *FPIU( (cgip = pcgip, &(currentmap->get_cellshape(c))) );
}
2021-07-13 16:10:19 +00:00
transmatrix ray_iadj(cell *c, int i) override {
2021-08-05 09:56:12 +00:00
if(WDIM == 2)
return to_other_side(get_corner(c, i), get_corner(c, i+1));
2022-02-17 20:00:10 +00:00
#if MAXMDIM >= 4
2021-07-13 16:10:19 +00:00
if(PURE) return iadj(c, i);
auto& v = get_cellshape(c).faces_local[i];
hyperpoint h =
project_on_triangle(v[0], v[1], v[2]);
transmatrix T = rspintox(h);
return T * xpush(-2*hdist0(h)) * spintox(h);
2022-02-17 20:00:10 +00:00
#else
return Id;
#endif
2021-07-13 16:10:19 +00:00
}
2020-05-15 09:46:26 +00:00
};
2020-05-22 13:11:30 +00:00
EX hrmap* new_map() { return new hrmap_fake; }
2020-05-15 09:46:26 +00:00
EX hrmap* get_umap() { if(!dynamic_cast<hrmap_fake*>(currentmap)) return nullptr; else return ((hrmap_fake*)currentmap)->underlying_map; }
#if HDR
template<class T> auto in_underlying_geometry(const T& f) -> decltype(f()) {
if(!fake::in()) return f();
2021-07-13 00:10:34 +00:00
pcgip = cgip;
2020-05-15 09:46:26 +00:00
dynamicval<eGeometry> g(geometry, underlying);
dynamicval<eGeometry> gag(actual_geometry, geometry);
dynamicval<geometry_information*> gc(cgip, underlying_cgip);
dynamicval<hrmap*> gpm(pmap, currentmap);
dynamicval<hrmap*> gm(currentmap, get_umap());
return f();
}
#define FPIU(x) hr::fake::in_underlying_geometry([&] { return (x); })
#endif
EX hyperpoint befake(hyperpoint h) {
2021-08-05 09:56:12 +00:00
auto h1 = h / h[LDIM] * scale;
h1[LDIM] = 1;
2020-05-15 09:46:26 +00:00
if(material(h1) > 1e-3)
h1 = normalize(h1);
return h1;
}
EX vector<hyperpoint> befake(const vector<hyperpoint>& v) {
vector<hyperpoint> res;
for(auto& h: v) res.push_back(befake(h));
return res;
}
2021-03-25 11:47:52 +00:00
EX vector<vector<hyperpoint>> befake(const vector<vector<hyperpoint>>& v) {
vector<vector<hyperpoint>> res;
for(auto& h: v) res.push_back(befake(h));
return res;
}
2020-05-15 09:46:26 +00:00
EX ld compute_around(bool setup) {
auto &ucgi = *underlying_cgip;
auto fcs = befake(ucgi.heptshape->faces);
2020-05-15 09:46:26 +00:00
if(setup) {
cgi.heptshape->faces = fcs;
cgi.heptshape->compute_hept();
2020-05-15 09:46:26 +00:00
}
hyperpoint h = Hypc;
2021-03-25 11:47:52 +00:00
for(int i=0; i<ucgi.face; i++) h += fcs[0][i];
2020-05-15 09:46:26 +00:00
if(material(h) > 0)
h = normalize(h);
if(setup)
cgi.adjcheck = 2 * hdist0(h);
2020-07-03 13:07:59 +00:00
hyperpoint h2 = rspintox(h) * xpush0(2 * hdist0(h));
auto kh= kleinize(h);
2021-03-25 11:47:52 +00:00
auto k0 = kleinize(fcs[0][0]);
auto k1 = kleinize(fcs[0][1]);
2020-07-03 13:07:59 +00:00
auto vec = k1 - k0;
// u = fcs[0] + vec * z
// (f1-u) | (vec-u) = 0
// (f1 - f0 + vec*z) |
// (vec | h2-vec*z) == (vec | h2) - (vec | vec*z) == 0
2020-05-15 09:46:26 +00:00
2020-07-03 13:07:59 +00:00
auto z = (vec|(kh-k0)) / (vec|vec);
hyperpoint u = k0 + vec * z;
2020-05-15 09:46:26 +00:00
if(material(u) <= 0)
return HUGE_VAL;
u = normalize(u);
h2 = spintox(u) * h2;
u = spintox(u) * u;
h2 = gpushxto0(u) * h2;
u = gpushxto0(u) * u;
2020-05-27 23:50:00 +00:00
2020-05-15 09:46:26 +00:00
ld x = hypot(h2[1], h2[2]);
ld y = h2[0];
2020-07-03 13:07:59 +00:00
ld ans = 360 / (90 + atan(y/x) / degree);
return ans;
2020-05-15 09:46:26 +00:00
}
EX void generate() {
FPIU( cgi.require_basics() );
2020-05-31 15:21:16 +00:00
#if MAXMDIM >= 4
2020-05-15 09:46:26 +00:00
auto &ucgi = *underlying_cgip;
cgi.loop = ucgi.loop;
cgi.face = ucgi.face;
cgi.schmid = ucgi.schmid;
2020-05-15 09:46:26 +00:00
auto& hsh = get_hsh();
hsh = *ucgi.heptshape;
2020-05-15 09:46:26 +00:00
2021-07-13 00:11:24 +00:00
for(int b=0; b<32; b++)
2020-05-15 09:46:26 +00:00
cgi.spins[b] = ucgi.spins[b];
compute_around(true);
hsh.compute_hept();
2021-07-13 00:10:34 +00:00
reg3::compute_ultra();
reg3::generate_subcells();
if(variation == eVariation::coxeter) {
for(int i=0; i<isize(cgi.subshapes); i++) {
auto& s = cgi.subshapes[i];
s.faces_local = ucgi.subshapes[i].faces_local;
for(auto &face: s.faces_local) for(auto& v: face) {
v = kleinize(v);
for(int i=0; i<3; i++) v[i] *= scale;
}
reg3::make_vertices_only(s.vertices_only, s.faces_local);
}
}
2020-05-31 15:21:16 +00:00
#endif
2020-05-15 09:46:26 +00:00
}
int get_middle() {
if(S7 == 20) return 5;
if(S7 == 8) return 4;
return 3;
}
EX ld around;
2020-05-16 00:14:24 +00:00
/** @brief the value of 'around' which makes the tiling Euclidean */
EX ld compute_euclidean() {
2020-10-15 14:33:52 +00:00
#if CAP_ARCM
2020-05-31 14:18:44 +00:00
if(arcm::in()) return arcm::current.N * 2 / arcm::current.euclidean_angle_sum;
2020-10-15 14:33:52 +00:00
#endif
2020-05-31 01:30:14 +00:00
if(WDIM == 2) return 4 / (S7-2.) + 2;
2020-07-03 13:07:59 +00:00
if(underlying == gRhombic3) return 3;
if(underlying == gBitrunc3) return 2.55208;
2020-05-15 09:46:26 +00:00
int middle = get_middle();
2021-07-13 19:31:44 +00:00
if(!fake::in()) underlying_cgip = cgip;
2020-05-31 01:30:14 +00:00
2020-05-16 00:14:24 +00:00
return M_PI / asin(cos(M_PI/middle) / sin(M_PI/underlying_cgip->face));
}
2020-07-03 13:07:59 +00:00
EX ld around_orig() {
2020-10-15 14:33:52 +00:00
#if CAP_ARCM
2020-05-31 14:18:44 +00:00
if(arcm::in())
return arcm::current.N;
2020-10-15 14:33:52 +00:00
#endif
2020-05-31 14:18:44 +00:00
if(WDIM == 2)
return S3;
2020-07-03 13:07:59 +00:00
if(underlying == gRhombic3)
return 3;
if(underlying == gBitrunc3)
return 2.24259;
2020-05-31 14:18:44 +00:00
return
2020-07-03 13:07:59 +00:00
geometry == gFake ? underlying_cgip->loop : cgi.loop;
}
EX geometryinfo1 geometry_of_curvature(ld curvature, int dim) {
if(curvature == 0)
return WDIM == 3 ? giEuclid3 : giEuclid2;
if(curvature < 0)
return WDIM == 3 ? giHyperb3 : giHyperb2;
return WDIM == 3 ? giSphere3 : giSphere2;
2020-05-31 14:18:44 +00:00
}
2020-05-16 00:14:24 +00:00
EX void compute_scale() {
ld good = compute_euclidean();
2020-05-15 09:46:26 +00:00
2020-05-16 00:14:24 +00:00
if(around < 0) around = good;
2020-05-15 09:46:26 +00:00
if(abs(good - around) < 1e-6) good = around;
2020-05-31 01:30:14 +00:00
2020-05-31 14:18:44 +00:00
int s3 = around_orig();
2020-05-15 09:46:26 +00:00
2020-05-16 00:13:10 +00:00
multiple = false;
2020-05-31 01:30:14 +00:00
int mcount = int(around / s3 + .5);
multiple = abs(around - mcount * s3) < 1e-6;
2020-05-15 09:46:26 +00:00
2020-07-03 13:07:59 +00:00
ginf[gFake].g = geometry_of_curvature(good - around, WDIM);
2020-05-15 09:46:26 +00:00
2020-06-03 13:11:20 +00:00
geom3::apply_always3();
2020-05-15 09:46:26 +00:00
ld around_ideal = 1/(1/2. - 1./get_middle());
2020-07-03 13:07:59 +00:00
bool have_ideal = abs(around_ideal - around) < 1e-6;
if(underlying == gRhombic3 || underlying == gBitrunc3) have_ideal = false;
2020-05-31 14:45:06 +00:00
if(arcm::in()) {
ginf[gFake].tiling_name = "(" + ginf[gArchimedean].tiling_name + ")^" + fts(around / around_orig());
return;
}
else if(WDIM == 2) {
2020-05-31 01:30:14 +00:00
ginf[gFake].tiling_name = lalign(0, "{", S7, ",", around, "}");
return;
}
else if(euclid) scale = 1;
2020-07-03 13:07:59 +00:00
else if(have_ideal) {
hyperpoint h0 = underlying_cgip->heptshape->faces[0][0];
2020-05-15 09:46:26 +00:00
auto s = kleinize(h0);
ld d = hypot_d(LDIM, s);
scale = 1/d;
hyperpoint h = h0;
auto h1 = h / h[WDIM] * scale;
h1[WDIM] = 1;
set_flag(ginf[gFake].flags, qIDEAL, true);
set_flag(ginf[gFake].flags, qULTRA, false);
2020-05-15 09:46:26 +00:00
}
else {
set_flag(ginf[gFake].flags, qIDEAL, false);
set_flag(ginf[gFake].flags, qULTRA, around > around_ideal);
2020-05-15 09:46:26 +00:00
ld minscale = 0, maxscale = 10;
for(int it=0; it<100; it++) {
scale = (minscale + maxscale) / 2;
ld ar = compute_around(false);
if(sphere) {
if(ar < around) maxscale = scale;
else minscale = scale;
}
else {
if(ar > around) maxscale = scale;
else minscale = scale;
}
}
2020-07-03 13:07:59 +00:00
/* ultra a bit earlier */
if(underlying == gRhombic3 || underlying == gBitrunc3) {
auto fcs = befake(underlying_cgip->heptshape->faces[0][0]);
2020-07-03 13:07:59 +00:00
set_flag(ginf[gFake].flags, qULTRA, material(fcs) < 0);
}
}
auto& u = underlying_cgip;
ginf[gFake].tiling_name = lalign(0, "{", u->face, ",", get_middle(), ",", around, "}");
2020-05-15 09:46:26 +00:00
}
2020-05-16 00:14:24 +00:00
void set_gfake(ld _around) {
2020-05-15 09:46:26 +00:00
cgi.require_basics();
underlying = geometry;
underlying_cgip = cgip;
ginf[gFake] = ginf[underlying];
2020-05-16 00:14:24 +00:00
geometry = gFake;
2020-05-15 09:46:26 +00:00
around = _around;
compute_scale();
check_cgi();
2020-05-31 14:18:44 +00:00
cgi.require_basics();
2020-05-16 00:14:24 +00:00
if(currentmap) new hrmap_fake(currentmap);
2020-05-15 09:46:26 +00:00
}
EX void change_around() {
2020-05-16 00:14:24 +00:00
if(around >= 0 && around <= 2) return;
2020-05-16 09:16:49 +00:00
ld t = in() ? scale : 1;
hyperpoint h = inverse_exp(shiftless(tC0(View)));
2020-05-16 09:16:49 +00:00
transmatrix T = gpushxto0(tC0(View)) * View;
ld range = sightranges[geometry];
2020-05-16 00:14:24 +00:00
if(!fake::in()) {
2020-07-03 13:07:59 +00:00
underlying = geometry;
2020-05-31 14:18:44 +00:00
if(around == around_orig()) return; /* do nothing */
2020-05-16 00:14:24 +00:00
set_gfake(around);
}
2020-05-16 09:16:49 +00:00
else {
2020-05-15 09:46:26 +00:00
compute_scale();
ray::reset_raycaster();
2020-05-31 01:30:14 +00:00
/* to compute scale */
if(WDIM == 2)
cgi.prepare_basics();
2020-05-15 09:46:26 +00:00
}
2020-05-16 09:16:49 +00:00
t = scale / t;
h *= t;
View = rgpushxto0(direct_exp(h)) * T;
2020-05-28 23:53:20 +00:00
fixmatrix(View);
2020-07-03 13:07:59 +00:00
2020-05-16 09:16:49 +00:00
sightranges[gFake] = range * t;
2020-06-06 16:42:58 +00:00
#if CAP_TEXTURE
2020-06-02 00:25:12 +00:00
texture::config.remap();
2020-06-06 16:42:58 +00:00
#endif
2020-06-03 13:11:20 +00:00
geom3::apply_always3();
2020-05-16 09:16:49 +00:00
}
2020-05-16 00:15:34 +00:00
EX void configure() {
if(!in()) {
underlying_cgip = cgip;
around = around_orig();
2020-05-16 00:15:34 +00:00
}
dialog::editNumber(around, 2.01, 10, 1, around, "fake curvature",
"This feature lets you construct the same tiling, but "
"from shapes of different curvature.\n\n"
"The number you give here is (2D) vertex degree or (3D) "
"the number of cells around an edge.\n\n"
2020-05-16 00:15:34 +00:00
);
if(fake::in())
dialog::reaction = change_around;
else
dialog::reaction_final = change_around;
dialog::extra_options = [] {
ld e = compute_euclidean();
dialog::addSelItem("Euclidean", fts(e), 'E');
dialog::add_action([e] {
around = e;
popScreen();
change_around();
});
dialog::addSelItem("original", fts(around_orig()), 'O');
2020-05-31 15:45:02 +00:00
dialog::add_action([] {
around = around_orig();
popScreen();
change_around();
});
dialog::addSelItem("double original", fts(2 * around_orig()), 'D');
2020-05-31 15:45:02 +00:00
dialog::add_action([] {
around = 2 * around_orig();
popScreen();
change_around();
});
dialog::addBoolItem_action("draw all if multiple of original", multiple_special_draw, 'M');
dialog::addBoolItem_action("draw copies (2D only)", recursive_draw, 'C');
2020-07-03 13:06:33 +00:00
dialog::addBoolItem_choice("unordered", ordered_mode, 0, 'U');
dialog::addBoolItem_choice("pre-ordered", ordered_mode, 1, 'P');
dialog::addBoolItem_choice("post-ordered", ordered_mode, 2, 'Q');
2020-05-16 00:15:34 +00:00
};
}
2020-05-15 09:46:26 +00:00
#if CAP_COMMANDLINE
2020-05-15 09:46:26 +00:00
int readArgs() {
using namespace arg;
if(0) ;
2021-07-13 19:30:17 +00:00
else if(argis("-gfake-euc")) {
start_game();
around = compute_euclidean();
change_around();
}
2020-05-15 09:46:26 +00:00
else if(argis("-gfake")) {
start_game();
2020-05-16 00:14:24 +00:00
shift_arg_formula(around, change_around);
2020-05-15 09:46:26 +00:00
}
2020-07-03 13:06:33 +00:00
else if(argis("-gfake-order")) {
shift(); ordered_mode = argi();
}
2020-05-15 09:46:26 +00:00
else return 1;
return 0;
}
auto fundamentalhook = addHook(hooks_args, 100, readArgs);
#endif
2020-05-15 09:46:26 +00:00
EX }
}