Make hookset<T> a pointer type, just like purehookset.

No more declaring `hookset<T> *hooks_foo`; now it's just
`hookset<T> hooks_foo` at global scope. This clears the way to
make `hookset<T>` into a class type if we want.
This commit is contained in:
Arthur O'Dwyer 2020-04-11 14:47:14 -04:00
parent 934e3d9a42
commit 0d42168139
23 changed files with 44 additions and 43 deletions

View File

@ -219,7 +219,7 @@ void setcameraangle(bool b) { }
#if CAP_GL
#if CAP_VR
EX hookset<bool()> *hooks_vr_eye_view, *hooks_vr_eye_projection;
EX hookset<bool()> hooks_vr_eye_view, hooks_vr_eye_projection;
#endif
EX void eyewidth_translate(int ed) {

View File

@ -1332,7 +1332,7 @@ EX bool quickfind(eLand l) {
#define I2000 (INVLUCK?600:2000)
#define I10000 (INVLUCK?3000:10000)
EX hookset<int(cell*, bool)> *hooks_wallchance;
EX hookset<int(cell*, bool)> hooks_wallchance;
EX int wallchance(cell *c, bool deepOcean) {
int i = callhandlers(-1, hooks_wallchance, c, deepOcean);

View File

@ -279,7 +279,7 @@ EX void eumerge(cell* c1, int s1, cell *c2, int s2, bool mirror) {
// map<pair<eucoord, eucoord>, cell*> euclidean;
EX hookset<hrmap*()> *hooks_newmap;
EX hookset<hrmap*()> hooks_newmap;
/** create a map in the current geometry */
EX void initcells() {

View File

@ -347,7 +347,7 @@ int arg::readCommon() {
EX purehookset hooks_config;
EX hookset<int()> *hooks_args;
EX hookset<int()> hooks_args;
namespace arg {

View File

@ -554,7 +554,7 @@ EX bool mightBeMine(cell *c) {
return c->wall == waMineUnknown || c->wall == waMineMine;
}
EX hookset<bool(cell*)> *hooks_mark;
EX hookset<bool(cell*)> hooks_mark;
EX void performMarkCommand(cell *c) {
if(!c) return;

View File

@ -2028,7 +2028,7 @@ EX void draw_main() {
}
#if CAP_VR
EX hookset<bool()> *hooks_vr_draw_all;
EX hookset<bool()> hooks_vr_draw_all;
#endif
EX void drawqueue() {

View File

@ -40,8 +40,8 @@ EX bool hide_player() {
#define ADC(V,c) for(const transmatrix& V: current_display->all_drawn_copies[c])
EX hookset<bool(int sym, int uni)> *hooks_handleKey;
EX hookset<bool(cell *c, const transmatrix& V)> *hooks_drawcell;
EX hookset<bool(int sym, int uni)> hooks_handleKey;
EX hookset<bool(cell *c, const transmatrix& V)> hooks_drawcell;
EX purehookset hooks_frame, hooks_markers;
EX ld animation_factor = 1;

View File

@ -772,7 +772,7 @@ EX void appendHelp(string s) {
unsigned char lastval;
int windtotal;
EX hookset<void(cell*)> *hooks_mouseover;
EX hookset<void(cell*)> hooks_mouseover;
EX void describeMouseover() {
DEBBI(DF_GRAPH, ("describeMouseover"));
@ -1017,7 +1017,7 @@ EX void showHelp() {
};
}
EX hookset<bool()> *hooks_default_help;
EX hookset<bool()> hooks_default_help;
EX void gotoHelp(const string& h) {
help = h;

View File

@ -217,7 +217,7 @@ void addSpin(heptagon *h, int d, heptagon *from, int rot, int spin) {
extern int hrand(int);
EX hookset<void(heptagon*, int)> *hooks_createStep;
EX hookset<void(heptagon*, int)> hooks_createStep;
// create h->move(d) if not created yet
heptagon *createStep(heptagon *h, int d) {

View File

@ -328,7 +328,7 @@ void displayglyph2(int cx, int cy, int buttonsize, int i) {
EX bool nohud, nomenukey;
EX hookset<bool()> *hooks_prestats;
EX hookset<bool()> hooks_prestats;
#if CAP_SHAPES
void drawMobileArrow(int i) {

View File

@ -29,7 +29,7 @@ void moreStack() {
#endif
namespace hr {
EX hookset<bool(int argc, char** argv)> *hooks_main;
EX hookset<bool(int argc, char** argv)> hooks_main;
EX int hyper_main(int argc, char **argv) {
using namespace hr;

13
hyper.h
View File

@ -407,8 +407,9 @@ struct movedir {
// shmup
template<class T> class hookset : public map<int, function<T>> {};
typedef hookset<void()> *purehookset;
template<class T> class hookset_impl : public map<int, function<T>> {};
template<class T> using hookset = hookset_impl<T> *;
using purehookset = hookset_impl<void()> *;
static const int NOHINT = -1;
@ -633,8 +634,8 @@ color_t darkena(color_t c, int lev, int a);
static const int DISTANCE_UNKNOWN = 127;
template<class T, class U> int addHook(hookset<T>*& m, int prio, const U& hook) {
if(!m) m = new hookset<T> ();
template<class T, class U> int addHook(hookset<T>& m, int prio, const U& hook) {
if(!m) m = new hookset_impl<T> ();
while(m->count(prio)) {
prio++;
}
@ -642,11 +643,11 @@ template<class T, class U> int addHook(hookset<T>*& m, int prio, const U& hook)
return 0;
}
template<class T, class... U> void callhooks(hookset<T> *h, U&&... args) {
template<class T, class... U> void callhooks(hookset<T> h, U&&... args) {
if(h) for(auto& p: *h) p.second(std::forward<U>(args)...);
}
template<class T, class V, class... U> V callhandlers(V zero, hookset<T> *h, U&&... args) {
template<class T, class V, class... U> V callhandlers(V zero, hookset<T> h, U&&... args) {
if(h) for(auto& p: *h) {
auto z = p.second(std::forward<U>(args)...);
if(z != zero) return z;

View File

@ -2082,8 +2082,8 @@ EX transmatrix& get_view_orientation() {
return prod ? NLP : View;
}
EX hookset<bool(const transmatrix&)> *hooks_rotate_view;
EX hookset<bool(const hyperpoint&)> *hooks_shift_view;
EX hookset<bool(const transmatrix&)> hooks_rotate_view;
EX hookset<bool(const hyperpoint&)> hooks_shift_view;
/** rotate the view using the given rotation matrix */
EX void rotate_view(transmatrix T) {

View File

@ -276,7 +276,7 @@ EX bool createOnSea(eLand old) {
(old == laOcean && (chaosmode ? hrand(2) : !generatingEquidistant));
}
EX hookset<eLand(eLand)> *hooks_nextland;
EX hookset<eLand(eLand)> hooks_nextland;
EX eLand getNewLand(eLand old) {

View File

@ -951,7 +951,7 @@ typedef pair<string, reaction_t> named_functionality;
inline named_functionality named_dialog(string x, reaction_t dialog) { return named_functionality(x, [dialog] () { pushScreen(dialog); }); }
#endif
EX hookset<named_functionality()> *hooks_o_key;
EX hookset<named_functionality()> hooks_o_key;
EX named_functionality get_o_key() {

View File

@ -82,7 +82,7 @@ void gamedata::restoregame() {
gamedata_all(*this);
}
EX hookset<void(gamedata*)> *hooks_gamedata;
EX hookset<void(gamedata*)> hooks_gamedata;
EX namespace gamestack {

View File

@ -1666,7 +1666,7 @@ EX namespace patterns {
}
}
EX hookset<int(cell*)> *hooks_generate_canvas;
EX hookset<int(cell*)> hooks_generate_canvas;
EX int generateCanvas(cell *c) {

View File

@ -169,8 +169,8 @@ string build_getter(string type, string name, int index) {
#define GET(array, index) array "[" index "]"
#endif
EX hookset<void(string&, string&)> *hooks_rayshader;
EX hookset<bool(shared_ptr<raycaster>)> *hooks_rayset;
EX hookset<void(string&, string&)> hooks_rayshader;
EX hookset<bool(shared_ptr<raycaster>)> hooks_rayset;
void enable_raycaster() {
if(geometry != last_geometry) reset_raycaster();

View File

@ -107,11 +107,11 @@ namespace rogueviz {
extern colorpair dftcolor;
inline hookset<void(vertexdata&, cell*, shmup::monster*, int)> *hooks_drawvertex;
inline hookset<bool(edgeinfo*, bool store)> *hooks_alt_edges;
inline hookset<void(vertexdata&, cell*, shmup::monster*, int)> hooks_drawvertex;
inline hookset<bool(edgeinfo*, bool store)> hooks_alt_edges;
inline purehookset hooks_rvmenu;
inline hookset<bool()> *hooks_rvmenu_replace;
inline hookset<bool(int&, string&, FILE*)> *hooks_readcolor;
inline hookset<bool()> hooks_rvmenu_replace;
inline hookset<bool(int&, string&, FILE*)> hooks_readcolor;
inline purehookset hooks_close;
void readcolor(const string& cfname);
@ -121,7 +121,7 @@ namespace rogueviz {
namespace rvtour {
using namespace hr::tour;
inline hookset<void(vector<slide>&)> *hooks_build_rvtour;
inline hookset<void(vector<slide>&)> hooks_build_rvtour;
slide *gen_rvtour();
template<class T> function<void(presmode)> roguevizslide(char c, const T& t) {

View File

@ -236,7 +236,7 @@ bool isBullet(monster *m) {
bool isPlayer(monster *m) { return m->type == moPlayer; }
bool isMonster(monster *m) { return m->type != moPlayer && m->type != moBullet; }
EX hookset<bool(shmup::monster*)> *hooks_kill;
EX hookset<bool(shmup::monster*)> hooks_kill;
void killMonster(monster* m, eMonster who_kills, flagtype flags = 0) {
int tk = tkills();
@ -2456,7 +2456,7 @@ EX void fixStorage() {
for(monster *m: restore) m->store();
}
EX hookset<bool(int)> *hooks_turn;
EX hookset<bool(int)> hooks_turn;
EX void turn(int delta) {
@ -2771,7 +2771,7 @@ EX bool boatAt(cell *c) {
return false;
}
EX hookset<bool(const transmatrix&, cell*, shmup::monster*)> *hooks_draw;
EX hookset<bool(const transmatrix&, cell*, shmup::monster*)> hooks_draw;
EX void clearMonsters() {
for(mit it = monstersAt.begin(); it != monstersAt.end(); it++)
@ -2833,7 +2833,7 @@ EX void virtualRebase(shmup::monster *m) {
virtualRebase(m->base, m->at);
}
EX hookset<bool(shmup::monster*, string&)> *hooks_describe;
EX hookset<bool(shmup::monster*, string&)> hooks_describe;
EX void addShmupHelp(string& out) {
if(shmup::mousetarget && sqdist(mouseh, tC0(shmup::mousetarget->pat)) < .1) {

View File

@ -83,7 +83,7 @@ int musfadeval = 2000;
eLand cid = laNone;
hookset<bool(eLand&)> *hooks_music;
hookset<bool(eLand&)> hooks_music;
bool music_out_of_focus = false;
@ -129,7 +129,7 @@ EX void handlemusic() {
}
}
hookset<bool(eLand&)> *hooks_resetmusic;
hookset<bool(eLand&)> hooks_resetmusic;
EX void resetmusic() {
if(audio && musicvolume) {
@ -218,7 +218,7 @@ string wheresounds = SOUNDDESTDIR;
string wheresounds = HYPERPATH "sounds/";
#endif
hookset<bool(const string& s, int vol)> *hooks_sound;
hookset<bool(const string& s, int vol)> hooks_sound;
EX void playSound(cell *c, const string& fname, int vol) {
LATE( hr::playSound(c, fname, vol); )

View File

@ -76,7 +76,7 @@ bool do_use_special_land() {
}
/** \brief Hooks for welcomeMessage. Return true to capture. */
EX hookset<bool()> *hooks_welcome_message;
EX hookset<bool()> hooks_welcome_message;
/** \brief Print the welcome message during the start of game. Depends on the current mode and other settings. */
EX void welcomeMessage() {
@ -144,7 +144,7 @@ EX void welcomeMessage() {
}
/** \brief These hooks are called at the start of initgame. */
EX hookset<void()> *hooks_initgame;
EX hookset<void()> hooks_initgame;
/** \brief initialize the game */
EX void initgame() {

View File

@ -115,7 +115,7 @@ EX function<bool(eLand)> showland;
EX string slidecommand;
/** \brief hooks to execute after calling presentation */
EX hookset<void(int)> *hooks_slide;
EX hookset<void(int)> hooks_slide;
/** \brief call action(mode) for the current slide. Also sets up some default stuff */
EX void presentation(presmode mode) {
@ -377,7 +377,7 @@ EX namespace ss {
string slidechars = "abcdefghijklmnopqrsvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ23456789!@#$%^&*(";
EX hookset<int(bool)> *hooks_extra_slideshows;
EX hookset<int(bool)> hooks_extra_slideshows;
EX void slideshow_menu() {
dialog::init(XLAT("slideshows"), forecolor, 150, 100);