00001
00002
00003
00004
00005
00006
00007
00008
00009
00011
00012 #ifndef HGEDATAGRID__
00013 #define HGEDATAGRID__
00014
00015 #include <hge.h>
00016 #include <vector>
00017 #include <hgevector.h>
00018 #include <hgerect.h>
00019
00020 #include "hgeShape.h"
00021 #include "hgePolygon.h"
00022 #include "hgeEntity.h"
00023 #include "hgeIntersect.h"
00024
00025
00026 enum hgePolygonMapCollide
00027 {
00028 COLLIDE_STATIC = 1,
00029 COLLIDE_DYNAMIC = 2,
00030 COLLIDE_ALL = 3,
00031 COLLIDE_VISIBLE = 4,
00032 COLLIDE_MULTI = 8
00033 };
00034
00036
00037
00038 struct hgePolygonCellData
00039 {
00040 hgePolygon *polygon;
00041 byte layer;
00042 int sublayer;
00043 bool rflag;
00044
00045 hgePolygonCellData(hgePolygon *m_Polygon, byte m_Layer, int m_Sublayer)
00046 {
00047 polygon = m_Polygon;
00048 layer = m_Layer;
00049 sublayer = m_Sublayer;
00050 rflag = 0;
00051 }
00052 };
00053
00055
00056
00057 struct hgePolygonCell
00058 {
00059 hgeRect rect;
00060 std::vector<hgePolygonCellData*> objects;
00061 };
00062
00064
00065
00066 class hgePolygonGrid
00067 {
00068 private:
00069
00070
00071 HGE *hge;
00072
00073 hgeRect area;
00074 hgeVector cell_size;
00075
00076 int gs_x;
00077 int gs_y;
00078 int gs_count;
00079
00080
00081 int prev_x1;
00082 int prev_y1;
00083 int prev_x2;
00084 int prev_y2;
00085
00086
00087 std::vector<hgePolygonCellData*> polys;
00088
00089
00090 std::vector<hgePolygonCell *> cells;
00091
00092
00093 std::vector<hgePolygonCellData *> visible;
00094
00095
00096 hgeRect *viewport;
00097
00098 public:
00099
00100
00101 hgePolygonGrid(hgeRect m_Area, hgeRect *m_Viewport, hgeVector m_CellSize = hgeVector(800, 600));
00102
00103 ~hgePolygonGrid();
00104
00105
00106 void Prepare();
00107
00108
00109 void Render(int m_Layer = -1);
00110
00111 void Update(float dt);
00112
00113
00114 hgePolygon *TestPoint(hgeVector point, std::string class_filter = "", int layer_filter = -1);
00115
00116
00117 hgeIntersect Test(hgeShape *shape, hgeVector offset = hgeVector(0,0), hgePolygon **return_poly = NULL, int test_type = COLLIDE_STATIC, std::string class_filter = "", int layer_filter = -1);
00118
00119
00120 hgeIntersect TestEx(hgeEntityEx *polygon, hgeVector offset = hgeVector(0,0), float rot = 0, hgePolygon **return_poly = NULL, int test_type = COLLIDE_STATIC, std::string class_filter = "", int layer_filter = -1);
00121
00122
00123 void AddPolygon(hgePolygon *m_Poly, byte m_Layer);
00124 };
00125
00126 #endif