comparison 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
comparison
equal deleted inserted replaced
237:2236ef808bcb 238:e1cd27c5464f
93 /* 93 /*
94 * start_daemon: 94 * start_daemon:
95 * Start a daemon, takes a function. 95 * Start a daemon, takes a function.
96 */ 96 */
97 void 97 void
98 start_daemon(void (*func)(), int arg, int type) 98 start_daemon(void (*func)(), void *arg, int type)
99 { 99 {
100 reg struct delayed_action *dev; 100 reg struct delayed_action *dev;
101 101
102 dev = d_slot(); 102 dev = d_slot();
103 if (dev != NULL) { 103 if (dev != NULL) {
104 dev->d_type = type; 104 dev->d_type = type;
105 dev->d_func = func; 105 dev->d_func = func;
106 dev->d_.arg = arg; 106 dev->d_.varg = arg;
107 dev->d_time = DAEMON; 107 dev->d_time = DAEMON;
108 demoncnt += 1; /* update count */ 108 demoncnt += 1; /* update count */
109 } 109 }
110 } 110 }
111 111
152 for (dev = d_list; dev <= &d_list[MAXDAEMONS-1]; dev++) 152 for (dev = d_list; dev <= &d_list[MAXDAEMONS-1]; dev++)
153 /* 153 /*
154 * Executing each one, giving it the proper arguments 154 * Executing each one, giving it the proper arguments
155 */ 155 */
156 if (dev->d_type == flag && dev->d_time == DAEMON) 156 if (dev->d_type == flag && dev->d_time == DAEMON)
157 (*dev->d_func)(dev->d_.arg); 157 (*dev->d_func)(dev->d_.varg);
158 } 158 }
159 159
160 160
161 /* 161 /*
162 * fuse: 162 * fuse:
163 * Start a fuse to go off in a certain number of turns 163 * Start a fuse to go off in a certain number of turns
164 */ 164 */
165 void 165 void
166 fuse(void (*func)(), int arg, int time, int type) 166 fuse(void (*func)(), void *arg, int time, int type)
167 { 167 {
168 reg struct delayed_action *wire; 168 reg struct delayed_action *wire;
169 169
170 wire = f_slot(); 170 wire = f_slot();
171 if (wire != NULL) { 171 if (wire != NULL) {
172 wire->d_type = type; 172 wire->d_type = type;
173 wire->d_func = func; 173 wire->d_func = func;
174 wire->d_.arg = arg; 174 if (func == changeclass || func == res_strength)
175 wire->d_.arg = *(int *) arg;
176 else
177 wire->d_.varg = arg;
175 wire->d_time = time; 178 wire->d_time = time;
176 fusecnt += 1; /* update count */ 179 fusecnt += 1; /* update count */
177 } 180 }
178 } 181 }
179 182
230 * to remove the fuse from the list once it has gone off. 233 * to remove the fuse from the list once it has gone off.
231 */ 234 */
232 if(flag == wire->d_type && wire->d_time > 0 && 235 if(flag == wire->d_type && wire->d_time > 0 &&
233 --wire->d_time == 0) { 236 --wire->d_time == 0) {
234 wire->d_type = EMPTY; 237 wire->d_type = EMPTY;
235 if (wire->d_func != NULL) 238 if (wire->d_func == changeclass || wire->d_func == res_strength)
236 (*wire->d_func)(wire->d_.arg); 239 (*wire->d_func)(wire->d_.arg);
240 else if (wire->d_func != NULL)
241 (*wire->d_func)(wire->d_.varg);
237 fusecnt -= 1; 242 fusecnt -= 1;
238 } 243 }
239 } 244 }
240 } 245 }
241 246