00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021 #ifndef _TMWSERV_GAMESERVER_EVENTLISTENER_
00022 #define _TMWSERV_GAMESERVER_EVENTLISTENER_
00023
00024 class Thing;
00025 class Being;
00026 class Character;
00027
00028 struct EventDispatch;
00029
00033 struct EventListener
00034 {
00035 const EventDispatch *dispatch;
00036 EventListener(const EventDispatch *d): dispatch(d) {}
00037 };
00038
00042 struct EventDispatch
00043 {
00047 void (*inserted)(const EventListener *, Thing *);
00048
00052 void (*removed)(const EventListener *, Thing *);
00053
00057 void (*died)(const EventListener *, Being *);
00058
00062 void (*disconnected)(const EventListener *, Character *);
00063
00067 EventDispatch():
00068 inserted(0), removed(0), died(0), disconnected(0)
00069 {}
00070 };
00071
00084 template< class T, EventListener T::*D >
00085 struct EventListenerFactory
00086 {
00087 template< class U, void (T::*F)(U *), class V = U >
00088 struct create
00089 {
00090 static void function(const EventListener *d, V *u)
00091 {
00092
00093
00094 T *t = (T *)((char *)d -
00095 ((char *)&(((T *)42)->*D) - (char *)&(*(T *)42)));
00096
00097 (t->*F)(u);
00098 }
00099 };
00100 };
00101
00102 #endif