Shipwright/ZAPDTR/ZAPD/ZVector.cpp

127 lines
2.9 KiB
C++
Raw Normal View History

#include "ZVector.h"
#include <cassert>
#include "Globals.h"
#include "Utils/BitConverter.h"
#include <Utils/DiskFile.h>
#include "Utils/StringHelper.h"
#include "WarningHandler.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();
ZAPD Update (#2851) * git subrepo clone --force --branch=rebase2 C:/ZeldaStuff/ZAPDTR ZAPDTR/ subrepo: subdir: "ZAPDTR" merged: "6aa54a551" upstream: origin: "C:/ZeldaStuff/ZAPDTR" branch: "rebase2" commit: "6aa54a551" git-subrepo: version: "0.4.3" origin: "???" commit: "???" * git subrepo clone --force --branch=rebase2 C:/ZeldaStuff/ZAPDTR ZAPDTR/ subrepo: subdir: "ZAPDTR" merged: "88b012240" upstream: origin: "C:/ZeldaStuff/ZAPDTR" branch: "rebase2" commit: "88b012240" git-subrepo: version: "0.4.3" origin: "???" commit: "???" * Update (its broken) * fix the enum * git subrepo push --remote=C:/ZeldaStuff/ZAPDTR/ ZAPDTR subrepo: subdir: "ZAPDTR" merged: "b7b6e1c82" upstream: origin: "C:/ZeldaStuff/ZAPDTR/" branch: "rebase2" commit: "b7b6e1c82" git-subrepo: version: "0.4.3" origin: "???" commit: "???" * New names for LUS actions * git subrepo push --remote=C:/ZeldaStuff/ZAPDTR/ ZAPDTR subrepo: subdir: "ZAPDTR" merged: "c5cfebeee" upstream: origin: "C:/ZeldaStuff/ZAPDTR/" branch: "rebase2" commit: "c5cfebeee" git-subrepo: version: "0.4.3" origin: "???" commit: "???" * git subrepo clone (merge) --force --branch=rebase2 C:/ZeldaStuff/ZAPDTR ZAPDTR/ subrepo: subdir: "ZAPDTR" merged: "d5f4769b8" upstream: origin: "C:/ZeldaStuff/ZAPDTR" branch: "rebase2" commit: "d5f4769b8" git-subrepo: version: "0.4.3" origin: "???" commit: "???" * Fix missing commands in the exporter. * Cleanups. * git subrepo pull --force --remote=https://github.com/harbourmasters/ZAPDTR --branch=master ZAPDTR subrepo: subdir: "ZAPDTR" merged: "d4c35b90a" upstream: origin: "https://github.com/harbourmasters/ZAPDTR" branch: "master" commit: "d4c35b90a" git-subrepo: version: "0.4.3" origin: "???" commit: "???" * Add unordered_map include to fix MacOS * fix string_view * Update Main.cpp * fix string view * So close I can almost taste it * So close * Fix missed git marker. * Fix surface types and * Update ZFile.cpp * Delete Jenkinsfile --------- Co-authored-by: Christopher Leggett <chris@leggett.dev> Co-authored-by: briaguya <70942617+briaguya-ai@users.noreply.github.com>
2023-05-07 19:58:50 -04:00
scalars.reserve(dimensions);
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 msgHeader = StringHelper::Sprintf(
"encountered unsupported vector type: %d dimensions, %s type", dimensions,
ZScalar::MapScalarTypeToOutputType(scalarType).c_str());
HANDLE_ERROR_RESOURCE(WarningType::NotImplemented, parent, this, rawDataIndex, msgHeader,
"");
}
}
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();
}