event/event.c File Reference

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <sys/time.h>
#include <sys/types.h>
#include <time.h>
#include <event.h>
#include "muxevent.h"
#include "create.h"
#include "debug.h"

Include dependency graph for event.c:

Go to the source code of this file.

Defines

#define Zombie(e)   (e->flags & FLAG_ZOMBIE)
#define LoopType(type, var)
#define LoopEvent(var)

Functions

void prerun_event (MUXEVENT *e)
void postrun_event (MUXEVENT *e)
static void muxevent_delete (MUXEVENT *)
static void muxevent_wakeup (int fd, short event, void *arg)
void muxevent_add (int time, int flags, int type, void(*func)(MUXEVENT *), void *data, void *data2)
void muxevent_run ()
int muxevent_run_by_type (int type)
int muxevent_last_type ()
void muxevent_initialize ()
void muxevent_remove_data (void *data)
void muxevent_remove_type_data (int type, void *data)
void muxevent_remove_type_data2 (int type, void *data)
void muxevent_remove_type_data_data (int type, void *data, void *data2)
void muxevent_get_type_data (int type, void *data, int *data2)
int muxevent_count_type (int type)
int muxevent_count_type_data (int type, void *data)
int muxevent_count_type_data2 (int type, void *data)
int muxevent_count_type_data_data (int type, void *data, void *data2)
int muxevent_count_data (int type, void *data)
int muxevent_count_data_data (int type, void *data, void *data2)
void muxevent_gothru_type_data (int type, void *data, void(*func)(MUXEVENT *))
void muxevent_gothru_type (int type, void(*func)(MUXEVENT *))
int muxevent_last_type_data (int type, void *data)
int muxevent_first_type_data (int type, void *data)
int muxevent_count_type_data_firstev (int type, void *data)

Variables

int muxevent_tick = 0
static MUXEVENT ** muxevent_first_in_type = NULL
static MUXEVENTmuxevent_list = NULL
static MUXEVENTmuxevent_free_list = NULL
static int last_muxevent_type = -1


Define Documentation

#define LoopEvent ( var   ) 

Value:

for (var = muxevent_list ; var ; var = var->next_in_main) \
if (!Zombie(var))

Definition at line 94 of file event.c.

Referenced by muxevent_count_data(), and muxevent_count_data_data().

#define LoopType ( type,
var   ) 

Value:

for (var = muxevent_first_in_type[type] ; var ; var = var->next_in_type) \
if (!Zombie(var))

Definition at line 90 of file event.c.

Referenced by muxevent_count_type(), muxevent_count_type_data(), muxevent_count_type_data2(), muxevent_count_type_data_data(), muxevent_count_type_data_firstev(), muxevent_first_type_data(), muxevent_get_type_data(), muxevent_gothru_type(), muxevent_gothru_type_data(), and muxevent_last_type_data().

#define Zombie (  )     (e->flags & FLAG_ZOMBIE)

Definition at line 89 of file event.c.

Referenced by HandledCommand_sub(), Leave_DS(), muxevent_run_by_type(), and muxevent_wakeup().


Function Documentation

void muxevent_add ( int  time,
int  flags,
int  type,
void(*)(MUXEVENT *)  func,
void *  data,
void *  data2 
)

Definition at line 111 of file event.c.

References ADD_TO_BIDIR_LIST_HEAD, my_event_type::data, my_event_type::data2, my_event_type::ev, my_event_type::flags, my_event_type::function, last_muxevent_type, muxevent_first_in_type, muxevent_free_list, muxevent_list, muxevent_tick, muxevent_wakeup(), my_event_type::next, my_event_type::tick, and my_event_type::type.

Referenced by artillery_shoot(), and bomb_drop().

00112                                  {
00113     MUXEVENT *e = (MUXEVENT *)0xDEADBEEF;
00114     struct timeval tv = { 0, 0};
00115 
00116     int i, spot;
00117 
00118     if (time < 1)
00119         time = 1;
00120     /* Nasty thing about the new system : we _do_ have to allocate
00121        muxevent_first_in_type dynamically. */
00122     if (type > last_muxevent_type) {
00123         muxevent_first_in_type =
00124             realloc(muxevent_first_in_type, sizeof(MUXEVENT *) * (type + 1));
00125         for (i = last_muxevent_type + 1; i <= type; i++)
00126             muxevent_first_in_type[i] = NULL;
00127         last_muxevent_type = type;
00128     }
00129     if (muxevent_free_list) {
00130         e = muxevent_free_list;
00131         muxevent_free_list = muxevent_free_list->next;
00132     } else {
00133         e = malloc(sizeof(MUXEVENT));
00134         memset(e, 0, sizeof(MUXEVENT));
00135     }
00136 
00137     e->flags = flags;
00138     e->function = func;
00139     e->data = data;
00140     e->data2 = data2;
00141     e->type = type;
00142     e->tick = muxevent_tick + time;
00143     e->next = NULL;
00144 
00145 
00146     tv.tv_sec = time;
00147     tv.tv_usec = 0;
00148     
00149     evtimer_set(&e->ev, muxevent_wakeup, e);
00150     evtimer_add(&e->ev, &tv);
00151 
00152     ADD_TO_BIDIR_LIST_HEAD(muxevent_list, prev_in_main, next_in_main, e);
00153     ADD_TO_BIDIR_LIST_HEAD(muxevent_first_in_type[type], prev_in_type,
00154             next_in_type, e);
00155 }

int muxevent_count_data ( int  type,
void *  data 
)

Definition at line 311 of file event.c.

References my_event_type::data, and LoopEvent.

00311                                               {
00312     MUXEVENT *e;
00313     int count = 0;
00314 
00315     LoopEvent(e)
00316         if (e->data == data)
00317             count++;
00318     return count;
00319 }

int muxevent_count_data_data ( int  type,
void *  data,
void *  data2 
)

Definition at line 322 of file event.c.

References my_event_type::data, my_event_type::data2, and LoopEvent.

00322                                                                 {
00323     MUXEVENT *e;
00324     int count = 0;
00325 
00326     LoopEvent(e)
00327         if (e->data == data && e->data2 == data2)
00328             count++;
00329     return count;
00330 }

int muxevent_count_type ( int  type  ) 

Definition at line 263 of file event.c.

References last_muxevent_type, and LoopType.

Referenced by debug_EventTypes().

00263                                   {
00264     MUXEVENT *e;
00265     int count = 0;
00266 
00267     if (type > last_muxevent_type)
00268         return count;
00269     LoopType(type, e)
00270         count++;
00271     return count;
00272 }

int muxevent_count_type_data ( int  type,
void *  data 
)

Definition at line 275 of file event.c.

References my_event_type::data, last_muxevent_type, and LoopType.

Referenced by auto_eventstats(), auto_pilot_on(), and DestroySection().

00275                                                    {
00276     MUXEVENT *e;
00277     int count = 0;
00278 
00279     if (type > last_muxevent_type)
00280         return count;
00281     LoopType(type, e)
00282         if (e->data == data)
00283             count++;
00284     return count;
00285 }

int muxevent_count_type_data2 ( int  type,
void *  data 
)

Definition at line 287 of file event.c.

References my_event_type::data2, last_muxevent_type, and LoopType.

Referenced by DS_Bay_Is_EnterOK().

00287                                                     {
00288     MUXEVENT *e;
00289     int count = 0;
00290 
00291     if (type > last_muxevent_type)
00292         return count;
00293     LoopType(type, e)
00294         if (e->data2 == data)
00295             count++;
00296     return count;
00297 }

int muxevent_count_type_data_data ( int  type,
void *  data,
void *  data2 
)

Definition at line 299 of file event.c.

References my_event_type::data, my_event_type::data2, last_muxevent_type, and LoopType.

00299                                                                      {
00300     MUXEVENT *e;
00301     int count = 0;
00302 
00303     if (type > last_muxevent_type)
00304         return count;
00305     LoopType(type, e)
00306         if (e->data == data && e->data2 == data2)
00307             count++;
00308     return count;
00309 }

int muxevent_count_type_data_firstev ( int  type,
void *  data 
)

Definition at line 378 of file event.c.

References my_event_type::data, my_event_type::data2, last_muxevent_type, and LoopType.

00378                                                            {
00379     MUXEVENT *e;
00380 
00381     if (type > last_muxevent_type)
00382         return -1;
00383     LoopType(type, e)
00384         if (e->data == data)
00385         {
00386             return (int) (e->data2);
00387         }
00388     return -1;
00389 }

static void muxevent_delete ( MUXEVENT  )  [static]

Definition at line 159 of file event.c.

References ADD_TO_LIST_HEAD, my_event_type::data, my_event_type::data2, my_event_type::ev, FLAG_FREE_DATA, FLAG_FREE_DATA2, my_event_type::flags, muxevent_first_in_type, muxevent_free_list, muxevent_list, REMOVE_FROM_BIDIR_LIST, and my_event_type::type.

Referenced by muxevent_wakeup().

00159                                           {
00160     if(evtimer_pending(&e->ev, NULL)) {
00161         evtimer_del(&e->ev);
00162     }
00163 
00164     if (e->flags & FLAG_FREE_DATA)
00165         free((void *) e->data);
00166     if (e->flags & FLAG_FREE_DATA2)
00167         free((void *) e->data2);
00168 
00169     REMOVE_FROM_BIDIR_LIST(muxevent_list, prev_in_main, next_in_main, e);
00170     REMOVE_FROM_BIDIR_LIST(muxevent_first_in_type[(int) e->type],
00171             prev_in_type, next_in_type, e);
00172     ADD_TO_LIST_HEAD(muxevent_free_list, next, e);
00173 }

int muxevent_first_type_data ( int  type,
void *  data 
)

Definition at line 364 of file event.c.

References my_event_type::data, last_muxevent_type, LoopType, muxevent_tick, and my_event_type::tick.

00364                                                    {
00365     MUXEVENT *e;
00366     int last = -1, t;
00367 
00368     if (type > last_muxevent_type)
00369         return last;
00370     LoopType(type, e)
00371         if (e->data == data)
00372             if ((t = (e->tick - muxevent_tick)) < last || last < 0)
00373                 if (t > 0)
00374                     last = t;
00375     return last;
00376 }

void muxevent_get_type_data ( int  type,
void *  data,
int *  data2 
)

Definition at line 254 of file event.c.

References my_event_type::data, my_event_type::data2, and LoopType.

00254                                                               {
00255     MUXEVENT *e;
00256 
00257     LoopType(type, e)
00258         if (e->data == data)
00259             *data2 = (int) e->data2;
00260 }

void muxevent_gothru_type ( int  type,
void(*)(MUXEVENT *)  func 
)

Definition at line 342 of file event.c.

References last_muxevent_type, and LoopType.

Referenced by saverepairs().

00342                                                                {
00343     MUXEVENT *e;
00344 
00345     if (type > last_muxevent_type)
00346         return;
00347     LoopType(type, e)
00348         func(e);
00349 }

void muxevent_gothru_type_data ( int  type,
void *  data,
void(*)(MUXEVENT *)  func 
)

Definition at line 332 of file event.c.

References my_event_type::data, last_muxevent_type, and LoopType.

Referenced by CanScrapLoc(), figure_latest_tech_event(), mechSensorInfo(), show_sensor(), and tech_repairs().

00332                                                                                 {
00333     MUXEVENT *e;
00334 
00335     if (type > last_muxevent_type)
00336         return;
00337     LoopType(type, e)
00338         if (e->data == data)
00339             func(e);
00340 }

void muxevent_initialize ( void   ) 

Definition at line 205 of file event.c.

References dprintk.

Referenced by LoadSpecialObjects(), and main().

00205                            {
00206     dprintk("muxevent initializing");
00207 }

int muxevent_last_type ( void   ) 

Definition at line 199 of file event.c.

References last_muxevent_type.

Referenced by debug_EventTypes().

00199                          {
00200     return last_muxevent_type;
00201 }

int muxevent_last_type_data ( int  type,
void *  data 
)

Definition at line 351 of file event.c.

References my_event_type::data, last_muxevent_type, LoopType, muxevent_tick, and my_event_type::tick.

Referenced by inferno_burn(), and ProlongUncon().

00351                                                   {
00352     MUXEVENT *e;
00353     int last = 0, t;
00354 
00355     if (type > last_muxevent_type)
00356         return last;
00357     LoopType(type, e)
00358         if (e->data == data)
00359             if ((t = (e->tick - muxevent_tick)) > last)
00360                 last = t;
00361     return last;
00362 }

void muxevent_remove_data ( void *  data  ) 

Definition at line 211 of file event.c.

References my_event_type::data, FLAG_ZOMBIE, my_event_type::flags, muxevent_list, and my_event_type::next_in_main.

Referenced by DisposeSpecialObject(), fun_btloadmech(), and mechrep_Rloadnew().

00211                                       {
00212     MUXEVENT *e;
00213 
00214     for (e = muxevent_list; e; e = e->next_in_main)
00215         if (e->data == data)
00216             e->flags |= FLAG_ZOMBIE;
00217 }

void muxevent_remove_type_data ( int  type,
void *  data 
)

Definition at line 219 of file event.c.

References my_event_type::data, FLAG_ZOMBIE, my_event_type::flags, last_muxevent_type, muxevent_first_in_type, and my_event_type::next_in_type.

Referenced by auto_radio_command_sensor(), auto_stop_pilot(), inferno_burn(), ProlongUncon(), and water_extinguish_inferno().

00219                                                      {
00220     MUXEVENT *e;
00221 
00222     if (type > last_muxevent_type)
00223         return;
00224     for (e = muxevent_first_in_type[type]; e; e = e->next_in_type)
00225         if (e->data == data) {
00226                 
00227             e->flags |= FLAG_ZOMBIE;
00228         }
00229 }

void muxevent_remove_type_data2 ( int  type,
void *  data 
)

Definition at line 231 of file event.c.

References my_event_type::data2, FLAG_ZOMBIE, my_event_type::flags, last_muxevent_type, muxevent_first_in_type, and my_event_type::next_in_type.

00231                                                       {
00232     MUXEVENT *e;
00233 
00234     if (type > last_muxevent_type)
00235         return;
00236     for (e = muxevent_first_in_type[type]; e; e = e->next_in_type)
00237         if (e->data2 == data)
00238             e->flags |= FLAG_ZOMBIE;
00239 }

void muxevent_remove_type_data_data ( int  type,
void *  data,
void *  data2 
)

Definition at line 241 of file event.c.

References my_event_type::data, my_event_type::data2, FLAG_ZOMBIE, my_event_type::flags, last_muxevent_type, muxevent_first_in_type, and my_event_type::next_in_type.

00241                                                                        {
00242     MUXEVENT *e;
00243 
00244     if (type > last_muxevent_type)
00245         return;
00246     for (e = muxevent_first_in_type[type]; e; e = e->next_in_type)
00247         if (e->data == data && e->data2 == data2)
00248             e->flags |= FLAG_ZOMBIE;
00249 }

void muxevent_run ( void   ) 

Definition at line 177 of file event.c.

References muxevent_tick.

Referenced by main(), and UpdateSpecialObjects().

00177                     {
00178     muxevent_tick += 1;
00179 }

int muxevent_run_by_type ( int  type  ) 

Definition at line 181 of file event.c.

References FLAG_ZOMBIE, last_muxevent_type, muxevent_first_in_type, my_event_type::next_in_type, postrun_event(), prerun_event(), and Zombie.

Referenced by ResetSpecialObjects().

00181                                    {
00182     MUXEVENT *e;
00183     int ran = 0;
00184 
00185     if (type <= last_muxevent_type) {
00186         for (e = muxevent_first_in_type[type]; e; e = e->next_in_type) {
00187             if (!Zombie(e)) {
00188                 prerun_event(e);
00189                 e->function(e);
00190                 postrun_event(e);
00191                 e->flags |= FLAG_ZOMBIE;
00192                 ran++;
00193             }
00194         }
00195     }
00196     return ran;
00197 }

static void muxevent_wakeup ( int  fd,
short  event,
void *  arg 
) [static]

Definition at line 98 of file event.c.

References muxevent_delete(), postrun_event(), prerun_event(), and Zombie.

Referenced by muxevent_add().

00098                                                             {
00099     MUXEVENT *e = (MUXEVENT *)arg;
00100 
00101     if(Zombie(e)) {
00102         muxevent_delete(e);
00103         return;
00104     }
00105     prerun_event(e);
00106     e->function(e);
00107     postrun_event(e);
00108     muxevent_delete(e);
00109 }

void postrun_event ( MUXEVENT e  ) 

Definition at line 90 of file events.c.

Referenced by muxevent_run_by_type(), and muxevent_wakeup().

00091 {
00092 }

void prerun_event ( MUXEVENT e  ) 

Definition at line 86 of file events.c.

Referenced by muxevent_run_by_type(), and muxevent_wakeup().

00087 {
00088 }


Variable Documentation

int last_muxevent_type = -1 [static]

Definition at line 81 of file event.c.

Referenced by muxevent_add(), muxevent_count_type(), muxevent_count_type_data(), muxevent_count_type_data2(), muxevent_count_type_data_data(), muxevent_count_type_data_firstev(), muxevent_first_type_data(), muxevent_gothru_type(), muxevent_gothru_type_data(), muxevent_last_type(), muxevent_last_type_data(), muxevent_remove_type_data(), muxevent_remove_type_data2(), muxevent_remove_type_data_data(), and muxevent_run_by_type().

MUXEVENT** muxevent_first_in_type = NULL [static]

Definition at line 73 of file event.c.

Referenced by muxevent_add(), muxevent_delete(), muxevent_remove_type_data(), muxevent_remove_type_data2(), muxevent_remove_type_data_data(), and muxevent_run_by_type().

MUXEVENT* muxevent_free_list = NULL [static]

Definition at line 79 of file event.c.

Referenced by muxevent_add(), and muxevent_delete().

MUXEVENT* muxevent_list = NULL [static]

Definition at line 76 of file event.c.

Referenced by muxevent_add(), muxevent_delete(), and muxevent_remove_data().

int muxevent_tick = 0

Definition at line 70 of file event.c.

Referenced by aero_move_event(), ai_check_path(), cause_internaldamage(), cheat_find_last(), CheckDamage(), describe_repairs(), DestroyParts(), DSOkToNotify(), Dump_Decrease(), game_lag(), HandleOverheat(), map_update(), MNumber(), muxevent_add(), muxevent_first_type_data(), muxevent_last_type_data(), muxevent_run(), recycle_weaponry(), save_event(), sendchannelstuff(), UpdateHeat(), and UpdatePilotSkillRolls().


Generated on Mon May 28 04:25:26 2007 for BattletechMUX by  doxygen 1.4.7