5 entity CallbackChain_New(string name)
9 e.classname = "callbackchain";
14 float CallbackChain_Add(entity cb, float() func, float order)
17 if(order & CBC_ORDER_FIRST)
19 if(order & CBC_ORDER_LAST)
20 if(cb.cbc_order & CBC_ORDER_ANY)
22 if(cb.cbc_order & CBC_ORDER_FIRST)
25 else if(order & CBC_ORDER_LAST)
27 if(cb.cbc_order & CBC_ORDER_LAST)
32 thiscb.classname = "callback";
33 thiscb.cbc_func = func;
34 thiscb.cbc_order = order;
35 if(order & CBC_ORDER_FIRST)
37 thiscb.cbc_next = cb.cbc_next;
40 else if(order & CBC_ORDER_LAST)
42 for(e = cb; e.cbc_next; e = e.cbc_next);
47 // by default we execute last, but before a possible CBC_ORDER_LAST callback
48 for(e = cb; e.cbc_next && !(e.cbc_next.cbc_order & CBC_ORDER_LAST); e = e.cbc_next); // we must make sure that we insert BEFORE an CBC_ORDER_LAST mutator!
49 thiscb.cbc_next = e.cbc_next;
52 cb.cbc_order |= (order | CBC_ORDER_ANY);
56 float CallbackChain_Remove(entity cb, float() func)
62 for(e = cb; e.cbc_next; e = e.cbc_next)
64 while(e.cbc_next.cbc_func == func)
66 // remove e.cbc_next from the chain
68 e2 = e.cbc_next.cbc_next;
73 // e.cbc_next is now something we want to keep
74 order |= (e.cbc_next.cbc_order & CBC_ORDER_ANY);
80 float CallbackChain_Call(entity cb)
85 for(e = cb; e.cbc_next; e = e.cbc_next)
86 r |= e.cbc_next.cbc_func();
87 return r; // callbacks return an error status, so 0 is default return value
90 float Mutator_Add(float(float) func)
92 if(func(MUTATOR_ADDING) == 0)
97 backtrace("WARNING: when adding mutator: adding failed\n");
101 void Mutator_Remove(float(float) func)
103 if(func(MUTATOR_REMOVING) != 0)
106 error("Mutator_Remove: removing mutator failed");