diff options
| author | louist103 <35883445+louist103@users.noreply.github.com> | 2023-05-04 20:05:45 -0400 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2023-05-04 20:05:45 -0400 |
| commit | 0dbba745dfed52be5cab97257dbf56a2223dd874 (patch) | |
| tree | ec50457b1f5973d5679556e369f0f5b5e6d66d8f | |
| parent | cc01a0629af59dc45f775c0c42210d4e215da4de (diff) | |
Waterbox nodes (#289)
* Waterbox nodes
* emplace
* VS Filters.
| -rw-r--r-- | ZAPD/ZAPD.vcxproj | 2 | ||||
| -rw-r--r-- | ZAPD/ZAPD.vcxproj.filters | 12 | ||||
| -rw-r--r-- | ZAPD/ZArray.cpp | 1 | ||||
| -rw-r--r-- | ZAPD/ZCollision.cpp | 42 | ||||
| -rw-r--r-- | ZAPD/ZCollision.h | 20 | ||||
| -rw-r--r-- | ZAPD/ZResource.h | 1 | ||||
| -rw-r--r-- | ZAPD/ZWaterbox.cpp | 74 | ||||
| -rw-r--r-- | ZAPD/ZWaterbox.h | 30 |
8 files changed, 137 insertions, 45 deletions
diff --git a/ZAPD/ZAPD.vcxproj b/ZAPD/ZAPD.vcxproj index 505e411..f6bc351 100644 --- a/ZAPD/ZAPD.vcxproj +++ b/ZAPD/ZAPD.vcxproj @@ -249,6 +249,7 @@ mkdir build\ZAPD <ClCompile Include="ZTextureAnimation.cpp" />
<ClCompile Include="ZVector.cpp" />
<ClCompile Include="ZVtx.cpp" />
+ <ClCompile Include="ZWaterbox.cpp" />
</ItemGroup>
<ItemGroup>
<ClInclude Include="..\lib\elfio\elfio\elfio.hpp" />
@@ -339,6 +340,7 @@ mkdir build\ZAPD <ClInclude Include="ZTextureAnimation.h" />
<ClInclude Include="ZVector.h" />
<ClInclude Include="ZVtx.h" />
+ <ClInclude Include="ZWaterbox.h" />
</ItemGroup>
<ItemGroup>
<Text Include="..\SymbolMap_OoTMqDbg.txt">
diff --git a/ZAPD/ZAPD.vcxproj.filters b/ZAPD/ZAPD.vcxproj.filters index ce89882..ea07eb7 100644 --- a/ZAPD/ZAPD.vcxproj.filters +++ b/ZAPD/ZAPD.vcxproj.filters @@ -291,6 +291,12 @@ <ClCompile Include="ZSurfaceType.cpp">
<Filter>Source Files\Z64</Filter>
</ClCompile>
+ <ClCompile Include="ZActorList.cpp">
+ <Filter>Source Files\Z64</Filter>
+ </ClCompile>
+ <ClCompile Include="ZWaterbox.cpp">
+ <Filter>Source Files\Z64</Filter>
+ </ClCompile>
</ItemGroup>
<ItemGroup>
<ClInclude Include="ZRoom\ZRoom.h">
@@ -554,6 +560,12 @@ <ClInclude Include="ZSurfaceType.h">
<Filter>Header Files\Z64</Filter>
</ClInclude>
+ <ClInclude Include="ZActorList.h">
+ <Filter>Header Files\Z64</Filter>
+ </ClInclude>
+ <ClInclude Include="ZWaterbox.h">
+ <Filter>Header Files</Filter>
+ </ClInclude>
</ItemGroup>
<ItemGroup>
<Text Include="..\SymbolMap_OoTMqDbg.txt">
diff --git a/ZAPD/ZArray.cpp b/ZAPD/ZArray.cpp index 28d35f3..686420c 100644 --- a/ZAPD/ZArray.cpp +++ b/ZAPD/ZArray.cpp @@ -109,6 +109,7 @@ std::string ZArray::GetBodySourceCode() const case ZResourceType::Vertex: case ZResourceType::CollisionPoly: case ZResourceType::SurfaceType: + case ZResourceType::Waterbox: output += resList.at(i)->GetBodySourceCode(); break; diff --git a/ZAPD/ZCollision.cpp b/ZAPD/ZCollision.cpp index 25d4c7e..e0350d9 100644 --- a/ZAPD/ZCollision.cpp +++ b/ZAPD/ZCollision.cpp @@ -1,4 +1,5 @@ #include "ZCollision.h" +#include "ZWaterbox.h" #include <cassert> #include <cstdint> @@ -50,6 +51,7 @@ void ZCollisionHeader::ParseRawData() vertices.reserve(numVerts); polygons.reserve(numPolygons); + waterBoxes.reserve(numWaterBoxes); offset_t currentPtr = vtxSegmentOffset; @@ -125,10 +127,14 @@ void ZCollisionHeader::ParseRawData() new CameraDataList(parent, name, rawData, camDataSegmentOffset, upperCameraBoundary); } - for (uint16_t i = 0; i < numWaterBoxes; i++) - waterBoxes.push_back(WaterBoxHeader( - rawData, - waterBoxSegmentOffset + (i * (Globals::Instance->game == ZGame::OOT_SW97 ? 12 : 16)))); + for (int32_t i = 0; i < numWaterBoxes; i++) { + ZWaterbox waterbox(parent); + + waterbox.SetRawDataIndex(waterBoxSegmentOffset + + (i * (Globals::Instance->game == ZGame::OOT_SW97 ? 12 : 16))); + waterbox.ParseRawData(); + waterBoxes.emplace_back(waterbox); + } } void ZCollisionHeader::DeclareReferences(const std::string& prefix) @@ -149,9 +155,11 @@ void ZCollisionHeader::DeclareReferences(const std::string& prefix) declaration += "\n"; } - parent->AddDeclarationArray( - waterBoxSegmentOffset, DeclarationAlignment::Align4, 16 * waterBoxes.size(), "WaterBox", - StringHelper::Sprintf("%sWaterBoxes", auxName.c_str()), waterBoxes.size(), declaration); + parent->AddDeclarationArray(waterBoxSegmentOffset, DeclarationAlignment::Align4, + waterBoxes[0].GetRawDataSize() * waterBoxes.size(), + waterBoxes[0].GetSourceTypeName().c_str(), + StringHelper::Sprintf("%sWaterBoxes", auxName.c_str()), + waterBoxes.size(), declaration); } if (polygons.size() > 0) @@ -272,26 +280,6 @@ size_t ZCollisionHeader::GetRawDataSize() const return 44; } -WaterBoxHeader::WaterBoxHeader(const std::vector<uint8_t>& rawData, uint32_t rawDataIndex) -{ - xMin = BitConverter::ToInt16BE(rawData, rawDataIndex + 0); - ySurface = BitConverter::ToInt16BE(rawData, rawDataIndex + 2); - zMin = BitConverter::ToInt16BE(rawData, rawDataIndex + 4); - xLength = BitConverter::ToInt16BE(rawData, rawDataIndex + 6); - zLength = BitConverter::ToInt16BE(rawData, rawDataIndex + 8); - - if (Globals::Instance->game == ZGame::OOT_SW97) - properties = BitConverter::ToInt16BE(rawData, rawDataIndex + 10); - else - properties = BitConverter::ToInt32BE(rawData, rawDataIndex + 12); -} - -std::string WaterBoxHeader::GetBodySourceCode() const -{ - return StringHelper::Sprintf("%i, %i, %i, %i, %i, 0x%08X", xMin, ySurface, zMin, xLength, - zLength, properties); -} - CameraDataList::CameraDataList(ZFile* parent, const std::string& prefix, const std::vector<uint8_t>& rawData, offset_t rawDataIndex, offset_t upperCameraBoundary) diff --git a/ZAPD/ZCollision.h b/ZAPD/ZCollision.h index 35c6321..8298986 100644 --- a/ZAPD/ZCollision.h +++ b/ZAPD/ZCollision.h @@ -6,23 +6,7 @@ #include "ZRoom/ZRoom.h" #include "ZSurfaceType.h" #include "ZVector.h" - -class WaterBoxHeader -{ -public: - WaterBoxHeader(const std::vector<uint8_t>& rawData, uint32_t rawDataIndex); - - std::string GetBodySourceCode() const; - -protected: - int16_t xMin; - int16_t ySurface; - int16_t zMin; - int16_t xLength; - int16_t zLength; - int16_t pad; - int32_t properties; -}; +#include "ZWaterbox.h" class CameraPositionData { @@ -72,7 +56,7 @@ public: std::vector<ZVector> vertices; std::vector<ZCollisionPoly> polygons; std::vector<ZSurfaceType> polygonTypes; - std::vector<WaterBoxHeader> waterBoxes; + std::vector<ZWaterbox> waterBoxes; CameraDataList* camData = nullptr; ZCollisionHeader(ZFile* nParent); diff --git a/ZAPD/ZResource.h b/ZAPD/ZResource.h index f97b259..7c271a6 100644 --- a/ZAPD/ZResource.h +++ b/ZAPD/ZResource.h @@ -54,6 +54,7 @@ enum class ZResourceType TextureAnimationParams, Vector, Vertex, + Waterbox, }; class ResourceAttribute diff --git a/ZAPD/ZWaterbox.cpp b/ZAPD/ZWaterbox.cpp new file mode 100644 index 0000000..9a289db --- /dev/null +++ b/ZAPD/ZWaterbox.cpp @@ -0,0 +1,74 @@ +#include "ZWaterbox.h" + +#include "Globals.h" +#include "Utils/BitConverter.h" +#include "Utils/StringHelper.h" + +REGISTER_ZFILENODE(Waterbox, ZWaterbox); + +ZWaterbox::ZWaterbox(ZFile* nParent) : ZResource(nParent) +{ +} + +ZWaterbox::~ZWaterbox() +{ +} + +void ZWaterbox::ParseRawData() +{ + const auto& rawData = parent->GetRawData(); + + xMin = BitConverter::ToInt16BE(rawData, rawDataIndex + 0); + ySurface = BitConverter::ToInt16BE(rawData, rawDataIndex + 2); + zMin = BitConverter::ToInt16BE(rawData, rawDataIndex + 4); + xLength = BitConverter::ToInt16BE(rawData, rawDataIndex + 6); + zLength = BitConverter::ToInt16BE(rawData, rawDataIndex + 8); + + if (Globals::Instance->game == ZGame::OOT_SW97) + properties = BitConverter::ToInt16BE(rawData, rawDataIndex + 10); + else + properties = BitConverter::ToInt32BE(rawData, rawDataIndex + 12); +} + +void ZWaterbox::DeclareReferences(const std::string& prefix) +{ + std::string declaration; + std::string auxName = name; + + if (name == "") + auxName = GetDefaultName(prefix); + + parent->AddDeclaration(rawDataIndex, DeclarationAlignment::Align4, GetRawDataSize(), + GetSourceTypeName(), name.c_str(), GetBodySourceCode()); +} + +std::string ZWaterbox::GetBodySourceCode() const +{ + return StringHelper::Sprintf("%i, %i, %i, %i, %i, 0x%08X", xMin, ySurface, zMin, xLength, + zLength, properties); +} + +std::string ZWaterbox::GetDefaultName(const std::string& prefix) const +{ + return StringHelper::Sprintf("%sWaterBoxes_%06X", prefix.c_str(), rawDataIndex); +} + +ZResourceType ZWaterbox::GetResourceType() const +{ + return ZResourceType::Waterbox; +} + +size_t ZWaterbox::GetRawDataSize() const +{ + return 16; +} + +std::string ZWaterbox::GetSourceTypeName() const +{ + return "WaterBox"; +} + +bool ZWaterbox::DoesSupportArray() const +{ + return true; +} diff --git a/ZAPD/ZWaterbox.h b/ZAPD/ZWaterbox.h new file mode 100644 index 0000000..e901e80 --- /dev/null +++ b/ZAPD/ZWaterbox.h @@ -0,0 +1,30 @@ +#pragma once + +#include "ZFile.h" +#include "ZResource.h" + +class ZWaterbox : public ZResource +{ + public: + int16_t xMin; + int16_t ySurface; + int16_t zMin; + int16_t xLength; + int16_t zLength; + int32_t properties; + + ZWaterbox(ZFile* nParent); + ~ZWaterbox(); + + void ParseRawData() override; + void DeclareReferences(const std::string& prefix) override; + std::string GetBodySourceCode() const override; + std::string GetDefaultName(const std::string& prefix) const override; + + std::string GetSourceTypeName() const override; + ZResourceType GetResourceType() const override; + + bool DoesSupportArray() const override; + + size_t GetRawDataSize() const override; +}; |
