From 3791daf9e374d7352e1b4cd10964259d590c4954 Mon Sep 17 00:00:00 2001 From: Zeno Rogue Date: Sat, 23 Mar 2024 21:21:16 +0100 Subject: [PATCH] map editor now can save irregular maps (also should save modes too) --- irregular.cpp | 80 ++++++++++++++++++++++++++++++++++++++++++++++++--- mapeditor.cpp | 6 ++++ 2 files changed, 82 insertions(+), 4 deletions(-) diff --git a/irregular.cpp b/irregular.cpp index 56527105..2007dabc 100644 --- a/irregular.cpp +++ b/irregular.cpp @@ -770,7 +770,7 @@ EX int celldist(cell *c, bool alts) { return hi.celldists[alts][cells[cellindex[c]].localindex]; } -eGeometry orig_geometry; +eGeometry orig_geometry, base_geometry; void start_game_on_created_map() { popScreen(); @@ -807,6 +807,31 @@ bool save_map(const string& fname) { return true; } +EX void save_map_bin(hstream& f) { + auto& all = base->allcells(); + int origcells = 0; + for(cellinfo& ci: cells) + if(ci.generation == 0) + origcells++; + f.write (base_geometry); + f.write (isize(all)); + f.write (origcells); + + for(auto h: all) { + origcells = 0; + for(auto i: cells_of_heptagon[h->master]) + if(cells[i].generation == 0) + origcells++; + f.write (origcells); + for(auto i: cells_of_heptagon[h->master]) if(cells[i].generation == 0) { + auto &ci = cells[i]; + f.write(ci.p[0]); + f.write(ci.p[1]); + f.write(ci.p[LDIM]); + } + } + } + bool load_map(const string &fname) { fhstream f(fname, "rt"); if(!f.f) return false; @@ -839,6 +864,47 @@ bool load_map(const string &fname) { return true; } +EX void load_map_bin(hstream& f) { + auto& all = base->allcells(); + eGeometry g = (eGeometry) f.get(); + int sa = f.get(); + cellcount = f.get(); + + if(g != geometry) throw hstream_exception("bad geometry"); + if(sa != isize(all)) throw hstream_exception("bad size of all"); + density = cellcount * 1. / isize(all); + + cells.clear(); + + for(auto h: all) { + int q = f.get(); + if(q < 0 || q > cellcount) throw hstream_exception("incorrect quantity"); + while(q--) { + cells.emplace_back(); + cellinfo& s = cells.back(); + s.patterndir = -1; + double a, b, c; + a = f.get(); + b = f.get(); + c = f.get(); + s.p = hpxyz(a, b, c); + s.p = normalize(s.p); + for(auto c0: all) s.relmatrices[c0] = calc_relative_matrix(c0, h, s.p); + s.owner = h; + } + } + + make_cells_of_heptagon(); + runlevel = 2; + } + +EX void load_map_full(hstream& f) { + init(); + load_map_bin(f); + while(runlevel < 10) step(1000); + start_game_on_created_map(); + } + void cancel_map_creation() { base = NULL; runlevel = 0; @@ -950,7 +1016,7 @@ void show_gridmaker() { }; } -EX void visual_creator() { +EX void init() { stop_game(); orig_geometry = geometry; switch(geometry) { @@ -966,13 +1032,19 @@ EX void visual_creator() { break; } + base_geometry = geometry; variation = eVariation::pure; start_game(); if(base) delete base; base = currentmap; base_config = euc::eu; - drawthemap(); cellcount = int(isize(base->allcells()) * density + .5); + gridmaking = true; + drawthemap(); + } + +EX void visual_creator() { + init(); pushScreen(show_gridmaker); runlevel = 0; gridmaking = true; @@ -1015,7 +1087,7 @@ int readArgs() { else if(argis("-irrload")) { PHASE(3); restart_game(); - visual_creator(); + init(); showstartmenu = false; shift(); load_map(args()); diff --git a/mapeditor.cpp b/mapeditor.cpp index dd1e8761..5da37fe7 100644 --- a/mapeditor.cpp +++ b/mapeditor.cpp @@ -491,6 +491,9 @@ EX namespace mapstream { f.write(gp::param.second); } #endif + #if CAP_IRR + if(IRREGULAR) irr::save_map_bin(f); + #endif #if MAXMDIM >= 4 if(variation == eVariation::coxeter) { f.write(reg3::coxeter_param); @@ -587,6 +590,9 @@ EX namespace mapstream { f.read(gp::param.second); } #endif + #if CAP_IRR + if(IRREGULAR) { irr::load_map_full(f); stop_game(); } + #endif #if MAXMDIM >= 4 if(variation == eVariation::coxeter && vernum >= 0xA908) { f.read(reg3::coxeter_param);