1
0
mirror of https://github.com/zenorogue/hyperrogue.git synced 2024-11-27 06:27:17 +00:00

Add explicit and override consistently everywhere else. NFCI.

This commit is contained in:
Arthur O'Dwyer 2021-07-11 18:03:08 -04:00
parent a2989a3d39
commit 090e084dd4
6 changed files with 79 additions and 80 deletions

View File

@ -27,9 +27,9 @@ struct supersaver {
virtual void load(const string& s) = 0; virtual void load(const string& s) = 0;
virtual bool dosave() = 0; virtual bool dosave() = 0;
virtual void reset() = 0; virtual void reset() = 0;
virtual ~supersaver() {}
virtual bool affects(void* v) { return false; } virtual bool affects(void* v) { return false; }
virtual void set_default() = 0; virtual void set_default() = 0;
virtual ~supersaver() = default;
}; };
typedef vector<shared_ptr<supersaver>> saverlist; typedef vector<shared_ptr<supersaver>> saverlist;
@ -56,7 +56,7 @@ struct setting {
return parameter_name + "|" + config_name + "|" + menu_item_name + "|" + help_text; return parameter_name + "|" + config_name + "|" + menu_item_name + "|" + help_text;
} }
virtual cld get_cld() = 0; virtual cld get_cld() = 0;
setting() { restrict = auto_restrict; is_editable = false; } explicit setting() { restrict = auto_restrict; is_editable = false; }
virtual void check_change() { virtual void check_change() {
cld val = get_cld(); cld val = get_cld();
if(val != last_value) { if(val != last_value) {
@ -68,7 +68,7 @@ struct setting {
setting *set_sets(const reaction_t& s) { sets = s; return this; } setting *set_sets(const reaction_t& s) { sets = s; return this; }
setting *set_extra(const reaction_t& r); setting *set_extra(const reaction_t& r);
setting *set_reaction(const reaction_t& r); setting *set_reaction(const reaction_t& r);
virtual ~setting() {} virtual ~setting() = default;
virtual void load_from(const string& s) { virtual void load_from(const string& s) {
println(hlog, "cannot load this parameter"); println(hlog, "cannot load this parameter");
exit(1); exit(1);
@ -100,7 +100,7 @@ struct list_setting : setting {
default_key = key; default_key = key;
return this; return this;
} }
virtual void show_edit_option(char key) override; void show_edit_option(char key) override;
}; };
template<class T> struct enum_setting : list_setting { template<class T> struct enum_setting : list_setting {
@ -108,10 +108,10 @@ template<class T> struct enum_setting : list_setting {
T dft; T dft;
int get_value() override { return (int) *value; } int get_value() override { return (int) *value; }
void set_value(int i) override { *value = (T) i; } void set_value(int i) override { *value = (T) i; }
virtual bool affects(void* v) override { return v == value; } bool affects(void* v) override { return v == value; }
virtual void add_as_saver() override; void add_as_saver() override;
virtual cld get_cld() override { return get_value(); } cld get_cld() override { return get_value(); }
virtual void load_from(const string& s) override { void load_from(const string& s) override {
*value = (T) parseint(s); *value = (T) parseint(s);
} }
}; };
@ -134,11 +134,10 @@ struct float_setting : public setting {
function<void(float_setting*)> modify_me; function<void(float_setting*)> modify_me;
float_setting *modif(const function<void(float_setting*)>& r) { modify_me = r; return this; } float_setting *modif(const function<void(float_setting*)>& r) { modify_me = r; return this; }
void add_as_saver() override; void add_as_saver() override;
virtual bool affects(void *v) override { return v == value; } bool affects(void *v) override { return v == value; }
virtual void show_edit_option(char key) override; void show_edit_option(char key) override;
virtual cld get_cld() override { return *value; } cld get_cld() override { return *value; }
void load_from(const string& s) override;
virtual void load_from(const string& s) override;
}; };
struct int_setting : public setting { struct int_setting : public setting {
@ -149,9 +148,9 @@ struct int_setting : public setting {
void add_as_saver() override; void add_as_saver() override;
function<void(int_setting*)> modify_me; function<void(int_setting*)> modify_me;
int_setting *modif(const function<void(int_setting*)>& r) { modify_me = r; return this; } int_setting *modif(const function<void(int_setting*)>& r) { modify_me = r; return this; }
virtual bool affects(void *v) override { return v == value; } bool affects(void *v) override { return v == value; }
virtual void show_edit_option(char key) override; void show_edit_option(char key) override;
virtual cld get_cld() override { return *value; } cld get_cld() override { return *value; }
int_setting *editable(int min_value, int max_value, ld step, string menu_item_name, string help_text, char key) { int_setting *editable(int min_value, int max_value, ld step, string menu_item_name, string help_text, char key) {
this->min_value = min_value; this->min_value = min_value;
this->max_value = max_value; this->max_value = max_value;
@ -162,7 +161,7 @@ struct int_setting : public setting {
return this; return this;
} }
virtual void load_from(const string& s) override { void load_from(const string& s) override {
*value = parseint(s); *value = parseint(s);
} }
}; };
@ -176,10 +175,10 @@ struct bool_setting : public setting {
is_editable = true; is_editable = true;
menu_item_name = cap; default_key = key; return this; menu_item_name = cap; default_key = key; return this;
} }
virtual bool affects(void *v) override { return v == value; } bool affects(void *v) override { return v == value; }
virtual void show_edit_option(char key) override; void show_edit_option(char key) override;
virtual cld get_cld() override { return *value ? 1 : 0; } cld get_cld() override { return *value ? 1 : 0; }
virtual void load_from(const string& s) override { void load_from(const string& s) override {
*value = parseint(s); *value = parseint(s);
} }
}; };
@ -188,9 +187,9 @@ struct custom_setting : public setting {
function<void(char)> custom_viewer; function<void(char)> custom_viewer;
function<cld()> custom_value; function<cld()> custom_value;
function<bool(void*)> custom_affect; function<bool(void*)> custom_affect;
virtual void show_edit_option(char key) override { custom_viewer(key); } void show_edit_option(char key) override { custom_viewer(key); }
virtual cld get_cld() override { return custom_value(); } cld get_cld() override { return custom_value(); }
virtual bool affects(void *v) override { return custom_affect(v); } bool affects(void *v) override { return custom_affect(v); }
}; };
#if CAP_CONFIG #if CAP_CONFIG
@ -198,11 +197,11 @@ struct custom_setting : public setting {
template<class T> struct dsaver : supersaver { template<class T> struct dsaver : supersaver {
T& val; T& val;
T dft; T dft;
bool dosave() { return val != dft; } bool dosave() override { return val != dft; }
void reset() { val = dft; } void reset() override { val = dft; }
dsaver(T& val) : val(val) { } explicit dsaver(T& val) : val(val) { }
bool affects(void* v) { return v == &val; } bool affects(void* v) override { return v == &val; }
void set_default() { dft = val; } void set_default() override { dft = val; }
}; };
template<class T> struct saver : dsaver<T> {}; template<class T> struct saver : dsaver<T> {};
@ -233,13 +232,13 @@ template<class T> void set_saver_default(T& val) {
template<class T> struct saverenum : supersaver { template<class T> struct saverenum : supersaver {
T& val; T& val;
T dft; T dft;
bool dosave() { return val != dft; } explicit saverenum(T& v) : val(v) { }
void reset() { val = dft; } bool dosave() override { return val != dft; }
saverenum<T>(T& v) : val(v) { } void reset() override { val = dft; }
string save() { return its(int(val)); } string save() override { return its(int(val)); }
void load(const string& s) { val = (T) atoi(s.c_str()); } void load(const string& s) override { val = (T) atoi(s.c_str()); }
virtual bool affects(void* v) { return v == &val; } bool affects(void* v) override { return v == &val; }
virtual void set_default() { dft = val; } void set_default() override { dft = val; }
}; };
template<class T, class U> void addsaverenum(T& i, U name, T dft) { template<class T, class U> void addsaverenum(T& i, U name, T dft) {
@ -254,39 +253,39 @@ template<class T, class U> void addsaverenum(T& i, U name) {
} }
template<> struct saver<int> : dsaver<int> { template<> struct saver<int> : dsaver<int> {
saver<int>(int& val) : dsaver<int>(val) { } explicit saver(int& val) : dsaver<int>(val) { }
string save() { return its(val); } string save() override { return its(val); }
void load(const string& s) { val = atoi(s.c_str()); } void load(const string& s) override { val = atoi(s.c_str()); }
}; };
template<> struct saver<char> : dsaver<char> { template<> struct saver<char> : dsaver<char> {
saver<char>(char& val) : dsaver<char>(val) { } explicit saver(char& val) : dsaver<char>(val) { }
string save() { return its(val); } string save() override { return its(val); }
void load(const string& s) { val = atoi(s.c_str()); } void load(const string& s) override { val = atoi(s.c_str()); }
}; };
template<> struct saver<bool> : dsaver<bool> { template<> struct saver<bool> : dsaver<bool> {
saver<bool>(bool& val) : dsaver<bool>(val) { } explicit saver(bool& val) : dsaver<bool>(val) { }
string save() { return val ? "yes" : "no"; } string save() override { return val ? "yes" : "no"; }
void load(const string& s) { val = isize(s) && s[0] == 'y'; } void load(const string& s) override { val = isize(s) && s[0] == 'y'; }
}; };
template<> struct saver<unsigned> : dsaver<unsigned> { template<> struct saver<unsigned> : dsaver<unsigned> {
saver<unsigned>(unsigned& val) : dsaver<unsigned>(val) { } explicit saver(unsigned& val) : dsaver<unsigned>(val) { }
string save() { return itsh(val); } string save() override { return itsh(val); }
void load(const string& s) { val = (unsigned) strtoll(s.c_str(), NULL, 16); } void load(const string& s) override { val = (unsigned) strtoll(s.c_str(), NULL, 16); }
}; };
template<> struct saver<string> : dsaver<string> { template<> struct saver<string> : dsaver<string> {
saver<string>(string& val) : dsaver<string>(val) { } explicit saver(string& val) : dsaver<string>(val) { }
string save() { return val; } string save() override { return val; }
void load(const string& s) { val = s; } void load(const string& s) override { val = s; }
}; };
template<> struct saver<ld> : dsaver<ld> { template<> struct saver<ld> : dsaver<ld> {
saver<ld>(ld& val) : dsaver<ld>(val) { } explicit saver(ld& val) : dsaver<ld>(val) { }
string save() { return fts(val, 10); } string save() override { return fts(val, 10); }
void load(const string& s) { void load(const string& s) override {
if(s == "0.0000000000e+000") ; // ignore! if(s == "0.0000000000e+000") ; // ignore!
else val = atof(s.c_str()); else val = atof(s.c_str());
} }

View File

@ -56,7 +56,7 @@ struct drawqueueitem {
virtual void draw() = 0; virtual void draw() = 0;
/** \brief Draw the object as background. */ /** \brief Draw the object as background. */
virtual void draw_back() {} virtual void draw_back() {}
virtual ~drawqueueitem() {} virtual ~drawqueueitem() = default;
/** \brief When minimizing OpenGL calls, we need to group items of the same color, etc. together. This value is used as an extra sorting key. */ /** \brief When minimizing OpenGL calls, we need to group items of the same color, etc. together. This value is used as an extra sorting key. */
virtual color_t outline_group() = 0; virtual color_t outline_group() = 0;
}; };
@ -85,12 +85,12 @@ struct dqi_poly : drawqueueitem {
hyperpoint intester; hyperpoint intester;
/** \brief temporarily cached data */ /** \brief temporarily cached data */
float cache; float cache;
void draw(); void draw() override;
#if CAP_GL #if CAP_GL
void gldraw(); void gldraw();
#endif #endif
void draw_back(); void draw_back() override;
virtual color_t outline_group() { return outline; } color_t outline_group() override { return outline; }
}; };
/** \brief Drawqueueitem used to draw lines */ /** \brief Drawqueueitem used to draw lines */
@ -101,9 +101,9 @@ struct dqi_line : drawqueueitem {
int prf; int prf;
/** \brief width of this line */ /** \brief width of this line */
double width; double width;
void draw(); void draw() override;
void draw_back(); void draw_back() override;
virtual color_t outline_group() { return color; } color_t outline_group() override { return color; }
}; };
/** \brief Drawqueueitem used to draw strings, using sccreen coodinates */ /** \brief Drawqueueitem used to draw strings, using sccreen coodinates */
@ -120,8 +120,8 @@ struct dqi_string : drawqueueitem {
int frame; int frame;
/** alignment (0-8-16) */ /** alignment (0-8-16) */
int align; int align;
void draw(); void draw() override;
virtual color_t outline_group() { return 1; } color_t outline_group() override { return 1; }
}; };
/** Drawqueueitem used to draw circles, using screen coordinates */ /** Drawqueueitem used to draw circles, using screen coordinates */
@ -134,16 +134,16 @@ struct dqi_circle : drawqueueitem {
color_t fillcolor; color_t fillcolor;
/** \brief width of the circle */ /** \brief width of the circle */
double linewidth; double linewidth;
void draw(); void draw() override;
virtual color_t outline_group() { return 2; } color_t outline_group() override { return 2; }
}; };
/** \brief Perform an arbitrary action. May temporarily change the model, etc. */ /** \brief Perform an arbitrary action. May temporarily change the model, etc. */
struct dqi_action : drawqueueitem { struct dqi_action : drawqueueitem {
reaction_t action; reaction_t action;
dqi_action(const reaction_t& a) : action(a) {} explicit dqi_action(const reaction_t& a) : action(a) {}
void draw() { action(); } void draw() override { action(); }
virtual color_t outline_group() { return 2; } color_t outline_group() override { return 2; }
}; };
#endif #endif

View File

@ -19,10 +19,10 @@ template<class T, class R, class... Args>
struct function_state : function_state_base<R, Args...> { struct function_state : function_state_base<R, Args...> {
T t_; T t_;
explicit function_state(T t) : t_(std::move(t)) {} explicit function_state(T t) : t_(std::move(t)) {}
R call(Args... args) const /*override*/ { R call(Args... args) const override {
return const_cast<T&>(t_)(static_cast<Args&&>(args)...); return const_cast<T&>(t_)(static_cast<Args&&>(args)...);
} }
function_state_base<R, Args...> *clone() const /*override*/ { function_state_base<R, Args...> *clone() const override {
return new function_state(*this); return new function_state(*this);
} }
}; };

View File

@ -21,7 +21,7 @@ EX namespace inforder {
struct hrmap_inforder : hrmap_hyperbolic { struct hrmap_inforder : hrmap_hyperbolic {
heptagon *create_step(heptagon *h, int direction) { heptagon *create_step(heptagon *h, int direction) override {
int deg = h->type; int deg = h->type;
if(mixed()) deg = 7 - deg; if(mixed()) deg = 7 - deg;
auto h1 = init_heptagon(deg); auto h1 = init_heptagon(deg);

View File

@ -64,16 +64,16 @@ struct hrmap_quotient : hrmap_standard {
void build(); void build();
hrmap_quotient() { explicit hrmap_quotient() {
generate_connections(); generate_connections();
build(); build();
} }
hrmap_quotient(const vector<int>& con) : connections(con) { explicit hrmap_quotient(const vector<int>& con) : connections(con) {
build(); build();
} }
heptagon *getOrigin() { return allh[0]; } heptagon *getOrigin() override { return allh[0]; }
~hrmap_quotient() { ~hrmap_quotient() {
for(int i=0; i<isize(allh); i++) { for(int i=0; i<isize(allh); i++) {
@ -82,7 +82,7 @@ struct hrmap_quotient : hrmap_standard {
} }
} }
vector<cell*>& allcells() { return celllist; } vector<cell*>& allcells() override { return celllist; }
}; };
#endif #endif

View File

@ -24,11 +24,11 @@ struct sky_item {
struct dqi_sky : drawqueueitem { struct dqi_sky : drawqueueitem {
vector<sky_item> sky; vector<sky_item> sky;
void draw(); void draw() override;
virtual color_t outline_group() { return 3; } color_t outline_group() override { return 3; }
// singleton // singleton
dqi_sky() { hr::sky = this; } explicit dqi_sky() { hr::sky = this; }
~dqi_sky() { hr::sky = NULL; } ~dqi_sky() override { hr::sky = NULL; }
}; };
EX struct dqi_sky *sky; EX struct dqi_sky *sky;