25e21d9b6c88cece29e78c47950febdd0d1e53f4.svn-base (3818B)
1 #ifndef EVENT_H 2 #define EVENT_H 3 4 #include "Utils.h" 5 #include "Console.h" 6 7 enum EventType 8 { 9 UNSUBSCRIBE, 10 11 //ASSIGN_HANDLE, 12 //GET_ACTOR_ADDRESS, 13 14 ANIM_COMPLETE, 15 16 KEY_DOWN, 17 KEY_UP, 18 19 ACTOR_COLLISION, 20 SENSOR_COLLISION, 21 PLAYER_CHECK, 22 PLAYER_CONFIRM, 23 24 MOVED_THIS_FRAME, 25 CHECK_RECT_SENSOR, 26 CHECK_BLOCKERS, 27 28 CAMERA_TARGET, 29 30 EMIT_PARTICLE, 31 CREATE_PARTICLE, 32 33 CREATE_POINT_SOUND, 34 ACTOR_PLAY_SOUND, 35 SOUND_COMPLETE, 36 37 SWITCH, 38 39 DIALOGUE, 40 SCROLL, 41 TERMINATE_DIALOGUE, 42 43 FADE, 44 45 TELEPORT, 46 47 INTERACT, 48 49 DAMAGE, 50 51 SPAWN, 52 DEATH, 53 54 GAME_OVER 55 }; 56 57 enum SensorType 58 { 59 LOS, //Line Of Sight 60 Attack, 61 Touch, 62 }; 63 64 struct SensorData 65 { 66 SensorType st; 67 SDL_Rect* sensor; 68 int id; 69 }; 70 71 struct SensorResponse 72 { 73 SensorType st; 74 int id; 75 }; 76 77 struct PointSpawnData 78 { 79 int x; 80 int y; 81 char* name; 82 char* type; 83 }; 84 85 struct DialogueData 86 { 87 char* str; 88 int talkerID; 89 }; 90 91 struct FadeData 92 { 93 int duration; 94 int color; 95 int opacity; 96 }; 97 98 struct DamageData 99 { 100 int damage; 101 int attackerID; 102 }; 103 104 union EventData 105 { 106 int i; 107 void* p; 108 bool b; 109 char* str; 110 SDL_Rect* rect; 111 SensorData sd; 112 SensorResponse sr; 113 PointSpawnData psd; 114 DialogueData dd; 115 FadeData fd; 116 DamageData damd; 117 }; 118 119 class EventReceiver; //Forward Declare event receiver 120 121 class Event 122 { 123 public: 124 Event() : mType(), mEvData() {} //, mReturnAddress(NULL) {} 125 126 Event(EventType EvType) : mType(EvType), mEvData() {} 127 128 //Event(EventType EvType, ActHandle ReturnAddress = NULL) : mType(EvType), mEvData(), mReturnAddress(ReturnAddress) {} 129 130 Event(EventType EvType, EventData EvData, int ReturnAddress = NULL) : mType(EvType), mEvData(EvData), mReturnAddress(ReturnAddress) {} 131 132 Event(EventType EvType, int i) : mType(EvType), mReturnAddress(NULL) 133 { 134 mEvData.i = i; 135 } 136 137 Event(EventType EvType, void* P) : mType(EvType), mReturnAddress(NULL) 138 { 139 mEvData.p = P; 140 } 141 142 Event(EventType EvType, char* str) : mType(EvType), mReturnAddress(NULL) 143 { 144 mEvData.str = str; 145 } 146 147 Event(EventType EvType, SensorType SeType, SDL_Rect* sensor, int ID) : mType(EvType), mReturnAddress(NULL) //CHECK_RECT_SENSOR constructor 148 { 149 mEvData.sd.st = SeType; 150 mEvData.sd.sensor = sensor; 151 mEvData.sd.id = ID; 152 } 153 154 Event(EventType EvType, SensorType SeType, ActHandle ID) : mType(EvType), mReturnAddress(NULL) //collision response constructor: SENSOR_COLLISION, 155 { 156 mEvData.sr.st = SeType; 157 mEvData.sr.id = ID; 158 } 159 160 Event(EventType EvType, char* type, char* name, int x, int y) : mType(EvType), mReturnAddress(NULL) 161 { 162 mEvData.psd.x = x; 163 mEvData.psd.y = y; 164 mEvData.psd.name = name; 165 mEvData.psd.type = type; 166 } 167 168 Event(EventType EvType, char* str, int talkID) : mType(EvType), mReturnAddress(NULL) 169 { 170 mEvData.dd.str = str; 171 mEvData.dd.talkerID = talkID; 172 } 173 174 Event(EventType EvType, int duration, int color, int opacity) : mType(EvType), mReturnAddress(NULL) 175 { 176 mEvData.fd.duration = duration; 177 mEvData.fd.color = color; 178 mEvData.fd.opacity = opacity; 179 } 180 181 Event(EventType EvType, int damage, int attacker_handle) : mType(EvType), mReturnAddress(NULL) 182 { 183 mEvData.damd.damage = damage; 184 mEvData.damd.attackerID = attacker_handle; 185 } 186 187 EventType* GetEventType() 188 { 189 return &mType; 190 } 191 192 EventData* GetEventData() 193 { 194 return &mEvData; 195 } 196 197 int GetReturnAddress() 198 { 199 if(mReturnAddress != NULL) 200 { 201 return mReturnAddress; 202 } 203 gCons->ConsPrintf("No return address listed for this event\n"); 204 return NULL; 205 } 206 207 protected: 208 209 EventType mType; 210 EventData mEvData; 211 int mReturnAddress; 212 }; 213 214 class EventReceiver 215 { 216 public: 217 218 virtual bool EventProcess(Event eve) = 0; 219 }; 220 221 class EventFeed : EventReceiver 222 { 223 public: 224 225 EventFeed() : mSubs(), mNumberOfSubs(0) {} 226 227 bool Subscribe(EventReceiver* sub); 228 229 bool Unsubscribe(EventReceiver* sub); 230 231 bool EventProcess(Event eve); 232 233 protected: 234 235 std::vector<EventReceiver*> mSubs; 236 int mNumberOfSubs; 237 }; 238 239 class EventManager 240 { 241 public: 242 protected: 243 }; 244 245 #endif