1
0
mirror of https://github.com/zenorogue/hyperrogue.git synced 2025-02-03 04:39:17 +00:00

replaced rogueviz::kind with rogueviz::vizid and rogueviz::vizflags

This commit is contained in:
Zeno Rogue 2020-03-29 15:14:23 +02:00
parent 2b4b035604
commit 24dd8c9376
6 changed files with 63 additions and 69 deletions

View File

@ -12,8 +12,10 @@ namespace collatz {
edgetype *collatz1, *collatz2; edgetype *collatz1, *collatz2;
int collatz_id;
void start() { void start() {
init(); kind = kCollatz; init(&collatz_id, RV_GRAPH);
collatz1 = add_edgetype("1"); collatz1 = add_edgetype("1");
collatz2 = add_edgetype("2"); collatz2 = add_edgetype("2");
vdata.resize(1); vdata.resize(1);
@ -75,7 +77,7 @@ namespace collatz {
} }
void act(vertexdata& vd, cell *c, shmup::monster *m, int i) { void act(vertexdata& vd, cell *c, shmup::monster *m, int i) {
if(kind != kCollatz) return; if(vizid != &collatz_id) return;
if(c->cpdist > 7 && euclid) ; if(c->cpdist > 7 && euclid) ;
else if(vd.data == 2) { else if(vd.data == 2) {
// doubler vertex // doubler vertex
@ -140,7 +142,7 @@ namespace collatz {
// see: https://www.youtube.com/watch?v=4Vu3F95jpQ4&t=6s (Collatz) // see: https://www.youtube.com/watch?v=4Vu3F95jpQ4&t=6s (Collatz)
void collatz_video(const string &fname) { void collatz_video(const string &fname) {
if(kind == kCollatz) { if(vizid == &collatz_id) {
sightrange_bonus = 3; sightrange_bonus = 3;
genrange_bonus = 3; genrange_bonus = 3;
dronemode = true; vid.camera_angle = -45; rog3 = true; patterns::whichShape = '8'; dronemode = true; vid.camera_angle = -45; rog3 = true; patterns::whichShape = '8';
@ -263,7 +265,7 @@ int readArgs() {
} }
else if(argis("-collatz-go")) { else if(argis("-collatz-go")) {
if(kind != kCollatz) { printf("not in Collatz\n"); throw hr_exception(); } if(vizid != &collatz_id) { printf("not in Collatz\n"); throw hr_exception(); }
shift(); int i = argi(); shift(); int j = argi(); shift(); int i = argi(); shift(); int j = argi();
if(i <= 0) i = 763; if(i <= 0) i = 763;
if(j < 0 || j > 61) j = 61; if(j < 0 || j > 61) j = 61;
@ -288,7 +290,7 @@ int readArgs() {
} }
#if CAP_SHOT #if CAP_SHOT
else if(argis("-rvvideo") && kind == kCollatz) { else if(argis("-rvvideo") && vizid == &collatz_id) {
shift(); collatz_video(arg::args()); shift(); collatz_video(arg::args());
} }
#endif #endif
@ -322,7 +324,6 @@ int ah = addHook(hooks_args, 100, readArgs) +
rogueviz::showlabels = true; rogueviz::showlabels = true;
rogueviz::on = true;
gmatrix.clear(); gmatrix.clear();
drawthemap(); drawthemap();
gmatrix0 = gmatrix; gmatrix0 = gmatrix;

View File

@ -44,6 +44,8 @@ namespace rogueviz {
namespace flocking { namespace flocking {
int flock_id;
int N; int N;
bool draw_lines = false; bool draw_lines = false;
@ -85,7 +87,7 @@ namespace flocking {
return; return;
} }
stop_game(); stop_game();
rogueviz::init(); kind = kFlocking; rogueviz::init(&flock_id, RV_GRAPH);
vdata.resize(N); vdata.resize(N);
const auto v = currentmap->allcells(); const auto v = currentmap->allcells();
@ -277,8 +279,8 @@ namespace flocking {
} }
bool turn(int delta) { bool turn(int delta) {
if(!on) return false; if(vizid != &flock_id) return false;
if(kind == kFlocking) simulate(delta), timetowait = 0; simulate(delta), timetowait = 0;
if(follow) { if(follow) {
@ -496,7 +498,7 @@ namespace flocking {
} }
named_functionality o_key() { named_functionality o_key() {
if(kind == kFlocking) return named_dialog("flocking", show); if(vizid == &flock_id) return named_dialog("flocking", show);
return named_functionality(); return named_functionality();
} }

View File

@ -6,6 +6,8 @@
namespace rogueviz { namespace kohonen { namespace rogueviz { namespace kohonen {
int kohonen_id;
int columns; int columns;
typedef vector<double> kohvec; typedef vector<double> kohvec;
@ -277,7 +279,7 @@ void analyze() {
} }
bool coloring_3d(cell *c, const transmatrix& V) { bool coloring_3d(cell *c, const transmatrix& V) {
if(WDIM == 3 && on && kind == kKohonen) if(WDIM == 3 && vizid == &kohonen_id)
queuepoly(face_the_player(V), cgi.shRing, darkena(c->landparam_color, 0, 0xFF)); queuepoly(face_the_player(V), cgi.shRing, darkena(c->landparam_color, 0, 0xFF));
return false; return false;
} }
@ -646,7 +648,8 @@ void sominit(int initto, bool load_compressed) {
exit(1); exit(1);
} }
init(); kind = kKohonen; init(&kohonen_id, RV_GRAPH | RV_HAVE_WEIGHT);
weight_label = "quantity";
printf("Initializing SOM (1)\n"); printf("Initializing SOM (1)\n");
@ -740,7 +743,7 @@ void sominit(int initto, bool load_compressed) {
void describe_cell(cell *c) { void describe_cell(cell *c) {
if(cmode & sm::HELP) return; if(cmode & sm::HELP) return;
if(kind != kKohonen) return; if(vizid != &kohonen_id) return;
neuron *n = getNeuronSlow(c); neuron *n = getNeuronSlow(c);
if(!n) return; if(!n) return;
string h; string h;
@ -1204,7 +1207,7 @@ void shift_color(int i) {
} }
void showMenu() { void showMenu() {
if(kind != kKohonen) return; if(vizid != &kohonen_id) return;
string parts[3] = {"red", "green", "blue"}; string parts[3] = {"red", "green", "blue"};
for(int i=0; i<3; i++) { for(int i=0; i<3; i++) {
string c; string c;
@ -1525,8 +1528,7 @@ auto hooks = addHook(hooks_args, 100, readArgs);
#endif #endif
bool turn(int delta) { bool turn(int delta) {
if(!on) return false; if(vizid == &kohonen_id) kohonen::steps(), timetowait = 0;
if(kind == kKohonen) kohonen::steps(), timetowait = 0;
return false; return false;
// shmup::pc[0]->rebase(); // shmup::pc[0]->rebase();
} }
@ -1569,7 +1571,7 @@ void clear() {
namespace rogueviz { namespace rogueviz {
void mark(cell *c) { void mark(cell *c) {
using namespace kohonen; using namespace kohonen;
if(kind == kKohonen && inited >= 1) { if(vizid == &kohonen_id && inited >= 1) {
distfrom = getNeuronSlow(c); distfrom = getNeuronSlow(c);
coloring(); coloring();
} }

View File

@ -35,8 +35,6 @@ using namespace hr;
edgetype default_edgetype = { .1, .1, .1, DEFAULT_COLOR, 0xFF0000FF, "default" }; edgetype default_edgetype = { .1, .1, .1, DEFAULT_COLOR, 0xFF0000FF, "default" };
void init();
bool showlabels = false; bool showlabels = false;
bool specialmark = false; bool specialmark = false;
bool edge_legend = false; bool edge_legend = false;
@ -50,10 +48,6 @@ string fname;
// const char *fname; // const char *fname;
// const char *cfname; // const char *cfname;
eVizkind kind;
bool on;
vector<shared_ptr<edgetype>> edgetypes; vector<shared_ptr<edgetype>> edgetypes;
edgetype *add_edgetype(const string& name) { edgetype *add_edgetype(const string& name) {
@ -268,6 +262,8 @@ colorpair dftcolor = 0x282828FF;
namespace spiral { namespace spiral {
int spiral_id;
ld mul; ld mul;
transmatrix at(double d) { transmatrix at(double d) {
@ -276,7 +272,8 @@ namespace spiral {
void place(int N, ld _mul) { void place(int N, ld _mul) {
mul = _mul; mul = _mul;
init(); kind = kSpiral; init(&spiral_id, RV_GRAPH | RV_HAVE_WEIGHT | RV_INVERSE_WEIGHT);
weight_label = "extent";
vdata.resize(N); vdata.resize(N);
for(int i=0; i<N; i++) { for(int i=0; i<N; i++) {
@ -331,6 +328,7 @@ namespace anygraph {
edgetype *any; edgetype *any;
int vzid;
int N; int N;
@ -347,7 +345,7 @@ namespace anygraph {
void tst() {} void tst() {}
void read(string fn, bool subdiv, bool doRebase, bool doStore) { void read(string fn, bool subdiv, bool doRebase, bool doStore) {
init(); kind = kAnyGraph; init(&vzid, RV_GRAPH);
any = add_edgetype("embedded edges"); any = add_edgetype("embedded edges");
fname = fn; fname = fn;
fhstream f(fn + "-coordinates.txt", "rt"); fhstream f(fn + "-coordinates.txt", "rt");
@ -451,7 +449,7 @@ void rogueviz_help(int id, int pagenumber) {
int k = ei->i ^ ei->j ^ id; int k = ei->i ^ ei->j ^ id;
hex.text = vdata[k].name; hex.text = vdata[k].name;
hex.color = vdata[k].cp.color1 >> 8; hex.color = vdata[k].cp.color1 >> 8;
if(kind == kSAG) { if(vizflags & RV_WHICHWEIGHT) {
if(which_weight) if(which_weight)
hex.subtext = fts(ei->weight2); hex.subtext = fts(ei->weight2);
else else
@ -471,7 +469,7 @@ void rogueviz_help(int id, int pagenumber) {
help_extensions.push_back(hex); help_extensions.push_back(hex);
} }
if(kind == kSAG && noedges) { if((vizflags & RV_WHICHWEIGHT) && noedges) {
help_extension hex; help_extension hex;
hex.key = 'w'; hex.key = 'w';
hex.text = "displayed weight"; hex.text = "displayed weight";
@ -677,7 +675,7 @@ bool drawVertex(const transmatrix &V, cell *c, shmup::monster *m) {
color_t col = (hilite ? ei->type->color_hi : ei->type->color); color_t col = (hilite ? ei->type->color_hi : ei->type->color);
auto& alpha = part(col, 0); auto& alpha = part(col, 0);
if(kind == kSAG) { if(vizflags & RV_AUTO_MAXWEIGHT) {
if(ei->weight2 > maxweight) maxweight = ei->weight2; if(ei->weight2 > maxweight) maxweight = ei->weight2;
alpha *= pow(ei->weight2 / maxweight, ggamma); alpha *= pow(ei->weight2 / maxweight, ggamma);
} }
@ -729,7 +727,7 @@ bool drawVertex(const transmatrix &V, cell *c, shmup::monster *m) {
col |= (forecolor << 8); col |= (forecolor << 8);
} }
bool onspiral = kind == kSpiral && abs(ei->i - ei->j) == 1; bool onspiral = (vizid == &spiral::spiral_id) && abs(ei->i - ei->j) == 1;
if((pmodel || onspiral) && !fat_edges) { if((pmodel || onspiral) && !fat_edges) {
if(onspiral) { if(onspiral) {
@ -777,7 +775,7 @@ bool drawVertex(const transmatrix &V, cell *c, shmup::monster *m) {
store(a+30, d); store(a+30, d);
} }
} }
else if(kind == kSpiral && abs(ei->i - ei->j) == 1) { else if((vizid == spiral::place) && abs(ei->i - ei->j) == 1) {
ei->orig = currentmap->gamestart(); ei->orig = currentmap->gamestart();
hyperpoint l1 = tC0(spiral::at(1+ei->i)); hyperpoint l1 = tC0(spiral::at(1+ei->i));
storevertex(ei->prec, l1); storevertex(ei->prec, l1);
@ -806,7 +804,7 @@ bool drawVertex(const transmatrix &V, cell *c, shmup::monster *m) {
if(showlabels) { if(showlabels) {
bool doshow = true; bool doshow = true;
if(kind == kTree && i > 0 && !vd.virt) { if((vizflags & RV_COMPRESS_LABELS) && i > 0 && !vd.virt) {
vertexdata& vdp = vdata[vd.data]; vertexdata& vdp = vdata[vd.data];
hyperpoint h2 = ggmatrix(vdp.m->base) * vdp.m->at * C0; hyperpoint h2 = ggmatrix(vdp.m->base) * vdp.m->at * C0;
if(hdist(h2, V * m->at * C0) < 0.1) doshow = false; if(hdist(h2, V * m->at * C0) < 0.1) doshow = false;
@ -835,7 +833,7 @@ color_t chosen_legend_color = DEFAULT_COLOR;
bool rogueviz_hud() { bool rogueviz_hud() {
color_t legend_color = chosen_legend_color == DEFAULT_COLOR ? forecolor : chosen_legend_color; color_t legend_color = chosen_legend_color == DEFAULT_COLOR ? forecolor : chosen_legend_color;
if(!rogueviz::on) return false; if(!vizid) return false;
if(cmode & sm::DRAW) return false; if(cmode & sm::DRAW) return false;
int qet = isize(edgetypes); int qet = isize(edgetypes);
@ -978,7 +976,7 @@ void readcolor(const string& cfname) {
int i = getid(lab); int i = getid(lab);
again: vdata[i].cp = x; again: vdata[i].cp = x;
if(kind == kTree) { if(vizflags & RV_COLOR_TREE) {
i = vdata[i].data; i = vdata[i].data;
if(i >= 0) goto again; if(i >= 0) goto again;
} }
@ -986,8 +984,13 @@ void readcolor(const string& cfname) {
} }
} }
void init() { void init(void *_vizid, flagtype _vizflags) {
if(on) return; bool was_on = vizid;
vizid = _vizid;
vizflags = _vizflags;
if(was_on) return;
autocheat = true; autocheat = true;
showstartmenu = false; showstartmenu = false;
#if !ISWEB #if !ISWEB
@ -1000,7 +1003,6 @@ void init() {
firstland = specialland = laCanvas; firstland = specialland = laCanvas;
restart_game(rg::nothing); restart_game(rg::nothing);
#endif #endif
on = true;
autocheat = true; autocheat = true;
items[itOrbLife] = 0; items[itOrbLife] = 0;
timerghost = false; timerghost = false;
@ -1028,7 +1030,7 @@ void close() {
anygraph::coords.clear(); anygraph::coords.clear();
callhooks(hooks_close); callhooks(hooks_close);
edgetypes.clear(); edgetypes.clear();
on = false; vizid = nullptr;
relmatrices.clear(); relmatrices.clear();
} }
@ -1176,7 +1178,6 @@ void configure_edge_display() {
static int mode = 0; static int mode = 0;
gamescreen(0); gamescreen(0);
dialog::init(XLAT("rogueviz edges")); dialog::init(XLAT("rogueviz edges"));
string s3 = kind == kSAG ? "min weight" : kind == kKohonen ? "quantity" : "extent";
for(int i=0; i<isize(edgetypes); i++) { for(int i=0; i<isize(edgetypes); i++) {
auto t = edgetypes[i]; auto t = edgetypes[i];
switch(mode) { switch(mode) {
@ -1189,7 +1190,7 @@ void configure_edge_display() {
}); });
break; break;
case 1: case 1:
if(kind == kSAG) { if(!(vizflags & RV_INVERSE_WEIGHT)) {
dialog::addSelItem(t->name, fts(t->visible_from), 'a'+i); dialog::addSelItem(t->name, fts(t->visible_from), 'a'+i);
dialog::add_action([t] { dialog::add_action([t] {
dialog::editNumber(t->visible_from, 0.001, 1000, .1, .1, "min weight", ""); dialog::editNumber(t->visible_from, 0.001, 1000, .1, .1, "min weight", "");
@ -1198,10 +1199,10 @@ void configure_edge_display() {
} }
else { else {
dialog::addSelItem(t->name, its(1 / t->visible_from), 'a'+i); dialog::addSelItem(t->name, its(1 / t->visible_from), 'a'+i);
dialog::add_action([t,s3] { dialog::add_action([t] {
static int i; static int i;
i = 1 / t->visible_from; i = 1 / t->visible_from;
dialog::editNumber(i, 1, 1000000, 1, 500, s3, ""); dialog::editNumber(i, 1, 1000000, 1, 500, weight_label, "");
dialog::reaction = [t] () { t->visible_from = i ? 1. / i : 5; }; dialog::reaction = [t] () { t->visible_from = i ? 1. / i : 5; };
dialog::scaleLog(); dialog::ne.step = .2; dialog::scaleLog(); dialog::ne.step = .2;
}); });
@ -1211,9 +1212,9 @@ void configure_edge_display() {
} }
} }
dialog::addBreak(100); dialog::addBreak(100);
if(among(kind, kSAG, kKohonen, kSpiral)) { if(vizflags & RV_HAVE_WEIGHT) {
dialog::addBoolItem_choice("color/alpha", mode, 0, '1'); dialog::addBoolItem_choice("color/alpha", mode, 0, '1');
dialog::addBoolItem_choice(s3, mode, 1, '2'); dialog::addBoolItem_choice(weight_label, mode, 1, '2');
} }
else mode = 0; else mode = 0;
@ -1432,30 +1433,18 @@ int rvtour_hooks =
#endif #endif
bool default_help() { bool default_help() {
if(!rogueviz::on) return false; if(!vizid) return false;
help = help =
"This is RogueViz, a visualization engine based on HyperRogue.\n\nUse WASD to move, v for menu.\n\n" "This is RogueViz, a visualization engine based on HyperRogue.\n\nUse WASD to move, v for menu.\n\n"
"Read more about RogueViz on : http://roguetemple.com/z/hyper/rogueviz.php\n\n"; "Read more about RogueViz on : http://roguetemple.com/z/hyper/rogueviz.php\n\n";
if(kind == kAnyGraph)
help += "Current visualization: any graph\n\n" + fname;
if(kind == kTree)
help += "Current visualization: tree\n\n" + fname;
if(kind == kSpiral)
help += "Current visualization: spiral\n\n";
if(kind == kSAG)
help += "Current visualization: SAG\n\n" + fname;
if(kind == kCollatz)
help += "Current visualization: Collatz conjecture\n\n";
if(kind == kFullNet)
help += "Current visualization: full net\n\n";
help_extensions.push_back(help_extension{'u', XLAT("RogueViz menu"), [] () { popScreen(); pushScreen(showMenu); }}); help_extensions.push_back(help_extension{'u', XLAT("RogueViz menu"), [] () { popScreen(); pushScreen(showMenu); }});
return true; return true;
} }
named_functionality o_key() { named_functionality o_key() {
if(rogueviz::on) return named_dialog(XLAT("rogueviz menu"), rogueviz::showMenu); if(vizid) return named_dialog(XLAT("rogueviz menu"), rogueviz::showMenu);
return named_functionality(); return named_functionality();
} }
@ -1498,8 +1487,8 @@ auto hooks =
#endif #endif
}) + }) +
addHook(hooks_welcome_message, 100, [] () { addHook(hooks_welcome_message, 100, [] () {
if(rogueviz::on) addMessage(XLAT("Welcome to RogueViz!")); if(vizid) addMessage(XLAT("Welcome to RogueViz!"));
return rogueviz::on; return bool(vizid);
}) + }) +
addHook(hooks_default_help, 100, default_help) + addHook(hooks_default_help, 100, default_help) +
addHook(hooks_markers, 100, search_marker) + addHook(hooks_markers, 100, search_marker) +

View File

@ -12,6 +12,8 @@ namespace rogueviz {
namespace sag { namespace sag {
int sag_id;
int sagpar = 0; int sagpar = 0;
enum eSagmode { sagOff, sagHC, sagSA }; enum eSagmode { sagOff, sagHC, sagSA };
@ -419,7 +421,8 @@ namespace sag {
void read(string fn) { void read(string fn) {
fname = fn; fname = fn;
init(); kind = kSAG; init(&sag_id, RV_GRAPH | RV_WHICHWEIGHT | RV_AUTO_MAXWEIGHT | RV_HAVE_WEIGHT);
weight_label = "min weight";
temperature = 0; sagmode = sagOff; temperature = 0; sagmode = sagOff;
readsag(fname.c_str()); readsag(fname.c_str());
@ -535,8 +538,7 @@ int readArgs() {
} }
bool turn(int delta) { bool turn(int delta) {
if(!on) return false; if(vizid == &sag_id) sag::iterate(), timetowait = 0;
if(kind == kSAG) sag::iterate(), timetowait = 0;
return false; return false;
// shmup::pc[0]->rebase(); // shmup::pc[0]->rebase();
} }
@ -545,7 +547,7 @@ int ah = addHook(hooks_args, 100, readArgs)
+ addHook(shmup::hooks_turn, 100, turn) + addHook(shmup::hooks_turn, 100, turn)
+ addHook(rogueviz::hooks_close, 100, [] { sag::sagedges.clear(); }) + addHook(rogueviz::hooks_close, 100, [] { sag::sagedges.clear(); })
+ addHook(rogueviz::hooks_rvmenu, 100, [] { + addHook(rogueviz::hooks_rvmenu, 100, [] {
if(kind != kSAG) return; if(vizid != &sag_id) return;
dialog::addSelItem(XLAT("temperature"), fts(sag::temperature), 't'); dialog::addSelItem(XLAT("temperature"), fts(sag::temperature), 't');
dialog::add_action([] { dialog::add_action([] {
dialog::editNumber(sag::temperature, sag::lowtemp, sag::hightemp, 1, 0, XLAT("temperature"), ""); dialog::editNumber(sag::temperature, sag::lowtemp, sag::hightemp, 1, 0, XLAT("temperature"), "");
@ -567,7 +569,6 @@ int ah = addHook(hooks_args, 100, readArgs)
rogueviz::sag::edgepower = 1; rogueviz::sag::edgepower = 1;
rogueviz::sag::edgemul = 1; rogueviz::sag::edgemul = 1;
rogueviz::on = true;
gmatrix.clear(); gmatrix.clear();
drawthemap(); drawthemap();
gmatrix0 = gmatrix; gmatrix0 = gmatrix;
@ -588,7 +589,6 @@ int ah = addHook(hooks_args, 100, readArgs)
rogueviz::sag::edgepower = .4; rogueviz::sag::edgepower = .4;
rogueviz::sag::edgemul = .02; rogueviz::sag::edgemul = .02;
rogueviz::on = true;
gmatrix.clear(); gmatrix.clear();
drawthemap(); drawthemap();
gmatrix0 = gmatrix; gmatrix0 = gmatrix;
@ -610,7 +610,6 @@ int ah = addHook(hooks_args, 100, readArgs)
rogueviz::sag::edgepower = 1; rogueviz::sag::edgepower = 1;
rogueviz::sag::edgemul = 1; rogueviz::sag::edgemul = 1;
rogueviz::on = true;
gmatrix.clear(); gmatrix.clear();
drawthemap(); drawthemap();
gmatrix0 = gmatrix; gmatrix0 = gmatrix;

View File

@ -8,6 +8,8 @@ namespace rogueviz {
namespace tree { namespace tree {
int tree_id;
edgetype *tree_edge; edgetype *tree_edge;
struct treevertex { struct treevertex {
@ -61,7 +63,7 @@ namespace tree {
void read(string fn) { void read(string fn) {
fname = fn; fname = fn;
init(); kind = kTree; init(&tree_id, RV_GRAPH | RV_COMPRESS_LABELS | RV_COLOR_TREE);
tree_edge = add_edgetype("tree edge"); tree_edge = add_edgetype("tree edge");
printf("Reading the tree of life...\n"); printf("Reading the tree of life...\n");
FILE *f = fopen(fname.c_str(), "rt"); FILE *f = fopen(fname.c_str(), "rt");
@ -132,7 +134,6 @@ int ah = addHook(hooks_args, 100, readArgs)
rogueviz::showlabels = true; rogueviz::showlabels = true;
rogueviz::on = true;
gmatrix.clear(); gmatrix.clear();
drawthemap(); drawthemap();
gmatrix0 = gmatrix; gmatrix0 = gmatrix;