AzerothCore 3.3.5a
OpenSource WoW Emulator
Loading...
Searching...
No Matches
VMAP::WmoLiquid Class Reference

#include "WorldModel.h"

Public Member Functions

 WmoLiquid (uint32 width, uint32 height, const G3D::Vector3 &corner, uint32 type)
 
 WmoLiquid (const WmoLiquid &other)
 
 ~WmoLiquid ()
 
WmoLiquidoperator= (const WmoLiquid &other)
 
bool GetLiquidHeight (const G3D::Vector3 &pos, float &liqHeight) const
 
uint32 GetType () const
 
float * GetHeightStorage ()
 
uint8GetFlagsStorage ()
 
uint32 GetFileSize ()
 
bool writeToFile (FILE *wf)
 
void GetPosInfo (uint32 &tilesX, uint32 &tilesY, G3D::Vector3 &corner) const
 

Static Public Member Functions

static bool readFromFile (FILE *rf, WmoLiquid *&liquid)
 

Private Member Functions

 WmoLiquid ()
 

Private Attributes

uint32 iTilesX {0}
 number of tiles in x direction, each
 
uint32 iTilesY {0}
 
G3D::Vector3 iCorner
 the lower corner
 
uint32 iType {0}
 liquid type
 
float * iHeight {nullptr}
 (tilesX + 1)*(tilesY + 1) height values
 
uint8iFlags {nullptr}
 info if liquid tile is used
 

Detailed Description

Constructor & Destructor Documentation

◆ WmoLiquid() [1/3]

VMAP::WmoLiquid::WmoLiquid ( uint32  width,
uint32  height,
const G3D::Vector3 &  corner,
uint32  type 
)

◆ WmoLiquid() [2/3]

VMAP::WmoLiquid::WmoLiquid ( const WmoLiquid other)
122 : iHeight(0), iFlags(0)
123 {
124 *this = other; // use assignment operator...
125 }
float * iHeight
(tilesX + 1)*(tilesY + 1) height values
Definition: WorldModel.h:67
uint8 * iFlags
info if liquid tile is used
Definition: WorldModel.h:68

◆ ~WmoLiquid()

VMAP::WmoLiquid::~WmoLiquid ( )
128 {
129 delete[] iHeight;
130 delete[] iFlags;
131 }

References iFlags, and iHeight.

◆ WmoLiquid() [3/3]

VMAP::WmoLiquid::WmoLiquid ( )
inlineprivate
62{ }

Referenced by readFromFile().

Member Function Documentation

◆ GetFileSize()

uint32 VMAP::WmoLiquid::GetFileSize ( )
234 {
235 return 2 * sizeof(uint32) +
236 sizeof(Vector3) +
237 sizeof(uint32) +
238 (iFlags ? ((iTilesX + 1) * (iTilesY + 1) * sizeof(float) + iTilesX * iTilesY) : sizeof(float));
239 }
std::uint32_t uint32
Definition: Define.h:108
uint32 iTilesY
Definition: WorldModel.h:64
uint32 iTilesX
number of tiles in x direction, each
Definition: WorldModel.h:63

References iFlags, iTilesX, and iTilesY.

Referenced by VMAP::GroupModel::writeToFile().

◆ GetFlagsStorage()

uint8 * VMAP::WmoLiquid::GetFlagsStorage ( )
inline
56{ return iFlags; }

References iFlags.

Referenced by MMAP::TerrainBuilder::loadVMap(), and VMAP::GroupModel_Raw::Read().

◆ GetHeightStorage()

float * VMAP::WmoLiquid::GetHeightStorage ( )
inline
55{ return iHeight; }

References iHeight.

Referenced by MMAP::TerrainBuilder::loadVMap(), and VMAP::GroupModel_Raw::Read().

◆ GetLiquidHeight()

bool VMAP::WmoLiquid::GetLiquidHeight ( const G3D::Vector3 &  pos,
float &  liqHeight 
) const
167 {
168 // simple case
169 if (!iFlags)
170 {
171 liqHeight = iHeight[0];
172 return true;
173 }
174
175 float tx_f = (pos.x - iCorner.x) / LIQUID_TILE_SIZE;
176 uint32 tx = uint32(tx_f);
177 if (tx_f < 0.0f || tx >= iTilesX)
178 {
179 return false;
180 }
181 float ty_f = (pos.y - iCorner.y) / LIQUID_TILE_SIZE;
182 uint32 ty = uint32(ty_f);
183 if (ty_f < 0.0f || ty >= iTilesY)
184 {
185 return false;
186 }
187
188 // check if tile shall be used for liquid level
189 // checking for 0x08 *might* be enough, but disabled tiles always are 0x?F:
190 if (iFlags && (iFlags[tx + ty * iTilesX] & 0x0F) == 0x0F)
191 {
192 return false;
193 }
194
195 // (dx, dy) coordinates inside tile, in [0, 1]^2
196 float dx = tx_f - (float)tx;
197 float dy = ty_f - (float)ty;
198
199 /* Tesselate tile to two triangles (not sure if client does it exactly like this)
200
201 ^ dy
202 |
203 1 x---------x (1, 1)
204 | (b) / |
205 | / |
206 | / |
207 | / (a) |
208 x---------x---> dx
209 0 1
210 */
211
212 if (!iHeight)
213 {
214 return false;
215 }
216
217 const uint32 rowOffset = iTilesX + 1;
218 if (dx > dy) // case (a)
219 {
220 float sx = iHeight[tx + 1 + ty * rowOffset] - iHeight[tx + ty * rowOffset];
221 float sy = iHeight[tx + 1 + (ty + 1) * rowOffset] - iHeight[tx + 1 + ty * rowOffset];
222 liqHeight = iHeight[tx + ty * rowOffset] + dx * sx + dy * sy;
223 }
224 else // case (b)
225 {
226 float sx = iHeight[tx + 1 + (ty + 1) * rowOffset] - iHeight[tx + (ty + 1) * rowOffset];
227 float sy = iHeight[tx + (ty + 1) * rowOffset] - iHeight[tx + ty * rowOffset];
228 liqHeight = iHeight[tx + ty * rowOffset] + dx * sx + dy * sy;
229 }
230 return true;
231 }
#define LIQUID_TILE_SIZE
Definition: VMapDefinitions.h:22
G3D::Vector3 iCorner
the lower corner
Definition: WorldModel.h:65

References iCorner, iFlags, iHeight, iTilesX, iTilesY, and LIQUID_TILE_SIZE.

Referenced by VMAP::GroupModel::GetLiquidLevel().

◆ GetPosInfo()

void VMAP::WmoLiquid::GetPosInfo ( uint32 tilesX,
uint32 tilesY,
G3D::Vector3 &  corner 
) const
306 {
307 tilesX = iTilesX;
308 tilesY = iTilesY;
309 corner = iCorner;
310 }

References iCorner, iTilesX, and iTilesY.

Referenced by MMAP::TerrainBuilder::loadVMap().

◆ GetType()

uint32 VMAP::WmoLiquid::GetType ( ) const
inline
54{ return iType; }
uint32 iType
liquid type
Definition: WorldModel.h:66

References iType.

Referenced by VMAP::GroupModel::GetLiquidType(), and MMAP::TerrainBuilder::loadVMap().

◆ operator=()

WmoLiquid & VMAP::WmoLiquid::operator= ( const WmoLiquid other)
134 {
135 if (this == &other)
136 {
137 return *this;
138 }
139 iTilesX = other.iTilesX;
140 iTilesY = other.iTilesY;
141 iCorner = other.iCorner;
142 iType = other.iType;
143 delete[] iHeight;
144 delete[] iFlags;
145 if (other.iHeight)
146 {
147 iHeight = new float[(iTilesX + 1) * (iTilesY + 1)];
148 memcpy(iHeight, other.iHeight, (iTilesX + 1) * (iTilesY + 1)*sizeof(float));
149 }
150 else
151 {
152 iHeight = 0;
153 }
154 if (other.iFlags)
155 {
156 iFlags = new uint8[iTilesX * iTilesY];
157 memcpy(iFlags, other.iFlags, iTilesX * iTilesY);
158 }
159 else
160 {
161 iFlags = 0;
162 }
163 return *this;
164 }
std::uint8_t uint8
Definition: Define.h:110

References iCorner, iFlags, iHeight, iTilesX, iTilesY, and iType.

◆ readFromFile()

bool VMAP::WmoLiquid::readFromFile ( FILE *  rf,
WmoLiquid *&  liquid 
)
static
266 {
267 bool result = false;
268 WmoLiquid* liquid = new WmoLiquid();
269
270 if (fread(&liquid->iTilesX, sizeof(uint32), 1, rf) == 1 &&
271 fread(&liquid->iTilesY, sizeof(uint32), 1, rf) == 1 &&
272 fread(&liquid->iCorner, sizeof(Vector3), 1, rf) == 1 &&
273 fread(&liquid->iType, sizeof(uint32), 1, rf) == 1)
274 {
275 if (liquid->iTilesX && liquid->iTilesY)
276 {
277 uint32 size = (liquid->iTilesX + 1) * (liquid->iTilesY + 1);
278 liquid->iHeight = new float[size];
279 if (fread(liquid->iHeight, sizeof(float), size, rf) == size)
280 {
281 size = liquid->iTilesX * liquid->iTilesY;
282 liquid->iFlags = new uint8[size];
283 result = fread(liquid->iFlags, sizeof(uint8), size, rf) == size;
284 }
285 }
286 else
287 {
288 liquid->iHeight = new float[1];
289 result = fread(liquid->iHeight, sizeof(float), 1, rf) == 1;
290 }
291 }
292
293 if (!result)
294 {
295 delete liquid;
296 }
297 else
298 {
299 out = liquid;
300 }
301
302 return result;
303 }
WmoLiquid()
Definition: WorldModel.h:62

References iCorner, iFlags, iHeight, iTilesX, iTilesY, iType, and WmoLiquid().

Referenced by VMAP::GroupModel::readFromFile().

◆ writeToFile()

bool VMAP::WmoLiquid::writeToFile ( FILE *  wf)
242 {
243 bool result = false;
244 if (fwrite(&iTilesX, sizeof(uint32), 1, wf) == 1 &&
245 fwrite(&iTilesY, sizeof(uint32), 1, wf) == 1 &&
246 fwrite(&iCorner, sizeof(Vector3), 1, wf) == 1 &&
247 fwrite(&iType, sizeof(uint32), 1, wf) == 1)
248 {
249 if (iTilesX && iTilesY)
250 {
251 uint32 size = (iTilesX + 1) * (iTilesY + 1);
252 if (fwrite(iHeight, sizeof(float), size, wf) == size)
253 {
254 size = iTilesX * iTilesY;
255 result = fwrite(iFlags, sizeof(uint8), size, wf) == size;
256 }
257 }
258 else
259 result = fwrite(iHeight, sizeof(float), 1, wf) == 1;
260 }
261
262 return result;
263 }

References iCorner, iFlags, iHeight, iTilesX, iTilesY, and iType.

Referenced by VMAP::GroupModel::writeToFile().

Member Data Documentation

◆ iCorner

G3D::Vector3 VMAP::WmoLiquid::iCorner
private

the lower corner

Referenced by GetLiquidHeight(), GetPosInfo(), operator=(), readFromFile(), and writeToFile().

◆ iFlags

uint8* VMAP::WmoLiquid::iFlags {nullptr}
private

◆ iHeight

float* VMAP::WmoLiquid::iHeight {nullptr}
private

(tilesX + 1)*(tilesY + 1) height values

Referenced by GetHeightStorage(), GetLiquidHeight(), operator=(), readFromFile(), writeToFile(), and ~WmoLiquid().

◆ iTilesX

uint32 VMAP::WmoLiquid::iTilesX {0}
private

number of tiles in x direction, each

Referenced by GetFileSize(), GetLiquidHeight(), GetPosInfo(), operator=(), readFromFile(), and writeToFile().

◆ iTilesY

uint32 VMAP::WmoLiquid::iTilesY {0}
private

◆ iType

uint32 VMAP::WmoLiquid::iType {0}
private

liquid type

Referenced by GetType(), operator=(), readFromFile(), and writeToFile().