diff arogue7/daemon.c @ 238:e1cd27c5464f

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.
author John "Elwin" Edwards
date Fri, 11 Mar 2016 17:40:00 -0500
parents b67b99f6c92b
children
line wrap: on
line diff
--- a/arogue7/daemon.c	Tue Mar 08 20:47:57 2016 -0500
+++ b/arogue7/daemon.c	Fri Mar 11 17:40:00 2016 -0500
@@ -95,7 +95,7 @@
  *	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 @@
 	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 @@
 	 * 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 @@
  *	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 @@
 	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 @@
 	    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;
 	    }
 	}