diff options
| author | Nicholas Estelami <NEstelami@users.noreply.github.com> | 2022-08-23 20:58:16 -0400 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2022-08-23 20:58:16 -0400 |
| commit | b9160e98bf1a46e5fb64923af1f2cf0f3cfc7e3c (patch) | |
| tree | b7363abfd2760c83be7d787914cc6bfebc466a21 | |
| parent | 27a8620dc7b72395dbb64907da11c4050077a10d (diff) | |
| parent | 338b79d1c4a4e8d13d9924865f8d4ed72af11fdd (diff) | |
Merge pull request #260 from louist103/surfaceTypes
Create files for ZSurfaceTypes
| -rw-r--r-- | ExporterTest/CollisionExporter.cpp | 8 | ||||
| -rw-r--r-- | ZAPD/ZAPD.vcxproj | 22 | ||||
| -rw-r--r-- | ZAPD/ZAPD.vcxproj.filters | 6 | ||||
| -rw-r--r-- | ZAPD/ZArray.cpp | 5 | ||||
| -rw-r--r-- | ZAPD/ZCollision.cpp | 28 | ||||
| -rw-r--r-- | ZAPD/ZCollision.h | 15 | ||||
| -rw-r--r-- | ZAPD/ZResource.h | 1 | ||||
| -rw-r--r-- | ZAPD/ZSurfaceType.cpp | 65 | ||||
| -rw-r--r-- | ZAPD/ZSurfaceType.h | 27 |
9 files changed, 137 insertions, 40 deletions
diff --git a/ExporterTest/CollisionExporter.cpp b/ExporterTest/CollisionExporter.cpp index 87b9a05..0f25a60 100644 --- a/ExporterTest/CollisionExporter.cpp +++ b/ExporterTest/CollisionExporter.cpp @@ -58,9 +58,11 @@ void ExporterExample_Collision::Save(ZResource* res, [[maybe_unused]] fs::path o writer->Seek(col->polyTypeDefSegmentOffset, SeekOffsetType::Start); - for (uint16_t i = 0; i < col->polygonTypes.size(); i++) - writer->Write(col->polygonTypes[i]); - + for (const auto poly : col->polygonTypes) + { + writer->Write(poly.data[0]); + writer->Write(poly.data[1]); + } writer->Seek(col->camDataSegmentOffset, SeekOffsetType::Start); for (auto entry : col->camData->entries) diff --git a/ZAPD/ZAPD.vcxproj b/ZAPD/ZAPD.vcxproj index 645cb51..2995021 100644 --- a/ZAPD/ZAPD.vcxproj +++ b/ZAPD/ZAPD.vcxproj @@ -36,7 +36,7 @@ <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="Configuration">
<ConfigurationType>Application</ConfigurationType>
<UseDebugLibraries>false</UseDebugLibraries>
- <PlatformToolset>v143</PlatformToolset>
+ <PlatformToolset>v142</PlatformToolset>
<WholeProgramOptimization>true</WholeProgramOptimization>
<CharacterSet>MultiByte</CharacterSet>
</PropertyGroup>
@@ -49,7 +49,7 @@ <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'" Label="Configuration">
<ConfigurationType>Application</ConfigurationType>
<UseDebugLibraries>false</UseDebugLibraries>
- <PlatformToolset>v143</PlatformToolset>
+ <PlatformToolset>v142</PlatformToolset>
<WholeProgramOptimization>true</WholeProgramOptimization>
<CharacterSet>MultiByte</CharacterSet>
</PropertyGroup>
@@ -98,8 +98,8 @@ <SubSystem>Console</SubSystem>
</Link>
<PreBuildEvent>
- <Command>cd .. -mkdir build\ZAPD + <Command>cd ..
+mkdir build\ZAPD
python ZAPD/genbuildinfo.py</Command>
</PreBuildEvent>
</ItemDefinitionGroup>
@@ -123,8 +123,8 @@ mkdir build\ZAPD <SubSystem>Console</SubSystem>
</Link>
<PreBuildEvent>
- <Command>cd .. -mkdir build\ZAPD + <Command>cd ..
+mkdir build\ZAPD
python ZAPD/genbuildinfo.py</Command>
</PreBuildEvent>
</ItemDefinitionGroup>
@@ -143,8 +143,8 @@ mkdir build\ZAPD <OptimizeReferences>true</OptimizeReferences>
</Link>
<PreBuildEvent>
- <Command>cd .. -mkdir build\ZAPD + <Command>cd ..
+mkdir build\ZAPD
python ZAPD/genbuildinfo.py</Command>
</PreBuildEvent>
</ItemDefinitionGroup>
@@ -165,8 +165,8 @@ mkdir build\ZAPD <OptimizeReferences>true</OptimizeReferences>
</Link>
<PreBuildEvent>
- <Command>cd .. -mkdir build\ZAPD + <Command>cd ..
+mkdir build\ZAPD
python ZAPD/genbuildinfo.py</Command>
</PreBuildEvent>
</ItemDefinitionGroup>
@@ -243,6 +243,7 @@ mkdir build\ZAPD <ClCompile Include="ZRoom\ZRoom.cpp" />
<ClCompile Include="ZRoom\ZRoomCommand.cpp" />
<ClCompile Include="ZString.cpp" />
+ <ClCompile Include="ZSurfaceType.cpp" />
<ClCompile Include="ZSymbol.cpp" />
<ClCompile Include="ZTexture.cpp" />
<ClCompile Include="ZTextureAnimation.cpp" />
@@ -332,6 +333,7 @@ mkdir build\ZAPD <ClInclude Include="ZRoom\ZRoom.h" />
<ClInclude Include="ZRoom\ZRoomCommand.h" />
<ClInclude Include="ZString.h" />
+ <ClInclude Include="ZSurfaceType.h" />
<ClInclude Include="ZSymbol.h" />
<ClInclude Include="ZTexture.h" />
<ClInclude Include="ZTextureAnimation.h" />
diff --git a/ZAPD/ZAPD.vcxproj.filters b/ZAPD/ZAPD.vcxproj.filters index b5fefd6..68c3e5b 100644 --- a/ZAPD/ZAPD.vcxproj.filters +++ b/ZAPD/ZAPD.vcxproj.filters @@ -291,6 +291,9 @@ <ClCompile Include="CrashHandler.cpp">
<Filter>Source Files</Filter>
</ClCompile>
+ <ClCompile Include="ZSurfaceType.cpp">
+ <Filter>Source Files\Z64</Filter>
+ </ClCompile>
</ItemGroup>
<ItemGroup>
<ClInclude Include="ZRoom\ZRoom.h">
@@ -554,6 +557,9 @@ <ClInclude Include="CrashHandler.h">
<Filter>Header Files</Filter>
</ClInclude>
+ <ClInclude Include="ZSurfaceType.h">
+ <Filter>Header Files\Z64</Filter>
+ </ClInclude>
</ItemGroup>
<ItemGroup>
<Text Include="..\SymbolMap_OoTMqDbg.txt">
diff --git a/ZAPD/ZArray.cpp b/ZAPD/ZArray.cpp index 3cf2392..0a9797b 100644 --- a/ZAPD/ZArray.cpp +++ b/ZAPD/ZArray.cpp @@ -95,7 +95,7 @@ Declaration* ZArray::DeclareVar(const std::string& prefix, const std::string& bo std::string ZArray::GetBodySourceCode() const { - std::string output = ""; + std::string output; for (size_t i = 0; i < arrayCnt; i++) { @@ -108,6 +108,7 @@ std::string ZArray::GetBodySourceCode() const case ZResourceType::Scalar: case ZResourceType::Vertex: case ZResourceType::CollisionPoly: + case ZResourceType::SurfaceType: output += resList.at(i)->GetBodySourceCode(); break; @@ -126,7 +127,7 @@ std::string ZArray::GetBodySourceCode() const size_t ZArray::GetRawDataSize() const { size_t size = 0; - for (auto res : resList) + for (const auto res : resList) size += res->GetRawDataSize(); return size; } diff --git a/ZAPD/ZCollision.cpp b/ZAPD/ZCollision.cpp index debf037..5bd3d93 100644 --- a/ZAPD/ZCollision.cpp +++ b/ZAPD/ZCollision.cpp @@ -51,7 +51,7 @@ void ZCollisionHeader::ParseRawData() vertices.reserve(numVerts); polygons.reserve(numPolygons); - uint32_t currentPtr = vtxSegmentOffset; + offset_t currentPtr = vtxSegmentOffset; for (uint16_t i = 0; i < numVerts; i++) { @@ -72,14 +72,21 @@ void ZCollisionHeader::ParseRawData() uint16_t highestPolyType = 0; - for (ZCollisionPoly poly : polygons) + for (const ZCollisionPoly& poly : polygons) { if (poly.type > highestPolyType) highestPolyType = poly.type; } + for (uint16_t i = 0; i < highestPolyType + 1; i++) - polygonTypes.push_back( - BitConverter::ToUInt64BE(rawData, polyTypeDefSegmentOffset + (i * 8))); + { + ZSurfaceType surfaceType(parent); + surfaceType.SetRawDataIndex(polyTypeDefSegmentOffset + (i * 8)); + surfaceType.ParseRawData(); + polygonTypes.push_back(surfaceType); + } + // polygonTypes.push_back( + // BitConverter::ToUInt64BE(rawData, polyTypeDefSegmentOffset + (i * 8))); if (camDataAddress != SEGMENTED_NULL) { @@ -165,18 +172,15 @@ void ZCollisionHeader::DeclareReferences(const std::string& prefix) } declaration.clear(); - for (size_t i = 0; i < polygonTypes.size(); i++) + for (const auto& polyType : polygonTypes) { - declaration += StringHelper::Sprintf("\t{ 0x%08lX, 0x%08lX },", polygonTypes[i] >> 32, - polygonTypes[i] & 0xFFFFFFFF); - - if (i < polygonTypes.size() - 1) - declaration += "\n"; + declaration += StringHelper::Sprintf("\t%s,", polyType.GetBodySourceCode().c_str()); } - if (polyTypeDefAddress != 0) + if (polyTypeDefAddress != SEGMENTED_NULL) parent->AddDeclarationArray(polyTypeDefSegmentOffset, DeclarationAlignment::Align4, - polygonTypes.size() * 8, "SurfaceType", + polygonTypes.size() * 8, + polygonTypes[0].GetSourceTypeName().c_str(), StringHelper::Sprintf("%sSurfaceType", auxName.c_str()), polygonTypes.size(), declaration); diff --git a/ZAPD/ZCollision.h b/ZAPD/ZCollision.h index 6a49484..35c6321 100644 --- a/ZAPD/ZCollision.h +++ b/ZAPD/ZCollision.h @@ -4,20 +4,9 @@ #include "ZFile.h" #include "ZResource.h" #include "ZRoom/ZRoom.h" +#include "ZSurfaceType.h" #include "ZVector.h" -#if 0 -class PolygonEntry -{ -public: - uint16_t type; - uint16_t vtxA, vtxB, vtxC; - uint16_t a, b, c, d; - - PolygonEntry(const std::vector<uint8_t>& rawData, uint32_t rawDataIndex); -}; -#endif - class WaterBoxHeader { public: @@ -82,7 +71,7 @@ public: std::vector<ZVector> vertices; std::vector<ZCollisionPoly> polygons; - std::vector<uint64_t> polygonTypes; + std::vector<ZSurfaceType> polygonTypes; std::vector<WaterBoxHeader> waterBoxes; CameraDataList* camData = nullptr; diff --git a/ZAPD/ZResource.h b/ZAPD/ZResource.h index 3598467..3bb2012 100644 --- a/ZAPD/ZResource.h +++ b/ZAPD/ZResource.h @@ -46,6 +46,7 @@ enum class ZResourceType Scene, Skeleton, String, + SurfaceType, Symbol, Texture, TextureAnimation, diff --git a/ZAPD/ZSurfaceType.cpp b/ZAPD/ZSurfaceType.cpp new file mode 100644 index 0000000..27e73ac --- /dev/null +++ b/ZAPD/ZSurfaceType.cpp @@ -0,0 +1,65 @@ +#include "ZSurfaceType.h"
+
+#include "Globals.h"
+#include "Utils/BitConverter.h"
+#include "Utils/StringHelper.h"
+
+REGISTER_ZFILENODE(SurfaceType, ZSurfaceType);
+
+ZSurfaceType::ZSurfaceType(ZFile* nParent) : ZResource(nParent)
+{
+}
+
+ZSurfaceType::~ZSurfaceType()
+{
+}
+
+void ZSurfaceType::ParseRawData()
+{
+ const auto& rawData = parent->GetRawData();
+
+ data[0] = BitConverter::ToUInt32BE(rawData, rawDataIndex + 0);
+ data[1] = BitConverter::ToUInt32BE(rawData, rawDataIndex + 4);
+}
+
+void ZSurfaceType::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 ZSurfaceType::GetBodySourceCode() const
+{
+ return StringHelper::Sprintf("{0x%08X, 0x%08X}", data[0], data[1]);
+}
+
+std::string ZSurfaceType::GetDefaultName(const std::string& prefix) const
+{
+ return StringHelper::Sprintf("%sSurfaceType_%06X", prefix.c_str(), rawDataIndex);
+}
+
+ZResourceType ZSurfaceType::GetResourceType() const
+{
+ return ZResourceType::SurfaceType;
+}
+
+size_t ZSurfaceType::GetRawDataSize() const
+{
+ return 8;
+}
+
+std::string ZSurfaceType::GetSourceTypeName() const
+{
+ return "SurfaceType";
+}
+
+bool ZSurfaceType::DoesSupportArray() const
+{
+ return true;
+}
diff --git a/ZAPD/ZSurfaceType.h b/ZAPD/ZSurfaceType.h new file mode 100644 index 0000000..3bbddee --- /dev/null +++ b/ZAPD/ZSurfaceType.h @@ -0,0 +1,27 @@ +#pragma once
+
+#include <array>
+#include "ZFile.h"
+#include "ZResource.h"
+
+class ZSurfaceType : public ZResource
+{
+public:
+ std::array<uint32_t, 2> data;
+
+ ZSurfaceType(ZFile* nParent);
+ ~ZSurfaceType();
+
+ 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;
+};
|
