1 // Ryzom - MMORPG Framework <http://dev.ryzom.com/projects/ryzom/>
2 // Copyright (C) 2010 Winch Gate Property Limited
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.
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
23 #include "nel/misc/types_nl.h"
24 #include "nel/misc/stream.h"
27 #include "nel/ligo/primitive.h"
30 #include "move_grid.h"
39 // resolution in meters
40 #define PatatGridResolution 1.0f
41 #define mmPatatGridResolution 1000
45 * \author Benjamin Legros
46 * \author Nevrax France
52 /// \name public Typedefs
55 /// The grid entry index
56 typedef uint16 TEntryIndex
;
64 /// The container of prim zone
65 typedef std::vector
<NLLIGO::CPrimZone
> TZoneVector
;
71 CEntry() : EntryIndex(0), HashCode(0), NumSamples(0) {}
72 /// The entry index for this entry
73 TEntryIndex EntryIndex
;
74 /// The entry hash code
76 /// The number of point in grid that point to this entry
78 /// The zones for this
79 std::vector
<uint32
> Zones
;
82 void serial(NLMISC::IStream
&f
)
84 sint version
= f
.serialVersion(0);
85 f
.serial(EntryIndex
, HashCode
, NumSamples
);
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
;
108 TZoneVector _PrimZones
;
117 TEntryTable _EntryTable
;
120 std::vector
<bool> _FlagTable
;
122 /// The fast entry map
125 /// The free table entries
126 std::deque
<TEntryIndex
> _FreeEntries
;
130 /// \name Class filtering
133 std::set
<std::string
> _PrimZoneFilters
;
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()); }
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();
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
;
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());
193 /// Get zone name from its id
194 const std::string
&getZoneName(uint32 id
) const
197 if (_PrimZones
[id
].getPropertyByName("name", ret
))
201 static std::string noName
;
206 /// Get zone differences between 2 entry
207 bool diff(TEntryIndex previous
, TEntryIndex next
, std::vector
<uint32
> &in
, std::vector
<uint32
> &out
);
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
);
223 f
.serialCont(_PrimZoneFilters
);
227 void displayInfo(NLMISC::CLog
*log
= NLMISC::InfoLog
)
229 log
->displayNL("Display PatatGrid PrimZones: %d zones", _PrimZones
.size());
231 for (i
=0; i
<_PrimZones
.size(); ++i
)
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();
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 */