mirror of
https://github.com/zenorogue/hyperrogue.git
synced 2026-01-01 18:09:04 +00:00
rogueviz:: dhrg:: modern saving/loading
This commit is contained in:
@@ -65,7 +65,6 @@ void clear() {
|
||||
void dhrg_init() {
|
||||
if(!mroot) {
|
||||
println(hlog, "DHRG version " DHRGVER "\n");
|
||||
rogueviz::init(0);
|
||||
rogueviz::rv_hook(hooks_handleKey, 100, dhrg_animate);
|
||||
regular_info();
|
||||
generate_root();
|
||||
@@ -82,14 +81,7 @@ bool stored;
|
||||
int dhrgArgs() {
|
||||
using namespace arg;
|
||||
|
||||
if(argis("-dhrg")) {
|
||||
PHASE(3); dhrg_init(); graph_from_rv();
|
||||
next_timestamp++;
|
||||
ts_rogueviz = next_timestamp;
|
||||
ts_vertices = next_timestamp;
|
||||
}
|
||||
|
||||
else if(argis("-analyze_grid")) {
|
||||
if(argis("-analyze_grid")) {
|
||||
PHASE(3); shift(); dhrg_init(); do_analyze_grid(argi());
|
||||
}
|
||||
|
||||
@@ -149,7 +141,7 @@ int dhrgArgs() {
|
||||
shift(); ground_truth_test(args());
|
||||
}
|
||||
|
||||
else if(argis("-eload")) {
|
||||
else if(argis("-el-dhrg")) {
|
||||
PHASE(3); shift(); dhrg_init(); load_embedded(args());
|
||||
next_timestamp++;
|
||||
ts_rogueviz = next_timestamp;
|
||||
|
||||
@@ -224,6 +224,15 @@ struct dhrg_embedding : public rogueviz::embeddings::tiled_embedding {
|
||||
ld zero_distance(int i) override {
|
||||
return vertices[i]->lev;
|
||||
}
|
||||
|
||||
void save(fhstream& f) override {
|
||||
int N = isize(rogueviz::vdata);
|
||||
for(int i=0; i<N; i++) {
|
||||
string p = get_path(vertices[i]);
|
||||
if(p == "") p = "X";
|
||||
println(f, rogueviz::vdata[i].name.c_str(), " ", p.c_str());
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
void graph_from_rv() {
|
||||
@@ -237,17 +246,17 @@ void graph_from_rv() {
|
||||
progressbar pb(N, "Translating to cells");
|
||||
|
||||
for(int i=0; i<N; i++) {
|
||||
hyperpoint T0 = rogueviz::embeddings::current->as_hyperpoint(i);
|
||||
#if BUILD_ON_HR
|
||||
cell *c = currentmap->gamestart();
|
||||
hyperpoint T0 = vdata[i].m->at * C0;
|
||||
virtualRebase2(vdata[i].m->base, T0, true);
|
||||
vertices[i] = find_mycell(vdata[i].m->base);
|
||||
#else
|
||||
vertices[i] = find_mycell_by_path(computePath(vdata[i].m->at));
|
||||
vertices[i] = find_mycell_by_path(computePath(T0));
|
||||
#endif
|
||||
vdata[i].m->at = Id;
|
||||
pb++;
|
||||
// printf("%s\n", computePath(vdata[i].m->base).c_str());
|
||||
// printf("%s %s\n", vdata[i].name.c_str(), computePath(vdata[i].m->base).c_str());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -284,44 +293,28 @@ void embedder_loop(int max) {
|
||||
}
|
||||
}
|
||||
|
||||
void save_embedding(const string s) {
|
||||
FILE *f = fopen(s.c_str(), "wt");
|
||||
int N = isize(rogueviz::vdata);
|
||||
for(int i=0; i<N; i++) {
|
||||
string p = get_path(vertices[i]);
|
||||
if(p == "") p = "X";
|
||||
fprintf(f, "%s %s\n", rogueviz::vdata[i].name.c_str(), p.c_str());
|
||||
}
|
||||
fclose(f);
|
||||
}
|
||||
|
||||
void load_embedded(const string& s) {
|
||||
|
||||
|
||||
if(s == "-") return graph_from_rv();
|
||||
|
||||
if(true) {
|
||||
int N = isize(rogueviz::vdata);
|
||||
progressbar pb(N, "reading embedding");
|
||||
vertices.resize(N, NULL);
|
||||
|
||||
map<string, int> ids;
|
||||
for(int i=0; i<N; i++) ids[rogueviz::vdata[i].name] = i;
|
||||
|
||||
FILE *f = fopen(s.c_str(), "rt");
|
||||
fhstream f(s, "rt");
|
||||
while(true) {
|
||||
char who[500], where[500];
|
||||
who[0] = 0;
|
||||
if(fscanf(f, "%s%s", who, where) < 0) throw hstream_exception("error loading embedding");
|
||||
if(who[0] == 0) break;
|
||||
if(!ids.count(who)) printf("unknown vertex: %s\n", who);
|
||||
string wh = where;
|
||||
if(wh == "X") wh = "";
|
||||
vertices[ids[who]] = find_mycell_by_path(wh);
|
||||
string who = scan<string>(f);
|
||||
if(who == "") break;
|
||||
string where = scan<string>(f);
|
||||
if(where == "X") where = "";
|
||||
vertices[rogueviz::labeler.at(who)] = find_mycell_by_path(where);
|
||||
pb++;
|
||||
}
|
||||
fclose(f);
|
||||
|
||||
for(int i=0; i<N; i++) if(vertices[i] == NULL) {
|
||||
printf("unmapped: %s\n", rogueviz::vdata[i].name.c_str());
|
||||
exit(1);
|
||||
throw hr_exception("unmapped vertex");
|
||||
}
|
||||
}
|
||||
preparegraph();
|
||||
|
||||
@@ -37,14 +37,13 @@ void recycle_compute_map() {
|
||||
}
|
||||
}
|
||||
|
||||
string computePath(const transmatrix& T) {
|
||||
string computePath(hyperpoint T0) {
|
||||
if(recycle_counter >= 1000)
|
||||
recycle_compute_map();
|
||||
if(!mapptr) mapptr = bt::in() ? bt::new_map() : new hrmap_hyperbolic;
|
||||
recycle_counter++;
|
||||
dynamicval<hrmap*> dv (currentmap, mapptr);
|
||||
cell *c = mapptr->gamestart();
|
||||
hyperpoint T0 = T * C0;
|
||||
// call HyperRogue's function virtualRebase:
|
||||
// a point in the hyperbolic plane is given by cell c and point T0 relative to c
|
||||
// change c and T0 so that the same point is specified, but with minimal T0
|
||||
|
||||
Reference in New Issue
Block a user