mirror of
https://github.com/zenorogue/hyperrogue.git
synced 2025-07-04 18:52:51 +00:00
formula pattern: extra parameters available, also shielded some parameters from crashes
This commit is contained in:
parent
4dfa168ce4
commit
e075bc8c6d
@ -748,6 +748,7 @@ EX namespace nilv {
|
|||||||
"return vec4(c*w*cos(alpha), c*w*sin(alpha), w, 1.);"
|
"return vec4(c*w*cos(alpha), c*w*sin(alpha), w, 1.);"
|
||||||
"}";
|
"}";
|
||||||
|
|
||||||
|
#if HDR
|
||||||
struct mvec : array<int, 3> {
|
struct mvec : array<int, 3> {
|
||||||
|
|
||||||
mvec() { }
|
mvec() { }
|
||||||
@ -765,6 +766,7 @@ EX namespace nilv {
|
|||||||
return mvec(a[0] + b[0], a[1] + b[1], a[2] + b[2] + a[0] * b[1]);
|
return mvec(a[0] + b[0], a[1] + b[1], a[2] + b[2] + a[0] * b[1]);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
#endif
|
||||||
|
|
||||||
static const mvec mvec_zero = mvec(0, 0, 0);
|
static const mvec mvec_zero = mvec(0, 0, 0);
|
||||||
|
|
||||||
@ -880,6 +882,8 @@ EX namespace nilv {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
EX mvec get_coord(heptagon *h) { return ((hrmap_nil*)currentmap)->coords[h]; }
|
||||||
|
|
||||||
void set_flags() {
|
void set_flags() {
|
||||||
int coords = 0;
|
int coords = 0;
|
||||||
for(int a=0; a<3; a++) if(nilperiod[a]) coords++;
|
for(int a=0; a<3; a++) if(nilperiod[a]) coords++;
|
||||||
|
84
pattern2.cpp
84
pattern2.cpp
@ -348,7 +348,8 @@ EX int zebra40(cell *c) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
EX int zebra3(cell *c) {
|
EX int zebra3(cell *c) {
|
||||||
if(ctof(c)) return (c->master->zebraval/10)/4;
|
if(masterless) return 0;
|
||||||
|
else if(ctof(c)) return (c->master->zebraval/10)/4;
|
||||||
else if(euclid || sphere || S7>7 || S6>6) return 0;
|
else if(euclid || sphere || S7>7 || S6>6) return 0;
|
||||||
else {
|
else {
|
||||||
int ii[3];
|
int ii[3];
|
||||||
@ -462,7 +463,7 @@ EX int getHemisphere(heptagon *h, int which) {
|
|||||||
};
|
};
|
||||||
return hemitable[which][id];
|
return hemitable[which][id];
|
||||||
}
|
}
|
||||||
else if(S7 == 4) {
|
else if(S7 == 4 && which < 6) {
|
||||||
int hemitable[3][6] = {
|
int hemitable[3][6] = {
|
||||||
{ 2, 2, 2,-1,-1,-1},
|
{ 2, 2, 2,-1,-1,-1},
|
||||||
{ 2,-1, 2, 2,-1,-1},
|
{ 2,-1, 2, 2,-1,-1},
|
||||||
@ -1505,31 +1506,70 @@ EX namespace patterns {
|
|||||||
cld compute_map_function(cell *c, int p, const string& formula) {
|
cld compute_map_function(cell *c, int p, const string& formula) {
|
||||||
exp_parser ep;
|
exp_parser ep;
|
||||||
ep.extra_params["p"] = p;
|
ep.extra_params["p"] = p;
|
||||||
switch(geometry) {
|
|
||||||
#if CAP_CRYSTAL
|
|
||||||
case gCrystal: {
|
|
||||||
crystal::ldcoord co = crystal::get_ldcoord(c);
|
|
||||||
for(int i=0; i<crystal::MAXDIM; i++)
|
|
||||||
ep.extra_params["x"+its(i)] = co[i];
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
|
|
||||||
default: {
|
|
||||||
hyperpoint h = calc_relative_matrix(c, currentmap->gamestart(), C0) * C0;
|
hyperpoint h = calc_relative_matrix(c, currentmap->gamestart(), C0) * C0;
|
||||||
ep.extra_params["x"] = h[0];
|
ep.extra_params["x"] = h[0];
|
||||||
ep.extra_params["y"] = h[1];
|
ep.extra_params["y"] = h[1];
|
||||||
ep.extra_params["z"] = h[2];
|
ep.extra_params["z"] = h[2];
|
||||||
|
ep.extra_params["w"] = h[3];
|
||||||
|
ep.extra_params["z40"] = zebra40(c);
|
||||||
|
ep.extra_params["z3"] = zebra3(c);
|
||||||
|
ep.extra_params["ev"] = emeraldval(c);
|
||||||
|
ep.extra_params["fv50"] = fiftyval(c);
|
||||||
|
ep.extra_params["pa"] = polara50(c);
|
||||||
|
ep.extra_params["pb"] = polarb50(c);
|
||||||
|
ep.extra_params["pd"] = cdist50(c);
|
||||||
|
ep.extra_params["fu"] = fieldpattern::fieldval_uniq(c);
|
||||||
|
ep.extra_params["threecolor"] = pattern_threecolor(c);
|
||||||
|
ep.extra_params["chess"] = chessvalue(c);
|
||||||
|
ep.extra_params["ph"] = pseudohept(c);
|
||||||
|
ep.extra_params["kph"] = kraken_pseudohept(c);
|
||||||
|
if(!masterless) {
|
||||||
|
ep.extra_params["md"] = c->master->distance;
|
||||||
|
ep.extra_params["me"] = c->master->emeraldval;
|
||||||
|
ep.extra_params["mf"] = c->master->fieldval;
|
||||||
|
ep.extra_params["mz"] = c->master->zebraval;
|
||||||
|
}
|
||||||
|
|
||||||
|
if(sphere) {
|
||||||
|
ep.extra_params["h0"] = getHemisphere(c, 0);
|
||||||
|
ep.extra_params["h1"] = getHemisphere(c, 1);
|
||||||
|
ep.extra_params["h2"] = getHemisphere(c, 2);
|
||||||
|
}
|
||||||
if(euclid) {
|
if(euclid) {
|
||||||
int x, y;
|
int x, y;
|
||||||
tie(x,y) = cell_to_pair(c);
|
tie(x,y) = cell_to_pair(c);
|
||||||
ep.extra_params["ex"] = x;
|
ep.extra_params["ex"] = x;
|
||||||
ep.extra_params["ey"] = y;
|
ep.extra_params["ey"] = y;
|
||||||
ep.extra_params["ez"] = -x-y;
|
if(S7 == 6) ep.extra_params["ez"] = -x-y;
|
||||||
}
|
}
|
||||||
break;
|
if(cryst) {
|
||||||
|
crystal::ldcoord co = crystal::get_ldcoord(c);
|
||||||
|
for(int i=0; i<crystal::MAXDIM; i++)
|
||||||
|
ep.extra_params["x"+its(i)] = co[i];
|
||||||
}
|
}
|
||||||
|
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);
|
||||||
}
|
}
|
||||||
|
if(nil) {
|
||||||
|
auto co = nilv::get_coord(c->master);
|
||||||
|
ep.extra_params["nx"] = szgmod(co[0], nilv::nilperiod[0]);
|
||||||
|
ep.extra_params["ny"] = szgmod(co[1], nilv::nilperiod[1]);
|
||||||
|
ep.extra_params["nz"] = szgmod(co[2], nilv::nilperiod[2]);
|
||||||
|
}
|
||||||
|
if(hybri)
|
||||||
|
ep.extra_params["level"] = hybrid::get_where(c).second;
|
||||||
|
|
||||||
|
if(geometry_supports_cdata()) {
|
||||||
|
ep.extra_params["d0"] = getCdata(c, 0);
|
||||||
|
ep.extra_params["d1"] = getCdata(c, 1);
|
||||||
|
ep.extra_params["d2"] = getCdata(c, 2);
|
||||||
|
ep.extra_params["d3"] = getCdata(c, 3);
|
||||||
|
}
|
||||||
|
|
||||||
ep.s = formula;
|
ep.s = formula;
|
||||||
return ep.parse();
|
return ep.parse();
|
||||||
}
|
}
|
||||||
@ -1803,16 +1843,24 @@ EX namespace patterns {
|
|||||||
pushScreen(linepatterns::showMenu);
|
pushScreen(linepatterns::showMenu);
|
||||||
|
|
||||||
else if(uni == 'f') {
|
else if(uni == 'f') {
|
||||||
dialog::edit_string(color_formula, "formula",
|
string s = XLAT(
|
||||||
XLAT(
|
|
||||||
"This lets you specify the color pattern as a function of the cell. "
|
"This lets you specify the color pattern as a function of the cell. "
|
||||||
"Available parameters:\n\n"
|
"Available parameters:\n\n"
|
||||||
"x, y, z (hyperboloid/sphere/plane coordinates in non-crystal geometries)\n"
|
"x, y, z (hyperboloid/sphere/plane coordinates in non-crystal geometries)\n"
|
||||||
"ex, ey, ez (in Euclidean geometries)\n"
|
"ex, ey, ez (in Euclidean geometries)\n"
|
||||||
"x0, x1, x2... (crystal geometry only)\n"
|
"x0, x1, x2... (crystal geometry only)\n"
|
||||||
"0 is black, 1 is white, rgb(1,0,0) is red, ifp(p-2,1,0) is blue (p=1 for red, 2 for green, 3 for blue).")
|
"0 is black, 1 is white, rgb(1,0,0) is red, ifp(p-2,1,0) is blue (p=1 for red, 2 for green, 3 for blue).");
|
||||||
+ "\n\n" + parser_help()
|
|
||||||
|
if(MDIM == 4) s += XLAT(
|
||||||
|
"w (fourth coordinate)\n"
|
||||||
|
"wallif(condition, color)\n"
|
||||||
);
|
);
|
||||||
|
|
||||||
|
s += "see compute_map_function in pattern2.cpp for more\n";
|
||||||
|
|
||||||
|
s += "\n\n" + parser_help();
|
||||||
|
|
||||||
|
dialog::edit_string(color_formula, "formula", s);
|
||||||
dialog::reaction_final = [instant] () {
|
dialog::reaction_final = [instant] () {
|
||||||
if(instant) stop_game();
|
if(instant) stop_game();
|
||||||
whichCanvas = 'f';
|
whichCanvas = 'f';
|
||||||
|
Loading…
x
Reference in New Issue
Block a user