1
0
mirror of https://github.com/zenorogue/hyperrogue.git synced 2024-06-24 22:23:18 +00:00

rogueviz:: used rv_hook in some viz

This commit is contained in:
Zeno Rogue 2021-03-31 00:23:01 +02:00
parent 19a1358607
commit 73c5b5e881
5 changed files with 123 additions and 112 deletions

View File

@ -13,6 +13,10 @@ namespace collatz {
int collatz_id;
void act(vertexdata& vd, cell *c, shmup::monster *m, int i);
void lookup(long long reached, int bits);
void collatz_video(const string &fname);
void start() {
init(&collatz_id, RV_GRAPH);
collatz1 = add_edgetype("1");
@ -29,6 +33,30 @@ namespace collatz {
T2 = spin(collatz::s2) * xpush(collatz::p2);
T3 = spin(collatz::s3) * xpush(collatz::p3);
rv_hook(hooks_drawvertex, 100, act);
rv_hook(hooks_args, 100, [] {
using namespace arg;
if(0) ;
#if CAP_SHOT
else if(argis("-rvvideo")) {
shift(); collatz_video(arg::args());
}
#endif
else if(argis("-collatz-go")) {
shift(); int i = argi(); shift(); int j = argi();
if(i <= 0) i = 763;
if(j < 0 || j > 61) j = 61;
collatz::lookup(i, j);
}
else return 1;
return 0;
});
}
void lookup(long long reached, int bits) {
@ -76,7 +104,6 @@ namespace collatz {
}
void act(vertexdata& vd, cell *c, shmup::monster *m, int i) {
if(vizid != &collatz_id) return;
if(c->cpdist > 7 && euclid) ;
else if(vd.data == 2) {
// doubler vertex
@ -141,7 +168,7 @@ namespace collatz {
// see: https://www.youtube.com/watch?v=4Vu3F95jpQ4&t=6s (Collatz)
void collatz_video(const string &fname) {
if(vizid == &collatz_id) {
if(true) {
sightrange_bonus = 3;
genrange_bonus = 3;
dronemode = true; pconf.camera_angle = -45; rog3 = true; patterns::whichShape = '8';
@ -273,14 +300,6 @@ int readArgs() {
start();
}
else if(argis("-collatz-go")) {
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;
collatz::lookup(i, j);
}
else if(argis("-collatz3")) {
PHASE(3);
using namespace collatz;
@ -298,12 +317,6 @@ int readArgs() {
unshift();
}
#if CAP_SHOT
else if(argis("-rvvideo") && vizid == &collatz_id) {
shift(); collatz_video(arg::args());
}
#endif
else if(argis("-cshift")) {
shift_arg_formula(collatz::cshift);
}
@ -341,8 +354,7 @@ int ah = addHook(hooks_args, 100, readArgs) +
rogueviz::collatz::start();
})
});
})
+ addHook(hooks_drawvertex, 100, act);
});
EX }

View File

@ -46,6 +46,8 @@ namespace rogueviz {
namespace flocking {
void init();
int flock_id;
int N;
@ -83,52 +85,6 @@ namespace flocking {
// m->at * (m->vel, 0, 0) is the current velocity vector (tangent to the Minkowski hyperboloid)
// m->pat: like m->at but relative to the screen
void init() {
if(!bounded) {
addMessage("Flocking simulation needs a bounded space.");
return;
}
stop_game();
rogueviz::init(&flock_id, RV_GRAPH);
vdata.resize(N);
const auto v = currentmap->allcells();
printf("computing relmatrices...\n");
// relmatrices[c1][c2] is the matrix we have to multiply by to
// change from c1-relative coordinates to c2-relative coordinates
for(cell* c1: v) {
manual_celllister cl;
cl.add(c1);
for(int i=0; i<isize(cl.lst); i++) {
cell *c2 = cl.lst[i];
transmatrix T = calc_relative_matrix(c2, c1, C0);
if(hypot_d(WDIM, inverse_exp(shiftless(tC0(T)))) <= check_range) {
relmatrices[c1][c2] = T;
forCellEx(c3, c2) cl.add(c3);
}
}
}
printf("setting up...\n");
for(int i=0; i<N; i++) {
vertexdata& vd = vdata[i];
// set initial base and at to random cell and random position there
createViz(i, v[hrand(isize(v))], Id);
rotate_object(vd.m->pat.T, vd.m->ori, random_spin());
apply_parallel_transport(vd.m->pat.T, vd.m->ori, xtangent(hrand(100) / 200.));
vd.name = its(i+1);
vd.cp = dftcolor;
vd.cp.color2 = ((hrand(0x1000000) << 8) + 0xFF) | 0x808080FF;
vd.cp.shade = shape;
vd.m->vel = ini_speed;
}
storeall();
printf("done\n");
}
int precision = 10;
void simulate(int delta) {
@ -281,7 +237,6 @@ namespace flocking {
}
bool turn(int delta) {
if(vizid != &flock_id) return false;
simulate(delta), timetowait = 0;
if(follow) {
@ -500,15 +455,60 @@ namespace flocking {
}
void o_key(o_funcs& v) {
if(vizid == &flock_id) v.push_back(named_dialog("flocking", show));
v.push_back(named_dialog("flocking", show));
}
auto hooks =
addHook(hooks_args, 100, readArgs) +
addHook(shmup::hooks_turn, 100, turn) +
addHook(hooks_frame, 100, flock_marker) +
addHook(hooks_o_key, 80, o_key) +
0;
void init() {
if(!bounded) {
addMessage("Flocking simulation needs a bounded space.");
return;
}
stop_game();
rogueviz::init(&flock_id, RV_GRAPH);
rv_hook(shmup::hooks_turn, 100, turn);
rv_hook(hooks_frame, 100, flock_marker);
rv_hook(hooks_o_key, 80, o_key);
vdata.resize(N);
const auto v = currentmap->allcells();
printf("computing relmatrices...\n");
// relmatrices[c1][c2] is the matrix we have to multiply by to
// change from c1-relative coordinates to c2-relative coordinates
for(cell* c1: v) {
manual_celllister cl;
cl.add(c1);
for(int i=0; i<isize(cl.lst); i++) {
cell *c2 = cl.lst[i];
transmatrix T = calc_relative_matrix(c2, c1, C0);
if(hypot_d(WDIM, inverse_exp(shiftless(tC0(T)))) <= check_range) {
relmatrices[c1][c2] = T;
forCellEx(c3, c2) cl.add(c3);
}
}
}
printf("setting up...\n");
for(int i=0; i<N; i++) {
vertexdata& vd = vdata[i];
// set initial base and at to random cell and random position there
createViz(i, v[hrand(isize(v))], Id);
rotate_object(vd.m->pat.T, vd.m->ori, random_spin());
apply_parallel_transport(vd.m->pat.T, vd.m->ori, xtangent(hrand(100) / 200.));
vd.name = its(i+1);
vd.cp = dftcolor;
vd.cp.color2 = ((hrand(0x1000000) << 8) + 0xFF) | 0x808080FF;
vd.cp.shade = shape;
vd.m->vel = ini_speed;
}
storeall();
printf("done\n");
}
auto hooks = addHook(hooks_args, 100, readArgs);
#endif
}

View File

@ -11,40 +11,37 @@ namespace fullnet {
int fullnet_id;
void drawExtra() {
if(vizid == &fullnet_id) {
for(map<cell*, shiftmatrix>::iterator it = gmatrix.begin(); it != gmatrix.end(); it++) {
cell *c = it->first;
c->wall = waChasm;
}
int index = 0;
for(map<cell*, shiftmatrix>::iterator it = gmatrix.begin(); it != gmatrix.end(); it++) {
cell *c = it->first;
bool draw = true;
for(int i=0; i<isize(named); i++) if(named[i] == c) draw = false;
if(draw && gmatrix.count(c))
queuedisk(it->second, dftcolor, false, NULL, index++);
// queuepolyat(it->second, shDisk, dftcolor., PPR::LINE);
}
for(int i=0; i<isize(named); i++) if(gmatrix.count(named[i])) {
string s = ""; s += 'A'+i;
queuestr(gmatrix[named[i]], 1, s, forecolor, 1);
}
canmove = true; items[itOrbAether] = true;
void drawExtra() {
for(map<cell*, shiftmatrix>::iterator it = gmatrix.begin(); it != gmatrix.end(); it++) {
cell *c = it->first;
c->wall = waChasm;
}
int index = 0;
for(map<cell*, shiftmatrix>::iterator it = gmatrix.begin(); it != gmatrix.end(); it++) {
cell *c = it->first;
bool draw = true;
for(int i=0; i<isize(named); i++) if(named[i] == c) draw = false;
if(draw && gmatrix.count(c))
queuedisk(it->second, dftcolor, false, NULL, index++);
// queuepolyat(it->second, shDisk, dftcolor., PPR::LINE);
}
for(int i=0; i<isize(named); i++) if(gmatrix.count(named[i])) {
string s = ""; s += 'A'+i;
queuestr(gmatrix[named[i]], 1, s, forecolor, 1);
}
canmove = true; items[itOrbAether] = true;
}
auto hooks =
addHook(hooks_frame, 0, drawExtra) +
addHook(hooks_args, 100, [] {
using namespace arg;
if(argis("-net")) {
PHASE(3);
init(&fullnet_id, 0);
rv_hook(hooks_frame, 0, drawExtra);
linepatterns::patTriTree.color = 0x30;
linepatterns::patTriOther.color = 0x10;
linepatterns::patTriRings.color = 0xFF;

View File

@ -11,6 +11,8 @@ namespace rogueviz {
namespace sag {
bool turn(int delta);
int sag_id;
int sagpar = 0;
@ -421,6 +423,18 @@ namespace sag {
void read(string fn) {
fname = fn;
init(&sag_id, RV_GRAPH | RV_WHICHWEIGHT | RV_AUTO_MAXWEIGHT | RV_HAVE_WEIGHT);
rv_hook(rogueviz::hooks_close, 100, [] { sag::sagedges.clear(); });
rv_hook(shmup::hooks_turn, 100, turn);
rv_hook(rogueviz::hooks_rvmenu, 100, [] {
dialog::addSelItem(XLAT("temperature"), fts(sag::temperature), 't');
dialog::add_action([] {
dialog::editNumber(sag::temperature, sag::lowtemp, sag::hightemp, 1, 0, XLAT("temperature"), "");
});
dialog::addSelItem(XLAT("SAG mode"), sag::sagmodes[sag::sagmode], 'm');
dialog::add_action([] { sag::sagmode = sag::eSagmode( (1+sag::sagmode) % 3 ); });
});
weight_label = "min weight";
temperature = 0; sagmode = sagOff;
readsag(fname.c_str());
@ -537,7 +551,6 @@ int readArgs() {
}
bool turn(int delta) {
if(vizid == &sag_id) sag::iterate(), timetowait = 0;
return false;
// shmup::pc[0]->rebase();
}
@ -549,17 +562,6 @@ string cname() {
}
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(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"), "");
});
dialog::addSelItem(XLAT("SAG mode"), sag::sagmodes[sag::sagmode], 'm');
dialog::add_action([] { sag::sagmode = sag::eSagmode( (1+sag::sagmode) % 3 ); });
})
+ addHook(pres::hooks_build_rvtour, 120, [] (string s, vector<tour::slide>& v) {
if(s != "data") return;
using namespace pres;

View File

@ -21,6 +21,8 @@ namespace spiral {
void place(int N, ld _mul) {
mul = _mul;
init(&spiral_id, RV_GRAPH | RV_HAVE_WEIGHT | RV_INVERSE_WEIGHT);
rv_hook(hooks_alt_edges, 100, spiral_altedge);
rv_hook(hooks_frame, 0, drawExtra);
weight_label = "extent";
vdata.resize(N);
@ -65,7 +67,7 @@ namespace spiral {
}
bool spiral_altedge(edgeinfo* ei, bool store) {
bool onspiral = (vizid == &spiral::spiral_id) && abs(ei->i - ei->j) == 1;
bool onspiral = abs(ei->i - ei->j) == 1;
if(onspiral) {
const int prec = 20;
@ -88,8 +90,6 @@ bool spiral_altedge(edgeinfo* ei, bool store) {
}
auto hooks =
addHook(hooks_frame, 0, drawExtra) +
addHook(hooks_alt_edges, 100, spiral_altedge) +
addHook(hooks_args, 100, [] {
using namespace arg;