feat(Tools/Mapextractor): Implemented liquid object detection (#11402)

* .

* .

* .

* .

* .

* .

* .

* Delete Utils.cpp
This commit is contained in:
IntelligentQuantum
2022-05-09 02:08:22 +04:30
committed by GitHub
parent 5036360c1e
commit a31a30566e
13 changed files with 394 additions and 382 deletions

View File

@@ -327,7 +327,7 @@ namespace VMAP
float pos_x;
float pos_y;
float pos_z;
short type;
short material;
};
#pragma pack(pop)
//=================================================================
@@ -532,19 +532,29 @@ namespace VMAP
delete[] vectorarray;
}
// ----- liquid
liquid = 0;
if (liquidflags & 1)
liquid = nullptr;
if (liquidflags & 3)
{
WMOLiquidHeader hlq;
READ_OR_RETURN(&blockId, 4);
CMP_OR_RETURN(blockId, "LIQU");
READ_OR_RETURN(&blocksize, sizeof(int));
READ_OR_RETURN(&hlq, sizeof(WMOLiquidHeader));
liquid = new WmoLiquid(hlq.xtiles, hlq.ytiles, Vector3(hlq.pos_x, hlq.pos_y, hlq.pos_z), hlq.type);
uint32 size = hlq.xverts * hlq.yverts;
READ_OR_RETURN(liquid->GetHeightStorage(), size * sizeof(float));
size = hlq.xtiles * hlq.ytiles;
READ_OR_RETURN(liquid->GetFlagsStorage(), size);
uint32 liquidType;
READ_OR_RETURN(&liquidType, sizeof(uint32));
if (liquidflags & 1)
{
WMOLiquidHeader hlq;
READ_OR_RETURN(&hlq, sizeof(WMOLiquidHeader));
liquid = new WmoLiquid(hlq.xtiles, hlq.ytiles, Vector3(hlq.pos_x, hlq.pos_y, hlq.pos_z), liquidType);
uint32 size = hlq.xverts * hlq.yverts;
READ_OR_RETURN(liquid->GetHeightStorage(), size * sizeof(float));
size = hlq.xtiles * hlq.ytiles;
READ_OR_RETURN(liquid->GetFlagsStorage(), size);
}
else
{
liquid = new WmoLiquid(0, 0, Vector3::zero(), liquidType);
liquid->GetHeightStorage()[0] = bounds.high().z;
}
}
return true;

View File

@@ -107,8 +107,16 @@ namespace VMAP
WmoLiquid::WmoLiquid(uint32 width, uint32 height, const Vector3& corner, uint32 type):
iTilesX(width), iTilesY(height), iCorner(corner), iType(type)
{
iHeight = new float[(width + 1) * (height + 1)];
iFlags = new uint8[width * height];
if (width && height)
{
iHeight = new float[(width + 1) * (height + 1)];
iFlags = new uint8[width * height];
}
else
{
iHeight = new float[1];
iFlags = nullptr;
}
}
WmoLiquid::WmoLiquid(const WmoLiquid& other): iHeight(0), iFlags(0)
@@ -157,6 +165,13 @@ namespace VMAP
bool WmoLiquid::GetLiquidHeight(const Vector3& pos, float& liqHeight) const
{
// simple case
if (!iFlags)
{
liqHeight = iHeight[0];
return true;
}
float tx_f = (pos.x - iCorner.x) / LIQUID_TILE_SIZE;
uint32 tx = uint32(tx_f);
if (tx_f < 0.0f || tx >= iTilesX)
@@ -219,8 +234,8 @@ namespace VMAP
{
return 2 * sizeof(uint32) +
sizeof(Vector3) +
(iTilesX + 1) * (iTilesY + 1) * sizeof(float) +
iTilesX * iTilesY;
sizeof(uint32) +
(iFlags ? ((iTilesX + 1) * (iTilesY + 1) * sizeof(float) + iTilesX * iTilesY) : sizeof(float));
}
bool WmoLiquid::writeToFile(FILE* wf)
@@ -231,12 +246,17 @@ namespace VMAP
fwrite(&iCorner, sizeof(Vector3), 1, wf) == 1 &&
fwrite(&iType, sizeof(uint32), 1, wf) == 1)
{
uint32 size = (iTilesX + 1) * (iTilesY + 1);
if (fwrite(iHeight, sizeof(float), size, wf) == size)
if (iTilesX && iTilesY)
{
size = iTilesX * iTilesY;
result = fwrite(iFlags, sizeof(uint8), size, wf) == size;
uint32 size = (iTilesX + 1) * (iTilesY + 1);
if (fwrite(iHeight, sizeof(float), size, wf) == size)
{
size = iTilesX * iTilesY;
result = fwrite(iFlags, sizeof(uint8), size, wf) == size;
}
}
else
result = fwrite(iHeight, sizeof(float), 1, wf) == 1;
}
return result;
@@ -252,13 +272,21 @@ namespace VMAP
fread(&liquid->iCorner, sizeof(Vector3), 1, rf) == 1 &&
fread(&liquid->iType, sizeof(uint32), 1, rf) == 1)
{
uint32 size = (liquid->iTilesX + 1) * (liquid->iTilesY + 1);
liquid->iHeight = new float[size];
if (fread(liquid->iHeight, sizeof(float), size, rf) == size)
if (liquid->iTilesX && liquid->iTilesY)
{
size = liquid->iTilesX * liquid->iTilesY;
liquid->iFlags = new uint8[size];
result = fread(liquid->iFlags, sizeof(uint8), size, rf) == size;
uint32 size = (liquid->iTilesX + 1) * (liquid->iTilesY + 1);
liquid->iHeight = new float[size];
if (fread(liquid->iHeight, sizeof(float), size, rf) == size)
{
size = liquid->iTilesX * liquid->iTilesY;
liquid->iFlags = new uint8[size];
result = fread(liquid->iFlags, sizeof(uint8), size, rf) == size;
}
}
else
{
liquid->iHeight = new float[1];
result = fread(liquid->iHeight, sizeof(float), 1, rf) == 1;
}
}

View File

@@ -23,8 +23,8 @@
namespace VMAP
{
const char VMAP_MAGIC[] = "VMAP_4.6";
const char RAW_VMAP_MAGIC[] = "VMAP046"; // used in extracted vmap files with raw data
const char VMAP_MAGIC[] = "VMAP_4.7";
const char RAW_VMAP_MAGIC[] = "VMAP047"; // used in extracted vmap files with raw data
const char GAMEOBJECT_MODELS[] = "GameObjectModels.dtree";
// defined in TileAssembler.cpp currently...