TapestryEngine

A 2D Platformer Game Engine
Log | Files | Refs

64f2a85cb0ce09b148d5f68c6cf515cd97055706.svn-base (3021B)


      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 	ANIM_COMPLETE,
     12 
     13 	KEY_DOWN,
     14 	KEY_UP,
     15 
     16 	ACTOR_COLLISION,
     17 	SENSOR_COLLISION,
     18 	PLAYER_CHECK,
     19 	PLAYER_CONFIRM,
     20 
     21 	MOVED_THIS_FRAME,
     22 	CHECK_RECT_SENSOR,
     23 	CHECK_BLOCKERS,
     24 
     25 	CAMERA_TARGET,
     26 
     27 	EMIT_PARTICLE,
     28 	CREATE_PARTICLE,
     29 
     30 	CREATE_POINT_SOUND,
     31 	ACTOR_PLAY_SOUND,
     32 	SOUND_COMPLETE,
     33 
     34 	SWITCH,
     35 
     36 	DIALOGUE,
     37 	SCROLL,
     38 	TERMINATE_DIALOGUE,
     39 
     40 	FADE,
     41 
     42 	TELEPORT,
     43 
     44 	INTERACT,
     45 
     46 	DAMAGE,
     47 
     48 	SPAWN,
     49 	DEATH
     50 };
     51 
     52 enum SensorType
     53 {
     54 	LOS, //Line Of Sight
     55 	Attack,
     56 	Touch,
     57 };
     58 
     59 struct SensorData
     60 {
     61 	SensorType st;
     62 	SDL_Rect* sensor;
     63 	int ID;
     64 };
     65 
     66 struct SensorResponse
     67 {
     68 	SensorType st;
     69 	void* er;
     70 };
     71 
     72 struct PointSpawnData
     73 {
     74 	int x;
     75 	int y;
     76 	char* name;
     77 	char* type;
     78 };
     79 
     80 struct DialogueData
     81 {
     82 	char* str;
     83 	void* talker;
     84 };
     85 
     86 union EventData
     87 {
     88 	int i;
     89 	void* p;
     90 	bool b;
     91 	char* str;
     92 	SDL_Rect* rect;
     93 	SensorData sd;
     94 	SensorResponse sr;
     95 	PointSpawnData psd;
     96 	DialogueData dd;
     97 };
     98 
     99 class Event
    100 {
    101 public:
    102 	Event() : mType(), mEvData(), mReturnAddress(NULL) {}
    103 
    104 	Event(EventType EvType) : mType(EvType), mEvData(), mReturnAddress(NULL) {}
    105 
    106 	Event(EventType EvType, EventData EvData, void* ReturnAddress = NULL) : mType(EvType), mEvData(EvData), mReturnAddress(ReturnAddress) {}
    107 
    108 	Event(EventType EvType, int j) : mType(EvType), mReturnAddress(NULL)
    109 	{
    110 		mEvData.i = j;
    111 	}
    112 
    113 	Event(EventType EvType, void* P) : mType(EvType), mReturnAddress(NULL)
    114 	{
    115 		mEvData.p = P;
    116 	}
    117 
    118 	Event(EventType EvType, char* str) : mType(EvType), mReturnAddress(NULL)
    119 	{
    120 		mEvData.str = str;
    121 	}
    122 
    123 	Event(EventType EvType, SensorType SeType, SDL_Rect* sensor, int ID) : mType(EvType), mReturnAddress(NULL) //CHECK_RECT_SENSOR constructor
    124 	{
    125 		mEvData.sd.st = SeType;
    126 		mEvData.sd.sensor = sensor;
    127 		mEvData.sd.ID = ID;
    128 	}
    129 
    130 	Event(EventType EvType, SensorType SeType, void* er) : mType(EvType), mReturnAddress(NULL)
    131 	{
    132 		mEvData.sr.st = SeType;
    133 		mEvData.sr.er = er;
    134 	}
    135 
    136 	Event(EventType EvType, char* type, char* name, int x, int y) : mType(EvType), mReturnAddress(NULL)
    137 	{
    138 		mEvData.psd.x = x;
    139 		mEvData.psd.y = y;
    140 		mEvData.psd.name = name;
    141 		mEvData.psd.type = type;
    142 	}
    143 
    144 	Event(EventType EvType, char* str, void* talk) : mType(EvType), mReturnAddress(NULL)
    145 	{
    146 		mEvData.dd.str = str;
    147 		mEvData.dd.talker = talk;
    148 	}
    149 
    150 	EventType* GetEventType()
    151 	{
    152 		return &mType;
    153 	}
    154 
    155 	EventData* GetEventData()
    156 	{
    157 		return &mEvData;
    158 	}
    159 
    160 	void* GetReturnAddress()
    161 	{
    162 		if(mReturnAddress != NULL)
    163 		{
    164 			return mReturnAddress;
    165 		}
    166 		gCons->ConsPrintf("No return address listed for this event\n");
    167 		return NULL;
    168 	}
    169 
    170 protected:
    171 
    172 	EventType mType;
    173 	EventData mEvData;
    174 	void* mReturnAddress;
    175 };
    176 
    177 class EventReceiver
    178 {
    179 public:
    180 
    181 	virtual bool EventProcess(Event eve) = 0;
    182 };
    183 
    184 class EventFeed  :  EventReceiver
    185 {
    186 public:
    187 	
    188 	EventFeed() : mSubs(), mNumberOfSubs(0) {}
    189 
    190 	bool Subscribe(EventReceiver* sub);
    191 
    192 	bool Unsubscribe(EventReceiver* sub);
    193 
    194 	bool EventProcess(Event eve);
    195 
    196 protected:
    197 
    198 	std::vector<EventReceiver*> mSubs;
    199 	int mNumberOfSubs;
    200 };
    201 
    202 class EventManager
    203 {
    204 public:
    205 protected:
    206 };
    207 
    208 #endif