diff --git a/hyper.h b/hyper.h index c3837427..a2bbbf1d 100644 --- a/hyper.h +++ b/hyper.h @@ -4030,5 +4030,18 @@ string bygen(reaction_t h); void open_url(string s); #endif +namespace mapstream { + extern FILE *f; + + inline void saveChar(char c) { fwrite(&c, 1, 1, f); } + template void save(T& c) { fwrite(&c, sizeof(T), 1, f); } + + inline char loadChar() { char c; int i=fread(&c, 1, 1, f); if(i!=1) return 0; else return c; } + template int load(T& c) { return fread(&c, sizeof(T), 1, f); } + inline int32_t loadInt() { int i; if(load(i) < 1) return -1; else return i; } + void saveString(const string& s); + string loadString(); + } + } diff --git a/mapeditor.cpp b/mapeditor.cpp index 89f30e00..0c8d4e22 100644 --- a/mapeditor.cpp +++ b/mapeditor.cpp @@ -74,13 +74,38 @@ namespace mapeditor { #endif } -#if CAP_EDIT namespace mapstream { + FILE *f; + + void savePoint(const hyperpoint& h) { + for(int i=0; i<3; i++) { double x = h[i]; save(x); } + } + + hyperpoint loadPoint() { + hyperpoint h; + for(int i=0; i<3; i++) { double x; load(x); h[i] = x; } + return h; + } + + void saveString(const string& s) { + saveChar(isize(s)); + for(char c: s) saveChar(c); + } + + string loadString() { + string s; + int l = loadChar(); + for(int i=0; i cellids; vector cellbyid; vector relspin; - FILE *f; void addToQueue(cell* c) { if(cellids.count(c)) return; @@ -89,23 +114,6 @@ namespace mapstream { cellids[c] = numcells; } - void saveChar(char c) { fwrite(&c, 1, 1, f); } - template void save(T& c) { fwrite(&c, sizeof(T), 1, f); } - - char loadChar() { char c; int i=fread(&c, 1, 1, f); if(i!=1) return 0; else return c; } - template int load(T& c) { return fread(&c, sizeof(T), 1, f); } - int32_t loadInt() { int i; if(load(i) < 1) return -1; else return i; } - - void savePoint(const hyperpoint& h) { - for(int i=0; i<3; i++) { double x = h[i]; save(x); } - } - - hyperpoint loadPoint() { - hyperpoint h; - for(int i=0; i<3; i++) { double x; load(x); h[i] = x; } - return h; - } - bool saveMap(const char *fname) { f = fopen(fname, "wb"); if(!f) return false; @@ -131,12 +139,7 @@ namespace mapstream { save(fgeomextras[current_extra].current_prime_id); } } - if(geometry == gArchimedean) { - const string& symbol = arcm::current.symbol; - char size = isize(symbol); - save(size); - for(int i=0; igamestart() : cwt.at->master->c7); for(int i=0; i 0) { printf("Errors! %s\n", arcm::current.errormsg.c_str()); @@ -356,8 +356,8 @@ namespace mapstream { return true; } - } #endif + } namespace mapeditor { diff --git a/rogueviz-kohonen.cpp b/rogueviz-kohonen.cpp index 9365ca21..f9d95463 100644 --- a/rogueviz-kohonen.cpp +++ b/rogueviz-kohonen.cpp @@ -69,7 +69,7 @@ double vnorm(kohvec& a, kohvec& b) { return diff; } -void sominit(int); +void sominit(int, bool load_compressed = false); void uninit(int); bool noshow = false; @@ -497,8 +497,6 @@ int krad; double ttpower = 1; -void sominit(int); - void step() { if(t == 0) return; @@ -627,11 +625,11 @@ void showbestsamples() { int kohrestrict = 1000000; -void sominit(int initto) { +void sominit(int initto, bool load_compressed) { if(inited < 1 && initto >= 1) { inited = 1; - if(!samples) { + if(!samples && !load_compressed) { fprintf(stderr, "Error: SOM without samples\n"); exit(1); } @@ -660,6 +658,7 @@ void sominit(int initto) { net[i].where->land = laCanvas; alloc(net[i].net); + if(samples) for(int k=0; k saved_id; + int ss = isize(sample_vdata_id); + mapstream::save(ss); + int index = 0; + for(auto p: sample_vdata_id) { + int i = p.first; + for(int j=0; jname); + saveFloat(et->visible_from); + mapstream::save(et->color); + } + // save edge infos + int qei = isize(edgeinfos); + mapstream::save(qei); + for(auto& ei: edgeinfos) { + for(int x=0; xtype == &*edgetypes[x]) mapstream::saveChar(x); + mapstream::save(saved_id[ei->i]); + mapstream::save(saved_id[ei->j]); + saveFloat(ei->weight); + } + fclose(mapstream::f); + } + +void load_compressed(string name) { + // save everything in compressed form + mapstream::f = fopen(name.c_str(), "rb"); + if(!mapstream::f) { + printf("failed to open for load_compressed: %s\n", name.c_str()); + return; + } + // load columns + mapstream::load(columns); + colnames.resize(columns); + for(int i=0; istore(); + id++; + } + // load edge types + int qet = mapstream::loadInt(); + for(int i=0; ivisible_from = loadFloat(); + mapstream::load(et->color); + } + // load edge infos + int qei = mapstream::loadInt(); + for(int i=0; ivisible_from *= d; } + else if(argis("-som-save-compressed")) { + shift(); + save_compressed(args()); + } + else if(argis("-som-load-compressed")) { + shift(); + load_compressed(args()); + } else return 1; return 0;