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

@ -95,7 +95,7 @@ find_slot(void (*func)())
* Start a daemon, takes a function.
*/
void
start_daemon(void (*func)(), int arg, int type)
start_daemon(void (*func)(), void *arg, int type)
{
reg struct delayed_action *dev;
@ -103,7 +103,7 @@ start_daemon(void (*func)(), int arg, int type)
if (dev != NULL) {
dev->d_type = type;
dev->d_func = func;
dev->d_.arg = arg;
dev->d_.varg = arg;
dev->d_time = DAEMON;
demoncnt += 1; /* update count */
}
@ -154,7 +154,7 @@ do_daemons(int flag)
* Executing each one, giving it the proper arguments
*/
if (dev->d_type == flag && dev->d_time == DAEMON)
(*dev->d_func)(dev->d_.arg);
(*dev->d_func)(dev->d_.varg);
}
@ -163,7 +163,7 @@ do_daemons(int flag)
* Start a fuse to go off in a certain number of turns
*/
void
fuse(void (*func)(), int arg, int time, int type)
fuse(void (*func)(), void *arg, int time, int type)
{
reg struct delayed_action *wire;
@ -171,7 +171,10 @@ fuse(void (*func)(), int arg, int time, int type)
if (wire != NULL) {
wire->d_type = type;
wire->d_func = func;
wire->d_.arg = arg;
if (func == changeclass || func == res_strength)
wire->d_.arg = *(int *) arg;
else
wire->d_.varg = arg;
wire->d_time = time;
fusecnt += 1; /* update count */
}
@ -232,8 +235,10 @@ do_fuses(int flag)
if(flag == wire->d_type && wire->d_time > 0 &&
--wire->d_time == 0) {
wire->d_type = EMPTY;
if (wire->d_func != NULL)
if (wire->d_func == changeclass || wire->d_func == res_strength)
(*wire->d_func)(wire->d_.arg);
else if (wire->d_func != NULL)
(*wire->d_func)(wire->d_.varg);
fusecnt -= 1;
}
}