00001
00002
00003
00004
00005
00007
00012 #ifndef HGEPOLYGONMAP__
00013 #define HGEPOLYGONMAP__
00014
00015 #include "hgeDataGrid.h"
00016 #include "hgePolygon.h"
00017 #include "hgeEntity.h"
00018
00019
00020 enum hgePolygonMapLayers
00021 {
00022 HGELAYER_BACK = 0,
00023 HGELAYER_MIDDLE = 1,
00024 HGELAYER_FRONT = 2
00025 };
00026
00027
00028 struct __quickEntityLookup
00029 {
00030 int id;
00031 int layer;
00032 std::string classname;
00033 std::vector<hgeEntity *> entitys;
00034
00035 __quickEntityLookup() : id(-1), layer(-1) {}
00036 __quickEntityLookup(int m_id, int m_layer, std::string m_classname) : id(m_id), layer(m_layer), classname(m_classname) { }
00037 };
00038
00046 class hgePolygonMap
00047 {
00048 private:
00049
00050
00051 hgeRect view;
00052 hgeVector viewSize;
00053 hgeVector viewSize_2;
00054
00055
00056 hgeRect map_size;
00057
00058
00059 HGE *hge;
00060
00061
00062
00063 std::vector<hgePolygon *> background;
00064 std::vector<hgePolygon *> middleground;
00065 std::vector<hgePolygon *> foreground;
00066
00067
00068 std::vector<hgeEntity *> entitys;
00069
00070
00071 std::vector<__quickEntityLookup *> entity_lookup;
00072
00073
00074 void CreateEntityLookup(__quickEntityLookup lookup);
00075
00076
00077 int entityClassIDCounter;
00078
00079
00080 std::vector<hgeEntity*> entClasses;
00081
00082
00083 hgePolygonGrid *grid;
00084
00085
00086 float zoom;
00087 float rotation;
00088 hgeVector pos;
00089
00090 hgePolygon *AddPolygon(hgePolygon * p, int layer = HGELAYER_BACK);
00091
00092
00093 std::vector<hgePolygon *> * GetLayer(int l);
00094
00095 public:
00096
00097
00098 bool SaveFile(std::string filename = "MyFile.map");
00099 bool LoadFile(std::string filename = "MyFile.map");
00100
00101
00102 std::vector<hgeEntity *> *GetDynamicEntityList(int m_renderlayer);
00103 std::vector<hgeEntity *> *GetDynamicEntityList(std::string m_classname);
00104
00105
00106 hgePolygon *GetStaticEntityFromProperty(std::string m_pname, std::string m_pval);
00107 hgePolygon *GetDynamicEntityFromProperty(std::string m_pname, std::string m_pval);
00108
00109
00110
00111
00112
00113
00114 void RegisterEntityClass(std::string entclass, hgeEntity *ent);
00115
00116
00117 void SetTransform(hgeVector m_pos, float m_zoom = 1);
00118
00119
00120 hgeVector MapToScreen(hgeVector pos);
00121
00122
00123 hgeVector ScreenToMap(hgeVector pos);
00124
00125
00126 void hgePolygonMap::AddDynamicEntity(hgeEntity *entity, bool initialize_entity = true);
00127
00128
00129 void hgePolygonMap::RemoveDynamicEntitys(std::string entity_class);
00130
00131
00132 bool TestVisibility(hgePolygon *p, float padding = 0);
00133
00134
00135 hgePolygon * TestPoint(hgeVector pos, int test_type = COLLIDE_STATIC, std::string class_filter = "", int layer_filter = -1);
00136
00137
00138 hgeIntersect Test( hgeShape *shape,
00139 hgeVector offset = hgeVector(0,0),
00140 hgePolygon **return_poly = NULL,
00141 int test_type = COLLIDE_STATIC,
00142 std::string class_filter = "",
00143 int layer_filter = -1 );
00144
00145
00146 hgeIntersect TestEx( hgeEntityEx *polygon,
00147 hgeVector offset = hgeVector(0,0),
00148 float rot = 0,
00149 hgePolygon **return_poly = NULL,
00150 int test_type = COLLIDE_STATIC,
00151 std::string class_filter = "",
00152 int layer_filter = -1 );
00153
00154
00155 void Clear();
00156
00157
00158 void Update(float dt);
00159
00160
00161 void Render();
00162
00163
00164 hgePolygonMap(hgeVector m_viewSize = hgeVector(800, 600));
00165 };
00166
00167 #endif