Add infos into target window
[ryzomcore.git] / ryzom / server / src / gpm_service / patat_grid.h
blob0c168e0bf659582faf97b23cceffc7ca50c3d25e
1 // Ryzom - MMORPG Framework <http://dev.ryzom.com/projects/ryzom/>
2 // Copyright (C) 2010 Winch Gate Property Limited
3 //
4 // This program is free software: you can redistribute it and/or modify
5 // it under the terms of the GNU Affero General Public License as
6 // published by the Free Software Foundation, either version 3 of the
7 // License, or (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 Affero General Public License for more details.
14 // You should have received a copy of the GNU Affero General Public License
15 // along with this program. If not, see <http://www.gnu.org/licenses/>.
19 #ifndef NL_PATAT_GRID_H
20 #define NL_PATAT_GRID_H
22 // Nel Misc
23 #include "nel/misc/types_nl.h"
24 #include "nel/misc/stream.h"
26 // Nel Ligo
27 #include "nel/ligo/primitive.h"
30 #include "move_grid.h"
32 // stl
33 #include <deque>
34 #include <vector>
35 #include <map>
36 #include <set>
37 #include <string>
39 // resolution in meters
40 #define PatatGridResolution 1.0f
41 #define mmPatatGridResolution 1000
43 /**
44 * <Class description>
45 * \author Benjamin Legros
46 * \author Nevrax France
47 * \date 2002
49 class CPatatGrid
51 public:
52 /// \name public Typedefs
53 //@{
55 /// The grid entry index
56 typedef uint16 TEntryIndex;
58 //@}
60 protected:
61 /// \name typedefs
62 //@{
64 /// The container of prim zone
65 typedef std::vector<NLLIGO::CPrimZone> TZoneVector;
67 /// The entry type
68 class CEntry
70 public:
71 CEntry() : EntryIndex(0), HashCode(0), NumSamples(0) {}
72 /// The entry index for this entry
73 TEntryIndex EntryIndex;
74 /// The entry hash code
75 uint32 HashCode;
76 /// The number of point in grid that point to this entry
77 uint32 NumSamples;
78 /// The zones for this
79 std::vector<uint32> Zones;
81 /// serial
82 void serial(NLMISC::IStream &f)
84 sint version = f.serialVersion(0);
85 f.serial(EntryIndex, HashCode, NumSamples);
86 f.serialCont(Zones);
90 /// The entry table type
91 typedef std::vector<CEntry> TEntryTable;
93 /// The entry map type to find entry quickly
94 typedef std::multimap<uint32, TEntryIndex> TEntryMap;
96 /// The map of zone name (to zone id)
97 typedef std::map<std::string, sint32> TZoneMap;
99 /// The move grid, used as grid
100 typedef CMoveGrid<TEntryIndex, 1024, mmPatatGridResolution> TGrid;
102 //@}
104 /// \name Attributes
105 //@{
107 /// Patats
108 TZoneVector _PrimZones;
110 /// Patat map
111 TZoneMap _ZoneMap;
113 /// The move grid
114 TGrid _SelectGrid;
116 /// The entry table
117 TEntryTable _EntryTable;
119 /// The flag table
120 std::vector<bool> _FlagTable;
122 /// The fast entry map
123 TEntryMap _EntryMap;
125 /// The free table entries
126 std::deque<TEntryIndex> _FreeEntries;
128 //@}
130 /// \name Class filtering
131 //@{
133 std::set<std::string> _PrimZoneFilters;
135 //@}
137 public:
139 /// Constructor
140 CPatatGrid();
142 /// Destructor
143 ~CPatatGrid();
145 /// Init grid;
146 void init();
148 /// Use a prim file
149 void usePrim(const std::string &primFile, std::vector<uint32> &inFile);
151 /// Check if patat exists
152 bool exist(const std::string &name) const { return (_ZoneMap.find(name) != _ZoneMap.end()); }
154 /// Get entry index
155 sint32 getEntryIndex(const NLMISC::CVector &v)
157 _SelectGrid.select(v);
158 TGrid::CIterator it = _SelectGrid.begin();
159 sint32 index = (it != _SelectGrid.end()) ? (*it) : 0;
160 _SelectGrid.clearSelection();
161 return index;
164 /// Set entry index
165 void setEntryIndex(const NLMISC::CVector &v, sint32 entry)
167 _SelectGrid.select(v);
168 TGrid::CIterator it = _SelectGrid.begin();
169 if (it != _SelectGrid.end())
171 (*it) = (TEntryIndex)entry;
173 else
175 TEntryIndex idx = (TEntryIndex)entry;
176 _SelectGrid.insert(idx, v);
178 _SelectGrid.clearSelection();
181 /// Get zone id from its name
182 sint32 getZoneId(const std::string &name) const
184 TZoneMap::const_iterator it = _ZoneMap.find(name);
185 if (it == _ZoneMap.end())
187 nlwarning("Can't find Prim zone %s", name.c_str());
188 return 0;
190 return (*it).second;
193 /// Get zone name from its id
194 const std::string &getZoneName(uint32 id) const
196 std::string *ret;
197 if (_PrimZones[id].getPropertyByName("name", ret))
198 return *ret;
199 else
201 static std::string noName;
202 return noName;
206 /// Get zone differences between 2 entry
207 bool diff(TEntryIndex previous, TEntryIndex next, std::vector<uint32> &in, std::vector<uint32> &out);
209 /// Serial
210 void serial(NLMISC::IStream &f)
212 sint version = f.serialVersion(1);
214 f.serialCont(_PrimZones);
215 f.serialCont(_ZoneMap);
216 f.serial(_SelectGrid);
217 f.serialCont(_EntryTable);
218 f.serialCont(_FlagTable);
219 f.serialCont(_EntryMap);
220 f.serialCont(_FreeEntries);
222 if (version >= 1)
223 f.serialCont(_PrimZoneFilters);
226 /// Display
227 void displayInfo(NLMISC::CLog *log = NLMISC::InfoLog)
229 log->displayNL("Display PatatGrid PrimZones: %d zones", _PrimZones.size());
230 uint i, j;
231 for (i=0; i<_PrimZones.size(); ++i)
233 std::string name;
234 _PrimZones[i].getPropertyByName("name", name);
235 log->displayNL(" + %d: Name:%s Points:%d", i, name.c_str(), _PrimZones[i].VPoints.size());
238 log->displayNL("Display PatatGrid entries: %d entries", _EntryTable.size());
239 for (i=0; i<_EntryTable.size(); ++i)
241 log->displayNL(" + %d: EntryIndex:%d HashCode:%d NumSamples:%d", i, _EntryTable[i].EntryIndex, _EntryTable[i].HashCode, _EntryTable[i].NumSamples);
242 for (j=0; j<_EntryTable[i].Zones.size(); ++j)
243 log->displayNL(" + Zone %d", _EntryTable[i].Zones[j]);
246 log->displayNL("Display quick EntryMap: %d in map", _EntryMap.size());
247 TEntryMap::iterator ite;
248 for (ite=_EntryMap.begin(); ite!=_EntryMap.end(); ++ite)
249 log->displayNL(" + %d->%d", (*ite).first, (*ite).second);
251 log->displayNL("Display free Entries: %d free entries", _FreeEntries.size());
252 for (i=0; i<_FreeEntries.size(); ++i)
253 log->displayNL(" + %d", _FreeEntries[i]);
255 log->displayNL("End of PatatGrid info");
258 /// Add CPrimZone class filter
259 void addPrimZoneFilter(const std::string &filter)
261 _PrimZoneFilters.insert(filter);
264 /// Remove CPrimZone class filter
265 void removePrimZoneFilter(const std::string &filter)
267 _PrimZoneFilters.erase(filter);
270 /// Reset CPrimZone class filter
271 void resetPrimZoneFilter()
273 _PrimZoneFilters.clear();
276 protected:
278 /// read recursive primitive
279 void readPrimitive(NLLIGO::IPrimitive *primitive, std::vector<uint32> &inFile);
284 #endif // NL_PATAT_GRID_H
286 /* End of patat_grid.h */