1
0
mirror of https://github.com/zenorogue/hyperrogue.git synced 2024-12-24 01:00:25 +00:00

expansion_analyzer is now in cgi

This commit is contained in:
Zeno Rogue 2021-12-11 23:28:05 +01:00
parent cfcd8a5e57
commit 5d81260f0b
10 changed files with 28 additions and 11 deletions

View File

@ -1814,7 +1814,7 @@ EX void buildCamelot(cell *c) {
c->monst = camelot_monster();
if(d == 1) {
// roughly as many knights as table cells
if(hrand(1000000) < 1000000 / expansion.get_growth() && !reptilecheat)
if(hrand(1000000) < 1000000 / get_expansion().get_growth() && !reptilecheat)
c->monst = moKnight;
if(!eubinary) for(int i=0; i<c->master->type; i++) currentmap->extend_altmap(c->master->move(i));
for(int i=0; i<c->type; i++)

View File

@ -1003,6 +1003,7 @@ EX namespace clearing {
cell *c1 = c;
if(c->mondir < c->type)
c1 = c->move(c->mondir);
auto& expansion = get_expansion();
return make_tuple(
celldistAlt(c), type_in(expansion, c, celldistAlt),
celldistAlt(c1), type_in(expansion, c1, celldistAlt)

View File

@ -460,7 +460,7 @@ EX void knightFlavorMessage(cell *c2) {
s = crystal::get_table_boundary();
#endif
else if(!quotient && rad)
s = expansion.get_descendants(rad).get_str(100);
s = get_expansion().get_descendants(rad).get_str(100);
if(s == "") { msgid++; goto retry; }
addMessage(XLAT("\"Our Table seats %1 Knights!\"", s));
}
@ -472,7 +472,7 @@ EX void knightFlavorMessage(cell *c2) {
s = crystal::get_table_volume();
#endif
else if(!quotient && rad)
s = expansion.get_descendants(rad-1, expansion.diskid).get_str(100);
s = get_expansion().get_descendants(rad-1, get_expansion().diskid).get_str(100);
if(s == "") { msgid++; goto retry; }
addMessage(XLAT("\"There are %1 floor tiles inside our Table!\"", s));
}

View File

@ -23,6 +23,7 @@ void canonicize(vector<int>& t) {
#if HDR
struct expansion_analyzer {
int sibling_limit;
vector<int> gettype(cell *c);
int N;
vector<cell*> samples;
@ -456,6 +457,7 @@ int position;
EX int type_in_reduced(expansion_analyzer& ea, cell *c, const cellfunction& f) {
int a = ea.N;
int t = type_in(ea, c, f);
auto& expansion = get_expansion();
if(expansion.N != a) {
expansion.reduce_grouping();
t = type_in(ea, c, f);
@ -598,7 +600,7 @@ void celldrawer::do_viewdist() {
if(c->master->alt) t = c->master->alt->fieldval;
break;
}
else t = type_in_reduced(expansion, c, curr_dist);
else t = type_in_reduced(get_expansion(), c, curr_dist);
if(t >= 0) label = its(t), dc = distribute_color(t);
break;
}
@ -727,6 +729,7 @@ void expansion_analyzer::view_distances_dialog() {
int maxlen = bounded ? 128 : 16 + first_distance;
vector<bignum> qty(maxlen);
auto& expansion = get_expansion();
bool really_use_analyzer = use_analyzer && sizes_known();
@ -826,6 +829,7 @@ void compute_coefficients() {
println(hlog, gp::operation_name(), " ", ginf[geometry].tiling_name);
start_game();
auto& expansion = get_expansion();
printf(" sizes:");
for(int i=0; i<expansion.valid_from+10; i++) printf(" %d", expansion.get_descendants(i).approx_int());
@ -847,6 +851,7 @@ int expansion_readArgs() {
else if(argis("-vap")) {
PHASEFROM(2);
start_game();
auto& expansion = get_expansion();
shift(); int radius = argi();
while(true) {
string s = expansion.approximate_descendants(radius, 100);
@ -857,6 +862,7 @@ int expansion_readArgs() {
else if(argis("-csizes")) {
PHASEFROM(2);
start_game();
auto& expansion = get_expansion();
expansion.get_growth();
shift(); for(int i=0; i<argi(); i++)
printf("%s / %s\n", expansion.get_descendants(i).get_str(1000).c_str(), expansion.get_descendants(i, expansion.diskid).get_str(1000).c_str());
@ -864,6 +870,7 @@ int expansion_readArgs() {
else if(argis("-csolve")) {
PHASEFROM(2);
start_game();
auto& expansion = get_expansion();
printf("preliminary_grouping...\n");
expansion.preliminary_grouping();
printf("N = %d\n", expansion.N);
@ -949,11 +956,13 @@ auto ea_hook = addHook(hooks_args, 100, expansion_readArgs);
#endif
#endif
EX expansion_analyzer expansion;
EX int sibling_limit = 0;
EX expansion_analyzer& get_expansion() {
if(!cgi.expansion) cgi.expansion = make_shared<expansion_analyzer> ();
return *cgi.expansion;
}
EX void set_sibling_limit() {
auto& sibling_limit = get_expansion().sibling_limit;
if(0) ;
#if CAP_IRR
else if(IRREGULAR) sibling_limit = 3;
@ -1006,6 +1015,7 @@ EX int hyperbolic_celldistance(cell *c1, cell *c2) {
int found_distance = INF;
int d = 0, d1 = celldist0(c1), d2 = celldist0(c2), sl_used = 0;
auto& sibling_limit = get_expansion().sibling_limit;
cell *cl1=c1, *cr1=c1, *cl2=c2, *cr2=c2;
while(true) {

View File

@ -107,6 +107,8 @@ struct gi_extension {
virtual ~gi_extension() {}
};
struct expansion_analyzer;
/** both for 'heptagon' 3D cells and subdivided 3D cells */
struct subcellshape {
/** \brief raw coordinates of vertices of all faces */
@ -499,6 +501,8 @@ hpcshape
};
shared_ptr<gpdata_t> gpdata = nullptr;
#endif
shared_ptr<expansion_analyzer> expansion = nullptr;
int state = 0;
int usershape_state = 0;

View File

@ -876,6 +876,7 @@ EX pathgen generate_random_path(cellwalker start, int length, bool for_yendor, b
cellwalker ycw = start;
if(for_yendor) setdist(p.path[0], 7, NULL);
auto& expansion = get_expansion();
for(int i=0; i<length; i++) {
@ -939,7 +940,7 @@ EX pathgen generate_random_path(cellwalker start, int length, bool for_yendor, b
t = type_in(expansion, randomdir ? start.at : start.cpeek(), sdist);
ycw--;
if(valence() == 3) ycw--;
bignum b = expansion.get_descendants(randomdir ? length : length-1, t);
bignum b = get_expansion().get_descendants(randomdir ? length : length-1, t);
p.full_id_0 = full_id = hrand(b);
}

View File

@ -412,7 +412,7 @@ EX void drawStats() {
if(nohud) return;
if(callhandlers(false, hooks_prestats)) return;
if(viewdists && show_distance_lists)
expansion.view_distances_dialog();
get_expansion().view_distances_dialog();
if(current_display->sidescreen) return;
first_cell_to_draw = true;

View File

@ -254,7 +254,7 @@ EX hint hints[] = {
[]() { return !canmove && sizes_known() && celldist(cwt.at) >= 50; },
[]() {
int d = celldist(cwt.at);
string s = expansion.approximate_descendants(d, 10000);
string s = get_expansion().approximate_descendants(d, 10000);
dialog::addHelp(XLAT(
"You are %1 cells away from the starting point, or "
"the place where you used an Orb of Safety last time. "

View File

@ -1561,7 +1561,7 @@ EX void start_game() {
arcm::current_or_fake().compute_geometry();
#endif
initcells();
expansion.reset();
get_expansion().reset();
if(randomPatternsMode) {
for(int i=0; i<landtypes; i++) {

View File

@ -317,6 +317,7 @@ EX namespace yendor {
if(key->land == laWestWall && trees_known()) {
auto& expansion = get_expansion();
int t = type_in(expansion, yendor, [yendor] (cell *c) { return celldistance(yendor, c); });
int maxage = 10;
for(int i=0; i<min(items[itOrbYendor], 8); i++)