0d7e75cfa6439ee0bae376ec0028f4d2ecfd694f.svn-base (2207B)
1 #ifndef ACTORCOLLISION_H 2 #define ACTORCOLLISION_H 3 4 #include "Utils.h" 5 #include "Console.h" 6 #include "DiagnosticDraw.h" 7 #include "Event.h" 8 #include "Actor.h" 9 10 #define MAX_ACTORS 1024 11 12 #define CELLS_X 10 13 #define CELLS_Y 4 14 #define CELL_COUNT (CELLS_X*CELLS_Y) 15 16 class SpatialMonitor : public EventReceiver 17 { 18 public: 19 20 SpatialMonitor() : mActorCount(0), mAdjacentActorCount(0) 21 { 22 } 23 24 SpatialMonitor(int worldH, int worldW) : mActorCount(0), mAdjacentActorCount(0) 25 { 26 PartitionCells(worldH, worldW); 27 } 28 29 bool VecLogActor(Actor& act) 30 { 31 //mvActors.push_back( &act ); 32 //act.SetSpatID(mActorCount); 33 mActorCount += 1; 34 return true; 35 } 36 37 int* GetAdjacentCells(int cellnum, int cells[9]); 38 39 bool LogActor(Actor& act); //Logs an actor with the spatial monitor. called on program startup 40 41 bool EventProcess(Event eve); 42 43 SDL_Rect GetCell(int i) //Gets the cell rect of a cell number 44 { 45 return mCells[i]; 46 } 47 48 protected: 49 50 bool PartitionCells(int worldH, int worldW); //divides the level into cells based on macro parameters 51 52 bool GetActorsInCell(int cellnum); 53 54 bool GetAdjacentActors(int cellnum); 55 56 bool DetectActorCollision(int id1, int id2); //checks two logged actors for intersection 57 58 bool DetectRectSensors(SDL_Rect* sensor, int detectorID, int foreignID); //Called in HandleRectSensors, checks given rectangle for intersects 59 60 int UpdateActorCell(int id); //Updates the the cell number that contains a logged actor, Called when an MOVED_THIS_FRAME event is processed 61 62 int GetActorCell(int id) //Gets the cell number of an actor 63 { 64 return mActorCells[id]; 65 } 66 67 //int* GetAdjacentCells(int cellnum, int cells[9]); //populates and returns cells[9] with the cell numbers of cellnum and the 8 surrounding cells 68 69 bool HandleCollisions(int CallerID); //Called in event process, finds the actors in the cells adjacent to the cell of CallerID and checks them for collision with CallerID 70 71 bool HandleRectSensors(SDL_Rect* sensor, int CallerID, SensorType SeType); 72 73 bool TestBlockers(SDL_Rect* sensor, int CallerID); 74 75 76 Actor* mActors[MAX_ACTORS]; 77 int mActorCells[MAX_ACTORS]; 78 SDL_Rect mCells[CELL_COUNT]; 79 int mActorCount; 80 int mAdjacentActorIDs[MAX_ACTORS]; 81 int mAdjacentActorCount; 82 }; 83 84 #endif 85