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

added some guards for MAXMDIM >= 4 and CAP_SOLV

This commit is contained in:
Zeno Rogue 2021-03-30 11:27:48 +02:00
parent 1f939920d2
commit 5a73510c4f
22 changed files with 110 additions and 13 deletions

View File

@ -13,20 +13,24 @@
namespace hr {
EX namespace asonov {
#if !CAP_SOLV
#if HDR
int zgmod(int a, int b);
inline bool in() { return false; }
#endif
#endif
EX namespace asonov {
EX int period_xy = 8;
EX int period_z = 8;
#if CAP_SOLV
EX bool in() { return cgflags & qCAT; }
EX hyperpoint tx, ty, tz;
EX transmatrix straighten;
EX int period_xy = 8;
EX int period_z = 8;
#if HDR
struct coord: public array<int,3> {
coord() {}
@ -259,5 +263,7 @@ EX void show_config() {
dialog::display();
}
#endif
}
}

View File

@ -656,6 +656,7 @@ EX namespace bt {
ld z3 = -log(3) / 2;
ld bwhn = vid.binary_width / 2;
ld bwh = vid.binary_width * z2;
ignore(bwh); ignore(bwhn);
ld r2 = sqrt(2);
const ld hs = hororec_scale;
auto &x = h[0], &y = h[1], &z = h[2];
@ -664,12 +665,14 @@ EX namespace bt {
return bt::parabolic(y/2) * xpush(x*z2);
case gTernary:
return bt::parabolic(y/2) * xpush(x*z3);
#if CAP_SOLV
case gSol:
return xpush(bwh*x) * ypush(bwh*y) * zpush(z2*z);
case gSolN: case gNIH:
return xpush(bwhn*x) * ypush(bwhn*y) * zpush(-z*.5);
case gArnoldCat:
return rgpushxto0(asonov::tx*x/2 + asonov::ty*y/2 + asonov::tz*z/2);
#endif
case gNil:
return rgpushxto0(point31(x/2, y/2, z/2));
case gEuclidSquare:

View File

@ -296,7 +296,9 @@ EX void initcells() {
hrmap* res = callhandlers((hrmap*)nullptr, hooks_newmap);
if(res) currentmap = res;
#if CAP_SOLV
else if(asonov::in()) currentmap = asonov::new_map();
#endif
else if(nonisotropic || hybri) currentmap = nisot::new_map();
else if(INVERSE) currentmap = gp::new_inverse();
else if(fake::in()) currentmap = fake::new_map();
@ -1086,11 +1088,13 @@ EX cell *random_in_distance(cell *c, int d) {
EX int bounded_celldistance(cell *c1, cell *c2) {
int limit = 6000;
#if CAP_SOLV
if(asonov::in()) {
c2 = asonov::get_at(asonov::get_coord(c2->master) - asonov::get_coord(c1->master))->c7;
c1 = currentmap->gamestart();
limit = 100000000;
}
#endif
if(saved_distances.count(make_pair(c1,c2)))
return saved_distances[make_pair(c1,c2)];

View File

@ -1160,6 +1160,7 @@ EX void flip_z() {
}
#if CAP_RUG
#if MAXMDIM >= 4
hyperpoint coord_to_flat(ldcoord co, int dim = 3) {
auto& cs = crystal_map()->cs;
hyperpoint res = Hypc;
@ -1169,6 +1170,7 @@ hyperpoint coord_to_flat(ldcoord co, int dim = 3) {
res[b] += crug_rotation[b][a] * co[a] * rug::modelscale;
return res;
}
#endif
EX void switch_z_coordinate() {
auto& cs = crystal_map()->cs;
@ -1234,6 +1236,7 @@ void cut_triangle(const hyperpoint pa, const hyperpoint pb, const hyperpoint pc,
cut_triangle2(pb, pc, pa, hb, hc, ha);
}
#if MAXMDIM >= 4
EX void build_rugdata() {
using namespace rug;
rug::clear_model();
@ -1293,6 +1296,7 @@ EX void build_rugdata() {
println(hlog, "cut ", cut_level, "r ", crug_rotation);
}
#endif
#endif
EX void set_land(cell *c) {
setland(c, specialland);

View File

@ -469,7 +469,9 @@ void addpoly(const shiftmatrix& V, const vector<glvertex> &tab, int ofs, int cnt
if(pmodel == mdPixel) {
for(int i=ofs; i<ofs+cnt; i++) {
hyperpoint h = glhr::gltopoint(tab[i]);
#if MAXMDIM >= 4
h[3] = 1;
#endif
h = V.T * h;
add1(h);
}

View File

@ -735,6 +735,7 @@ EX namespace euc {
return;
}
}
#if MAXMDIM >= 4
if(twisted & 16) {
int period = T0[2][2];
transmatrix RotYZX = Zero;
@ -767,7 +768,9 @@ EX namespace euc {
}
return;
}
#endif
if(WDIM == 3) {
#if MAXMDIM >= 4
auto& coo = x;
while(coo[2] >= T0[2][2]) {
coo[2] -= T0[2][2];
@ -784,6 +787,7 @@ EX namespace euc {
for(int i: {0,1})
if(T0[i][i]) coo[i] = gmod(coo[i], T0[i][i]);
return;
#endif
}
else {
gp::loc coo = to_loc(x);

View File

@ -1428,12 +1428,14 @@ discovery::~discovery() { schedule_destruction(); if(discoverer) discoverer->joi
int hk =
#if CAP_THREAD
#if MAXMDIM >= 4
+ addHook(hooks_on_geometry_change, 100, [] { for(auto& d:discoveries) if(!d.second.is_suspended) d.second.suspend(); })
+ addHook(hooks_final_cleanup, 100, [] {
for(auto& d:discoveries) { d.second.schedule_destruction(); if(d.second.is_suspended) d.second.activate(); }
discoveries.clear();
})
#endif
#endif
#if CAP_COMMANDLINE
+ addHook(hooks_args, 0, [] {
using namespace arg;

View File

@ -594,10 +594,12 @@ EX void select_quotient() {
nilv::prepare_niltorus3(),
pushScreen(nilv::show_niltorus3);
}
#if CAP_SOLV
else if(asonov::in()) {
asonov::prepare_config();
pushScreen(asonov::show_config);
}
#endif
else if(prod)
pushScreen(product::show_config);
else if(rotspace)
@ -668,7 +670,9 @@ EX void menuitem_binary_width(char key) {
#if CAP_TEXTURE
texture::config.remap();
#endif
#if CAP_SOLV
if(asonov::in()) asonov::prepare();
#endif
};
});
}
@ -963,6 +967,7 @@ EX void showEuclideanMenu() {
});
}
#if MAXMDIM >= 4
if(hybri) {
auto r = rots::underlying_scale;
dialog::addSelItem(XLAT("view the underlying geometry"), r > 0 ? fts(r)+"x" : ONOFF(false), '6');
@ -981,6 +986,7 @@ EX void showEuclideanMenu() {
dialog::extra_options = [] () { rots::draw_underlying(true); };
});
}
#endif
if(stretch::applicable()) {
dialog::addSelItem(XLAT("stretched geometry"), fts(stretch::factor), 'S');

View File

@ -704,10 +704,12 @@ void geometry_information::prepare_basics() {
if(hyperbolic && &currfp != &fieldpattern::fp_invalid)
currfp.analyze();
#if CAP_SOLV
if(asonov::in()) {
asonov::prepare();
asonov::prepare_walls();
}
#endif
}
EX transmatrix xspinpush(ld dir, ld dist) {

View File

@ -217,11 +217,15 @@ struct horo_distance {
#endif
void horo_distance::become(hyperpoint h1) {
#if CAP_SOLV
if(sn::in()) {
a = abs(h1[2]);
if(asonov::in()) h1 = asonov::straighten * h1;
b = hypot_d(2, h1);
}
#else
if(0) {}
#endif
#if CAP_BT
else if(bt::in()) {
b = intval(h1, C0);

View File

@ -856,9 +856,9 @@ EX bool drawItemType(eItem it, cell *c, const shiftmatrix& V, color_t icol, int
}
else if(it == itPalace) {
ld h = cgi.human_height;
#if MAXMDIM >= 4
if(GDIM == 3 && WDIM == 2) {
ld h = cgi.human_height;
dynamicval<qfloorinfo> qfi2(qfi, qfi);
shiftmatrix V2 = V * spin(ticks / 1500.);
/* divisors should be higher than in plate renderer */

View File

@ -419,7 +419,9 @@ EX void drawStats() {
bool cornermode = (vid.xres > vid.yres * 85/100 && vid.yres > vid.xres * 85/100);
#if MAXMDIM >= 4
if(geometry == gRotSpace || geometry == gProduct) rots::draw_underlying(!cornermode);
#endif
{

View File

@ -1096,6 +1096,7 @@ EX ld hdist0(const hyperpoint& mh) {
auto d1 = product_decompose(mh);
return hypot(PIU(hdist0(d1.second)), d1.first);
}
#if MAXMDIM >= 4
case gcSL2: {
auto cosh_r = hypot(mh[2], mh[3]);
auto phi = atan2(mh[2], mh[3]);
@ -1105,6 +1106,7 @@ EX ld hdist0(const hyperpoint& mh) {
ld bz = mh[0] * mh[1] / 2;
return hypot(mh[0], mh[1]) + abs(mh[2] - bz);
}
#endif
default:
return hypot_d(GDIM, mh);
}
@ -1415,9 +1417,13 @@ EX hyperpoint tangent_length(hyperpoint dir, ld length) {
/** exponential function: follow the geodesic given by v */
EX hyperpoint direct_exp(hyperpoint v) {
#if CAP_SOLV
if(sn::in()) return nisot::numerical_exp(v);
#endif
#if MAXMDIM >= 4
if(nil) return nilv::formula_exp(v);
if(sl2 || stretch::in()) return stretch::mstretch ? nisot::numerical_exp(v) : rots::formula_exp(v);
#endif
if(prod) return product::direct_exp(v);
ld d = hypot_d(GDIM, v);
if(d > 0) for(int i=0; i<GDIM; i++) v[i] = v[i] * sin_auto(d) / d;
@ -1510,6 +1516,7 @@ EX unsigned bucketer(hyperpoint h) {
return dx;
}
#if MAXMDIM >= 4
/** @brief project the origin to the triangle [h1,h2,h3] */
EX hyperpoint project_on_triangle(hyperpoint h1, hyperpoint h2, hyperpoint h3) {
h1 /= h1[3];
@ -1526,6 +1533,7 @@ EX hyperpoint project_on_triangle(hyperpoint h1, hyperpoint h2, hyperpoint h3) {
result[3] = 1;
return normalize(result);
}
#endif
EX hyperpoint lerp(hyperpoint a0, hyperpoint a1, ld x) {
return a0 + (a1-a0) * x;

View File

@ -243,7 +243,9 @@ void move_y_to_z(hyperpoint& H, pair<ld, ld> coef) {
if(GDIM == 3) {
H[2] = H[1] * coef.second;
H[1] = H[1] * coef.first;
#if MAXMDIM >= 4
H[3] = 1;
#endif
}
}
@ -432,6 +434,7 @@ void vr_disk(hyperpoint& ret, hyperpoint& H) {
}
}
#if MAXMDIM >= 4
/** Compute the three-point projection. Currently only works in isotropic 3D spaces. */
EX void threepoint_projection(const hyperpoint& H, hyperpoint& ret) {
@ -488,6 +491,7 @@ EX void threepoint_projection(const hyperpoint& H, hyperpoint& ret) {
models::apply_orientation(ret[1], ret[0]);
models::apply_orientation_yz(ret[2], ret[1]);
}
#endif
EX void apply_other_model(shiftpoint H_orig, hyperpoint& ret, eModel md) {
@ -1036,7 +1040,11 @@ EX void apply_other_model(shiftpoint H_orig, hyperpoint& ret, eModel md) {
break;
case mdThreePoint:
#if MAXMDIM >= 4
threepoint_projection(H, ret);
#else
throw hr_exception();
#endif
break;
case mdMollweide:
@ -2737,6 +2745,7 @@ EX bool do_draw(cell *c, const shiftmatrix& T) {
if(cells_drawn > vid.cells_drawn_limit) return false;
if(cells_drawn < 50) { limited_generation(c); return true; }
#if MAXMDIM >= 4
if(nil && pmodel == mdGeodesic) {
ld dist = hypot_d(3, inverse_exp(tC0(T), pQUICK));
if(dist > sightranges[geometry] + (vid.sloppy_3d ? 0 : 0.9)) return false;
@ -2757,6 +2766,7 @@ EX bool do_draw(cell *c, const shiftmatrix& T) {
if(abs(T.shift * stretch::not_squared()) > sightranges[geometry]) return false;
if(!limited_generation(c)) return false;
}
#endif
else if(vid.use_smart_range) {
if(cells_drawn >= 50 && !in_smart_range(T)) return false;
if(!limited_generation(c)) return false;

View File

@ -474,10 +474,12 @@ EX namespace mapstream {
f.write(S7);
f.write(nilv::nilperiod);
}
#if CAP_SOLV
if(geometry == gArnoldCat) {
f.write(asonov::period_xy);
f.write(asonov::period_z);
}
#endif
if(prod) {
f.write(hybrid::csteps);
f.write(product::cspin);
@ -573,11 +575,13 @@ EX namespace mapstream {
f.read(nilv::nilperiod);
nilv::set_flags();
}
#if CAP_SOLV
if(geometry == gArnoldCat && vernum >= 0xA80C) {
f.read(asonov::period_xy);
f.read(asonov::period_z);
asonov::set_flags();
}
#endif
if(geometry == gProduct && vernum >= 0xA80C) {
f.read(hybrid::csteps);
if(vernum >= 0xA80D) f.read(product::cspin);

View File

@ -1031,7 +1031,9 @@ EX namespace hybrid {
});
return T;
}
#if MAXMDIM >= 4
if(rotspace) return rots::ray_iadj(c, i);
#endif
return currentmap->iadj(c, i);
}
@ -1337,6 +1339,7 @@ EX namespace hybrid {
return mscale(get_corner_position(c, i+next), exp(lev));
}
else {
#if MAXMDIM >= 4
ld tf, he, alpha;
in_underlying_geometry([&] {
hyperpoint h1 = get_corner_position(c, i);
@ -1347,6 +1350,9 @@ EX namespace hybrid {
alpha = atan2(hm[1], hm[0]);
});
return spin(alpha) * rots::uxpush(tf) * rots::uypush(next?he:-he) * rots::uzpush(lev) * C0;
#else
throw hr_exception();
#endif
}
}
@ -2043,7 +2049,9 @@ EX namespace slr {
EX }
EX namespace rots {
EX ld underlying_scale = 0;
#if MAXMDIM >= 4
EX transmatrix uxpush(ld x) {
if(sl2) return xpush(x);
return cspin(1, 3, x) * cspin(0, 2, x);
@ -2187,8 +2195,6 @@ EX namespace rots {
return M;
}
EX ld underlying_scale = 0;
EX void draw_underlying(bool cornermode) {
if(underlying_scale <= 0) return;
ld d = hybrid::get_where(centerover).second;
@ -2306,7 +2312,7 @@ EX namespace rots {
}
}
#endif
EX }
/** stretched rotation space (S3 or SLR) */
@ -2820,9 +2826,11 @@ EX namespace nisot {
#if CAP_SOLV
if(sn::in()) return new sn::hrmap_solnih;
#endif
if(nil) return new nilv::hrmap_nil;
if(prod) return new product::hrmap_product;
#if MAXMDIM >= 4
if(nil) return new nilv::hrmap_nil;
if(hybri) return new rots::hrmap_rotation_space;
#endif
return NULL;
}
@ -2911,6 +2919,7 @@ EX namespace nisot {
ginf[gNil].sides = argi();
return 0;
}
#if CAP_SOLV
else if(argis("-catperiod")) {
PHASEFROM(2);
if(sol) stop_game();
@ -2919,6 +2928,7 @@ EX namespace nisot {
asonov::set_flags();
return 0;
}
#endif
else if(argis("-prodperiod")) {
PHASEFROM(2);
if(prod) stop_game();

View File

@ -1662,7 +1662,9 @@ EX namespace patterns {
ep.extra_params["x"] = h[0];
ep.extra_params["y"] = h[1];
ep.extra_params["z"] = h[2];
#if MAXMDIM >= 4
ep.extra_params["w"] = h[3];
#endif
ep.extra_params["z40"] = zebra40(c);
ep.extra_params["z3"] = zebra3(c);
ep.extra_params["ev"] = emeraldval(c);
@ -1701,12 +1703,14 @@ EX namespace patterns {
ep.extra_params["x"+its(i)] = co[i];
}
#endif
#if CAP_SOLV
if(asonov::in()) {
auto co = asonov::get_coord(c->master);
ep.extra_params["ax"] = szgmod(co[0], asonov::period_xy);
ep.extra_params["ay"] = szgmod(co[1], asonov::period_xy);
ep.extra_params["az"] = szgmod(co[2], asonov::period_z);
}
#endif
if(nil) {
auto co = nilv::get_coord(c->master);
ep.extra_params["nx"] = szgmod(co[0], nilv::nilperiod[0]);

View File

@ -301,6 +301,7 @@ void find_track(cell *start, int sign, int len) {
case 4: id = start->master->emeraldval - c1->master->emeraldval; break;
}
}
#if CAP_SOLV
else if(asonov::in() && asonov::period_z) {
auto co = asonov::get_coord(c->master);
ld x = szgmod(co[0], asonov::period_xy);
@ -311,6 +312,7 @@ void find_track(cell *start, int sign, int len) {
}
else if(sn::in())
id = (start->master->distance - c1->master->distance) * sign;
#endif
else
id = trackval(c1);
cellbydist[id].push_back(c1);

View File

@ -20,6 +20,7 @@ EX vector<radarline> radarlines;
EX transmatrix radar_transform;
#if MAXMDIM >= 4
pair<bool, hyperpoint> makeradar(shiftpoint h) {
if(GDIM == 3 && WDIM == 2) h.h = radar_transform * h.h;
@ -93,9 +94,10 @@ void celldrawer::radar_grid() {
if(c->move(t) && (c->move(t) < c || fake::split()))
addradar(V*get_corner_position(c, t%c->type), V*get_corner_position(c, (t+1)%c->type), gridcolor(c, c->move(t)));
}
#endif
EX void draw_radar(bool cornermode) {
#if MAXMDIM >= 4
if(dual::split([] { dual::in_subscreen([] { calcparam(); draw_radar(false); }); })) return;
bool d3 = WDIM == 3;
bool hyp = hyperbolic;
@ -185,6 +187,14 @@ EX void draw_radar(bool cornermode) {
displaychr(int(h[0]), int(h[1]), 0, int(h[2]), r.glyph, r.color);
}
}
#endif
}
#if MAXMDIM < 4
EX void addradar(const shiftmatrix& V, char ch, color_t col, color_t outline) { }
void drawcell_in_radar();
void celldrawer::drawcell_in_radar() {}
void celldrawer::radar_grid() {}
#endif
}

View File

@ -423,6 +423,7 @@ ld clifford_torus::compute_mx() {
return mx;
}
#if MAXMDIM >= 4
EX void buildTorusRug() {
calcparam_rug();
@ -523,6 +524,7 @@ EX void buildTorusRug() {
return;
}
#endif
EX void verify() {
vector<ld> ratios;
@ -554,11 +556,13 @@ EX void buildRug() {
need_mouseh = true;
good_shape = false;
#if MAXMDIM >= 4
if(euclid && bounded) {
good_shape = true;
buildTorusRug();
return;
}
#endif
celllister cl(centerover ? centerover : cwt.at, get_sightrange(), vertex_limit, NULL);
@ -965,7 +969,7 @@ EX void addNewPoints() {
EX void physics() {
#if CAP_CRYSTAL
#if CAP_CRYSTAL && MAXMDIM >= 4
if(in_crystal()) {
crystal::build_rugdata();
return;

View File

@ -307,7 +307,9 @@ EX always_false in;
int j = i%3 ? i-1 : i+2;
int k = j%3 ? j-1 : j+2;
hyperpoint normal = (data[j] - data[i]) ^ (data[k] - data[i]);
#if MAXMDIM >= 4
normal[3] = 0;
#endif
if(sqhypot_d(3, normal) < 1e-6) {
println(hlog, "bug ", tie(data[i], data[j], data[k]));
}

View File

@ -197,8 +197,12 @@ EX namespace yendor {
EX bool exhaustive_distance_appropriate() {
if(euclid && (kite::in() || arcm::in() || arb::in() || quotient)) return true;
#if MAXMDIM >= 4
if(nil && quotient) return true;
#endif
#if CAP_SOLV
if(asonov::in() && asonov::period_xy && asonov::period_xy <= 256) return true;
#endif
if(bounded) return true;