00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021 #if !defined(__INCLUDE_TargetSpaceh_INCLUDE__)
00022 #define __INCLUDE_TargetSpaceh_INCLUDE__
00023
00024 #include <target/Target.h>
00025 #include <map>
00026 #include <set>
00027 #include <vector>
00028
00029 class ScorchedContext;
00030 class TargetSpace
00031 {
00032 public:
00033 TargetSpace();
00034 virtual ~TargetSpace();
00035
00036 void updateTarget(Target *target);
00037 void setContext(ScorchedContext *context) { context_ = context; }
00038
00039 Target *getCollision(FixedVector &position);
00040 void getCollisionSet(FixedVector &position, fixed radius,
00041 std::map<unsigned int, Target *> &collisionTargets,
00042 bool ignoreHeight = false);
00043
00044 void draw();
00045
00046 protected:
00047 class Square
00048 {
00049 public:
00050 std::map<unsigned int, Target *> targets;
00051 int squarenum;
00052 };
00053
00054 ScorchedContext *context_;
00055 Square *squares_;
00056 int spaceX_, spaceY_;
00057 int spaceW_, spaceH_;
00058 int spaceWSq_, spaceHSq_;
00059 int spaceSq_;
00060 int noSquares_;
00061
00062 void normalizeCoords(int &x, int &y)
00063 {
00064
00065 x = MIN(x, spaceW_ + spaceX_ - 1);
00066 x = MAX(x, spaceX_);
00067 y = MIN(y, spaceH_ + spaceY_ - 1);
00068 y = MAX(y, spaceY_);
00069
00070
00071 x -= spaceX_;
00072 y -= spaceY_;
00073 x /= spaceSq_;
00074 y /= spaceSq_;
00075 }
00076
00077 void getSquares(Target *target, std::vector<Square*> &squares);
00078 void removeTarget(Target *target);
00079
00080 private:
00081 TargetSpace(TargetSpace &other);
00082 TargetSpace &operator=(TargetSpace &other);
00083 };
00084
00085 #endif // __INCLUDE_TargetSpaceh_INCLUDE__