mirror of
https://github.com/zeldaret/oot.git
synced 2025-02-14 02:49:16 +00:00
750c0cab35
* remove fake match * git subrepo pull --force tools/ZAPD subrepo: subdir: "tools/ZAPD" merged: "3e9ed72e2" upstream: origin: "https://github.com/zeldaret/ZAPD.git" branch: "master" commit: "3e9ed72e2" git-subrepo: version: "0.4.3" origin: "https://github.com/ingydotnet/git-subrepo.git" commit: "2f68596" * new extraction script and a hack to make clear tag work * fix clear tag again * remove static from clear tag DLists * git subrepo pull --force tools/ZAPD subrepo: subdir: "tools/ZAPD" merged: "e7a8a48cf" upstream: origin: "https://github.com/zeldaret/ZAPD.git" branch: "master" commit: "e7a8a48cf" git-subrepo: version: "0.4.3" origin: "https://github.com/ingydotnet/git-subrepo.git" commit: "2f68596" * git subrepo pull --force tools/ZAPD subrepo: subdir: "tools/ZAPD" merged: "e243634e5" upstream: origin: "https://github.com/zeldaret/ZAPD.git" branch: "master" commit: "e243634e5" git-subrepo: version: "0.4.3" origin: "https://github.com/ingydotnet/git-subrepo.git" commit: "2f68596" * git subrepo pull --force tools/ZAPD subrepo: subdir: "tools/ZAPD" merged: "d0cd6b397" upstream: origin: "https://github.com/zeldaret/ZAPD.git" branch: "master" commit: "d0cd6b397" git-subrepo: version: "0.4.3" origin: "https://github.com/ingydotnet/git-subrepo.git" commit: "2f68596" * Update ovl_En_Clear_Tag.xml
127 lines
2.9 KiB
C++
127 lines
2.9 KiB
C++
#include "ZVector.h"
|
|
|
|
#include <cassert>
|
|
|
|
#include "Globals.h"
|
|
#include "Utils/BitConverter.h"
|
|
#include "Utils/File.h"
|
|
#include "Utils/StringHelper.h"
|
|
#include "ZFile.h"
|
|
|
|
REGISTER_ZFILENODE(Vector, ZVector);
|
|
|
|
ZVector::ZVector(ZFile* nParent) : ZResource(nParent)
|
|
{
|
|
scalarType = ZScalarType::ZSCALAR_NONE;
|
|
dimensions = 0;
|
|
|
|
RegisterRequiredAttribute("Type");
|
|
RegisterRequiredAttribute("Dimensions");
|
|
}
|
|
|
|
void ZVector::ExtractFromBinary(uint32_t nRawDataIndex, ZScalarType nScalarType,
|
|
uint32_t nDimensions)
|
|
{
|
|
rawDataIndex = nRawDataIndex;
|
|
scalarType = nScalarType;
|
|
dimensions = nDimensions;
|
|
|
|
// Don't parse raw data of external files
|
|
if (parent->GetMode() == ZFileMode::ExternalFile)
|
|
return;
|
|
|
|
ParseRawData();
|
|
}
|
|
|
|
void ZVector::ParseXML(tinyxml2::XMLElement* reader)
|
|
{
|
|
ZResource::ParseXML(reader);
|
|
|
|
this->scalarType = ZScalar::MapOutputTypeToScalarType(registeredAttributes.at("Type").value);
|
|
|
|
this->dimensions = StringHelper::StrToL(registeredAttributes.at("Dimensions").value, 16);
|
|
}
|
|
|
|
void ZVector::ParseRawData()
|
|
{
|
|
int32_t currentRawDataIndex = rawDataIndex;
|
|
// TODO: this shouldn't be necessary.
|
|
scalars.clear();
|
|
|
|
for (uint32_t i = 0; i < dimensions; i++)
|
|
{
|
|
ZScalar scalar(parent);
|
|
scalar.ExtractFromBinary(currentRawDataIndex, scalarType);
|
|
currentRawDataIndex += scalar.GetRawDataSize();
|
|
|
|
scalars.push_back(scalar);
|
|
}
|
|
|
|
// Ensure the scalars vector has the same number of elements as the vector dimension.
|
|
assert(scalars.size() == dimensions);
|
|
}
|
|
|
|
size_t ZVector::GetRawDataSize() const
|
|
{
|
|
size_t size = 0;
|
|
|
|
for (size_t i = 0; i < this->scalars.size(); i++)
|
|
size += this->scalars[i].GetRawDataSize();
|
|
|
|
return size;
|
|
}
|
|
|
|
bool ZVector::DoesSupportArray() const
|
|
{
|
|
return true;
|
|
}
|
|
|
|
std::string ZVector::GetSourceTypeName() const
|
|
{
|
|
if (dimensions == 3 && scalarType == ZScalarType::ZSCALAR_F32)
|
|
return "Vec3f";
|
|
else if (dimensions == 3 && scalarType == ZScalarType::ZSCALAR_S16)
|
|
return "Vec3s";
|
|
else if (dimensions == 3 && scalarType == ZScalarType::ZSCALAR_S32)
|
|
return "Vec3i";
|
|
else
|
|
{
|
|
std::string output = StringHelper::Sprintf(
|
|
"Encountered unsupported vector type: %d dimensions, %s type", dimensions,
|
|
ZScalar::MapScalarTypeToOutputType(scalarType).c_str());
|
|
|
|
if (Globals::Instance->verbosity >= VerbosityLevel::VERBOSITY_DEBUG)
|
|
printf("%s\n", output.c_str());
|
|
|
|
throw std::runtime_error(output);
|
|
}
|
|
}
|
|
|
|
std::string ZVector::GetBodySourceCode() const
|
|
{
|
|
std::string body;
|
|
|
|
for (size_t i = 0; i < scalars.size(); i++)
|
|
{
|
|
body += StringHelper::Sprintf("%6s", scalars[i].GetBodySourceCode().c_str());
|
|
|
|
if (i + 1 < scalars.size())
|
|
body += ", ";
|
|
}
|
|
|
|
return body;
|
|
}
|
|
|
|
ZResourceType ZVector::GetResourceType() const
|
|
{
|
|
return ZResourceType::Vector;
|
|
}
|
|
|
|
DeclarationAlignment ZVector::GetDeclarationAlignment() const
|
|
{
|
|
if (scalars.size() == 0)
|
|
{
|
|
return DeclarationAlignment::Align4;
|
|
}
|
|
return scalars.at(0).GetDeclarationAlignment();
|
|
}
|