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