TrinityCore
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
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
 number of tiles in x direction, each More...
 
uint32 iTilesY
 
G3D::Vector3 iCorner
 the lower corner More...
 
uint32 iType
 liquid type More...
 
float * iHeight
 (tilesX + 1)*(tilesY + 1) height values More...
 
uint8iFlags
 info if liquid tile is used More...
 

Constructor & Destructor Documentation

VMAP::WmoLiquid::WmoLiquid ( uint32  width,
uint32  height,
const G3D::Vector3 corner,
uint32  type 
)
104  :
105  iTilesX(width), iTilesY(height), iCorner(corner), iType(type)
106  {
107  iHeight = new float[(width+1)*(height+1)];
108  iFlags = new uint8[width*height];
109  }
float * iHeight
(tilesX + 1)*(tilesY + 1) height values
Definition: WorldModel.h:68
uint8 * iFlags
info if liquid tile is used
Definition: WorldModel.h:69
G3D::Vector3 iCorner
the lower corner
Definition: WorldModel.h:66
uint32 iTilesX
number of tiles in x direction, each
Definition: WorldModel.h:64
uint32 iType
liquid type
Definition: WorldModel.h:67
uint8_t uint8
Definition: Define.h:152
uint32 iTilesY
Definition: WorldModel.h:65
VMAP::WmoLiquid::WmoLiquid ( const WmoLiquid other)
111  : iHeight(nullptr), iFlags(nullptr)
112  {
113  *this = other; // use assignment operator...
114  }
float * iHeight
(tilesX + 1)*(tilesY + 1) height values
Definition: WorldModel.h:68
uint8 * iFlags
info if liquid tile is used
Definition: WorldModel.h:69
VMAP::WmoLiquid::~WmoLiquid ( )
117  {
118  delete[] iHeight;
119  delete[] iFlags;
120  }
float * iHeight
(tilesX + 1)*(tilesY + 1) height values
Definition: WorldModel.h:68
uint8 * iFlags
info if liquid tile is used
Definition: WorldModel.h:69
VMAP::WmoLiquid::WmoLiquid ( )
inlineprivate
63 : iTilesX(0), iTilesY(0), iCorner(), iType(0), iHeight(NULL), iFlags(NULL) { }
float * iHeight
(tilesX + 1)*(tilesY + 1) height values
Definition: WorldModel.h:68
arena_t NULL
Definition: jemalloc_internal.h:624
uint8 * iFlags
info if liquid tile is used
Definition: WorldModel.h:69
G3D::Vector3 iCorner
the lower corner
Definition: WorldModel.h:66
uint32 iTilesX
number of tiles in x direction, each
Definition: WorldModel.h:64
uint32 iType
liquid type
Definition: WorldModel.h:67
uint32 iTilesY
Definition: WorldModel.h:65

+ Here is the caller graph for this function:

Member Function Documentation

uint32 VMAP::WmoLiquid::GetFileSize ( )
199  {
200  return 2 * sizeof(uint32) +
201  sizeof(Vector3) +
202  (iTilesX + 1)*(iTilesY + 1) * sizeof(float) +
203  iTilesX * iTilesY;
204  }
Definition: Vector3.h:58
uint32 iTilesX
number of tiles in x direction, each
Definition: WorldModel.h:64
uint32 iTilesY
Definition: WorldModel.h:65
uint32_t uint32
Definition: g3dmath.h:168

+ Here is the caller graph for this function:

uint8* VMAP::WmoLiquid::GetFlagsStorage ( )
inline
57 { return iFlags; }
uint8 * iFlags
info if liquid tile is used
Definition: WorldModel.h:69

+ Here is the caller graph for this function:

float* VMAP::WmoLiquid::GetHeightStorage ( )
inline
56 { return iHeight; }
float * iHeight
(tilesX + 1)*(tilesY + 1) height values
Definition: WorldModel.h:68

+ Here is the caller graph for this function:

bool VMAP::WmoLiquid::GetLiquidHeight ( const G3D::Vector3 pos,
float &  liqHeight 
) const
150  {
151  float tx_f = (pos.x - iCorner.x)/LIQUID_TILE_SIZE;
152  uint32 tx = uint32(tx_f);
153  if (tx_f < 0.0f || tx >= iTilesX)
154  return false;
155  float ty_f = (pos.y - iCorner.y)/LIQUID_TILE_SIZE;
156  uint32 ty = uint32(ty_f);
157  if (ty_f < 0.0f || ty >= iTilesY)
158  return false;
159 
160  // check if tile shall be used for liquid level
161  // checking for 0x08 *might* be enough, but disabled tiles always are 0x?F:
162  if ((iFlags[tx + ty*iTilesX] & 0x0F) == 0x0F)
163  return false;
164 
165  // (dx, dy) coordinates inside tile, in [0, 1]^2
166  float dx = tx_f - (float)tx;
167  float dy = ty_f - (float)ty;
168 
169  /* Tesselate tile to two triangles (not sure if client does it exactly like this)
170 
171  ^ dy
172  |
173  1 x---------x (1, 1)
174  | (b) / |
175  | / |
176  | / |
177  | / (a) |
178  x---------x---> dx
179  0 1
180  */
181 
182  const uint32 rowOffset = iTilesX + 1;
183  if (dx > dy) // case (a)
184  {
185  float sx = iHeight[tx+1 + ty * rowOffset] - iHeight[tx + ty * rowOffset];
186  float sy = iHeight[tx+1 + (ty+1) * rowOffset] - iHeight[tx+1 + ty * rowOffset];
187  liqHeight = iHeight[tx + ty * rowOffset] + dx * sx + dy * sy;
188  }
189  else // case (b)
190  {
191  float sx = iHeight[tx+1 + (ty+1) * rowOffset] - iHeight[tx + (ty+1) * rowOffset];
192  float sy = iHeight[tx + (ty+1) * rowOffset] - iHeight[tx + ty * rowOffset];
193  liqHeight = iHeight[tx + ty * rowOffset] + dx * sx + dy * sy;
194  }
195  return true;
196  }
float x
Definition: Vector3.h:62
float * iHeight
(tilesX + 1)*(tilesY + 1) height values
Definition: WorldModel.h:68
uint8 * iFlags
info if liquid tile is used
Definition: WorldModel.h:69
float y
Definition: Vector3.h:62
#define LIQUID_TILE_SIZE
Definition: VMapDefinitions.h:24
G3D::Vector3 iCorner
the lower corner
Definition: WorldModel.h:66
uint32 iTilesX
number of tiles in x direction, each
Definition: WorldModel.h:64
uint32_t uint32
Definition: Define.h:150
uint32 iTilesY
Definition: WorldModel.h:65
uint32_t uint32
Definition: g3dmath.h:168

+ Here is the caller graph for this function:

void VMAP::WmoLiquid::getPosInfo ( uint32 tilesX,
uint32 tilesY,
G3D::Vector3 corner 
) const
254  {
255  tilesX = iTilesX;
256  tilesY = iTilesY;
257  corner = iCorner;
258  }
G3D::Vector3 iCorner
the lower corner
Definition: WorldModel.h:66
uint32 iTilesX
number of tiles in x direction, each
Definition: WorldModel.h:64
uint32 iTilesY
Definition: WorldModel.h:65

+ Here is the caller graph for this function:

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

+ Here is the caller graph for this function:

WmoLiquid & VMAP::WmoLiquid::operator= ( const WmoLiquid other)
123  {
124  if (this == &other)
125  return *this;
126  iTilesX = other.iTilesX;
127  iTilesY = other.iTilesY;
128  iCorner = other.iCorner;
129  iType = other.iType;
130  delete iHeight;
131  delete iFlags;
132  if (other.iHeight)
133  {
134  iHeight = new float[(iTilesX+1)*(iTilesY+1)];
135  memcpy(iHeight, other.iHeight, (iTilesX+1)*(iTilesY+1)*sizeof(float));
136  }
137  else
138  iHeight = nullptr;
139  if (other.iFlags)
140  {
141  iFlags = new uint8[iTilesX * iTilesY];
142  memcpy(iFlags, other.iFlags, iTilesX * iTilesY);
143  }
144  else
145  iFlags = nullptr;
146  return *this;
147  }
float * iHeight
(tilesX + 1)*(tilesY + 1) height values
Definition: WorldModel.h:68
uint8 * iFlags
info if liquid tile is used
Definition: WorldModel.h:69
G3D::Vector3 iCorner
the lower corner
Definition: WorldModel.h:66
uint32 iTilesX
number of tiles in x direction, each
Definition: WorldModel.h:64
uint32 iType
liquid type
Definition: WorldModel.h:67
uint8_t uint8
Definition: Define.h:152
uint32 iTilesY
Definition: WorldModel.h:65
bool VMAP::WmoLiquid::readFromFile ( FILE *  rf,
WmoLiquid *&  liquid 
)
static
226  {
227  bool result = false;
228  WmoLiquid* liquid = new WmoLiquid();
229 
230  if (fread(&liquid->iTilesX, sizeof(uint32), 1, rf) == 1 &&
231  fread(&liquid->iTilesY, sizeof(uint32), 1, rf) == 1 &&
232  fread(&liquid->iCorner, sizeof(Vector3), 1, rf) == 1 &&
233  fread(&liquid->iType, sizeof(uint32), 1, rf) == 1)
234  {
235  uint32 size = (liquid->iTilesX + 1) * (liquid->iTilesY + 1);
236  liquid->iHeight = new float[size];
237  if (fread(liquid->iHeight, sizeof(float), size, rf) == size)
238  {
239  size = liquid->iTilesX * liquid->iTilesY;
240  liquid->iFlags = new uint8[size];
241  result = fread(liquid->iFlags, sizeof(uint8), size, rf) == size;
242  }
243  }
244 
245  if (!result)
246  delete liquid;
247  else
248  out = liquid;
249 
250  return result;
251  }
Definition: Vector3.h:58
WmoLiquid()
Definition: WorldModel.h:63
uint32_t uint32
Definition: Define.h:150
uint8_t uint8
Definition: Define.h:152

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

bool VMAP::WmoLiquid::writeToFile ( FILE *  wf)
207  {
208  bool result = false;
209  if (fwrite(&iTilesX, sizeof(uint32), 1, wf) == 1 &&
210  fwrite(&iTilesY, sizeof(uint32), 1, wf) == 1 &&
211  fwrite(&iCorner, sizeof(Vector3), 1, wf) == 1 &&
212  fwrite(&iType, sizeof(uint32), 1, wf) == 1)
213  {
214  uint32 size = (iTilesX + 1) * (iTilesY + 1);
215  if (fwrite(iHeight, sizeof(float), size, wf) == size)
216  {
217  size = iTilesX*iTilesY;
218  result = fwrite(iFlags, sizeof(uint8), size, wf) == size;
219  }
220  }
221 
222  return result;
223  }
float * iHeight
(tilesX + 1)*(tilesY + 1) height values
Definition: WorldModel.h:68
uint8 * iFlags
info if liquid tile is used
Definition: WorldModel.h:69
Definition: Vector3.h:58
G3D::Vector3 iCorner
the lower corner
Definition: WorldModel.h:66
uint32 iTilesX
number of tiles in x direction, each
Definition: WorldModel.h:64
uint32_t uint32
Definition: Define.h:150
uint32 iType
liquid type
Definition: WorldModel.h:67
uint8_t uint8
Definition: Define.h:152
uint32 iTilesY
Definition: WorldModel.h:65

+ Here is the caller graph for this function:

Member Data Documentation

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

the lower corner

uint8* VMAP::WmoLiquid::iFlags
private

info if liquid tile is used

float* VMAP::WmoLiquid::iHeight
private

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

uint32 VMAP::WmoLiquid::iTilesX
private

number of tiles in x direction, each

uint32 VMAP::WmoLiquid::iTilesY
private
uint32 VMAP::WmoLiquid::iType
private

liquid type


The documentation for this class was generated from the following files: