root/trunk/src/shared/vmap/CoordModelMapping.h @ 2

Revision 2, 5.1 kB (checked in by yumileroy, 17 years ago)

[svn] * Proper SVN structure

Original author: Neo2003
Date: 2008-10-02 16:23:55-05:00

Line 
1/*
2 * Copyright (C) 2005-2008 MaNGOS <http://www.mangosproject.org/>
3 *
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.
8 *
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.
13 *
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
17 */
18
19#ifndef _COORDMODELMAPPING_H_
20#define _COORDMODELMAPPING_H_
21
22#include <G3D/Table.h>
23#include <G3D/Array.h>
24
25/**
26This Class is a helper Class to convert the raw vector data into BSP-Trees.
27We read the directory file of the raw data output and build logical groups.
28Models with a lot of vectors are not merged into a resulting model, but separated into an additional file.
29*/
30
31namespace VMAP
32{
33
34    #define MIN_VERTICES_FOR_OWN_CONTAINER_FILE 65000
35
36    // if we are in an instance
37    #define MIN_INST_VERTICES_FOR_OWN_CONTAINER_FILE 40000
38
39    //=====================================================
40    class NameCollection
41    {
42        public:
43            G3D::Array<std::string> iMainFiles;
44            G3D::Array<std::string> iSingeFiles;
45
46            void appendToMain(std::string pStr) { iMainFiles.append(pStr); }
47            void appendToSingle(std::string pStr) { iSingeFiles.append(pStr); }
48
49            size_t size() { return (iMainFiles.size() + iSingeFiles.size()); }
50    };
51
52    //=====================================================
53
54    class CMappingEntry
55    {
56        private:
57            int xPos;
58            int yPos;
59            unsigned int iMapId;
60            G3D::Array<std::string> iFilenames;
61
62        public:
63            CMappingEntry() { };
64            CMappingEntry(unsigned int pMapId, const int pXPos, const int pYPos)
65            {
66                iMapId = pMapId;
67                xPos = pXPos; yPos = pYPos;
68            };
69            ~CMappingEntry() {};
70
71            void addFilename(char *pName);
72            const std::string getKeyString() const;
73            inline const G3D::Array<std::string>& getFilenames() const { return(iFilenames); }
74
75            static const std::string getKeyString(unsigned int pMapId, int pXPos, int pYPos)
76            {
77                char b[100];
78                sprintf(b,"%03u_%d_%d", pMapId, pXPos, pYPos);
79                return(std::string(b));
80            }
81
82    };
83
84    //=====================================================
85
86    class CoordModelMapping
87    {
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);
94
95            inline void addCMappingEntry(CMappingEntry* pCMappingEntry)
96            {
97                iMapObjectFiles.set(pCMappingEntry->getKeyString(), pCMappingEntry);
98            }
99
100            inline CMappingEntry* getCMappingEntry(const std::string& pKey)
101            {
102                if(iMapObjectFiles.containsKey(pKey))
103                    return(iMapObjectFiles.get(pKey));
104                else
105                    return 0;
106            }
107
108        public:
109            CoordModelMapping() { iFilterMethod = NULL; }
110            virtual ~CoordModelMapping();
111
112            bool readCoordinateMapping(const std::string& pDirectoryFileName);
113
114            const NameCollection getFilenamesForCoordinate(unsigned int pMapId, int xPos, int yPos);
115
116            static unsigned int getMapIdFromFilename(std::string pName)
117            {
118                size_t spos;
119
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);
126            }
127
128            const G3D::Array<unsigned int>& getMaps() const { return iMapIds; }
129            inline bool isAlreadyProcessedSingleFile(std::string pName) { return(iProcesseSingleFiles.containsKey(pName)); }
130            inline void addAlreadyProcessedSingleFile(std::string pName) { iProcesseSingleFiles.set(pName,pName); }
131
132            inline void addWorldAreaMap(unsigned int pMapId)
133            {
134                if(!iWorldAreaGroups.contains(pMapId))
135                {
136                    iWorldAreaGroups.append(pMapId);
137                }
138            }
139            inline bool isWorldAreaMap(unsigned int pMapId) { return(iWorldAreaGroups.contains(pMapId)); }
140            void setModelNameFilterMethod(bool (*pFilterMethod)(char *pName)) { iFilterMethod = pFilterMethod; }
141
142    };
143}
144#endif                                                      /*_COORDMODELMAPPING_H_*/
Note: See TracBrowser for help on using the browser.