rogueviz::magiccube:: using rv_hook

This commit is contained in:
Zeno Rogue 2021-03-31 00:08:20 +02:00
parent bb5eaf0fc5
commit fbea016f03
2 changed files with 48 additions and 39 deletions

View File

@ -35,23 +35,6 @@ void build(crystal::coord co, int at) {
}
void magic(int sides) {
stop_game();
if(sides < 0)
set_geometry(gCrystal344);
else
crystal::set_crystal(sides);
set_variation(eVariation::pure);
firstland = specialland = laCanvas;
patterns::whichCanvas = 'g';
patterns::canvasback = back;
check_cgi();
start_game();
build(crystal::c0, 0);
vizid = (void*) &magic;
}
void curveline(hyperpoint a, hyperpoint b, int lev) {
if(lev>0) {
hyperpoint c = mid(a, b);
@ -62,7 +45,6 @@ void curveline(hyperpoint a, hyperpoint b, int lev) {
}
bool magic_markers(cell *c, const shiftmatrix& V) {
if(vizid != (void*) &magic) return false;
timerghost = false;
if(c->landparam == back) {
if(GDIM == 2) {
@ -91,22 +73,6 @@ bool magic_markers(cell *c, const shiftmatrix& V) {
return false;
}
int readArgs() {
using namespace arg;
if(0) ;
else if(argis("-magic")) {
PHASEFROM(2);
shift(); magic(argi());
}
else if(argis("-magic3")) {
PHASEFROM(2);
magic(-1);
}
else return 1;
return 0;
}
void twos_to_fours(vector<int>& zeros, crystal::coord co, int d) {
if(d == crystal::get_dim()) {
int facetable[5][5];
@ -133,7 +99,6 @@ void twos_to_fours(vector<int>& zeros, crystal::coord co, int d) {
}
bool magic_rotate(cell *c) {
if(vizid != (void*) &magic) return false;
if(c->landparam != back) return false;
vector<int> zeros;
auto co = crystal::get_coord(c->master);
@ -151,7 +116,6 @@ bool magic_rotate(cell *c) {
}
bool magic_rugkey(int sym, int uni) {
if(vizid != (void*) &magic) return false;
if((cmode & sm::NORMAL) && uni == 'p') {
rug::texturesize = 4096;
if(rug::rugged) rug::close();
@ -172,9 +136,43 @@ bool magic_rugkey(int sym, int uni) {
return false;
}
auto magichook = addHook(hooks_args, 100, readArgs) + addHook(hooks_drawcell, 100, magic_markers)
+ addHook(mine::hooks_mark, 150, magic_rotate)
+ addHook(hooks_handleKey, 150, magic_rugkey);
void magic(int sides) {
stop_game();
if(sides < 0)
set_geometry(gCrystal344);
else
crystal::set_crystal(sides);
set_variation(eVariation::pure);
firstland = specialland = laCanvas;
patterns::whichCanvas = 'g';
patterns::canvasback = back;
check_cgi();
start_game();
build(crystal::c0, 0);
rv_hook(hooks_drawcell, 100, magic_markers);
rv_hook(mine::hooks_mark, 150, magic_rotate);
rv_hook(hooks_handleKey, 150, magic_rugkey);
}
int readArgs() {
using namespace arg;
if(0) ;
else if(argis("-magic")) {
PHASEFROM(2);
shift(); magic(argi());
}
else if(argis("-magic3")) {
PHASEFROM(2);
magic(-1);
}
else return 1;
return 0;
}
auto magichook = addHook(hooks_args, 100, readArgs);
}
#endif

View File

@ -98,6 +98,17 @@ namespace rogueviz {
extern vector<vertexdata> vdata;
void storeall(int from = 0);
extern vector<reaction_t> cleanup;
template<class T, class U> void rv_hook(hookset<T>& m, int prio, U&& hook) {
int p = addHook(m, prio, hook);
auto del = [&m, p] {
delHook(m, p);
};
if(tour::on) tour::on_restore(del);
else cleanup.push_back(del);
}
namespace anygraph {
extern double R, alpha, T;