1
0
mirror of https://github.com/zenorogue/hyperrogue.git synced 2025-02-02 20:29: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;
int collatz_id;
void start() {
init(); kind = kCollatz;
init(&collatz_id, RV_GRAPH);
collatz1 = add_edgetype("1");
collatz2 = add_edgetype("2");
vdata.resize(1);
@ -75,7 +77,7 @@ namespace collatz {
}
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) ;
else if(vd.data == 2) {
// doubler vertex
@ -140,7 +142,7 @@ namespace collatz {
// see: https://www.youtube.com/watch?v=4Vu3F95jpQ4&t=6s (Collatz)
void collatz_video(const string &fname) {
if(kind == kCollatz) {
if(vizid == &collatz_id) {
sightrange_bonus = 3;
genrange_bonus = 3;
dronemode = true; vid.camera_angle = -45; rog3 = true; patterns::whichShape = '8';
@ -263,7 +265,7 @@ int readArgs() {
}
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();
if(i <= 0) i = 763;
if(j < 0 || j > 61) j = 61;
@ -288,7 +290,7 @@ int readArgs() {
}
#if CAP_SHOT
else if(argis("-rvvideo") && kind == kCollatz) {
else if(argis("-rvvideo") && vizid == &collatz_id) {
shift(); collatz_video(arg::args());
}
#endif
@ -322,7 +324,6 @@ int ah = addHook(hooks_args, 100, readArgs) +
rogueviz::showlabels = true;
rogueviz::on = true;
gmatrix.clear();
drawthemap();
gmatrix0 = gmatrix;

View File

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

View File

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

View File

@ -35,8 +35,6 @@ using namespace hr;
edgetype default_edgetype = { .1, .1, .1, DEFAULT_COLOR, 0xFF0000FF, "default" };
void init();
bool showlabels = false;
bool specialmark = false;
bool edge_legend = false;
@ -50,10 +48,6 @@ string fname;
// const char *fname;
// const char *cfname;
eVizkind kind;
bool on;
vector<shared_ptr<edgetype>> edgetypes;
edgetype *add_edgetype(const string& name) {
@ -268,6 +262,8 @@ colorpair dftcolor = 0x282828FF;
namespace spiral {
int spiral_id;
ld mul;
transmatrix at(double d) {
@ -276,7 +272,8 @@ namespace spiral {
void place(int N, ld _mul) {
mul = _mul;
init(); kind = kSpiral;
init(&spiral_id, RV_GRAPH | RV_HAVE_WEIGHT | RV_INVERSE_WEIGHT);
weight_label = "extent";
vdata.resize(N);
for(int i=0; i<N; i++) {
@ -331,6 +328,7 @@ namespace anygraph {
edgetype *any;
int vzid;
int N;
@ -347,7 +345,7 @@ namespace anygraph {
void tst() {}
void read(string fn, bool subdiv, bool doRebase, bool doStore) {
init(); kind = kAnyGraph;
init(&vzid, RV_GRAPH);
any = add_edgetype("embedded edges");
fname = fn;
fhstream f(fn + "-coordinates.txt", "rt");
@ -451,7 +449,7 @@ void rogueviz_help(int id, int pagenumber) {
int k = ei->i ^ ei->j ^ id;
hex.text = vdata[k].name;
hex.color = vdata[k].cp.color1 >> 8;
if(kind == kSAG) {
if(vizflags & RV_WHICHWEIGHT) {
if(which_weight)
hex.subtext = fts(ei->weight2);
else
@ -471,7 +469,7 @@ void rogueviz_help(int id, int pagenumber) {
help_extensions.push_back(hex);
}
if(kind == kSAG && noedges) {
if((vizflags & RV_WHICHWEIGHT) && noedges) {
help_extension hex;
hex.key = 'w';
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);
auto& alpha = part(col, 0);
if(kind == kSAG) {
if(vizflags & RV_AUTO_MAXWEIGHT) {
if(ei->weight2 > maxweight) maxweight = ei->weight2;
alpha *= pow(ei->weight2 / maxweight, ggamma);
}
@ -729,7 +727,7 @@ bool drawVertex(const transmatrix &V, cell *c, shmup::monster *m) {
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(onspiral) {
@ -777,7 +775,7 @@ bool drawVertex(const transmatrix &V, cell *c, shmup::monster *m) {
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();
hyperpoint l1 = tC0(spiral::at(1+ei->i));
storevertex(ei->prec, l1);
@ -806,7 +804,7 @@ bool drawVertex(const transmatrix &V, cell *c, shmup::monster *m) {
if(showlabels) {
bool doshow = true;
if(kind == kTree && i > 0 && !vd.virt) {
if((vizflags & RV_COMPRESS_LABELS) && i > 0 && !vd.virt) {
vertexdata& vdp = vdata[vd.data];
hyperpoint h2 = ggmatrix(vdp.m->base) * vdp.m->at * C0;
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() {
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;
int qet = isize(edgetypes);
@ -978,7 +976,7 @@ void readcolor(const string& cfname) {
int i = getid(lab);
again: vdata[i].cp = x;
if(kind == kTree) {
if(vizflags & RV_COLOR_TREE) {
i = vdata[i].data;
if(i >= 0) goto again;
}
@ -986,8 +984,13 @@ void readcolor(const string& cfname) {
}
}
void init() {
if(on) return;
void init(void *_vizid, flagtype _vizflags) {
bool was_on = vizid;
vizid = _vizid;
vizflags = _vizflags;
if(was_on) return;
autocheat = true;
showstartmenu = false;
#if !ISWEB
@ -1000,7 +1003,6 @@ void init() {
firstland = specialland = laCanvas;
restart_game(rg::nothing);
#endif
on = true;
autocheat = true;
items[itOrbLife] = 0;
timerghost = false;
@ -1028,7 +1030,7 @@ void close() {
anygraph::coords.clear();
callhooks(hooks_close);
edgetypes.clear();
on = false;
vizid = nullptr;
relmatrices.clear();
}
@ -1176,7 +1178,6 @@ void configure_edge_display() {
static int mode = 0;
gamescreen(0);
dialog::init(XLAT("rogueviz edges"));
string s3 = kind == kSAG ? "min weight" : kind == kKohonen ? "quantity" : "extent";
for(int i=0; i<isize(edgetypes); i++) {
auto t = edgetypes[i];
switch(mode) {
@ -1189,7 +1190,7 @@ void configure_edge_display() {
});
break;
case 1:
if(kind == kSAG) {
if(!(vizflags & RV_INVERSE_WEIGHT)) {
dialog::addSelItem(t->name, fts(t->visible_from), 'a'+i);
dialog::add_action([t] {
dialog::editNumber(t->visible_from, 0.001, 1000, .1, .1, "min weight", "");
@ -1198,10 +1199,10 @@ void configure_edge_display() {
}
else {
dialog::addSelItem(t->name, its(1 / t->visible_from), 'a'+i);
dialog::add_action([t,s3] {
dialog::add_action([t] {
static int i;
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::scaleLog(); dialog::ne.step = .2;
});
@ -1211,9 +1212,9 @@ void configure_edge_display() {
}
}
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(s3, mode, 1, '2');
dialog::addBoolItem_choice(weight_label, mode, 1, '2');
}
else mode = 0;
@ -1432,30 +1433,18 @@ int rvtour_hooks =
#endif
bool default_help() {
if(!rogueviz::on) return false;
if(!vizid) return false;
help =
"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";
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); }});
return true;
}
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();
}
@ -1498,8 +1487,8 @@ auto hooks =
#endif
}) +
addHook(hooks_welcome_message, 100, [] () {
if(rogueviz::on) addMessage(XLAT("Welcome to RogueViz!"));
return rogueviz::on;
if(vizid) addMessage(XLAT("Welcome to RogueViz!"));
return bool(vizid);
}) +
addHook(hooks_default_help, 100, default_help) +
addHook(hooks_markers, 100, search_marker) +

View File

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

View File

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