aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/tools/mesh_extractor/Constants.h2
-rw-r--r--src/tools/mesh_extractor/LiquidHandler.cpp40
-rw-r--r--src/tools/mesh_extractor/LiquidHandler.h3
-rw-r--r--src/tools/mesh_extractor/MapChunk.cpp4
-rw-r--r--src/tools/mesh_extractor/Utils.cpp11
-rw-r--r--src/tools/mesh_extractor/Utils.h3
6 files changed, 49 insertions, 14 deletions
diff --git a/src/tools/mesh_extractor/Constants.h b/src/tools/mesh_extractor/Constants.h
index 5a89be9fe9c..7d9d6f92b92 100644
--- a/src/tools/mesh_extractor/Constants.h
+++ b/src/tools/mesh_extractor/Constants.h
@@ -26,6 +26,8 @@ public:
TRIANGLE_TYPE_UNKNOWN,
TRIANGLE_TYPE_TERRAIN,
TRIANGLE_TYPE_WATER,
+ TRIANGLE_TYPE_MAGMA,
+ TRIANGLE_TYPE_SLIME,
TRIANGLE_TYPE_DOODAD,
TRIANGLE_TYPE_WMO
};
diff --git a/src/tools/mesh_extractor/LiquidHandler.cpp b/src/tools/mesh_extractor/LiquidHandler.cpp
index fa59d1bc7f0..6800cb773f7 100644
--- a/src/tools/mesh_extractor/LiquidHandler.cpp
+++ b/src/tools/mesh_extractor/LiquidHandler.cpp
@@ -23,6 +23,13 @@ LiquidHandler::LiquidHandler( ADT* adt ) : Source(adt)
HandleNewLiquid();
}
+LiquidHandler::~LiquidHandler()
+{
+ for (std::vector<MCNKLiquidData*>::iterator itr = MCNKData.begin(); itr != MCNKData.end(); ++itr)
+ delete *itr;
+ MCNKData.clear();
+}
+
void LiquidHandler::HandleNewLiquid()
{
Chunk* chunk = Source->Data->GetChunkByName("MH2O");
@@ -44,12 +51,13 @@ void LiquidHandler::HandleNewLiquid()
if (h.LayerCount == 0)
{
// Need to fill in missing data with dummies.
- MCNKData.push_back(MCNKLiquidData(NULL, H2ORenderMask()));
+ MCNKData.push_back(new MCNKLiquidData(NULL, H2ORenderMask()));
continue;
}
stream->Seek(chunk->Offset + h.OffsetInformation, SEEK_SET);
H2OInformation information = H2OInformation::Read(stream);
+ // This pointer will be passed to the MCNKLiquidData constructor, from that point on, it is the job of MCNKLiquidData's destructor to release it.
float** heights = new float*[9];
for (int j = 0; j < 9; ++j)
{
@@ -88,7 +96,7 @@ void LiquidHandler::HandleNewLiquid()
heights[x][y] = information.HeightLevel1;
}
- MCNKData.push_back(MCNKLiquidData(heights, renderMask));
+ MCNKData.push_back(new MCNKLiquidData(heights, renderMask));
for (int y = information.OffsetY; y < (information.OffsetY + information.Height); y++)
{
@@ -108,15 +116,27 @@ void LiquidHandler::HandleNewLiquid()
Vertices.push_back(Vector3(location.x - Constants::UnitSize, location.y, location.z));
Vertices.push_back(Vector3(location.x, location.y - Constants::UnitSize, location.z));
Vertices.push_back(Vector3(location.x - Constants::UnitSize, location.y - Constants::UnitSize, location.z));
-
- Triangles.push_back(Triangle<uint32>(Constants::TRIANGLE_TYPE_WATER, vertOffset, vertOffset+2, vertOffset + 1));
- Triangles.push_back(Triangle<uint32>(Constants::TRIANGLE_TYPE_WATER, vertOffset + 2, vertOffset + 3, vertOffset + 1));
+
+ // Define the liquid type
+ Constants::TriangleType type = Constants::TRIANGLE_TYPE_UNKNOWN;
+ switch (information.LiquidType)
+ {
+ case 1: // Water
+ case 2: // Ocean
+ default:
+ type = Constants::TRIANGLE_TYPE_WATER;
+ break;
+ case 3:
+ type = Constants::TRIANGLE_TYPE_MAGMA;
+ break;
+ case 4:
+ type = Constants::TRIANGLE_TYPE_SLIME;
+ break;
+ }
+
+ Triangles.push_back(Triangle<uint32>(type, vertOffset, vertOffset+2, vertOffset + 1));
+ Triangles.push_back(Triangle<uint32>(type, vertOffset + 2, vertOffset + 3, vertOffset + 1));
}
}
-
- // At this stage, heights is no longer needed, so we deallocate it
- for (int j = 0; j < 9; ++j)
- delete[] heights[j];
- delete[] heights;
}
}
diff --git a/src/tools/mesh_extractor/LiquidHandler.h b/src/tools/mesh_extractor/LiquidHandler.h
index c053b621088..2bb503cc7e7 100644
--- a/src/tools/mesh_extractor/LiquidHandler.h
+++ b/src/tools/mesh_extractor/LiquidHandler.h
@@ -27,11 +27,12 @@ class LiquidHandler
{
public:
LiquidHandler(ADT* adt);
+ ~LiquidHandler();
ADT* Source;
std::vector<Vector3> Vertices;
std::vector<Triangle<uint32> > Triangles;
- std::vector<MCNKLiquidData> MCNKData;
+ std::vector<MCNKLiquidData*> MCNKData;
private:
void HandleNewLiquid();
};
diff --git a/src/tools/mesh_extractor/MapChunk.cpp b/src/tools/mesh_extractor/MapChunk.cpp
index f9d49762209..ee6b4584396 100644
--- a/src/tools/mesh_extractor/MapChunk.cpp
+++ b/src/tools/mesh_extractor/MapChunk.cpp
@@ -47,12 +47,12 @@ void MapChunk::GenerateTriangles()
Constants::TriangleType triangleType = Constants::TRIANGLE_TYPE_TERRAIN;
if (Adt->_LiquidHandler && !Adt->_LiquidHandler->MCNKData.empty())
{
- MCNKLiquidData& data = Adt->_LiquidHandler->MCNKData[Index];
+ MCNKLiquidData* data = Adt->_LiquidHandler->MCNKData[Index];
float maxHeight = std::max(
std::max(
std::max(std::max(Vertices[topLeft].z, Vertices[topRight].z), Vertices[bottomLeft].z),
Vertices[bottomRight].z), Vertices[center].z);
- if (data.IsWater(x, y, maxHeight))
+ if (data->IsWater(x, y, maxHeight))
triangleType = Constants::TRIANGLE_TYPE_WATER;
}
diff --git a/src/tools/mesh_extractor/Utils.cpp b/src/tools/mesh_extractor/Utils.cpp
index 5395fb1c92b..9344776ae1f 100644
--- a/src/tools/mesh_extractor/Utils.cpp
+++ b/src/tools/mesh_extractor/Utils.cpp
@@ -403,6 +403,17 @@ bool MCNKLiquidData::IsWater(int x, int y, float height)
return false;
}
+MCNKLiquidData::~MCNKLiquidData()
+{
+ if (!Heights)
+ return;
+
+ for (uint32 i = 0; i < 9; ++i)
+ delete[] Heights[i];
+ delete[] Heights;
+ Heights = NULL;
+}
+
H2OHeader H2OHeader::Read(Stream* stream)
{
H2OHeader ret;
diff --git a/src/tools/mesh_extractor/Utils.h b/src/tools/mesh_extractor/Utils.h
index 0f2df672250..ec826c701f9 100644
--- a/src/tools/mesh_extractor/Utils.h
+++ b/src/tools/mesh_extractor/Utils.h
@@ -300,8 +300,9 @@ public:
class MCNKLiquidData
{
public:
- MCNKLiquidData() {}
+ MCNKLiquidData() : Heights(NULL) {}
MCNKLiquidData(float** heights, H2ORenderMask mask) : Heights(heights), Mask(mask) {}
+ ~MCNKLiquidData();
float** Heights;
H2ORenderMask Mask;