1
0
Fork 0
mirror of https://github.com/zeldaret/oot.git synced 2025-08-24 16:01:26 +00:00
oot/tools/ZAPD/ZAPD/ZVector.cpp
Nicholas Estelami 0432011bd9
Updated to use latest version of ZAPD (#777)
* Updated config file

* Added missing files

* Temporarily removed asm_processor changes.

* git subrepo pull --force tools/ZAPD

subrepo:
  subdir:   "tools/ZAPD"
  merged:   "96ffc1e62"
upstream:
  origin:   "https://github.com/zeldaret/ZAPD.git"
  branch:   "master"
  commit:   "96ffc1e62"
git-subrepo:
  version:  "0.4.3"
  origin:   "???"
  commit:   "???"

* git subrepo pull --force tools/ZAPD

subrepo:
  subdir:   "tools/ZAPD"
  merged:   "179af7d11"
upstream:
  origin:   "https://github.com/zeldaret/ZAPD.git"
  branch:   "master"
  commit:   "179af7d11"
git-subrepo:
  version:  "0.4.3"
  origin:   "???"
  commit:   "???"

* Cleanup and fixes.

* git subrepo pull --force tools/ZAPD

subrepo:
  subdir:   "tools/ZAPD"
  merged:   "50ad2fe78"
upstream:
  origin:   "https://github.com/zeldaret/ZAPD.git"
  branch:   "master"
  commit:   "50ad2fe78"
git-subrepo:
  version:  "0.4.3"
  origin:   "???"
  commit:   "???"

* Makefile fix

* git subrepo pull --force tools/ZAPD

subrepo:
  subdir:   "tools/ZAPD"
  merged:   "b9120803e"
upstream:
  origin:   "https://github.com/zeldaret/ZAPD.git"
  branch:   "master"
  commit:   "b9120803e"
git-subrepo:
  version:  "0.4.3"
  origin:   "???"
  commit:   "???"

Co-authored-by: Jack Walker <7463599+Jack-Walker@users.noreply.github.com>
2021-04-30 23:23:22 +02:00

127 lines
No EOL
3 KiB
C++

#include "ZVector.h"
#include <assert.h>
#include "BitConverter.h"
#include "File.h"
#include "Globals.h"
#include "StringHelper.h"
#include "ZFile.h"
REGISTER_ZFILENODE(Vector, ZVector);
ZVector::ZVector(ZFile* nParent) : ZResource(nParent)
{
scalars = std::vector<ZScalar*>();
this->scalarType = ZSCALAR_NONE;
this->dimensions = 0;
}
ZVector::~ZVector()
{
ClearScalars();
}
void ZVector::ClearScalars()
{
for (auto s : scalars)
delete s;
scalars.clear();
}
void ZVector::ExtractFromXML(tinyxml2::XMLElement* reader, const std::vector<uint8_t>& nRawData,
const uint32_t nRawDataIndex, const std::string& nRelPath)
{
ZResource::ExtractFromXML(reader, nRawData, nRawDataIndex, nRelPath);
}
void ZVector::ParseXML(tinyxml2::XMLElement* reader)
{
ZResource::ParseXML(reader);
std::string type = reader->Attribute("Type");
this->scalarType = ZScalar::MapOutputTypeToScalarType(type);
std::string dimensions = reader->Attribute("Dimensions");
this->dimensions = strtol(dimensions.c_str(), NULL, 16);
}
void ZVector::ParseRawData()
{
int32_t currentRawDataIndex = this->rawDataIndex;
ClearScalars();
for (uint32_t i = 0; i < this->dimensions; i++)
{
ZScalar* scalar = new ZScalar(this->scalarType, this->parent);
scalar->rawDataIndex = currentRawDataIndex;
scalar->rawData = this->rawData;
scalar->ParseRawData();
currentRawDataIndex += scalar->GetRawDataSize();
this->scalars.push_back(scalar);
}
// Ensure the scalars vector has the same number of elements as the vector dimension.
assert(this->scalars.size() == this->dimensions);
}
size_t ZVector::GetRawDataSize()
{
size_t size = 0;
for (size_t i = 0; i < this->scalars.size(); i++)
size += this->scalars[i]->GetRawDataSize();
return size;
}
bool ZVector::DoesSupportArray()
{
return true;
}
std::string ZVector::GetSourceTypeName()
{
if (dimensions == 3 && scalarType == ZSCALAR_F32)
return "Vec3f";
else if (dimensions == 3 && scalarType == ZSCALAR_S16)
return "Vec3s";
else if (dimensions == 3 && scalarType == 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 >= VERBOSITY_DEBUG)
printf("%s\n", output.c_str());
throw std::runtime_error(output);
}
}
std::string ZVector::GetSourceValue()
{
std::vector<std::string> strings = std::vector<std::string>();
for (size_t i = 0; i < this->scalars.size(); i++)
strings.push_back(scalars[i]->GetSourceValue());
return "{ " + StringHelper::Implode(strings, ", ") + " }";
}
std::string ZVector::GetSourceOutputCode(const std::string& prefix)
{
if (parent != nullptr)
parent->AddDeclaration(rawDataIndex, DeclarationAlignment::None, GetRawDataSize(),
GetSourceTypeName(), GetName(), GetSourceValue());
return "";
}
ZResourceType ZVector::GetResourceType()
{
return ZResourceType::Vector;
}