1 // NeL - MMORPG Framework <http://dev.ryzom.com/projects/nel/>
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/>.
17 #ifndef NL_PRIM_CHECKER_H
18 #define NL_PRIM_CHECKER_H
20 #include "nel/misc/types_nl.h"
21 #include "nel/misc/stream.h"
23 #include <nel/misc/polygon.h>
37 * A class that reads .primitive files from ligo and that allows
38 * to define flags over pacs surfaces with CPrimZone
39 * \author Benjamin Legros
40 * \author Nevrax France
51 /// Bits value for landscape
63 bool build(const std::string
&primitivesPath
, const std::string
&igLandPath
, const std::string
&igVillagePath
, const std::string
&outputDirectory
= "./", bool forceRebuild
= false);
65 /// load CPrimChecker state
66 bool load(const std::string
&outputDirectory
= "./");
68 /// Reads bits value at a given position
69 uint8
get(uint x
, uint y
) const { return _Grid
.get(x
, y
); }
71 /// Reads bits value at a given position
72 uint16
index(uint x
, uint y
) const { return _Grid
.index(x
, y
); }
75 float waterHeight(uint index
, bool &exists
) const
77 if (index
>= _WaterHeight
.size())
83 return _WaterHeight
[index
];
86 /// Render a CPolygon of bit value
87 void renderBits(const NLMISC::CPolygon
&poly
, uint8 bits
);
91 /// \name Grid management
95 * A class that allows to store 65536x65536 elements with minimum allocation and dynamic allocation of elements
105 void set(uint x
, uint y
, uint8 bits
)
107 CGridCell
*cell
= _Grid
[((x
&0xff00)>>8) + (y
&0xff00)];
110 cell
= new CGridCell();
111 _Grid
[((x
&0xff00)>>8) + (y
&0xff00)] = cell
;
113 cell
->set(x
, y
, bits
);
117 uint8
get(uint x
, uint y
) const
119 CGridCell
*cell
= _Grid
[((x
&0xff00)>>8) + (y
&0xff00)];
120 return cell
!= NULL
? cell
->get(x
, y
) : (uint8
)0;
124 void index(uint x
, uint y
, uint16 idx
)
126 CGridCell
*cell
= _Grid
[((x
&0xff00)>>8) + (y
&0xff00)];
129 cell
= new CGridCell();
130 _Grid
[((x
&0xff00)>>8) + (y
&0xff00)] = cell
;
132 cell
->index(x
, y
, idx
);
136 uint16
index(uint x
, uint y
) const
138 CGridCell
*cell
= _Grid
[((x
&0xff00)>>8) + (y
&0xff00)];
139 return cell
!= NULL
? cell
->index(x
, y
) : (uint16
)0;
146 for (uint i
=0; i
<256*256; ++i
)
155 void serial(NLMISC::IStream
&f
)
157 f
.serialCheck(NELID("PCHK"));
163 for (uint i
=0; i
<256*256; ++i
)
165 bool present
= (_Grid
[i
] != NULL
);
170 if (_Grid
[i
] == NULL
)
171 _Grid
[i
] = new CGridCell();
180 * A class that allows to store 256x256 elements
190 CGridElm() : _Value(0) {}
192 uint8
flags() const { return (uint8
)((_Value
>> 11) & 0x1f); }
193 void flags(uint8 bits
) { _Value
|= (((uint16
)bits
) << 11); }
194 uint16
index() const { return _Value
& 0x07ff; }
195 void index(uint16 idx
) { _Value
= ((idx
& 0x07ff) | (_Value
& 0xf800)); }
197 void serial(NLMISC::IStream
&f
) { f
.serial(_Value
); }
206 void set(uint x
, uint y
, uint8 bits
) { _Grid
[(x
&0xff) + ((y
&0xff)<<8)].flags(bits
); }
209 uint8
get(uint x
, uint y
) const { return _Grid
[(x
&0xff) + ((y
&0xff)<<8)].flags(); }
213 uint16
index(uint x
, uint y
) { return _Grid
[(x
&0xff) + ((y
&0xff)<<8)].index(); }
215 void index(uint x
, uint y
, uint idx
) { _Grid
[(x
&0xff) + ((y
&0xff)<<8)].index(idx
); }
219 void serial(NLMISC::IStream
&f
) { for (uint i
=0; i
<256*256; ++i
) f
.serial(_Grid
[i
]); }
222 CGridElm _Grid
[256*256];
225 CGridCell
*_Grid
[256*256];
230 std::vector
<float> _WaterHeight
;
236 /// Reads a primitive file and renders contained primitives into grid
237 void readFile(const std::string
&filename
);
239 /// Reads a primitive and its sub primitives
240 void readPrimitive(NLLIGO::IPrimitive
*primitive
);
242 /// Renders a primitive
243 void render(NLLIGO::CPrimZone
*zone
, uint8 bits
);
245 /// Render a water shape, as a CPolygon
246 void render(const NLMISC::CPolygon
&poly
, uint16 value
);
250 #endif // NL_PRIM_CHECKER_H
252 /* End of prim_checker.h */