1
0
mirror of https://github.com/zenorogue/hyperrogue.git synced 2024-11-24 05:17:17 +00:00
hyperrogue/conformal.cpp

1299 lines
41 KiB
C++
Raw Normal View History

2016-08-26 09:58:03 +00:00
// Hyperbolic Rogue -- the conformal/history mode
// Copyright (C) 2011-2018 Zeno Rogue, see 'hyper.cpp' for details
2016-08-26 09:58:03 +00:00
namespace hr {
#if ISMOBWEB
typedef double precise;
#else
typedef long double precise;
#endif
2017-07-16 21:00:55 +00:00
2016-08-26 09:58:03 +00:00
namespace polygonal {
typedef long double xld;
typedef complex<xld> cxld;
2016-08-26 09:58:03 +00:00
int SI = 4;
2017-03-23 10:53:57 +00:00
ld STAR = 0;
2016-08-26 09:58:03 +00:00
int deg = ISMOBWEB ? 2 : 20;
2016-08-26 09:58:03 +00:00
precise matrix[MSI][MSI];
precise ans[MSI];
2016-08-26 09:58:03 +00:00
cxld coef[MSI];
2017-07-16 21:00:55 +00:00
ld coefr[MSI], coefi[MSI];
2016-08-26 09:58:03 +00:00
int maxcoef, coefid;
void solve() {
2017-07-16 21:00:55 +00:00
if(pmodel == mdPolynomial) {
for(int i=0; i<MSI; i++) coef[i] = cxld(coefr[i], coefi[i]);
2017-07-16 21:00:55 +00:00
return;
}
if(pmodel != mdPolygonal) return;
if(SI < 3) SI = 3;
2016-08-26 09:58:03 +00:00
for(int i=0; i<MSI; i++) ans[i] = cos(M_PI / SI);
for(int i=0; i<MSI; i++)
for(int j=0; j<MSI; j++) {
precise i0 = (i+0.) / (MSI-1);
2016-08-26 09:58:03 +00:00
// i0 *= i0;
// i0 = 1 - i0;
i0 *= M_PI;
matrix[i][j] =
cos(i0 * (j + 1./SI)) * (STAR > 0 ? (1+STAR) : 1)
- sin(i0 * (j + 1./SI)) * (STAR > 0 ? STAR : STAR/(1+STAR));
}
for(int i=0; i<MSI; i++) {
precise dby = matrix[i][i];
2016-08-26 09:58:03 +00:00
for(int k=0; k<MSI; k++) matrix[i][k] /= dby;
ans[i] /= dby;
for(int j=i+1; j<MSI; j++) {
precise sub = matrix[j][i];
2016-08-26 09:58:03 +00:00
ans[j] -= ans[i] * sub;
for(int k=0; k<MSI; k++)
matrix[j][k] -= sub * matrix[i][k];
}
}
for(int i=MSI-1; i>=0; i--) {
for(int j=0; j<i; j++) {
precise sub = matrix[j][i];
2016-08-26 09:58:03 +00:00
ans[j] -= ans[i] * sub;
for(int k=0; k<MSI; k++)
matrix[j][k] -= sub * matrix[i][k];
}
}
}
pair<ld, ld> compute(ld x, ld y, int prec) {
if(x*x+y*y > 1) {
xld r = hypot(x,y);
x /= r;
y /= r;
}
2017-03-23 10:53:57 +00:00
if(pmodel == mdPolynomial) {
cxld z(x,y);
cxld res (0,0);
2016-08-26 09:58:03 +00:00
for(int i=maxcoef; i>=0; i--) { res += coef[i]; if(i) res *= z; }
return make_pair(real(res), imag(res));
}
cxld z(x, y);
cxld res (0,0);
cxld zp = 1; for(int i=0; i<SI; i++) zp *= z;
2016-08-26 09:58:03 +00:00
for(int i=prec; i>0; i--) {
res += ans[i];
res *= zp;
}
res += ans[0]; res *= z;
return make_pair(real(res), imag(res));
}
pair<ld, ld> compute(ld x, ld y) { return compute(x,y,deg); }
}
2017-07-22 23:33:27 +00:00
#if CAP_SDL
2016-08-26 09:58:03 +00:00
namespace spiral {
typedef long double ld;
typedef complex<long double> cxld;
2016-08-26 09:58:03 +00:00
int shiftx, shifty, velx, vely;
vector<pair<short, short> > quickmap;
int CX, CY, SX, SY, Yshift;
2017-04-08 15:18:29 +00:00
vector<SDL_Surface*> band;
SDL_Surface *out;
2016-08-26 09:58:03 +00:00
bool displayhelp = true;
color_t& bandpixel(int x, int y) {
2017-04-08 15:18:29 +00:00
int i = 0;
2018-06-22 12:47:24 +00:00
while(i < isize(band) && x >= band[i]->w)
2017-04-08 15:18:29 +00:00
x -= band[i]->w, i++;
return qpixel(band[i], x, y);
}
2016-08-26 09:58:03 +00:00
void precompute() {
2017-04-08 15:18:29 +00:00
CX = 0;
2018-06-22 12:47:24 +00:00
for(int i=0; i<isize(band); i++) CX += band[i]->w;
2017-04-08 15:18:29 +00:00
if(CX == 0) { printf("ERROR: no CX\n"); return; }
CY = band[0]->h;
2016-08-26 09:58:03 +00:00
SX = out->w;
SY = out->h;
ld k = -2*M_PI*M_PI / log(2.6180339);
// cxld mnoznik = cxld(0, M_PI) / cxld(k, M_PI);
2016-08-26 09:58:03 +00:00
cxld factor = cxld(0, -CY/2/M_PI/M_PI) * cxld(k, M_PI);
2016-08-26 09:58:03 +00:00
Yshift = CY * k / M_PI;
quickmap.clear();
double xc = ((SX | 1) - 2) / 2.;
double yc = ((SY | 1) - 2) / 2.;
for(int y=0; y<SY; y++)
for(int x=0; x<SX; x++) {
cxld z(x-xc, y-yc);
cxld z1 = log(z);
2016-08-26 09:58:03 +00:00
z1 = z1 * factor;
quickmap.push_back(make_pair(int(real(z1)) % CX, int(imag(z1))));
}
}
void draw() {
int c = 0;
for(int y=0; y<SY; y++) for(int x=0; x<SX; x++) {
pair<short,short> p = quickmap[c++];
int cx = p.first + shiftx;
int cy = p.second + + shifty;
int d = cy / CY;
cy -= d * CY; cx -= d * Yshift;
if(cy<0) cy += CY, cx += Yshift;
cx %= CX; if(cx<0) cx += CX;
2017-04-08 15:18:29 +00:00
qpixel(out, x, y) = bandpixel(cx, cy);
2016-08-26 09:58:03 +00:00
}
}
2017-04-08 15:18:29 +00:00
void loop(vector<SDL_Surface*> _band) {
2016-08-26 09:58:03 +00:00
band = _band;
out = s;
precompute();
2017-04-08 15:18:29 +00:00
if(CX == 0) return;
2016-08-26 09:58:03 +00:00
shiftx = shifty = 0;
velx=1; vely=1;
bool dosave = false;
bool saveGL = vid.usingGL;
if(saveGL) switchGL(); // { vid.usingGL = false; setvideomode(); }
2016-08-26 09:58:03 +00:00
while(true) {
time_t timer;
timer = time(NULL);
char buf[128];
strftime(buf, 128, "spiral-%y%m%d-%H%M%S" IMAGEEXT, localtime(&timer));
SDL_LockSurface(s);
draw();
if(dosave) { dosave = false; IMAGESAVE(s, buf); }
SDL_UnlockSurface(s);
if(displayhelp) {
2017-07-04 13:38:33 +00:00
displaystr(SX/2, vid.fsize*2, 0, vid.fsize, "arrows = navigate, ESC = return, h = hide help", forecolor, 8);
displaystr(SX/2, SY - vid.fsize*2, 0, vid.fsize, XLAT("s = save to " IMAGEEXT, buf), forecolor, 8);
2016-08-26 09:58:03 +00:00
}
SDL_UpdateRect(s, 0, 0, 0, 0);
shiftx += velx; shifty += vely;
SDL_Event event;
while(SDL_PollEvent(&event)) switch (event.type) {
case SDL_VIDEORESIZE: {
resize_screen_to(event.resize.w, event.resize.h);
precompute();
break;
}
2016-08-26 09:58:03 +00:00
case SDL_QUIT: case SDL_MOUSEBUTTONDOWN:
goto breakloop;
case SDL_KEYDOWN: {
int sym = event.key.keysym.sym;
int uni = event.key.keysym.unicode;
numlock_on = event.key.keysym.mod & KMOD_NUM;
if(DKEY == SDLK_RIGHT) velx++;
if(DKEY == SDLK_LEFT) velx--;
if(DKEY == SDLK_UP) vely++;
if(DKEY == SDLK_DOWN) vely--;
if(sym == SDLK_ESCAPE) goto breakloop;
if(uni == 'h') displayhelp = !displayhelp;
if(uni == 's') dosave = true;
2016-08-26 09:58:03 +00:00
}
}
}
breakloop:
quickmap.clear();
if(saveGL) switchGL(); // { vid.usingGL = true; setvideomode(); }
2016-08-26 09:58:03 +00:00
}
}
#endif
bool isbad(ld z) { return !isfinite(z) || fabs(z) > 1e6; }
namespace conformal {
string formula = "z^2";
eModel basic_model;
2017-07-10 18:47:38 +00:00
void handleKeyC(int sym, int uni);
2016-08-26 09:58:03 +00:00
int lastprogress;
2017-07-10 18:47:38 +00:00
void progress_screen() {
gamescreen(0);
mouseovers = "";
}
2016-08-26 09:58:03 +00:00
void progress(string str) {
2017-07-22 23:33:27 +00:00
#if CAP_SDL
2016-08-26 09:58:03 +00:00
int tick = SDL_GetTicks();
if(tick > lastprogress + 250) {
lastprogress = tick;
msgs.clear();
addMessage(str);
drawscreen();
}
#endif
}
bool on;
vector<shmup::monster*> v;
int llv;
double phase;
vector<pair<cell*, eMonster> > killhistory;
vector<pair<cell*, eItem> > findhistory;
vector<cell*> movehistory;
bool includeHistory;
2017-03-23 10:53:57 +00:00
ld lvspeed = 1;
2016-08-26 09:58:03 +00:00
int bandhalf = 200;
int bandsegment = 16000;
2018-03-25 13:07:11 +00:00
ld rotation = 0;
ld rotation_xz = 90;
2018-03-25 13:07:11 +00:00
int do_rotate = 1;
ld model_orientation, halfplane_scale, model_orientation_yz;
2019-03-20 23:25:38 +00:00
ld clip_min, clip_max;
ld ocos, osin, ocos_yz, osin_yz;
ld cos_ball, sin_ball;
bool model_straight, model_straight_yz;
2018-10-23 18:08:57 +00:00
ld top_z = 5;
ld model_transition = 1;
2018-10-23 14:58:19 +00:00
2016-08-26 09:58:03 +00:00
bool autoband = false;
bool autobandhistory = false;
bool dospiral = true;
ld extra_line_steps = 0;
2019-04-03 18:27:45 +00:00
vector<cell*> path_for_lineanimation;
2016-08-26 09:58:03 +00:00
void clear() {
on = false;
2018-06-22 12:47:24 +00:00
int N = isize(v);
2016-08-26 09:58:03 +00:00
for(int i=0; i<N; i++) delete v[i];
v.resize(0);
}
2019-04-03 18:27:45 +00:00
void create(cell *start, cell *target) {
if(target == start) {
2016-08-26 09:58:03 +00:00
addMessage("Must go a distance from the starting point");
return;
}
on = true;
2019-04-03 18:27:45 +00:00
if(!quotient) try {
path_for_lineanimation = build_shortest_path(start, target);
}
catch(hr_shortest_path_exception&) {
addMessage("Error: could not build a path");
return;
}
for(cell *c: path_for_lineanimation) {
2016-08-26 09:58:03 +00:00
shmup::monster *m = new shmup::monster;
m->at = Id;
m->base = c;
v.push_back(m);
}
2018-06-22 12:47:24 +00:00
int Q = isize(v)-1;
// virtualRebase(v[0], false);
// virtualRebase(v[Q], false);
2016-08-26 09:58:03 +00:00
for(int i=0; i<1000; i++) {
progress(XLAT("Preparing the line (%1/1000)...", its(i+1)));
for(int j=1; j<Q; j++) if((j^i)&1) {
// virtualRebase(v[j], false);
2016-08-26 09:58:03 +00:00
hyperpoint prev = calc_relative_matrix(v[j-1]->base, v[j]->base, C0) *
2016-08-26 09:58:03 +00:00
v[j-1]->at * C0;
hyperpoint next = calc_relative_matrix(v[j+1]->base, v[j]->base, C0) *
2016-08-26 09:58:03 +00:00
v[j+1]->at * C0;
hyperpoint hmid = mid(prev, next);
transmatrix at = rgpushxto0(hmid);
2016-08-26 09:58:03 +00:00
v[j]->at = at * rspintox(inverse(at) * next);
2016-08-26 09:58:03 +00:00
fixmatrix(v[j]->at);
}
}
hyperpoint next0 = calc_relative_matrix(v[1]->base, v[0]->base, C0) * v[1]->at * C0;
v[0]->at = v[0]->at * rspintox(inverse(v[0]->at) * next0);
2016-08-26 09:58:03 +00:00
llv = ticks;
phase = 0;
}
2019-04-03 18:27:45 +00:00
void create_playerpath() {
create(currentmap->gamestart(), cwt.at);
}
void create_recenter_to_view() {
create(path_for_lineanimation[0], centerover.at ? centerover.at : cwt.at);
}
2016-08-26 09:58:03 +00:00
void movetophase() {
2016-08-26 09:58:03 +00:00
int ph = int(phase);
2018-06-22 12:47:24 +00:00
int siz = isize(v);
if(ph<0) ph = 0;
if(ph >= siz-1) ph = siz-2;
2016-08-26 09:58:03 +00:00
heptagon *old = viewctr.at;
viewctr.at = v[ph]->base->master;
2016-08-26 09:58:03 +00:00
viewctr.spin = 0;
ld angle = 0;
if(DIM == 3) {
hyperpoint h = spin(-rotation * degree) * cspin(0, 2, rotation_xz * degree) * View * hpxy3(1,2,3);
angle = atan2(h[1], h[2]);
}
View = inverse(master_relative(v[ph]->base) * v[ph]->at);
hyperpoint now = v[ph]->at * C0;
2016-08-26 09:58:03 +00:00
hyperpoint next = calc_relative_matrix(v[ph+1]->base, v[ph]->base, C0) *
v[ph+1]->at * C0;
2016-08-26 09:58:03 +00:00
View = xpush(-(phase-ph) * hdist(now, next)) * View;
if(DIM == 2)
View = spin(rotation * degree) * View;
else {
if(celldistance(v[ph]->base, old->c7) <= 2) {
hyperpoint h1 = View * currentmap->relative_matrix(old, viewctr.at) * hpxy3(1,2,3);
ld angle1 = atan2(h1[1], h1[2]);
View = cspin(2, 1, angle1 - angle) * View;
}
View = cspin(0, 2, -rotation_xz * degree) * spin(rotation * degree) * View;
}
2016-08-26 09:58:03 +00:00
playermoved = false;
centerover.at = v[ph]->base;
compute_graphical_distance();
2016-08-26 09:58:03 +00:00
}
void apply() {
int t = ticks;
phase += (t-llv) * lvspeed / 400.;
llv = t;
2018-06-22 12:47:24 +00:00
int siz = isize(v);
while(phase > siz-1 + extra_line_steps) phase -= (siz + 2 * extra_line_steps-1);
while(phase < - extra_line_steps) phase += (siz + 2 * extra_line_steps-1);
movetophase();
}
2018-11-09 13:15:00 +00:00
2018-11-11 11:39:20 +00:00
ld spiral_angle = 70, spiral_x = 10, spiral_y = 7;
2018-11-10 15:56:08 +00:00
int spiral_id = 7;
bool use_atan = false;
2018-11-10 15:56:08 +00:00
cld spiral_multiplier;
2018-12-21 13:42:59 +00:00
ld right_spiral_multiplier = 1;
2019-04-03 18:30:35 +00:00
ld any_spiral_multiplier = 1;
ld sphere_spiral_multiplier = 2;
2018-12-21 13:42:59 +00:00
ld spiral_cone = 360;
ld spiral_cone_rad;
bool ring_not_spiral;
2018-10-23 14:58:19 +00:00
void configure() {
2018-11-08 17:18:25 +00:00
ld ball = -vid.ballangle * degree;
cos_ball = cos(ball), sin_ball = sin(ball);
2018-11-08 17:18:25 +00:00
ocos = cos(model_orientation * degree);
osin = sin(model_orientation * degree);
ocos_yz = cos(model_orientation_yz * degree);
osin_yz = sin(model_orientation_yz * degree);
2018-10-23 14:58:19 +00:00
model_straight = (ocos > 1 - 1e-9);
model_straight_yz = DIM == 2 || (ocos_yz > 1-1e-9);
2018-10-23 14:58:19 +00:00
if(conformal::on) conformal::apply();
2018-11-09 13:14:36 +00:00
2019-04-03 18:30:35 +00:00
if(!euclid) {
2018-11-10 15:56:08 +00:00
ld b = spiral_angle * degree;
ld cos_spiral = cos(b);
ld sin_spiral = sin(b);
2018-12-21 13:42:59 +00:00
spiral_cone_rad = spiral_cone * degree;
ring_not_spiral = abs(cos_spiral) < 1e-3;
2019-04-03 18:30:35 +00:00
ld mul = 1;
if(sphere) mul = .5 * sphere_spiral_multiplier;
else if(ring_not_spiral) mul = right_spiral_multiplier;
else mul = any_spiral_multiplier * cos_spiral;
spiral_multiplier = cld(cos_spiral, sin_spiral) * cld(spiral_cone_rad * mul / 2., 0);
2018-11-10 15:56:08 +00:00
}
if(euclid) {
hyperpoint h = tC0(eumove(spiral_x, spiral_y));
spiral_multiplier = cld(0, 2 * M_PI) / cld(h[0], h[1]);
}
2018-11-09 13:15:00 +00:00
2019-04-03 18:27:45 +00:00
if(centerover.at && !on)
if(isize(path_for_lineanimation) == 0 || (quotient && path_for_lineanimation.back() != centerover.at)) {
path_for_lineanimation.push_back(centerover.at);
}
2018-11-09 13:14:36 +00:00
band_shift = 0;
2018-10-23 14:58:19 +00:00
}
ld measureLength() {
ld r = bandhalf * vid.scale;
2016-08-26 09:58:03 +00:00
ld tpixels = 0;
2018-06-22 12:47:24 +00:00
int siz = isize(v);
2016-08-26 09:58:03 +00:00
for(int j=0; j<siz-1; j++) {
2016-08-26 09:58:03 +00:00
hyperpoint next =
inverse(v[j]->at) *
calc_relative_matrix(v[j+1]->base, v[j]->base, C0) *
2016-08-26 09:58:03 +00:00
v[j+1]->at * C0;
2017-03-23 10:53:57 +00:00
hyperpoint nextscr;
applymodel(next, nextscr);
tpixels += nextscr[0] * r;
if(j == 0 || j == siz-2)
tpixels += nextscr[0] * r * extra_line_steps;
2016-08-26 09:58:03 +00:00
}
return tpixels;
}
void restore();
void restoreBack();
2017-07-22 23:33:27 +00:00
#if CAP_SDL
2016-08-26 09:58:03 +00:00
void createImage(bool dospiral) {
int segid = 1;
if(includeHistory) restore();
int bandfull = 2*bandhalf;
ld len = measureLength();
2016-08-26 09:58:03 +00:00
time_t timer;
timer = time(NULL);
char timebuf[128];
strftime(timebuf, 128, "%y%m%d-%H%M%S", localtime(&timer));
2017-04-08 15:18:29 +00:00
vector<SDL_Surface*> bands;
resetbuffer rbuf;
2016-08-26 09:58:03 +00:00
if(1) {
// block for RAII
dynamicval<videopar> dv(vid, vid);
dynamicval<ld> dr(rotation, 0);
dynamicval<bool> di(inHighQual, true);
renderbuffer glbuf(bandfull, bandfull, vid.usingGL);
vid.xres = vid.yres = bandfull;
glbuf.enable(); current_display->radius = bandhalf;
calcparam();
current_display->set_viewport(0);
ld xpos = 0;
int seglen = min(int(len), bandsegment);
SDL_Surface *band = SDL_CreateRGBSurface(SDL_SWSURFACE, seglen, bandfull,32,0,0,0,0);
if(!band) {
addMessage("Could not create an image of that size.");
}
else {
2018-06-22 12:47:24 +00:00
int siz = isize(v);
2016-08-26 09:58:03 +00:00
int bonus = ceil(extra_line_steps);
cell *last_base = NULL;
hyperpoint last_relative;
2017-07-10 18:47:38 +00:00
for(int j=-bonus; j<siz+bonus; j++) {
/*
SDL_Surface *buffer = s;
s = sav;
pushScreen(progress_screen);
char buf[128];
sprintf(buf, "#%03d", segid);
progress(s0 + buf + " ("+its(j+bonus)+"/"+its(siz+bonus+bonus-1)+")"); */
// calcparam(); current_display->radius = bandhalf;
phase = j; movetophase();
glbuf.clear(backcolor);
drawfullmap();
if(last_base) {
hyperpoint last = ggmatrix(last_base) * last_relative;
hyperpoint hscr;
applymodel(last, hscr);
ld bwidth = -current_display->radius * hscr[0];
print(hlog, "bwidth = ", bwidth, "/", len);
drawsegment:
SDL_Surface *gr = glbuf.render();
for(int cy=0; cy<bandfull; cy++) for(int cx=0; cx<=bwidth+3; cx++)
qpixel(band, int(xpos+cx), cy) = qpixel(gr, int(bandhalf+cx-bwidth), cy);
if(j == 1-bonus)
xpos = bwidth * (extra_line_steps - bonus);
2016-08-26 09:58:03 +00:00
if(xpos+bwidth > bandsegment) {
char buf[154];
sprintf(buf, "bandmodel-%s-%03d" IMAGEEXT, timebuf, segid++);
2016-08-26 09:58:03 +00:00
IMAGESAVE(band, buf);
if(dospiral)
bands.push_back(band);
else
SDL_FreeSurface(band);
len -= bandsegment; xpos -= bandsegment;
seglen = min(int(len), bandsegment);
band = SDL_CreateRGBSurface(SDL_SWSURFACE, seglen, bandfull,32,0,0,0,0);
goto drawsegment;
}
xpos += bwidth;
}
last_base = viewctr.at->c7;
last_relative = inverse(ggmatrix(last_base)) * C0;
}
}
2017-04-08 15:18:29 +00:00
char buf[154];
sprintf(buf, "bandmodel-%s-%03d" IMAGEEXT, timebuf, segid++);
IMAGESAVE(band, buf);
addMessage(XLAT("Saved the band image as: ") + buf);
if(dospiral)
bands.push_back(band);
else
SDL_FreeSurface(band);
2016-08-26 09:58:03 +00:00
}
rbuf.reset();
current_display->set_viewport(0);
2017-04-08 15:18:29 +00:00
2016-08-26 09:58:03 +00:00
if(includeHistory) restoreBack();
2017-04-08 15:18:29 +00:00
if(dospiral) {
spiral::loop(bands);
2018-06-22 12:47:24 +00:00
for(int i=0; i<isize(bands); i++) SDL_FreeSurface(bands[i]);
2017-04-08 15:18:29 +00:00
}
2016-08-26 09:58:03 +00:00
}
#endif
2018-03-25 12:04:40 +00:00
bool model_available(eModel pm) {
if(sphere && (pm == mdHalfplane || pm == mdBall))
return false;
if(DIM == 2 && pm == mdPerspective) return false;
2019-03-30 16:45:56 +00:00
if(DIM == 2 && pm == mdEquivolume) return false;
if(DIM == 3 && among(pm, mdBall, mdHyperboloid, mdFormula, mdPolygonal, mdRotatedHyperboles, mdSpiral, mdHemisphere)) return false;
return true;
2018-03-25 12:04:40 +00:00
}
2018-10-23 14:58:19 +00:00
bool model_has_orientation() {
return
2018-11-09 13:15:00 +00:00
among(pmodel, mdHalfplane, mdPolynomial, mdPolygonal, mdTwoPoint, mdJoukowsky, mdJoukowskyInverted, mdSpiral) || mdBandAny();
2018-10-23 14:58:19 +00:00
}
bool model_has_transition() {
2019-03-20 01:12:37 +00:00
return among(pmodel, mdJoukowsky, mdJoukowskyInverted, mdBand) && DIM == 2;
}
int editpos = 0;
2018-11-09 13:13:01 +00:00
string get_model_name(eModel m) {
2019-03-20 01:12:37 +00:00
if(m == mdDisk && DIM == 3 && hyperbolic) return XLAT("ball model/Gans");
if(m == mdDisk && DIM == 3) return XLAT("perspective in 4D");
if(m == mdHalfplane && DIM == 3 && hyperbolic) return XLAT("half-space");
2018-11-09 13:13:01 +00:00
if(sphere)
2019-03-20 01:12:37 +00:00
return XLAT(models[m].name_spherical);
2018-11-09 13:13:01 +00:00
if(euclid)
2019-03-20 01:12:37 +00:00
return XLAT(models[m].name_euclidean);
2018-11-09 13:13:01 +00:00
if(hyperbolic)
2019-03-20 01:12:37 +00:00
return XLAT(models[m].name_hyperbolic);
2018-11-09 13:13:01 +00:00
return "?";
}
2018-11-10 15:56:08 +00:00
vector<pair<int, int> > torus_zeros;
void match_torus_period() {
2018-11-10 15:56:08 +00:00
torus_zeros.clear();
for(int y=0; y<=200; y++)
for(int x=-200; x<=200; x++) {
if(y == 0 && x <= 0) continue;
auto zero = vec_to_cellwalker(euclid_getvec(x, y));
if(zero.at == currentmap->gamestart() && !zero.mirrored)
torus_zeros.emplace_back(x, y);
}
sort(torus_zeros.begin(), torus_zeros.end(), [] (const pair<int,int> p1, const pair<int, int> p2) {
ld d1 = hdist0(tC0(eumove(p1.first, p1.second)));
ld d2 = hdist0(tC0(eumove(p2.first, p2.second)));
if(d1 < d2 - 1e-6) return true;
if(d1 > d2 + 1e-6) return false;
return p1 < p2;
});
if(spiral_id > isize(torus_zeros)) spiral_id = 0;
dialog::editNumber(spiral_id, 0, isize(torus_zeros)-1, 1, 10, XLAT("match the period of the torus"), "");
dialog::reaction = [] () {
tie(spiral_x, spiral_y) = torus_zeros[spiral_id];
};
dialog::bound_low(0);
dialog::bound_up(isize(torus_zeros)-1);
}
void edit_formula() {
if(pmodel != mdFormula) basic_model = pmodel;
dialog::edit_string(formula, "formula",
XLAT(
"This lets you specify the projection as a formula f. "
2018-11-11 11:48:08 +00:00
"The formula has access to the value 'z', which is a complex number corresponding to the (x,y) coordinates in the currently selected model; "
"the point z is mapped to f(z). You can also use the underlying coordinates ux, uy, uz."
) + "\n\n" + parser_help()
);
2019-02-21 17:46:53 +00:00
#if CAP_QUEUE && CAP_CURVE
dialog::extra_options = [] () {
initquickqueue();
queuereset(mdUnchanged, PPR::LINE);
for(int a=-1; a<=1; a++) {
2019-02-21 17:46:53 +00:00
curvepoint(point2(-M_PI/2 * current_display->radius, a*current_display->radius));
curvepoint(point2(+M_PI/2 * current_display->radius, a*current_display->radius));
queuecurve(forecolor, 0, PPR::LINE);
2019-02-21 17:46:53 +00:00
curvepoint(point2(a*current_display->radius, -M_PI/2*current_display->radius));
curvepoint(point2(a*current_display->radius, +M_PI/2*current_display->radius));
queuecurve(forecolor, 0, PPR::LINE);
}
queuereset(pmodel, PPR::LINE);
quickqueue();
};
2019-02-17 17:41:40 +00:00
#endif
dialog::reaction_final = [] () {
pmodel = mdFormula;
};
}
2018-03-25 12:04:40 +00:00
void model_menu() {
2018-03-25 13:07:11 +00:00
cmode = sm::SIDE | sm::MAYDARK | sm::CENTER;
2017-07-12 17:50:39 +00:00
gamescreen(0);
2019-03-30 22:46:46 +00:00
dialog::init(XLAT("models & projections"));
2018-03-25 12:04:40 +00:00
for(int i=0; i<mdGUARD; i++) {
eModel m = eModel(i);
2019-02-08 15:52:44 +00:00
if(m == mdFormula && ISMOBILE) continue;
if(model_available(m)) {
dialog::addBoolItem(get_model_name(m), pmodel == m, "0123456789!@#$%^&*()]" [m]);
dialog::add_action([m] () {
if(m == mdFormula) {
edit_formula();
return;
}
pmodel = m;
polygonal::solve();
vid.alpha = 1; vid.scale = 1;
if(pmodel == mdBand && sphere)
vid.scale = .3;
if(pmodel == mdDisk && sphere)
vid.scale = .4;
});
}
2018-03-25 12:04:40 +00:00
}
2017-07-12 17:50:39 +00:00
2018-03-25 12:04:40 +00:00
dialog::addBreak(100);
2018-03-25 13:07:11 +00:00
dialog::addBoolItem(XLAT("rotation"), do_rotate == 2, 'r');
if(do_rotate == 0) dialog::lastItem().value = XLAT("NEVER");
dialog::lastItem().value += " " + its(rotation) + "°";
if(DIM == 3) {
dialog::addBoolItem(XLAT("rotation (x/z plane)"), do_rotate == 2, 'k');
if(do_rotate == 0) dialog::lastItem().value = XLAT("NEVER");
dialog::lastItem().value += " " + its(rotation_xz) + "°";
}
2018-03-25 13:07:11 +00:00
2018-03-25 12:04:40 +00:00
// if(pmodel == mdBand && sphere)
if(pmodel != mdPerspective)
dialog::addSelItem(XLAT("scale factor"), fts(vid.scale), 'z');
2018-03-25 12:04:40 +00:00
if(abs(vid.alpha-1) > 1e-3 && pmodel != mdBall && pmodel != mdHyperboloid && pmodel != mdHemisphere && pmodel != mdDisk) {
dialog::addBreak(50);
dialog::addInfo("NOTE: this works 'correctly' only if the Poincaré model/stereographic projection is used.");
dialog::addBreak(50);
2018-03-25 12:04:40 +00:00
}
2018-12-24 00:19:52 +00:00
if(among(pmodel, mdDisk, mdBall, mdHyperboloid, mdRotatedHyperboles)) {
2019-03-20 01:12:37 +00:00
dialog::addSelItem(XLAT("projection distance"),
fts3(vid.alpha) + " (" + current_proj_name() + ")", 'p');
2018-03-25 12:04:40 +00:00
}
2018-10-23 14:58:19 +00:00
if(model_has_orientation()) {
dialog::addSelItem(XLAT("model orientation"), fts(model_orientation) + "°", 'l');
dialog::add_action([] () {
dialog::editNumber(model_orientation, 0, 360, 90, 0, XLAT("model orientation"), "");
});
if(DIM == 3) {
dialog::addSelItem(XLAT("model orientation (y/z plane)"), fts(model_orientation_yz) + "°", 'L');
dialog::add_action([] () {
dialog::editNumber(model_orientation_yz, 0, 360, 90, 0, XLAT("model orientation (y/z plane)"), "");
});
}
}
2019-03-20 23:25:38 +00:00
if(DIM == 3 && pmodel != mdPerspective) {
const string cliphelp = XLAT(
"Your view of the 3D model is naturally bounded from four directions by your window. "
"Here, you can also set up similar bounds in the Z direction. Radius of the ball/band "
"models, and the distance from the center to the plane in the halfspace model, are 1.\n\n");
dialog::addSelItem(XLAT("near clipping plane"), fts(clip_max), 'c');
dialog::add_action([cliphelp] () {
dialog::editNumber(clip_max, -10, 10, 0.2, 1, XLAT("near clipping plane"),
cliphelp + XLAT("Objects with Z coordinate "
"bigger than this parameter are not shown. This is useful with the models which "
"extend infinitely in the Z direction, or if you want things close to your character "
"to be not obscured by things closer to the camera."));
});
dialog::addSelItem(XLAT("far clipping plane"), fts(clip_min), 'C');
dialog::add_action([cliphelp] () {
dialog::editNumber(clip_min, -10, 10, 0.2, -1, XLAT("far clipping plane"),
2019-03-20 23:25:38 +00:00
cliphelp + XLAT("Objects with Z coordinate "
"smaller than this parameter are not shown; it also affects the fog effect"
" (near clipping plane = 0% fog, far clipping plane = 100% fog)."));
});
}
if(pmodel == mdPolynomial) {
2017-03-23 10:53:57 +00:00
dialog::addSelItem(XLAT("coefficient"),
2017-07-16 21:00:55 +00:00
fts4(polygonal::coefr[polygonal::coefid]), 'x');
dialog::add_action([] () {
polygonal::maxcoef = max(polygonal::maxcoef, polygonal::coefid);
int ci = polygonal::coefid + 1;
dialog::editNumber(polygonal::coefr[polygonal::coefid], -10, 10, .01/ci/ci, 0, XLAT("coefficient"), "");
});
2017-03-23 10:53:57 +00:00
dialog::addSelItem(XLAT("coefficient (imaginary)"),
2017-07-16 21:00:55 +00:00
fts4(polygonal::coefi[polygonal::coefid]), 'y');
dialog::add_action([] () {
polygonal::maxcoef = max(polygonal::maxcoef, polygonal::coefid);
int ci = polygonal::coefid + 1;
dialog::editNumber(polygonal::coefi[polygonal::coefid], -10, 10, .01/ci/ci, 0, XLAT("coefficient (imaginary)"), "");
});
2017-03-23 10:53:57 +00:00
dialog::addSelItem(XLAT("which coefficient"), its(polygonal::coefid), 'n');
dialog::add_action([] () {
dialog::editNumber(polygonal::coefid, 0, polygonal::MSI-1, 1, 0, XLAT("which coefficient"), "");
dialog::bound_low(0); dialog::bound_up(polygonal::MSI-1);
});
2016-08-26 09:58:03 +00:00
}
2018-10-23 14:58:19 +00:00
if(pmodel == mdHalfplane) {
dialog::addSelItem(XLAT("half-plane scale"), fts(halfplane_scale), 'b');
dialog::add_action([] () {
dialog::editNumber(halfplane_scale, 0, 2, 0.25, 1, XLAT("half-plane scale"), "");
});
2018-10-23 14:58:19 +00:00
}
2018-03-25 13:27:42 +00:00
if(pmodel == mdRotatedHyperboles) {
dialog::addBoolItem(XLAT("use atan to make it finite"), use_atan, 'x');
dialog::add_action([] () { use_atan = !use_atan; });
}
if(pmodel == mdBall) {
2018-03-25 12:04:40 +00:00
dialog::addSelItem(XLAT("projection in ball model"), fts3(vid.ballproj), 'x');
dialog::add_action([] () {
dialog::editNumber(vid.ballproj, 0, 100, .1, 0, XLAT("projection in ball model"),
"This parameter affects the ball model the same way as the projection parameter affects the disk model.");
});
}
2018-03-25 12:04:40 +00:00
if(pmodel == mdPolygonal) {
2017-03-23 10:53:57 +00:00
dialog::addSelItem(XLAT("polygon sides"), its(polygonal::SI), 'x');
dialog::add_action([] () {
dialog::editNumber(polygonal::SI, 3, 10, 1, 4, XLAT("polygon sides"), "");
dialog::reaction = polygonal::solve;
});
2017-03-23 10:53:57 +00:00
dialog::addSelItem(XLAT("star factor"), fts(polygonal::STAR), 'y');
dialog::add_action([]() {
dialog::editNumber(polygonal::STAR, -1, 1, .1, 0, XLAT("star factor"), "");
dialog::reaction = polygonal::solve;
});
2017-03-23 10:53:57 +00:00
dialog::addSelItem(XLAT("degree of the approximation"), its(polygonal::deg), 'n');
dialog::add_action([](){
dialog::editNumber(polygonal::deg, 2, polygonal::MSI-1, 1, 2, XLAT("degree of the approximation"), "");
dialog::reaction = polygonal::solve;
dialog::bound_low(0); dialog::bound_up(polygonal::MSI-1);
});
2016-08-26 09:58:03 +00:00
}
2018-12-21 13:42:59 +00:00
if(pmodel == mdBall || pmodel == mdHyperboloid || pmodel == mdHemisphere || (pmodel == mdSpiral && spiral_cone != 360)) {
dialog::addSelItem(XLAT("camera rotation in 3D models"), fts3(vid.ballangle) + "°", 'b');
dialog::add_action(config_camera_rotation);
}
if(pmodel == mdHyperboloid) {
dialog::addSelItem(XLAT("maximum z coordinate to show"), fts3(top_z), 'l');
dialog::add_action([](){
dialog::editNumber(top_z, 1, 20, 0.25, 4, XLAT("maximum z coordinate to show"), "");
});
}
2018-10-23 18:08:57 +00:00
if(model_has_transition()) {
dialog::addSelItem(XLAT("model transition"), fts3(model_transition), 't');
dialog::add_action([]() {
dialog::editNumber(model_transition, 0, 1, 0.1, 1, XLAT("model transition"),
"You can change this parameter for a transition from another model to this one."
);
});
}
2018-11-06 14:54:55 +00:00
2019-03-20 01:13:17 +00:00
if(among(pmodel, mdJoukowsky, mdJoukowskyInverted, mdSpiral) && DIM == 2) {
dialog::addSelItem(XLAT("Möbius transformations"), fts3(vid.skiprope) + "°", 'S');
dialog::add_action([](){
dialog::editNumber(vid.skiprope, 0, 360, 15, 0, XLAT("Möbius transformations"), "");
});
}
2018-03-26 17:06:47 +00:00
if(pmodel == mdHemisphere && euclid) {
2018-03-25 12:04:40 +00:00
dialog::addSelItem(XLAT("parameter"), fts3(vid.euclid_to_sphere), 'l');
dialog::add_action([] () {
dialog::editNumber(vid.euclid_to_sphere, 0, 10, .1, 1, XLAT("parameter"),
"Stereographic projection to a sphere. Choose the radius of the sphere."
);
dialog::scaleLog();
});
}
2018-03-26 17:06:47 +00:00
if(pmodel == mdTwoPoint) {
2018-10-23 14:58:19 +00:00
dialog::addSelItem(XLAT("parameter"), fts3(vid.twopoint_param), 'b');
dialog::add_action([](){
dialog::editNumber(vid.twopoint_param, 0, 10, .1, 1, XLAT("parameter"),
"This model maps the world so that the distances from two points "
"are kept. This parameter gives the distance from the two points to "
"the center."
);
dialog::scaleLog();
});
2018-03-26 17:06:47 +00:00
}
2018-11-10 15:56:08 +00:00
2019-04-03 18:30:35 +00:00
if(pmodel == mdSpiral && !euclid) {
dialog::addSelItem(XLAT("spiral angle"), fts(spiral_angle) + "°", 'x');
2018-11-10 15:56:08 +00:00
dialog::add_action([](){
dialog::editNumber(spiral_angle, 0, 360, 15, 0, XLAT("spiral angle"),
2019-04-03 18:50:39 +00:00
XLAT("set to 90° for the ring projection")
);
2018-11-10 15:56:08 +00:00
});
2018-12-21 13:42:59 +00:00
2019-04-03 18:30:35 +00:00
ld& which =
sphere ? sphere_spiral_multiplier :
ring_not_spiral ? right_spiral_multiplier :
any_spiral_multiplier;
dialog::addSelItem(XLAT("spiral multiplier"), fts(which) + "°", 'M');
2019-04-03 18:30:35 +00:00
dialog::add_action([&which](){
dialog::editNumber(which, 0, 10, -.1, 1, XLAT("spiral multiplier"),
XLAT(
"This parameter has a bit different scale depending on the settings:\n"
"(1) in spherical geometry (with spiral angle=90°, 1 produces a stereographic projection)\n"
2019-04-03 18:30:35 +00:00
"(2) in hyperbolic geometry, with spiral angle being +90° or -90°\n"
"(3) in hyperbolic geometry, with other spiral angles (1 makes the bands fit exactly)"
)
);
});
2018-12-21 13:42:59 +00:00
dialog::addSelItem(XLAT("spiral cone"), fts(spiral_cone) + "°", 'C');
2018-12-21 13:42:59 +00:00
dialog::add_action([](){
dialog::editNumber(spiral_cone, 0, 360, -45, 360, XLAT("spiral cone"), "");
});
2018-11-10 15:56:08 +00:00
}
if(pmodel == mdSpiral && euclid) {
dialog::addSelItem(XLAT("spiral period: x"), fts(spiral_x), 'x');
dialog::add_action([](){
dialog::editNumber(spiral_x, -20, 20, 1, 10, XLAT("spiral period: x"), "");
});
dialog::addSelItem(XLAT("spiral period: y"), fts(spiral_y), 'y');
2018-11-10 15:56:08 +00:00
dialog::add_action([](){
dialog::editNumber(spiral_y, -20, 20, 1, 10, XLAT("spiral period: y"), "");
});
if(euwrap) {
dialog::addSelItem(XLAT("match the period"), its(spiral_id), 'n');
2018-11-10 15:56:08 +00:00
dialog::add_action(match_torus_period);
}
}
dialog::addSelItem(XLAT("vertical stretch"), fts3(vid.stretch), 's');
2018-11-01 17:59:25 +00:00
dialog::addBoolItem(XLAT("use GPU to compute projections"), vid.consider_shader_projection, 'G');
if(vid.consider_shader_projection && !shaderside_projection)
dialog::lastItem().value = XLAT("N/A");
if(vid.consider_shader_projection && shaderside_projection && pmodel)
dialog::lastItem().value += XLAT(" (2D only)");
dialog::add_action([] { vid.consider_shader_projection = !vid.consider_shader_projection; });
2018-11-01 17:59:25 +00:00
menuitem_sightrange('R');
2018-03-26 17:06:47 +00:00
2018-03-25 12:04:40 +00:00
dialog::addBreak(100);
dialog::addItem(XLAT("history mode"), 'a');
2018-05-07 18:09:58 +00:00
#if CAP_RUG
2018-03-25 12:04:40 +00:00
dialog::addItem(XLAT("hypersian rug mode"), 'u');
2018-05-07 18:09:58 +00:00
#endif
dialog::addBack();
2018-11-01 18:01:23 +00:00
2018-03-25 12:04:40 +00:00
dialog::display();
2018-11-01 18:01:23 +00:00
mouseovers = XLAT("see http://www.roguetemple.com/z/hyper/models.php");
2018-03-25 12:04:40 +00:00
keyhandler = [] (int sym, int uni) {
dialog::handleNavigation(sym, uni);
if(uni == 'z')
2018-03-25 12:04:40 +00:00
editScale();
else if(uni == 'p')
projectionDialog();
2018-05-07 18:09:58 +00:00
#if CAP_RUG
2018-03-25 12:04:40 +00:00
else if(uni == 'u')
pushScreen(rug::show);
2018-05-07 18:09:58 +00:00
#endif
else if(uni == 's') {
dialog::editNumber(vid.stretch, 0, 10, .1, 1, XLAT("vertical stretch"),
"Vertical stretch factor."
);
dialog::extra_options = [] () {
dialog::addBreak(100);
if(sphere && pmodel == mdBandEquiarea) {
dialog::addBoolItem("Gall-Peters", vid.stretch == 2, 'O');
dialog::add_action([] { vid.stretch = 2; dialog::ne.s = "2"; });
}
if(pmodel == mdBandEquiarea) {
// y = K * sin(phi)
// cos(phi) * cos(phi) = 1/K
if(sphere && vid.stretch >= 1) {
ld phi = acos(sqrt(1/vid.stretch));
2018-11-08 17:18:25 +00:00
dialog::addInfo(XLAT("The current value makes the map conformal at the latitude of %1 (%2°).", fts(phi), fts(phi / degree)));
}
else if(hyperbolic && abs(vid.stretch) <= 1 && abs(vid.stretch) >= 1e-9) {
ld phi = acosh(abs(sqrt(1/vid.stretch)));
dialog::addInfo(XLAT("The current value makes the map conformal %1 units from the main line.", fts(phi)));
}
else dialog::addInfo("");
}
};
}
2018-03-25 12:04:40 +00:00
else if(uni == 'a')
pushScreen(history_menu);
else if(uni == 'r' || uni == 'k') {
ld& selected_rotation = uni == 'r' ? rotation : rotation_xz;
if(selected_rotation < 0) selected_rotation = 0;
dialog::editNumber(selected_rotation, 0, 360, 90, 0, XLAT("rotation"),
2018-03-25 13:07:11 +00:00
"This controls the automatic rotation of the world. "
"It affects the line animation in the history mode, and "
"lands which have a special direction. Note that if finding this special direction is a part of the puzzle, "
"it works only in the cheat mode.");
dialog::dialogflags |= sm::CENTER;
dialog::extra_options = [] () {
dialog::addBreak(100);
dialog::addBoolItem("line animation only", conformal::do_rotate == 0, 'N');
dialog::add_action([] () { conformal::do_rotate = 0; });
dialog::addBoolItem("gravity lands", conformal::do_rotate == 1, 'G');
dialog::add_action([] () { conformal::do_rotate = 1; });
dialog::addBoolItem("all directional lands", conformal::do_rotate == 2, 'D');
dialog::add_action([] () { conformal::do_rotate = 2; });
};
2018-03-25 13:07:11 +00:00
}
2018-03-25 12:04:40 +00:00
else if(doexiton(sym, uni)) popScreen();
};
}
bool band_renderable_now() {
return on && (pmodel == mdBand || pmodel == mdBandEquidistant || pmodel == mdBandEquiarea) && !euclid && !sphere;
}
2018-03-25 12:04:40 +00:00
void history_menu() {
cmode = sm::SIDE | sm::MAYDARK;
gamescreen(0);
dialog::init(XLAT("history mode"));
dialog::addBoolItem(XLAT("include history"), (includeHistory), 'i');
// bool notconformal0 = (pmodel >= 5 && pmodel <= 6) && !euclid;
// bool notconformal = notconformal0 || abs(vid.alpha-1) > 1e-3;
dialog::addSelItem(XLAT("projection"), current_proj_name(), 'm');
2018-03-25 12:04:40 +00:00
2019-04-03 18:27:45 +00:00
dialog::addBoolItem(XLAT("animate from start to current player position"), (on), 'e');
dialog::addBoolItem(XLAT("animate from last recenter to current view"), (on), 'E');
2017-03-23 10:53:57 +00:00
if(on) dialog::addSelItem(XLAT("animation speed"), fts(lvspeed), 'a');
2019-04-03 18:27:45 +00:00
else dialog::addBreak(100);
dialog::addSelItem(XLAT("extend the ends"), fts(extra_line_steps), 'p');
2016-08-26 09:58:03 +00:00
2017-07-22 23:33:27 +00:00
#if CAP_SDL
2017-03-23 10:53:57 +00:00
dialog::addBoolItem(XLAT("render bands automatically"), (autoband), 'o');
2016-08-26 09:58:03 +00:00
if(autoband)
2017-03-23 10:53:57 +00:00
dialog::addBoolItem(XLAT("include history when auto-rendering"), (autobandhistory), 'j');
2016-08-26 09:58:03 +00:00
if(band_renderable_now() || autoband) {
2017-03-23 10:53:57 +00:00
dialog::addSelItem(XLAT("band width"), "2*"+its(bandhalf), 'd');
dialog::addSelItem(XLAT("length of a segment"), its(bandsegment), 's');
dialog::addBoolItem(XLAT("spiral on rendering"), (dospiral), 'g');
if(band_renderable_now())
dialog::addItem(XLAT("render now (length: %1)", fts(measureLength())), 'f');
2016-08-26 09:58:03 +00:00
}
#endif
dialog::addBack();
2017-03-23 10:53:57 +00:00
dialog::display();
2018-03-27 12:09:10 +00:00
mouseovers = XLAT("see http://www.roguetemple.com/z/hyper/models.php");
2017-07-10 18:47:38 +00:00
keyhandler = handleKeyC;
2016-08-26 09:58:03 +00:00
}
2017-07-10 18:47:38 +00:00
void handleKeyC(int sym, int uni) {
2017-03-23 10:53:57 +00:00
dialog::handleNavigation(sym, uni);
2016-08-26 09:58:03 +00:00
2019-04-03 18:27:45 +00:00
if(uni == 'e' || uni == 'E') {
2016-08-26 09:58:03 +00:00
if(on) clear();
else {
if(canmove && !cheater) {
addMessage("Enable cheat mode or GAME OVER to use this");
return;
}
if(canmove && cheater) cheater++;
2019-04-03 18:27:45 +00:00
if(uni == 'E') create_recenter_to_view();
else create_playerpath();
2016-08-26 09:58:03 +00:00
}
}
else if(uni == 'o')
autoband = !autoband;
2018-03-25 12:04:40 +00:00
else if(uni == 'm')
pushScreen(model_menu);
else if(uni == 'a')
2017-03-23 10:53:57 +00:00
dialog::editNumber(lvspeed, -5, 5, .1, 1, XLAT("animation speed"), "");
else if(uni == 'd') {
2017-03-23 10:53:57 +00:00
dialog::editNumber(bandhalf, 5, 1000, 5, 200, XLAT("band width"), "");
dialog::bound_low(5);
}
else if(uni == 's') {
2017-03-23 10:53:57 +00:00
dialog::editNumber(bandsegment, 500, 32000, 500, 16000, XLAT("band segment"), "");
dialog::bound_low(500);
}
else if(uni == 'p')
dialog::editNumber(extra_line_steps, 0, 5, 1, 1, XLAT("extend the ends"),
"0 = start at the game start, endat the end position; "
"larger numbers give extra space at the ends."
);
else if(uni == 'g') { dospiral = !dospiral; }
else if(uni == 'i') {
2016-08-26 09:58:03 +00:00
if(canmove && !cheater) {
addMessage("Enable cheat mode or GAME OVER to use this");
return;
}
if(canmove && cheater) cheater++;
includeHistory = !includeHistory;
}
2018-03-25 12:04:40 +00:00
#if CAP_SDL
else if(uni == 'f' && band_renderable_now()) createImage(dospiral);
2018-03-25 12:04:40 +00:00
#endif
else if(uni == 'j') {
2016-08-26 09:58:03 +00:00
autobandhistory = !autobandhistory;
}
2017-07-10 18:47:38 +00:00
else if(doexiton(sym, uni)) popScreen();
2016-08-26 09:58:03 +00:00
}
set<cell*> inmovehistory, inkillhistory, infindhistory;
2016-08-26 09:58:03 +00:00
void restore() {
inmovehistory.clear();
inkillhistory.clear();
infindhistory.clear();
2018-06-22 12:47:24 +00:00
for(int i=0; i<isize(movehistory); i++)
inmovehistory.insert(movehistory[i]);
2018-06-22 12:47:24 +00:00
int sk = isize(killhistory);
2016-08-26 09:58:03 +00:00
for(int i=0; i<sk; i++) {
eMonster m = killhistory[i].second;
killhistory[i].second = killhistory[i].first->monst;
killhistory[i].first->monst = m;
inkillhistory.insert(killhistory[i].first);
2016-08-26 09:58:03 +00:00
}
2018-06-22 12:47:24 +00:00
int si = isize(findhistory);
2016-08-26 09:58:03 +00:00
for(int i=0; i<si; i++) {
eItem m = findhistory[i].second;
findhistory[i].second = findhistory[i].first->item;
findhistory[i].first->item = m;
infindhistory.insert(findhistory[i].first);
2016-08-26 09:58:03 +00:00
}
}
void restoreBack() {
2018-06-22 12:47:24 +00:00
int sk = isize(killhistory);
2016-08-26 09:58:03 +00:00
for(int i=sk-1; i>=0; i--) {
eMonster m = killhistory[i].second;
killhistory[i].second = killhistory[i].first->monst;
killhistory[i].first->monst = m;
}
2018-06-22 12:47:24 +00:00
int si = isize(findhistory);
2016-08-26 09:58:03 +00:00
for(int i=si-1; i>=0; i--) {
eItem m = findhistory[i].second;
findhistory[i].second = findhistory[i].first->item;
findhistory[i].first->item = m;
}
}
void renderAutoband() {
2017-07-22 23:33:27 +00:00
#if CAP_SDL
if(!cwt.at || celldist(cwt.at) <= 7) return;
2016-08-26 09:58:03 +00:00
if(!autoband) return;
2017-03-23 10:53:57 +00:00
eModel spm = pmodel;
2016-08-26 09:58:03 +00:00
bool ih = includeHistory;
includeHistory = autobandhistory;
2017-03-23 10:53:57 +00:00
pmodel = mdBand;
2019-04-03 18:27:45 +00:00
create_playerpath();
2016-08-26 09:58:03 +00:00
createImage(dospiral);
clear();
pmodel = spm;
includeHistory = ih;
#endif
2017-07-10 18:47:38 +00:00
}
2018-12-15 14:17:06 +00:00
#if CAP_COMMANDLINE
int readArgs() {
using namespace arg;
if(0) ;
else if(argis("-els")) {
shift_arg_formula(conformal::extra_line_steps);
}
else if(argis("-stretch")) {
PHASEFROM(2); shift_arg_formula(vid.stretch);
}
else if(argis("-PM")) {
PHASEFROM(2); shift(); pmodel = eModel(argi());
if(pmodel == mdFormula) {
shift(); basic_model = eModel(argi());
shift(); formula = args();
}
}
else if(argis("-ballangle")) {
PHASEFROM(2);
shift_arg_formula(vid.ballangle);
}
else if(argis("-topz")) {
PHASEFROM(2);
shift_arg_formula(conformal::top_z);
}
else if(argis("-hp")) {
PHASEFROM(2);
shift_arg_formula(conformal::halfplane_scale);
}
else if(argis("-mori")) {
PHASEFROM(2);
shift_arg_formula(conformal::model_orientation);
}
else if(argis("-mori2")) {
PHASEFROM(2);
shift_arg_formula(conformal::model_orientation);
shift_arg_formula(conformal::model_orientation_yz);
}
2019-03-20 23:25:38 +00:00
else if(argis("-clip")) {
PHASEFROM(2);
shift_arg_formula(conformal::clip_min);
shift_arg_formula(conformal::clip_max);
}
else if(argis("-mtrans")) {
PHASEFROM(2);
shift_arg_formula(conformal::model_transition);
}
2018-11-09 13:15:00 +00:00
else if(argis("-sang")) {
PHASEFROM(2);
shift_arg_formula(conformal::spiral_angle);
2019-04-03 18:30:35 +00:00
if(sphere)
shift_arg_formula(conformal::sphere_spiral_multiplier);
else if(conformal::spiral_angle == 90)
2018-12-21 13:42:59 +00:00
shift_arg_formula(conformal::right_spiral_multiplier);
2019-04-03 18:30:35 +00:00
}
else if(argis("-ssm")) {
PHASEFROM(2);
shift_arg_formula(conformal::any_spiral_multiplier);
2018-12-21 13:42:59 +00:00
}
else if(argis("-scone")) {
PHASEFROM(2);
shift_arg_formula(conformal::spiral_cone);
2018-11-09 13:15:00 +00:00
}
else if(argis("-sxy")) {
PHASEFROM(2);
shift_arg_formula(conformal::spiral_x);
shift_arg_formula(conformal::spiral_y);
}
2018-11-09 13:15:00 +00:00
else if(argis("-mob")) {
PHASEFROM(2);
shift_arg_formula(vid.skiprope);
2018-11-09 13:15:00 +00:00
}
else if(argis("-zoom")) {
PHASEFROM(2); shift_arg_formula(vid.scale);
}
else if(argis("-alpha")) {
PHASEFROM(2); shift_arg_formula(vid.alpha);
}
else if(argis("-d:model"))
launch_dialog(model_menu);
else if(argis("-d:formula")) {
launch_dialog();
edit_formula();
}
else if(argis("-d:match")) {
launch_dialog(match_torus_period);
edit_formula();
}
else return 1;
return 0;
}
2018-12-15 14:17:06 +00:00
auto hookArg = addHook(hooks_args, 100, readArgs);
#endif
2017-07-10 18:47:38 +00:00
auto hooks = addHook(clearmemory, 0, [] () {
conformal::renderAutoband();
conformal::on = false;
conformal::killhistory.clear();
conformal::findhistory.clear();
conformal::movehistory.clear();
2019-04-03 18:27:45 +00:00
conformal::path_for_lineanimation.clear();
2017-07-10 18:47:38 +00:00
conformal::includeHistory = false;
2018-12-15 14:17:06 +00:00
});
2017-07-10 18:47:38 +00:00
2016-08-26 09:58:03 +00:00
}
}