[7956] Fixed possible runtime crash.
[getmangos.git] / src / shared / vmap / CoordModelMapping.h
blob71b51631192c646b6c094e0a79954b3bb458f17f
1 /*
2 * Copyright (C) 2005-2009 MaNGOS <http://getmangos.com/>
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; either version 2 of the License, or
7 * (at your option) any later version.
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, write to the Free Software
16 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19 #ifndef _COORDMODELMAPPING_H_
20 #define _COORDMODELMAPPING_H_
22 #include <G3D/Table.h>
23 #include <G3D/Array.h>
25 /**
26 This Class is a helper Class to convert the raw vector data into BSP-Trees.
27 We read the directory file of the raw data output and build logical groups.
28 Models with a lot of vectors are not merged into a resulting model, but separated into an additional file.
31 namespace VMAP
34 #define MIN_VERTICES_FOR_OWN_CONTAINER_FILE 65000
36 // if we are in an instance
37 #define MIN_INST_VERTICES_FOR_OWN_CONTAINER_FILE 40000
39 //=====================================================
40 class NameCollection
42 public:
43 G3D::Array<std::string> iMainFiles;
44 G3D::Array<std::string> iSingeFiles;
46 void appendToMain(const std::string& pStr) { iMainFiles.append(pStr); }
47 void appendToSingle(const std::string& pStr) { iSingeFiles.append(pStr); }
49 size_t size() { return (iMainFiles.size() + iSingeFiles.size()); }
52 //=====================================================
54 class CMappingEntry
56 private:
57 int xPos;
58 int yPos;
59 unsigned int iMapId;
60 G3D::Array<std::string> iFilenames;
62 public:
63 CMappingEntry() { };
64 CMappingEntry(unsigned int pMapId, const int pXPos, const int pYPos)
66 iMapId = pMapId;
67 xPos = pXPos; yPos = pYPos;
69 ~CMappingEntry() {};
71 void addFilename(char *pName);
72 const std::string getKeyString() const;
73 inline const G3D::Array<std::string>& getFilenames() const { return(iFilenames); }
75 static const std::string getKeyString(unsigned int pMapId, int pXPos, int pYPos)
77 char b[100];
78 sprintf(b,"%03u_%d_%d", pMapId, pXPos, pYPos);
79 return(std::string(b));
84 //=====================================================
86 class CoordModelMapping
88 private:
89 G3D::Table<std::string, CMappingEntry *> iMapObjectFiles;
90 G3D::Table<std::string, std::string> iProcesseSingleFiles;
91 G3D::Array<unsigned int> iMapIds;
92 G3D::Array<unsigned int> iWorldAreaGroups;
93 bool (*iFilterMethod)(char *pName);
95 inline void addCMappingEntry(CMappingEntry* pCMappingEntry)
97 iMapObjectFiles.set(pCMappingEntry->getKeyString(), pCMappingEntry);
100 inline CMappingEntry* getCMappingEntry(const std::string& pKey)
102 if(iMapObjectFiles.containsKey(pKey))
103 return(iMapObjectFiles.get(pKey));
104 else
105 return 0;
108 public:
109 CoordModelMapping() { iFilterMethod = NULL; }
110 virtual ~CoordModelMapping();
112 bool readCoordinateMapping(const std::string& pDirectoryFileName);
114 const NameCollection getFilenamesForCoordinate(unsigned int pMapId, int xPos, int yPos);
116 static unsigned int getMapIdFromFilename(const std::string& pName)
118 size_t spos;
120 spos = pName.find_last_of('/');
121 std::string basename = pName.substr(0, spos);
122 spos = basename.find_last_of('/');
123 std::string groupname = basename.substr(spos+1, basename.length());
124 unsigned int mapId = atoi(groupname.c_str());
125 return(mapId);
128 const G3D::Array<unsigned int>& getMaps() const { return iMapIds; }
129 bool isAlreadyProcessedSingleFile(const std::string& pName) const { return iProcesseSingleFiles.containsKey(pName); }
130 void addAlreadyProcessedSingleFile(const std::string& pName) { iProcesseSingleFiles.set(pName,pName); }
132 inline void addWorldAreaMap(unsigned int pMapId)
134 if(!iWorldAreaGroups.contains(pMapId))
136 iWorldAreaGroups.append(pMapId);
139 bool isWorldAreaMap(unsigned int pMapId) const { return(iWorldAreaGroups.contains(pMapId)); }
140 void setModelNameFilterMethod(bool (*pFilterMethod)(char *pName)) { iFilterMethod = pFilterMethod; }
144 #endif /*_COORDMODELMAPPING_H_*/