arogue7, xrogue: improve the handling of the arguments to fuses.

fuse() now expects a pointer as the argument to a fuse function.  If
this is one of the functions that takes int, fuse() follows the pointer
and stores that value in the f_list slot, in the integer field of the
argument union.  When the fuse goes off, do_fuses() recognizes the
function and passes it the integer field instead of the pointer.

This has the disadvantage of hard-coding the functions that require int
in daemon.c, but since the int is copied into f_list, it no longer has
to be in static or global memory, which simplifies several files.
This commit is contained in:
John "Elwin" Edwards 2016-03-11 17:40:00 -05:00
parent dafa5cc722
commit 758c6b1bf0
21 changed files with 147 additions and 124 deletions

View file

@ -172,7 +172,10 @@ fuse(void (*dfunc)(), void *arg, int time, int type)
if (wire != NULL) {
wire->d_type = type;
wire->d_func = dfunc;
wire->d_arg.vp = arg;
if (dfunc == changeclass || dfunc == res_strength)
wire->d_arg.i = *(int *) arg;
else
wire->d_arg.vp = arg;
wire->d_time = time;
fusecnt += 1; /* update count */
}
@ -220,26 +223,28 @@ extinguish(void (*dfunc)())
void
do_fuses(int flag)
{
struct delayed_action *wire;
int i;
struct delayed_action *wire;
int i;
/*
* Step though the list
*/
for (i = 0; i < MAXFUSES; i++) {
wire = &f_list[i];
/*
* Step though the list
*/
for (i = 0; i < MAXFUSES; i++) {
wire = &f_list[i];
/*
* Decrementing counters and starting things we want. We also need
* to remove the fuse from the list once it has gone off.
*/
if(flag == wire->d_type && wire->d_time > 0 &&
if(flag == wire->d_type && wire->d_time > 0 &&
--wire->d_time == 0) {
wire->d_type = EMPTY;
if (wire->d_func != NULL)
(*wire->d_func)(wire->d_arg.vp);
fusecnt -= 1;
}
wire->d_type = EMPTY;
if (*wire->d_func == changeclass || *wire->d_func == res_strength)
(*wire->d_func)(wire->d_arg.i);
else if (wire->d_func != NULL)
(*wire->d_func)(wire->d_arg.vp);
fusecnt -= 1;
}
}
}
/*