// Hyperbolic Rogue // Copyright (C) 2011-2016 Zeno Rogue, see 'hyper.cpp' for details // Hyperbolic geometry is a good tool to visualize data, // especially trees and scale-free networks. This file // uses HyperRogue to browse such vizualizations. // Since it is not of use for general HyperRogue players, // it is disabled by default -- compile with the ROGUEVIZ flag to enable this. // How to use: // hyper -embed -- visualize a social network // embedded into hyperbolic plane, see: // https://bitbucket.org/HaiZhung/hyperbolic-embedder/overview // (it uses the same format) // hyper -tol -- visualize the tree of life, // based on a XML dump from https://tree.opentreeoflife.org/ // hyper -tess -- visualize a horocyclic tesselation, #include "rogueviz.h" namespace rogueviz { void init(); bool showlabels = false; bool specialmark = false; bool rog3 = false; ld ggamma = .5; string fname; // const char *fname; // const char *cfname; enum eVizkind { kNONE, kAnyGraph, kTree, kSpiral, kSAG, kCollatz, kFullNet, kKohonen }; eVizkind kind; bool on; colorpair parse(const string& s) { colorpair cp; cp.shade = 0; cp.color2 = 0; sscanf(s.c_str(), "%x:%c%x", &cp.color1, &cp.shade, &cp.color2); return cp; } int nh = 0; int hues[256*6]; void buildhue() { unsigned mh = 193; for(unsigned y=0; y<=mh; y++) hues[nh++] = (int) (0xFF + 0x1000000*mh + (unsigned) 0x10000 * y); for(unsigned y=0; y<=mh; y++) hues[nh++] = (int) (0xFF + 0x1010000*mh - 0x1000000 * y); for(unsigned y=0; y<=mh; y++) hues[nh++] = (int) (0xFF + 0x0010000*mh + 0x100 * y); for(unsigned y=0; y<=mh; y++) hues[nh++] = (int) (0xFF + 0x0010100*mh - 0x10000 * y); for(unsigned y=0; y<=mh; y++) hues[nh++] = (int) (0xFF + 0x0000100*mh + 0x1000000 * y); for(unsigned y=0; y<=mh; y++) hues[nh++] = (int) (0xFF + 0x1000100*mh - 0x100 * y); } int perturb(int c) { if(nh == 0) buildhue(); int hueid = 0; for(int t=0; t> (8*u)) & 0xFF; } int if(part[1] == 255 && part[2] == 0) int k = k += rand() % 16; k -= rand() % 16; if(k<0) k=-k; if(k>255) k = 255-(k-255); c &=~ (0xFF << (8*u)); c |= k << (8*u); } */ return c; } colorpair perturb(colorpair cp) { cp.color1 = perturb(cp.color1); cp.color2 = perturb(cp.color2); return cp; } vector vdata; transmatrix cspin(int i, int ch) { return spin(M_PI + (2 * M_PI * (i+1)) / (ch+1)); } map labeler; int getid(const string& s) { if(labeler.count(s)) return labeler[s]; else { int id = vdata.size(); vdata.resize(vdata.size() + 1); vdata[id].name = s; return labeler[s] = id; } } int getnewid(string s) { while(labeler.count(s)) s += "'"; return getid(s); } void addedge0(int i, int j, edgeinfo *ei) { vdata[i].edges.push_back(make_pair(j, ei)); vdata[j].edges.push_back(make_pair(i, ei)); } void createViz(int id, cell *c, transmatrix at) { vertexdata& vd(vdata[id]); vd.m = new shmup::monster; vd.m->pid = id; vd.m->type = moRogueviz; vd.m->base = c; vd.m->at = at; } void notimpl() { printf("Not implemented\n"); exit(1); } hyperpoint where(int i) { auto m = vdata[i].m; if(m->base == currentmap->gamestart()) return tC0(m->at); else { // notimpl(); // actually probably that's a buug return inverse(shmup::ggmatrix(currentmap->gamestart())) * (shmup::ggmatrix(m->base) * tC0(m->at)); } } void addedge(int i, int j, edgeinfo *ei) { hyperpoint hi = where(i); hyperpoint hj = where(j); double d = hdist(hi, hj); if(d >= 4) { // printf("splitting %lf\n", d); hyperpoint h = mid(hi, hj); int id = size(vdata); vdata.resize(id+1); vertexdata& vd(vdata[id]); vd.cp = colorpair(0x400000FF); vd.virt = ei; createViz(id, currentmap->gamestart(), rgpushxto0(h)); addedge(i, id, ei); addedge(id, j, ei); shmup::virtualRebase(vdata[i].m, true); } else addedge0(i, j, ei); } vector edgeinfos; void addedge(int i, int j, double wei, bool subdiv) { edgeinfo *ei = new edgeinfo; edgeinfos.push_back(ei); ei->i = i; ei->j = j; ei->weight = wei; if(subdiv) addedge(i, j, ei); else addedge0(i, j, ei); } void storeall() { for(int i=0; istore(); } int dftcolor = 0x282828FF; namespace spiral { ld mul; transmatrix at(double d) { return spin(log(d) * 2 * M_PI / log(mul)) * xpush(log(d)); } void place(int N, ld _mul) { mul = _mul; init(); kind = kSpiral; vdata.resize(N); for(int i=0; i= 0 && j0 < N) addedge(i, j0, 0, false); } } void color(ld start, ld period, colorpair c) { int N = size(vdata); int maxw = N; while(start >= 0 && start < N) { int i = int(start); vdata[i].cp = c; start += period; maxw--; if(maxw <= 0) break; } } } namespace collatz { double s2, s3, p2, p3; double cshift = -1; void start() { init(); kind = kCollatz; vdata.resize(1); vertexdata& vd = vdata[0]; createViz(0, cwt.c, xpush(cshift)); virtualRebase(vd.m, true); vd.cp = perturb(dftcolor); vd.data = 0; addedge(0, 0, 0, false); vd.name = "1"; storeall(); } } string readLabel_s(FILE *f) { char xlabel[10000]; if(fscanf(f, "%9500s", xlabel) <= 0) return ""; return xlabel; } int readLabel(FILE *f) { string s = readLabel_s(f); if(s == "") return -1; return getid(s); } namespace anygraph { double R, alpha, T; vector > coords; int N; void fixedges() { for(int i=N; idead = true; for(int i=0; iorig = NULL; addedge(e->i, e->j, e); } } void read(string fn, bool subdiv, bool doRebase, bool doStore) { init(); kind = kAnyGraph; fname = fn; FILE *f = fopen((fn + "-coordinates.txt").c_str(), "rt"); if(!f) { printf("Missing file: %s-coordinates.txt\n", fname.c_str()); exit(1); } printf("Reading coordinates...\n"); char buf[100]; int err; err = fscanf(f, "%s%s%s%s%d%lf%lf%lf", buf, buf, buf, buf, &N, &anygraph::R, &anygraph::alpha, &anygraph::T); if(err < 8) { printf("Error: incorrect format of the first line\n"); exit(1); } vdata.reserve(N); while(true) { string s = readLabel_s(f); if(s == "" || s == "#ROGUEVIZ_ENDOFDATA") break; int id = getid(s); vertexdata& vd(vdata[id]); vd.name = s; vd.cp = colorpair(dftcolor); double r, alpha; int err = fscanf(f, "%lf%lf", &r, &alpha); coords.push_back(make_pair(r, alpha)); if(err < 2) { printf("Error: incorrect format of r/alpha\n"); exit(1); } transmatrix h = spin(alpha * 2 * M_PI / 360) * xpush(r); createViz(id, currentmap->gamestart(), h); } fclose(f); f = fopen((fn + "-links.txt").c_str(), "rt"); if(!f) { printf("Missing file: %s-links.txt\n", fname.c_str()); exit(1); } printf("Reading links...\n"); int qlink = 0; while(true) { int i = readLabel(f), j = readLabel(f); if(i == -1 || j == -1) break; addedge(i, j, 0, subdiv); qlink++; } fclose(f); if(doRebase) { printf("Rebasing...\n"); for(int i=0; i children; }; vector tol; void child(int pid, int id) { if(size(tol) <= id) tol.resize(id+1); treevertex& v = tol[id]; v.parent = pid; tol.push_back(v); if(pid >= 0) tol[pid].children.push_back(id); } void readnode(FILE *f, int pid) { string lab = ""; while(true) { int c = fgetc(f); if(c == EOF) { fprintf(stderr, "Ended prematurely\n"); exit(1); } if(c == ',') break; if(c == ')') { int id = getnewid(lab); child(pid, id); return; } lab += c; } int id = getnewid(lab); child(pid, id); while(true) { int c = fgetc(f); // printf("c=%c at %d/%d\n", c, pid, id); if(c == EOF) { fprintf(stderr, "Ended prematurely\n"); exit(1); } if(c == ' ' || c == 10 || c == 13 || c == 9 || c == ',') continue; else if(c == '(') readnode(f, id); else if(c == ')') break; } } int xpos; void spos(int at, int d) { tol[at].spos = xpos++; tol[at].depth = d; for(int i=0; ipid = i; vd.data = lv.parent; createViz(i, cwt.c, h); vd.cp = dftcolor; if(tol[i].parent >= 0) addedge(i, tol[i].parent, 0, true); } for(int i=0; i snakecells; vector snakefirst, snakelast; vector snakenode; vector snakeid; vector lpbak; vector wpbak; bool snake_enabled; void setsnake(cellwalker& cw, int i) { lpbak[i] = cw.c->landparam; wpbak[i] = cw.c->wparam; cw.c->landparam = i; cw.c->wparam = INSNAKE; // cw.c->monst = moWormtail; cw.c->mondir = cw.spin; snakecells[i] = cw.c; } void snakeswitch() { for(int i=0; ilandparam; c->landparam = x; x = wpbak[i]; wpbak[i] = c->wparam; c->wparam = x; } snake_enabled = !snake_enabled; } void enable_snake() { if(!snake_enabled) snakeswitch(); } void disable_snake() { if(snake_enabled) snakeswitch(); } int snakedist(int i, int j) { if(i < insnaketab && j < insnaketab) return sdist[i][j]; if(bounded) return celldistance(snakecells[i], snakecells[j]); int i0 = i, i1 = i, j0 = j, j1 = j; int cost = 0; // intersect while(true) { if(j0 > i1+1) { j0 = snakefirst[j0], j1 = snakelast[j1]; cost++; } else if(i0 > j1+1) { i0 = snakefirst[i0], i1 = snakelast[i1]; cost++; } else if(j1+1 == i0) return cost+1; else if(i1+1 == j0) return cost+1; else return cost; } } void initSnake(int n) { if(bounded) n = size(currentmap->allcells()); numsnake = n; snakecells.resize(numsnake); snakefirst.resize(numsnake); snakelast.resize(numsnake); snakenode.resize(numsnake); lpbak.resize(numsnake); wpbak.resize(numsnake); if(bounded) { for(int i=0; iallcells()[i], 0); setsnake(cw, i); } } else { cellwalker cw = cwt; setsnake(cw, 0); cw += wstep; setsnake(cw, 1); for(int i=2; i<=numsnake; i++) { if(i == numsnake && sphere) break; cw += wstep; snakefirst[i-1] = cw.c->landparam; while(cw.c->wparam == INSNAKE) { snakelast[i-1] = cw.c->landparam; cw = cw + wstep + 1 + wstep; } if(i == numsnake) break; setsnake(cw, i); cw += 1; } } int stab = min(numsnake, MAXSNAKETAB); for(int i=0; iweight2; } /* cell *c = snakecells[id]; for(int i=0; itype; i++) { cell *c2 = c->mov[i]; if(c2 && c2->wparam == INSNAKE && snakenode[c2->landparam] >= 0) cost += 100; } */ return cost; } mt19937 los; bool infullsa; double cost; int N; vector chgs; void forgetedges(int id) { for(int i=0; iorig = NULL; } void saiter() { aiter: int t1 = hrand(N); int sid1 = snakeid[t1]; int sid2; int s = hrand(6); if(s == 3) s = 2; if(s == 4) s = 5; if((sagpar&1) && (s == 2 || s == 3 || s == 4)) return; if(s == 5) sid2 = hrand(numsnake); else { cell *c; if(s>=2 && size(vdata[t1].edges)) c = snakecells[snakeid[hrand(size(vdata[t1].edges))]]; else c = snakecells[sid1]; int it = s<2 ? (s+1) : s-2; for(int ii=0; iitype; c = c->mov[d]; if(!c) goto aiter; if(c->wparam != INSNAKE) goto aiter; } sid2 = c->landparam; } int t2 = snakenode[sid2]; snakenode[sid1] = -1; snakeid[t1] = -1; snakenode[sid2] = -1; if(t2 >= 0) snakeid[t2] = -1; double change = costat(t1,sid2) + costat(t2,sid1) - costat(t1,sid1) - costat(t2,sid2); snakenode[sid1] = t1; snakeid[t1] = sid1; snakenode[sid2] = t2; if(t2 >= 0) snakeid[t2] = sid2; if(change < 0) chgs.push_back(-change); if(change > 0 && (sagmode == sagHC || los() > exp(-change * exp(-temperature)))) return; snakenode[sid1] = t2; snakenode[sid2] = t1; snakeid[t1] = sid2; if(t2 >= 0) snakeid[t2] = sid1; if(vdata[t1].m) vdata[t1].m->base = snakecells[sid2]; if(t2 >= 0 && vdata[t2].m) vdata[t2].m->base = snakecells[sid1]; cost += 2*change; if(t1 >= 0) forgetedges(t1); if(t2 >= 0) forgetedges(t2); } void organize() { for(int i=0; i freenodes; for(int i=0; i= numsnake || err < 1) sid = -1; if(!labeler.count(lab)) { printf("unknown vertex: %s\n", lab.c_str()); } else { int id = getid(lab); snakeid[id] = sid; } } afterload: if(sf) fclose(sf); organize(); for(int i=0; ibase = snakecells[sag::snakeid[i]]; forgetedges(i); } } vector sagedges; /* bool totcmp(int i, int j) { return totwei[i] > totwei[j]; } */ int ipturn = 100; int numiter = 0; int hightemp = 10; int lowtemp = -15; void dofullsa(int satime) { sagmode = sagSA; enable_snake(); int t1 = SDL_GetTicks(); while(true) { int t2 = SDL_GetTicks(); double d = (t2-t1) / (1000. * satime); if(d > 1) break; temperature = hightemp - (d*(hightemp-lowtemp)); chgs.clear(); for(int i=0; i<50000; i++) { numiter++; sag::saiter(); } printf("it %8d temp %6.4" PLDF" [1/e at %13.6" PLDF"] cost = %lf ", numiter, sag::temperature, (ld) exp(sag::temperature), sag::cost); sort(chgs.begin(), chgs.end()); int cc = chgs.size() - 1; printf("%9.4lf .. %9.4lf .. %9.4lf .. %9.4lf .. %9.4lf\n", chgs[0], chgs[cc/4], chgs[cc/2], chgs[cc*3/4], chgs[cc]); fflush(stdout); } temperature = -5; disable_snake(); sagmode = sagOff; } void iterate() { if(!sagmode) return; int t1 = SDL_GetTicks(); enable_snake(); for(int i=0; i 200) ipturn /= 2; else ipturn = ipturn * 100 / t; printf("it %8d temp %6.4" PLDF" [2:%8.6" PLDF",10:%8.6" PLDF",50:%8.6" PLDF"] cost = %lf\n", numiter, sag::temperature, exp(-2 * exp(-sag::temperature)), exp(-10 * exp(-sag::temperature)), exp(-50 * exp(-sag::temperature)), sag::cost); } void savesnake(const string& fname) { FILE *f = fopen(fname.c_str(), "wt"); for(int i=0; i= 0.1; // (ei.weight >= maxwei[ei.i] / 5 || ei.weight >= maxwei[ei.j] / 5); ei.weight2 = pow((double) ei.weight, (double) edgepower) * edgemul; // LANG:: pow(ei.weight, .4) / 50; // ei.weight2 = 0; int w = ei.weight; while(w) { w >>= 1; ei.weight2++; } /* if(totwei[ei.i] <= 0 || totwei[ei.j] <= 0) { printf("BAD TOTWEI\n"); exit(1); } ei.weight2 = 3 * ( sqrt(ei.weight * 1. / totwei[ei.i]) * log(totwei[ei.i]) * log(totwei[ei.i]) + sqrt(ei.weight * 1. / totwei[ei.j]) * log(totwei[ei.j]) * log(totwei[ei.j])); */ // printf("%f\n", ei.weight2); addedge0(ei.i, ei.j, &ei); } initSnake(N*2); printf("numsnake = %d\n", numsnake); if(numsnake < N) { printf("Error: snake does not fit\n"); exit(1); } snakeid.resize(N); for(int i=0; iweight > e2->weight; } #include "kohonen.cpp" void describe(cell *c) { if(kind == kKohonen) return kohonen::describe(c); } string describe(shmup::monster *m) { int i = m->pid; vertexdata& vd = vdata[i]; string o = vd.name+", "+its(size(vd.edges))+" edges"; /* if(size(vd.edges) < 10) { for(int i=0; isnakeid)); } */ vector alledges; for(int j=0; jvisible) continue; int k = ei->i ^ ei->j ^ i; help += vdata[k].name; help += "/" + fts(ei->weight)+":" + fts(ei->weight2) + " "; } return o; } void activate(shmup::monster *m) { int i = m->pid; vertexdata& vd = vdata[i]; vd.cp = colorpair(rand() & 0xFFFFFFFF); for(int i=0; iorig = NULL; /* if(ealpha == 1) ealpha = 8; else if(ealpha == 8) ealpha = 32; else if(ealpha == 32) ealpha = 255; else ealpha = 1; */ } void storevertex(vector& tab, const hyperpoint& h) { tab.push_back(glhr::pointtogl(h)); } double linequality = .1; void storelineto(vector& tab, const hyperpoint& h1, const hyperpoint& h2) { if(intval(h1, h2) < linequality) storevertex(tab, h2); else { hyperpoint h3 = mid(h1, h2); storelineto(tab, h1, h3); storelineto(tab, h3, h2); } } void storeline(vector& tab, const hyperpoint& h1, const hyperpoint& h2) { storevertex(tab, h1); storelineto(tab, h1, h2); } void queuedisk(const transmatrix& V, const colorpair& cp, bool legend) { if(legend && (int) cp.color1 == (int) 0x000000FF && backcolor == 0) poly_outline = 0x606060FF; else poly_outline = 0x000000FF; if(rog3) { int p = poly_outline; poly_outline = OUTLINE_TRANS; queuepolyat(V, shDisk, 0x80, PPR_MONSTER_SHADOW); poly_outline = p; queuepolyat(mscale(V, geom3::BODY), shDisk, cp.color1, PPR_MONSTER_HEAD); } else { queuepoly(V, shDisk, cp.color1); } if(cp.shade == 't') queuepoly(V, shDiskT, cp.color2); if(cp.shade == 's') queuepoly(V, shDiskS, cp.color2); if(cp.shade == 'q') queuepoly(V, shDiskSq, cp.color2); if(cp.shade == 'm') queuepoly(V, shDiskM, cp.color2); } void drawVertex(const transmatrix &V, cell *c, shmup::monster *m) { if(m->dead) return; int i = m->pid; vertexdata& vd = vdata[i]; bool ghilite = false; if(vd.special && specialmark) ghilite = true; if(!gmatrix.count(m->base)) printf("base not in gmatrix\n"); int lid = shmup::lmousetarget ? shmup::lmousetarget->pid : -2; if(!leftclick) for(int j=0; jvisible) continue; vertexdata& vd1 = vdata[ei->i]; vertexdata& vd2 = vdata[ei->j]; int oi = ei->i, oj = ei->j; bool hilite = false; if(vdata[oi].special && vdata[oj].special && specialmark) hilite = true; else if(svg::in || inHighQual) hilite = false; else if(vd1.m == shmup::lmousetarget) hilite = true; else if(vd2.m == shmup::lmousetarget) hilite = true; else if(oi == lid || oj == lid) hilite = true; if(hilite) ghilite = true; if(ei->lastdraw < frameid) { ei->lastdraw = frameid; int xlalpha = (hilite || hiliteclick) ? 64 : 20; if(kind == kSAG) { if(ei->weight2 > maxweight) maxweight = ei->weight2; xlalpha = int(pow(ei->weight2/ maxweight, ggamma) * 255); } else xlalpha = int(pow(ld(.5), ggamma) * 255); if(svg::in && xlalpha < 16) continue; transmatrix& gm1 = shmup::ggmatrix(vd1.m->base); transmatrix& gm2 = shmup::ggmatrix(vd2.m->base); hyperpoint h1 = gm1 * vd1.m->at * C0; hyperpoint h2 = gm2 * vd2.m->at * C0; /* if(hdist0(h1) < .001 || hdist0(h2) < .001) { printf("h1 = %s\n", display(h1)); printf("h2 = %s\n", display(h2)); display(m->at); display(vd2.m->at); display(V); display(gmatrix[vd2.m->base]); display(shmup::calc_gmatrix(vd2.m->base)); } */ int col = ((hilite ? 0xFF0000 : forecolor) << 8) + xlalpha; bool onspiral = kind == kSpiral && abs(ei->i - ei->j) == 1; if(pmodel || onspiral) { if(onspiral) { const int prec = 20; transmatrix T = shmup::ggmatrix(currentmap->gamestart()); hyperpoint l1 = T*tC0(spiral::at(1+ei->i)); for(int z=1; z<=prec; z++) { hyperpoint l2 = T*tC0(spiral::at(1+ei->i+(ei->j-ei->i) * z / (prec+.0))); queueline(l1, l2, col, 0); l1 = l2; lastptd().prio = PPR_STRUCT0; } } else { queueline(h1, h2, col, 2); lastptd().prio = PPR_STRUCT0; } } else { if(ei->orig && ei->orig->cpdist >= 3) ei->orig = NULL; if(!ei->orig) { ei->orig = euclid ? cwt.c : viewctr.h->c7; // cwt.c; ei->prec.clear(); transmatrix T = inverse(shmup::ggmatrix(ei->orig)); if(kind == kSpiral && abs(ei->i - ei->j) == 1) { ei->orig = currentmap->gamestart(); hyperpoint l1 = tC0(spiral::at(1+ei->i)); storevertex(ei->prec, l1); const int prec = 20; for(int z=1; z<=prec; z++) { hyperpoint l2 = tC0(spiral::at(1+ei->i+(ei->j-ei->i) * z / (prec+.0))); storeline(ei->prec, l1, l2); l1 = l2; } } else storeline(ei->prec, T*h1, T*h2); } queuetable(shmup::ggmatrix(ei->orig), ei->prec, size(ei->prec), col, 0, PPR_STRUCT0); } } /* */ } if(!vd.virt) { queuedisk(V * m->at, ghilite ? colorpair(0xFF0000FF) : vd.cp, false); lastptd().info = vd.info; } if(showlabels) { bool doshow = true; if(kind == kTree && i > 0 && !vd.virt) { vertexdata& vdp = vdata[vd.data]; hyperpoint h2 = shmup::ggmatrix(vdp.m->base) * vdp.m->at * C0; if(hdist(h2, V * m->at * C0) < 0.1) doshow = false; } hyperpoint h = tC0(V * m->at); transmatrix V2 = rgpushxto0(h) * ypush(nonbitrunc ? .3 : .2); if(doshow && !behindsphere(V2)) queuestr(V2, (svg::in ? .28 : .2) * crossf / hcrossf, vd.name, backcolor ? 0x000000 : 0xFFFF00, svg::in ? 0 : 1); lastptd().info = vd.info; } if(kind == kCollatz) { if(c->cpdist > 7 && euclid) ; else if(vd.data == 2) { // doubler vertex string s = vd.name; colorpair cp = vd.cp; vd.data = 20; int i0 = size(vdata); vdata.resize(i0+1); vertexdata& vdn = vdata[i0]; createViz(i0, m->base, m->at * spin(collatz::s2) * xpush(collatz::p2)); virtualRebase(vdn.m, true); vdn.cp = perturb(cp); vdn.data = 0; addedge(i, i0, 0, false); vdn.m->store(); int carry = 0; string s2 = s; for(int i=size(s2)-1; i>=0; i--) { int x = 2*(s2[i] - '0') + carry; carry = x>=10; if(carry) x-=10; s2[i] = '0'+x; } if(carry) s2 = "1" + s2; vdn.name = s2; int m3 = 0; for(int i=0; ibase, m->at * spin(collatz::s3) * xpush(collatz::p3)); virtualRebase(vdn.m, true); vdn.cp = perturb(cp); vdn.data = 0; addedge(i, i0+1, 0, false); vdn.m->store(); int carry = -1; string s2 = s; for(int i=size(s2)-1; i>=0; i--) { carry += 2 * (s2[i] - '0'); int ncarry = 0; while(carry % 3) carry += 10, ncarry--; if(carry >= 30) carry -= 30, ncarry += 3; s2[i] = '0'+carry/3; carry = ncarry; } if(s2[0] == '0') s2 = s2.substr(1); vdn.name = s2; vdn.cp = perturb(vdn.cp); } } else if(vd.data < 2) { vd.data++; fixmatrix(vd.m->at); } } } bool virt(shmup::monster *m) { if(m->type != moRogueviz) return false; vertexdata& vd = vdata[m->pid]; return vd.virt; } vector legend; vector named; void drawExtra() { if(kind == kFullNet) { for(map::iterator it = gmatrix.begin(); it != gmatrix.end(); it++) { cell *c = it->first; c->wall = waChasm; } for(map::iterator it = gmatrix.begin(); it != gmatrix.end(); it++) { cell *c = it->first; bool draw = true; for(int i=0; isecond, shDisk, dftcolor, PPR_LINE); } for(int i=0; i 0) vdata[getid(lab)].info = new string(buf); // replace with std::shared_ptr in C++111 continue; } else { ungetc(c2, f); char buf[60]; int err = fscanf(f, "%30s", buf); if(err > 0) x = parse(buf); } if(size(lab) && lab[0] == '*') { lab = lab.substr(1); for(int i=0; i= 0) goto again; } } } } void init() { if(on) return; autocheat = true; showstartmenu = false; #if !ISWEB mapeditor::drawplayer = false; firstland = specialland = laCanvas; if(!shmup::on) restartGame(rg::shmup); else restartGame(); #else firstland = specialland = laCanvas; restartGame(); #endif on = true; items[itOrbLife] = 0; timerghost = false; gmatrix.clear(); calcparam(); drawthemap(); gmatrix0 = gmatrix; addMessage("RogueViz enabled"); } void close() { for(int i=0; idead = true; vdata.clear(); labeler.clear(); legend.clear(); for(int i=0; irebase(); } void fixparam() { if((svg::in || inHighQual) && size(legend) && pngformat == 0) vid.xres = vid.xres * 22/16; if(size(legend)) vid.xcenter = vid.ycenter; } #if CAP_SDL void rvvideo(const string &fname) { if(kind == kCollatz) { pngformat = 2; sightrange_bonus = 3; genrange_bonus = 3; dronemode = true; vid.camera_angle = -45; rog3 = true; patterns::whichShape = '8'; vid.aurastr = 512; long long reached = 763ll; while(reached < (1ll<<60)) { if(reached%3 == 2 && (2*reached-1) % 9 && hrand(100) < 50) reached = (2*reached-1) / 3; else reached *= 2; } printf("reached = %Ld\n", reached); vector seq; while(reached>1) { seq.push_back(llts(reached)); if(reached&1) reached += (reached>>1)+1; else reached >>= 1; } // seq.push_back("1"); reverse(seq.begin(), seq.end()); int id = 0; int next = 0; int steps = 0; while(true) { steps++; if(std::isnan(View[0][0])) exit(1); shmup::turn(100); drawthemap(); centerpc(100); optimizeview(); fixmatrix(View); bfs(); setdist(cwt.c, 7 - getDistLimit() - genrange_bonus, NULL); vertexdata& vd = vdata[id]; for(int e=0; ebase = vdata[id2].m->base; if(next == size(seq)) goto found; } } } found: printf("steps = %d\n", steps); conformal::create(), conformal::rotation = 1; // pmodel = mdBand; #define STORYCOUNT 24 #define T(m,ss) (60*24*(m)+24*(ss)) #define FRAMECOUNT T(4,55) printf("framecount = %d\n", FRAMECOUNT); struct storydata { int s; int e; const char *text; } story[] = { {T(0,14), T(0,17), "I am flying above a tree of numbers."}, {T(0,17), T(0,20), "It starts with the number 1."}, {T(0,20), T(0,23), "Each number n branches left to 2n."}, {T(0,23), T(0,28), "And it branches right to (2n-1)/3 if possible."}, {T(1, 8), T(1,11), "What I am flying above is not a plane."}, {T(1,11), T(1,14), "It is not a sphere either."}, {T(1,14), T(1,17), "To be honest, the space I live in..."}, {T(1,17), T(1,20), "...is not even Euclidean."}, {T(2,12), T(2,15), "Look, angles of a triangle add up to..."}, {T(2,15), T(2,18), "...less than 180 degrees in this world."}, {T(2,18), T(2,21), "6/7 of 180 degrees, to be exact."}, {T(2,21), T(2,24), "Do you see the regular heptagons?"}, {T(2,36), T(2,42), "And all these lines are straight."}, {T(3, 8), T(3,11), "Lots of space in my world."}, {T(3,11), T(3,14), "In 105 steps from the root..."}, {T(3,14), T(3,17), "...there are trillions of numbers."}, {T(3,17), T(3,20), "That would not fit in your world."}, {T(4,0), T(4,3), "Is every positive number somewhere in the tree?"}, {T(4,3), T(4,6), "Your mathematicians do not know this yet."}, {T(4,6), T(4,10), "Will you find the answer?"}, {T(4,44), T(4,54), "music: Ambient Flow, by Indjenuity"}, {T(2,6), T(2,27), "@triangles"}, {T(2,27), T(2,42), "@network"}, {0, T(0,7), "@fi"}, {T(4,48), T(4,55), "@fo"}, {0,0,NULL} }; int drawtris=0, drawnet=0; for(int i=0; i= story[j].s && i <= story[j].e) { if(story[j].text[0] != '@') caption = story[j].text; else if(story[j].text[1] == 't') dt = true; else if(story[j].text[1] == 'n') dn = true; else if(story[j].text[2] == 'i') fade = 255 * (i - story[j].s) / (story[j].e-story[j].s); else if(story[j].text[2] == 'o') fade = 255 * (story[j].e - i) / (story[j].e-story[j].s); } if(dt && drawtris < 255) drawtris++; else if(drawtris && !dt) drawtris--; linepatterns::setColor(linepatterns::patZebraTriangles, 0x40FF4000 + drawtris); if(dn && drawnet < 255) drawnet++; else if(drawnet && !dn) drawnet--; linepatterns::setColor(linepatterns::patZebraLines, 0xFF000000 + drawnet); vid.grid = drawnet; conformal::phase = 1 + (size(conformal::v)-3) * i * .95 / FRAMECOUNT; conformal::movetophase(); char buf[500]; snprintf(buf, 500, fname.c_str(), i); if(i == 0) drawthemap(); shmup::turn(100); printf("%s\n", buf); pngres = 1080; saveHighQualityShot(buf, caption, fade); } return; } for(int i=0; i<1800; i++) { char buf[500]; snprintf(buf, 500, fname.c_str(), i); shmup::pc[0]->base = currentmap->gamestart(); shmup::pc[0]->at = spin(i * 2 * M_PI / (58*30.)) * xpush(1.7); if(i == 0) drawthemap(); shmup::turn(100); if(i == 0) drawthemap(); centerpc(100); printf("%s\n", buf); saveHighQualityShot(buf); } } #endif #if CAP_COMMANDLINE int readArgs() { using namespace arg; // options before reading if(0) ; else if(argis("-dftcolor")) { shift(); dftcolor = strtol(args().c_str(), NULL, 16); } // tree visualizer (e.g. Tree of Life) //------------------------------------- else if(argis("-tree")) { PHASE(3); shift(); tree::read(args()); } // SAG visualizer (e.g. Reddit roguelikes, GitHub languages) //----------------------------------------------------------- // (1) configure edge weights else if(argis("-edgepower")) { shift(); sag::edgepower = argf(); shift(); sag::edgemul = argf(); } // (1) configure temperature (high, low) else if(argis("-sagtemp")) { shift(); sag::hightemp = argf(); shift(); sag::lowtemp = argf(); } // (2) read the edge data else if(argis("-sagpar")) { PHASE(3); shift(); sag::sagpar = argi(); } else if(argis("-sag")) { PHASE(3); shift(); sag::read(args()); } // (3) load the initial positioning else if(argis("-gload")) { PHASE(3); shift(); sag::loadsnake(args()); } // (4) perform simulated annealing: -fullsa