diff xrogue/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 7c1cb43f346e
children
line wrap: on
line diff
--- a/xrogue/daemon.c	Tue Mar 08 20:47:57 2016 -0500
+++ b/xrogue/daemon.c	Fri Mar 11 17:40:00 2016 -0500
@@ -172,7 +172,10 @@
         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 @@
 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;
         }
+    }
 }
 
 /*