summaryrefslogtreecommitdiff
path: root/src/factories/GenericArrayFactory.cpp
diff options
context:
space:
mode:
authorKiritoDv <kiritodev01@gmail.com>2026-03-23 21:23:59 -0600
committerKiritoDv <kiritodev01@gmail.com>2026-03-23 21:23:59 -0600
commit75f64161cb4addcbc6e29732df8d9b519a62c43f (patch)
tree92e2b17bd8c41af42bdf24a6eb4b7b08b90254f6 /src/factories/GenericArrayFactory.cpp
parent654b451ddc6cf25db201b2c858948f430784cc5f (diff)
Implemented clang-format
Diffstat (limited to 'src/factories/GenericArrayFactory.cpp')
-rw-r--r--src/factories/GenericArrayFactory.cpp84
1 files changed, 26 insertions, 58 deletions
diff --git a/src/factories/GenericArrayFactory.cpp b/src/factories/GenericArrayFactory.cpp
index 12b698f..ccff544 100644
--- a/src/factories/GenericArrayFactory.cpp
+++ b/src/factories/GenericArrayFactory.cpp
@@ -11,60 +11,26 @@
#define GET_MAG_U(num) ((uint32_t)((num > 1) ? std::log10(num) + 1 : 1))
std::unordered_map<std::string, ArrayType> arrayTypeMap = {
- { "u8", ArrayType::u8 },
- { "s8", ArrayType::s8 },
- { "u16", ArrayType::u16 },
- { "s16", ArrayType::s16 },
- { "u32", ArrayType::u32 },
- { "s32", ArrayType::s32 },
- { "u64", ArrayType::u64 },
- { "f32", ArrayType::f32 },
- { "f64", ArrayType::f64 },
- { "Vec2f", ArrayType::Vec2f },
- { "Vec3f", ArrayType::Vec3f },
- { "Vec3s", ArrayType::Vec3s },
- { "Vec3i", ArrayType::Vec3i },
- { "Vec3iu", ArrayType::Vec3iu },
- { "Vec4f", ArrayType::Vec4f },
+ { "u8", ArrayType::u8 }, { "s8", ArrayType::s8 }, { "u16", ArrayType::u16 },
+ { "s16", ArrayType::s16 }, { "u32", ArrayType::u32 }, { "s32", ArrayType::s32 },
+ { "u64", ArrayType::u64 }, { "f32", ArrayType::f32 }, { "f64", ArrayType::f64 },
+ { "Vec2f", ArrayType::Vec2f }, { "Vec3f", ArrayType::Vec3f }, { "Vec3s", ArrayType::Vec3s },
+ { "Vec3i", ArrayType::Vec3i }, { "Vec3iu", ArrayType::Vec3iu }, { "Vec4f", ArrayType::Vec4f },
{ "Vec4s", ArrayType::Vec4s },
};
std::unordered_map<ArrayType, size_t> typeSizeMap = {
- { ArrayType::u8, 1 },
- { ArrayType::s8, 1 },
- { ArrayType::u16, 2 },
- { ArrayType::s16, 2 },
- { ArrayType::u32, 4 },
- { ArrayType::s32, 4 },
- { ArrayType::u64, 8 },
- { ArrayType::f32, 4 },
- { ArrayType::f64, 8 },
- { ArrayType::Vec2f, 8 },
- { ArrayType::Vec3f, 12 },
- { ArrayType::Vec3s, 6 },
- { ArrayType::Vec3i, 12 },
- { ArrayType::Vec3iu, 12 },
- { ArrayType::Vec4f, 16 },
- { ArrayType::Vec4s, 8 },
+ { ArrayType::u8, 1 }, { ArrayType::s8, 1 }, { ArrayType::u16, 2 }, { ArrayType::s16, 2 },
+ { ArrayType::u32, 4 }, { ArrayType::s32, 4 }, { ArrayType::u64, 8 }, { ArrayType::f32, 4 },
+ { ArrayType::f64, 8 }, { ArrayType::Vec2f, 8 }, { ArrayType::Vec3f, 12 }, { ArrayType::Vec3s, 6 },
+ { ArrayType::Vec3i, 12 }, { ArrayType::Vec3iu, 12 }, { ArrayType::Vec4f, 16 }, { ArrayType::Vec4s, 8 },
};
std::unordered_map<ArrayType, size_t> structCountMap = {
- { ArrayType::u8, 1 },
- { ArrayType::s8, 1 },
- { ArrayType::u16, 1 },
- { ArrayType::s16, 1 },
- { ArrayType::u32, 1 },
- { ArrayType::s32, 1 },
- { ArrayType::u64, 1 },
- { ArrayType::f32, 1 },
- { ArrayType::f64, 1 },
- { ArrayType::Vec2f, 2 },
- { ArrayType::Vec3f, 3 },
- { ArrayType::Vec3s, 3 },
- { ArrayType::Vec3i, 3 },
- { ArrayType::Vec3iu, 3 },
- { ArrayType::Vec4f, 4 },
- { ArrayType::Vec4s, 4 },
+ { ArrayType::u8, 1 }, { ArrayType::s8, 1 }, { ArrayType::u16, 1 }, { ArrayType::s16, 1 },
+ { ArrayType::u32, 1 }, { ArrayType::s32, 1 }, { ArrayType::u64, 1 }, { ArrayType::f32, 1 },
+ { ArrayType::f64, 1 }, { ArrayType::Vec2f, 2 }, { ArrayType::Vec3f, 3 }, { ArrayType::Vec3s, 3 },
+ { ArrayType::Vec3i, 3 }, { ArrayType::Vec3iu, 3 }, { ArrayType::Vec4f, 4 }, { ArrayType::Vec4s, 4 },
};
static int GetPrecision(float f) {
@@ -72,7 +38,7 @@ static int GetPrecision(float f) {
int shift = 1;
float approx = std::round(f);
- while(f != approx && p < 12 ){
+ while (f != approx && p < 12) {
shift *= 10;
p++;
approx = std::round(f * shift) / shift;
@@ -83,7 +49,7 @@ static int GetPrecision(float f) {
GenericArray::GenericArray(std::vector<ArrayDatum> data) : mData(std::move(data)) {
mMaxWidth = 1;
mMaxPrec = 1;
- for (auto &datum : mData) {
+ for (auto& datum : mData) {
switch (static_cast<ArrayType>(datum.index())) {
case ArrayType::u8: {
mMaxWidth = std::max(mMaxWidth, GET_MAG_U((uint32_t)std::get<uint8_t>(datum)));
@@ -148,7 +114,7 @@ GenericArray::GenericArray(std::vector<ArrayDatum> data) : mData(std::move(data)
break;
}
case ArrayType::Vec4f: {
- mMaxWidth = std::max(mMaxWidth,(uint32_t)std::get<Vec4f>(datum).width());
+ mMaxWidth = std::max(mMaxWidth, (uint32_t)std::get<Vec4f>(datum).width());
mMaxPrec = std::max(mMaxPrec, (uint32_t)std::get<Vec4f>(datum).precision());
break;
}
@@ -160,11 +126,12 @@ GenericArray::GenericArray(std::vector<ArrayDatum> data) : mData(std::move(data)
}
}
-ExportResult ArrayHeaderExporter::Export(std::ostream &write, std::shared_ptr<IParsedData> raw, std::string& entryName, YAML::Node &node, std::string* replacement) {
+ExportResult ArrayHeaderExporter::Export(std::ostream& write, std::shared_ptr<IParsedData> raw, std::string& entryName,
+ YAML::Node& node, std::string* replacement) {
const auto symbol = GetSafeNode(node, "symbol", entryName);
const auto type = GetSafeNode<std::string>(node, "array_type");
- if(Companion::Instance->IsOTRMode()){
+ if (Companion::Instance->IsOTRMode()) {
write << "static const ALIGN_ASSET(2) char " << symbol << "[] = \"__OTR__" << (*replacement) << "\";\n\n";
return std::nullopt;
}
@@ -173,7 +140,8 @@ ExportResult ArrayHeaderExporter::Export(std::ostream &write, std::shared_ptr<IP
return std::nullopt;
}
-ExportResult ArrayCodeExporter::Export(std::ostream &write, std::shared_ptr<IParsedData> raw, std::string& entryName, YAML::Node &node, std::string* replacement ) {
+ExportResult ArrayCodeExporter::Export(std::ostream& write, std::shared_ptr<IParsedData> raw, std::string& entryName,
+ YAML::Node& node, std::string* replacement) {
const auto symbol = GetSafeNode(node, "symbol", entryName);
const auto type = GetSafeNode<std::string>(node, "array_type");
const auto offset = GetSafeNode<uint32_t>(node, "offset");
@@ -188,12 +156,11 @@ ExportResult ArrayCodeExporter::Export(std::ostream &write, std::shared_ptr<IPar
size_t typeSize = typeSizeMap.at(arrayType);
-
write << type << " " << symbol << "[] = {";
int columnCount = 120 / (structCountMap.at(arrayType) * array->mMaxWidth + 8);
int i = 0;
- for (auto &datum : array->mData) {
+ for (auto& datum : array->mData) {
if ((i++ % columnCount) == 0) {
write << "\n" << fourSpaceTab;
}
@@ -258,7 +225,8 @@ ExportResult ArrayCodeExporter::Export(std::ostream &write, std::shared_ptr<IPar
return offset + array->mData.size() * typeSize;
}
-ExportResult ArrayBinaryExporter::Export(std::ostream &write, std::shared_ptr<IParsedData> raw, std::string& entryName, YAML::Node &node, std::string* replacement ) {
+ExportResult ArrayBinaryExporter::Export(std::ostream& write, std::shared_ptr<IParsedData> raw, std::string& entryName,
+ YAML::Node& node, std::string* replacement) {
auto writer = LUS::BinaryWriter();
const auto type = GetSafeNode<std::string>(node, "array_type");
auto array = std::static_pointer_cast<GenericArray>(raw);
@@ -273,9 +241,9 @@ ExportResult ArrayBinaryExporter::Export(std::ostream &write, std::shared_ptr<IP
WriteHeader(writer, Torch::ResourceType::GenericArray, 0);
writer.Write(static_cast<uint32_t>(arrayType));
- writer.Write((uint32_t) array->mData.size());
+ writer.Write((uint32_t)array->mData.size());
- for (auto &datum : array->mData) {
+ for (auto& datum : array->mData) {
switch (static_cast<ArrayType>(datum.index())) {
case ArrayType::u8: {
writer.Write(std::get<uint8_t>(datum));