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

more header shifting

This commit is contained in:
Zeno Rogue 2019-08-09 21:18:13 +02:00
parent 1c6b8ad3f0
commit cb666fb24a
11 changed files with 278 additions and 309 deletions

View File

@ -6,6 +6,70 @@ namespace hr {
EX namespace arcm {
#if HDR
struct archimedean_tiling {
int coloring;
string symbol;
vector<int> faces;
vector<int> adj;
vector<bool> invert;
vector<int> nflags;
bool have_ph, have_line, have_symmetry;
int real_faces;
int real_face_type;
int repetition;
int N;
ld euclidean_angle_sum;
vector<int> flags;
vector<vector<pair<int, int>>> adjacent;
vector<vector<pair<ld, ld>>> triangles;
void make_match(int a, int i, int b, int j);
void prepare();
void compute_geometry();
void parse();
void parse(string s) { symbol = s; parse(); }
ld edgelength;
vector<ld> inradius, circumradius, alphas;
int matches[30][30];
int periods[30];
int tilegroup[30], groupoffset[30], tilegroups;
int errors;
string errormsg;
pair<int, int>& get_adj(heptagon *h, int cid);
pair<int, int>& get_adj(heptspin hs) { return get_adj(hs.at, hs.spin); }
pair<ld, ld>& get_triangle(heptagon *h, int cid);
pair<ld, ld>& get_triangle(heptspin hs) { return get_triangle(hs.at, hs.spin); }
pair<ld, ld>& get_triangle(const pair<int, int>& p, int delta = 0);
pair<int, int>& get_adj(const pair<int, int>& p, int delta = 0);
int support_threecolor();
int support_threecolor_bitruncated();
int support_football();
bool support_chessboard();
void regroup();
string world_size();
eGeometryClass get_class();
ld scale();
};
#endif
#if CAP_ARCM
static const int sfPH = 1;
@ -351,7 +415,7 @@ ld archimedean_tiling::scale() {
map<heptagon*, vector<pair<heptagon*, transmatrix> > > altmap;
map<heptagon*, pair<heptagon*, transmatrix>> archimedean_gmatrix;
EX map<heptagon*, pair<heptagon*, transmatrix>> archimedean_gmatrix;
hrmap *current_altmap;
@ -703,7 +767,7 @@ transmatrix adjcell_matrix(heptagon *h, int d) {
return spin(-t1.first) * xpush(t1.second) * spin(M_PI + t2.first);
}
int fix(heptagon *h, int spin) {
EX int fix(heptagon *h, int spin) {
int type = isize(current.adjacent[id_of(h)]);
spin %= type;
if(spin < 0) spin += type;

View File

@ -12,6 +12,10 @@ struct snowball {
snowball(int t) { T = rgpushxto0(randomPointIn(t)); phase = randd(); }
};
#if HDR
struct blizzardcell;
#endif
struct blizzardcell {
cell *c;
int frame;
@ -25,17 +29,17 @@ struct blizzardcell {
~blizzardcell() { for(auto i: inorder) delete i; }
};
map<cell*, blizzardcell> blizzardcells;
EX map<cell*, blizzardcell> blizzardcells;
EX void set_blizzard_frame(cell *c, int frameid) {
blizzardcells[c].frame = frameid;
}
vector<blizzardcell*> bcells;
EX vector<blizzardcell*> bcells;
int blizzard_N;
blizzardcell* getbcell(cell *c) {
EX blizzardcell* getbcell(cell *c) {
int i = c->listindex;
if(i<0 || i >= blizzard_N) return NULL;
if(bcells[i]->c != c) return NULL;
@ -205,7 +209,7 @@ EX void drawBlizzards() {
#endif
}
vector<cell*> arrowtraps;
EX vector<cell*> arrowtraps;
EX void drawArrowTraps() {
for(cell *c: arrowtraps) {

View File

@ -2213,7 +2213,7 @@ EX int read_gamemode_args() {
auto ah_config = addHook(hooks_args, 0, read_config_args) + addHook(hooks_args, 0, read_gamemode_args) + addHook(hooks_args, 0, read_color_args);
#endif
unordered_map<string, ld&> params = {
EX unordered_map<string, ld&> params = {
{"linewidth", vid.linewidth},
{"patternlinewidth", linepatterns::width},
{"scale", vid.scale},

View File

@ -7,6 +7,61 @@ int subtype(cell *c) {
return patterns::getpatterninfo(c, patterns::PAT_NONE, 0).id;
}
#if HDR
struct bignum {
static const int BASE = 1000000000;
static const long long BASE2 = BASE * (long long)BASE;
vector<int> digits;
bignum() {}
bignum(int i) : digits() { digits.push_back(i); }
void be(int i) { digits.resize(1); digits[0] = i; }
bignum& operator +=(const bignum& b);
void addmul(const bignum& b, int factor);
string get_str(int max_length);
bool operator < (const bignum&) const;
ld leading() const {
switch(isize(digits)) {
case 0:
return 0;
case 1:
return digits.back();
default:
return digits.back() + ld(digits[isize(digits)-2]) / BASE;
}
}
ld approx() const {
return leading() * pow(BASE, isize(digits) - 1);
}
ld log_approx() const {
return log(leading()) * log(BASE) * (isize(digits) - 1);
}
ld operator / (const bignum& b) const {
return leading() / b.leading() * pow(BASE, isize(digits) - isize(b.digits));
}
int approx_int() const {
if(isize(digits) > 1) return BASE;
if(digits.empty()) return 0;
return digits[0];
}
long long approx_ll() const {
if(isize(digits) > 2) return BASE2;
if(digits.empty()) return 0;
if(isize(digits) == 1) return digits[0];
return digits[0] + digits[1] * (long long) BASE;
}
friend inline bignum operator +(bignum a, const bignum& b) { a.addmul(b, 1); return a; }
friend inline bignum operator -(bignum a, const bignum& b) { a.addmul(b, -1); return a; }
};
#endif
bignum& bignum::operator +=(const bignum& b) {
int K = isize(b.digits);
if(K > isize(digits)) digits.resize(K);
@ -116,6 +171,40 @@ void canonicize(vector<int>& t) {
std::rotate(t.begin()+1, t.begin()+i, t.end());
}
#if HDR
struct expansion_analyzer {
vector<int> gettype(cell *c);
int N;
vector<cell*> samples;
map<vector<int>, int> codeid;
vector<vector<int> > children;
int rootid, diskid;
int coefficients_known;
vector<int> coef;
int valid_from, tested_to;
ld growth;
int sample_id(cell *c);
void preliminary_grouping();
void reduce_grouping();
vector<vector<bignum>> descendants;
bignum& get_descendants(int level);
bignum& get_descendants(int level, int type);
void find_coefficients();
void reset();
expansion_analyzer() { reset(); }
string approximate_descendants(int d, int max_length);
void view_distances_dialog();
ld get_growth();
private:
bool verify(int id);
int valid(int v, int step);
};
#endif
vector<int> expansion_analyzer::gettype(cell *c) {
vector<int> res;
res.push_back(subtype(c) * 4 + 2);
@ -445,7 +534,7 @@ int curr_dist(cell *c) {
int position;
int type_in_reduced(expansion_analyzer& ea, cell *c, const cellfunction& f) {
EX int type_in_reduced(expansion_analyzer& ea, cell *c, const cellfunction& f) {
int a = ea.N;
int t = type_in(ea, c, f);
if(expansion.N != a) {
@ -457,7 +546,7 @@ int type_in_reduced(expansion_analyzer& ea, cell *c, const cellfunction& f) {
// which=1 => right, which=-1 => left
int parent_id(cell *c, int which, const cellfunction& cf) {
EX int parent_id(cell *c, int which, const cellfunction& cf) {
int d = cf(c)-1;
for(int i=0; i<c->type; i++) {
@ -482,43 +571,49 @@ void generate_around(cell *c) {
forCellCM(c2, c) if(c2->mpdist > BARLEV) setdist(c2, BARLEV, c);
}
namespace ts {
cell *verified_add(cell *c, int which, int bonus, const cellfunction& cf) {
EX namespace ts {
EX cell *verified_add(cell *c, int which, int bonus, const cellfunction& cf) {
int id = parent_id(c, which, cf);
if(id == -1) return NULL;
return c->cmodmove(id + bonus);
}
cell *verified_add_gen(cell *c, int which, int bonus, const cellfunction& cf) {
EX cell *verified_add_gen(cell *c, int which, int bonus, const cellfunction& cf) {
return verified_add(c, which, bonus, cf);
}
cell *add(cell *c, int which, int bonus, const cellfunction& cf) {
EX cell *add(cell *c, int which, int bonus, const cellfunction& cf) {
int pid = parent_id(c, which, cf);
if(pid == -1) pid = 0;
return c->cmodmove(pid + bonus);
}
cell *left_of(cell *c, const cellfunction& cf) {
EX cell *left_of(cell *c, const cellfunction& cf) {
int pid = parent_id(c, 1, cf);
if(pid == -1) return c;
if(VALENCE == 3) return c->cmodmove(pid+1);
else return (cellwalker(c, pid) + wstep - 1).cpeek();
}
cell *right_of(cell *c, const cellfunction& cf) {
EX cell *right_of(cell *c, const cellfunction& cf) {
int pid = parent_id(c, -1, cf);
if(pid == -1) return c;
if(VALENCE == 3) return c->cmodmove(pid-1);
else return (cellwalker(c, pid) + wstep + 1).cpeek();
}
cell *child_number(cell *c, int id, const cellfunction& cf) {
EX cell *child_number(cell *c, int id, const cellfunction& cf) {
int pid = parent_id(c, 1, cf);
if(pid == -1) return c->cmove(id);
return c->cmodmove(pid + (VALENCE == 3 ? 2 : 1) + id);
}
}
#if HDR
inline cell *left_parent(cell *c, const cellfunction& cf) { return verified_add(c, 1, 0, cf); }
inline cell *right_parent(cell *c, const cellfunction& cf) { return verified_add(c, -1, 0, cf); }
#endif
EX }
bool viewdists = false, use_color_codes = true, use_analyzer = true, show_distance_lists = true;
@ -860,11 +955,11 @@ auto ea_hook = addHook(hooks_args, 100, expansion_readArgs);
#endif
#endif
expansion_analyzer expansion;
EX expansion_analyzer expansion;
int sibling_limit = 0;
EX int sibling_limit = 0;
void set_sibling_limit() {
EX void set_sibling_limit() {
if(0) ;
#if CAP_IRR
else if(IRREGULAR) sibling_limit = 3;

View File

@ -7,6 +7,18 @@ EX string help;
EX function<void()> help_delegate;
#if HDR
struct help_extension {
char key;
string text;
string subtext;
color_t color;
reaction_t action;
help_extension() { color = forecolor; }
help_extension(char k, string t, reaction_t a) : key(k), text(t), action(a) { color = forecolor; }
};
#endif
EX vector<help_extension> help_extensions;
vector<string> extra_keys = {

277
hyper.h
View File

@ -3754,27 +3754,7 @@ bool score_loaded(int id);
int score_default(int id);
void handle_event(SDL_Event& ev);
void start_game();
void stop_game();
void switch_game_mode(char switchWhat);
void stop_game_and_switch_mode(char switchWhat = rg::nothing); // stop_game + switch_game_mode
void restart_game(char switchWhat = rg::nothing); // popAllScreens + popAllGames + stop_game + switch_game_mode + start_game
// these work as stop_game_and_switch_mode
void set_variation(eVariation);
void set_geometry(eGeometry);
void generate_floorshapes();
void drawArrowTraps();
void drawBlizzards();
struct blizzardcell;
extern vector<cell*> arrowtraps;
extern map<cell*, blizzardcell> blizzardcells;
extern vector<blizzardcell*> bcells;
void set_blizzard_frame(cell *c, int frameid);
#define SIDE_SLEV 0
#define SIDE_WTS3 3
@ -4168,21 +4148,6 @@ struct pathdata {
extern int timetowait;
extern vector<pair<cell*, int> > airmap;
extern void compute_graphical_distance();
struct help_extension {
char key;
string text;
string subtext;
color_t color;
reaction_t action;
help_extension() { color = forecolor; }
help_extension(char k, string t, reaction_t a) : key(k), text(t), action(a) { color = forecolor; }
};
extern vector<help_extension> help_extensions;
#define RING(i) for(double i=0; i<=cgi.S84+1e-6; i+=SD3 * pow(.5, vid.linequality))
#define REVRING(i) for(double i=cgi.S84; i>=-1e-6; i-=SD3 * pow(.5, vid.linequality))
#define PRING(i) for(double i=0; i<=cgi.S84+1e-6; i+= pow(.5, vid.linequality))
@ -4212,81 +4177,6 @@ namespace reg3 {
}
#endif
namespace arcm {
#if CAP_ARCM
struct archimedean_tiling {
int coloring;
string symbol;
vector<int> faces;
vector<int> adj;
vector<bool> invert;
vector<int> nflags;
bool have_ph, have_line, have_symmetry;
int real_faces;
int real_face_type;
int repetition;
int N;
ld euclidean_angle_sum;
vector<int> flags;
vector<vector<pair<int, int>>> adjacent;
vector<vector<pair<ld, ld>>> triangles;
void make_match(int a, int i, int b, int j);
void prepare();
void compute_geometry();
void parse();
void parse(string s) { symbol = s; parse(); }
ld edgelength;
vector<ld> inradius, circumradius, alphas;
int matches[30][30];
int periods[30];
int tilegroup[30], groupoffset[30], tilegroups;
int errors;
string errormsg;
pair<int, int>& get_adj(heptagon *h, int cid);
pair<int, int>& get_adj(heptspin hs) { return get_adj(hs.at, hs.spin); }
pair<ld, ld>& get_triangle(heptagon *h, int cid);
pair<ld, ld>& get_triangle(heptspin hs) { return get_triangle(hs.at, hs.spin); }
pair<ld, ld>& get_triangle(const pair<int, int>& p, int delta = 0);
pair<int, int>& get_adj(const pair<int, int>& p, int delta = 0);
int support_threecolor();
int support_threecolor_bitruncated();
int support_football();
bool support_chessboard();
void regroup();
string world_size();
eGeometryClass get_class();
ld scale();
};
extern archimedean_tiling current;
extern map<heptagon*, pair<heptagon*, transmatrix>> archimedean_gmatrix;
void initialize(heptagon *root);
short& id_of(heptagon *);
int fix(heptagon *h, int spin);
#endif
}
namespace crystal {
#if CAP_CRYSTAL
static const int MAXDIM = 7;
@ -4328,141 +4218,8 @@ namespace crystal {
#endif
}
struct bignum {
static const int BASE = 1000000000;
static const long long BASE2 = BASE * (long long)BASE;
vector<int> digits;
bignum() {}
bignum(int i) : digits() { digits.push_back(i); }
void be(int i) { digits.resize(1); digits[0] = i; }
bignum& operator +=(const bignum& b);
void addmul(const bignum& b, int factor);
string get_str(int max_length);
bool operator < (const bignum&) const;
ld leading() const {
switch(isize(digits)) {
case 0:
return 0;
case 1:
return digits.back();
default:
return digits.back() + ld(digits[isize(digits)-2]) / BASE;
}
}
ld approx() const {
return leading() * pow(BASE, isize(digits) - 1);
}
ld log_approx() const {
return log(leading()) * log(BASE) * (isize(digits) - 1);
}
ld operator / (const bignum& b) const {
return leading() / b.leading() * pow(BASE, isize(digits) - isize(b.digits));
}
int approx_int() const {
if(isize(digits) > 1) return BASE;
if(digits.empty()) return 0;
return digits[0];
}
long long approx_ll() const {
if(isize(digits) > 2) return BASE2;
if(digits.empty()) return 0;
if(isize(digits) == 1) return digits[0];
return digits[0] + digits[1] * (long long) BASE;
}
friend inline bignum operator +(bignum a, const bignum& b) { a.addmul(b, 1); return a; }
friend inline bignum operator -(bignum a, const bignum& b) { a.addmul(b, -1); return a; }
};
struct expansion_analyzer {
vector<int> gettype(cell *c);
int N;
vector<cell*> samples;
map<vector<int>, int> codeid;
vector<vector<int> > children;
int rootid, diskid;
int coefficients_known;
vector<int> coef;
int valid_from, tested_to;
ld growth;
int sample_id(cell *c);
void preliminary_grouping();
void reduce_grouping();
vector<vector<bignum>> descendants;
bignum& get_descendants(int level);
bignum& get_descendants(int level, int type);
void find_coefficients();
void reset();
expansion_analyzer() { reset(); }
string approximate_descendants(int d, int max_length);
void view_distances_dialog();
ld get_growth();
private:
bool verify(int id);
int valid(int v, int step);
};
extern expansion_analyzer expansion;
int towerval(cell *c, const cellfunction& cf);
int parent_id(cell *c, int which, const cellfunction& cf);
extern int sibling_limit;
extern void set_sibling_limit();
int type_in_reduced(expansion_analyzer& ea, cell *c, const function<int(cell*)>& f);
namespace ts {
cell *verified_add(cell *c, int which, int bonus, const cellfunction& cf);
cell *add(cell *c, int which, int bonus, const cellfunction& cf);
inline cell *left_parent(cell *c, const cellfunction& cf) { return verified_add(c, 1, 0, cf); }
inline cell *right_parent(cell *c, const cellfunction& cf) { return verified_add(c, -1, 0, cf); }
cell *left_of(cell *c, const cellfunction& cf);
cell *right_of(cell *c, const cellfunction& cf);
cell *child_number(cell *c, int id, const cellfunction& cf);
}
struct exp_parser {
string s;
int at;
exp_parser() { at = 0; }
map<string, cld> extra_params;
bool ok() { return at == isize(s); }
char next(int step=0) { if(at >= isize(s)-step || at == -1) return 0; else return s[at+step]; }
bool eat(const char *c) {
int orig_at = at;
while(*c && *c == next()) at++, c++;
if(*c == 0) return true;
else at = orig_at;
return false;
}
cld parse(int prio = 0);
cld parsepar() {
cld res = parse();
if(next() != ')') { at = -1; return res; }
at++;
return res;
}
};
#if CAP_COMPLEX2
namespace brownian {
const int level = 5;
@ -4482,10 +4239,6 @@ namespace brownian {
void menuitem_sightrange(char c = 'r');
static const ld degree = M_PI / 180;
extern unordered_map<string, ld&> params;
namespace dq {
extern queue<tuple<heptagon*, transmatrix, ld>> drawqueue;
@ -4514,34 +4267,6 @@ template <class T> void texture_order(const T& f) {
}
}
struct gamedata {
// important parameters should be visible
eGeometry geo;
eVariation var;
eLand specland;
bool active;
// other properties are recorded
vector<char> record;
int index, mode;
void storegame();
void restoregame();
template<class T> void store(T& x) {
int ssize = sizeof(x);
if(ssize & 7) ssize = (ssize | 7) + 1;
if(mode == 0) {
record.resize(index+ssize);
T& at = *(new (&record[index]) T());
at = move(x);
}
else {
T& at = (T&) record[index];
x = move(at);
at.~T();
}
index += ssize;
}
};
/* lastmovetype uses lmSkip, lmMove, lmAttack, lmPush, lmTree */
enum eLastmovetype { lmSkip, lmMove, lmAttack, lmPush, lmTree, lmInstant };
extern eLastmovetype lastmovetype, nextmovetype;
@ -4549,8 +4274,6 @@ extern eLastmovetype lastmovetype, nextmovetype;
enum eForcemovetype { fmSkip, fmMove, fmAttack, fmInstant, fmActivate };
extern eForcemovetype forcedmovetype;
static const int PSEUDOKEY_MEMORY = 16397;
static const color_t NOCOLOR = 0;
typedef pair<cell**, bool> euc_pointer;

View File

@ -4,6 +4,10 @@
namespace hr {
#if HDR
static const ld degree = M_PI / 180;
#endif
eGeometry geometry;
eVariation variation;

View File

@ -7,6 +7,36 @@
namespace hr {
#if HDR
struct gamedata {
// important parameters should be visible
eGeometry geo;
eVariation var;
eLand specland;
bool active;
// other properties are recorded
vector<char> record;
int index, mode;
void storegame();
void restoregame();
template<class T> void store(T& x) {
int ssize = sizeof(x);
if(ssize & 7) ssize = (ssize | 7) + 1;
if(mode == 0) {
record.resize(index+ssize);
T& at = *(new (&record[index]) T());
at = move(x);
}
else {
T& at = (T&) record[index];
x = move(at);
at.~T();
}
index += ssize;
}
};
#endif
void gamedata_all(gamedata& gd) {
gd.index = 0;
gd.store(firstland);

View File

@ -3,6 +3,10 @@
namespace hr {
#if HDR
static const int PSEUDOKEY_MEMORY = 16397;
#endif
bool memory_saving_mode = true;
bool show_memory_warning = true;

View File

@ -102,7 +102,7 @@ bool trailer_safety = true;
hookset<void()> *hooks_initgame;
// initialize the game
void initgame() {
EX void initgame() {
DEBBI(DF_INIT, ("initGame"));
callhooks(hooks_initgame);
@ -834,7 +834,7 @@ void remove_emergency_save() {
#endif
}
void saveStats(bool emergency = false) {
EX void saveStats(bool emergency IS(false)) {
DEBBI(DF_INIT, ("saveStats [%s]", scorefile));
if(autocheat) return;
@ -958,7 +958,7 @@ void saveStats(bool emergency = false) {
}
// load the save
void loadsave() {
EX void loadsave() {
if(autocheat) return;
#if CAP_TOUR
if(tour::on) return;
@ -1088,7 +1088,7 @@ void loadsave() {
}
#endif
void stop_game() {
EX void stop_game() {
if(!game_active) return;
if(dual::split(stop_game)) return;
DEBBI(DF_INIT, ("stop_game"));
@ -1125,7 +1125,7 @@ void stop_game() {
#endif
}
void set_geometry(eGeometry target) {
EX void set_geometry(eGeometry target) {
if(geometry != target) {
int old_DIM = DIM;
stop_game();
@ -1161,7 +1161,7 @@ void set_geometry(eGeometry target) {
}
}
void set_variation(eVariation target) {
EX void set_variation(eVariation target) {
if(variation != target) {
stop_game();
if(euclid6 || binarytiling || sol || penrose) geometry = gNormal;
@ -1182,7 +1182,7 @@ void stop_tour() {
}
}
void switch_game_mode(char switchWhat) {
EX void switch_game_mode(char switchWhat) {
DEBBI(DF_INIT, ("switch_game_mode ", switchWhat));
switch(switchWhat) {
case rg::peace:
@ -1312,7 +1312,7 @@ void switch_game_mode(char switchWhat) {
}
}
void start_game() {
EX void start_game() {
if(game_active) return;
DEBBI(DF_INIT, ("start_game"));
if(dual::state == 1) dual::assign_landsides();
@ -1353,21 +1353,23 @@ void start_game() {
subscreens::prepare();
}
void restart_game(char switchWhat) {
// popAllScreens + popAllGames + stop_game + switch_game_mode + start_game
EX void restart_game(char switchWhat IS(rg::nothing)) {
popScreenAll();
stop_game();
switch_game_mode(switchWhat);
start_game();
}
void stop_game_and_switch_mode(char switchWhat) {
// stop_game + switch_game_mode
EX void stop_game_and_switch_mode(char switchWhat IS(rg::nothing)) {
stop_game();
switch_game_mode(switchWhat);
}
purehookset clearmemory;
EX purehookset clearmemory;
void clearMemory() {
EX void clearMemory() {
callhooks(clearmemory);
}

View File

@ -103,6 +103,37 @@ EX bool appears(const string& haystack, const string& needle) {
return simplify(haystack).find(simplify(needle)) != string::npos;
}
#if HDR
struct exp_parser {
string s;
int at;
exp_parser() { at = 0; }
map<string, cld> extra_params;
bool ok() { return at == isize(s); }
char next(int step=0) { if(at >= isize(s)-step || at == -1) return 0; else return s[at+step]; }
bool eat(const char *c) {
int orig_at = at;
while(*c && *c == next()) at++, c++;
if(*c == 0) return true;
else at = orig_at;
return false;
}
cld parse(int prio = 0);
cld parsepar() {
cld res = parse();
if(next() != ')') { at = -1; return res; }
at++;
return res;
}
};
#endif
cld exp_parser::parse(int prio) {
cld res;
while(next() == ' ') at++;