mirror of
https://github.com/Laupetin/OpenAssetTools.git
synced 2025-06-02 06:27:42 +00:00
chore: small code cleanups
This commit is contained in:
parent
45689a29a1
commit
05ce73049d
@ -6,7 +6,7 @@ ParsedCsvRow::ParsedCsvRow(std::unordered_map<std::string, size_t>& headers, std
|
|||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
std::string ParsedCsvRow::GetValue(const std::string& header, bool required) const
|
std::string ParsedCsvRow::GetValue(const std::string& header, const bool required) const
|
||||||
{
|
{
|
||||||
if (this->headers.find(header) == this->headers.end())
|
if (this->headers.find(header) == this->headers.end())
|
||||||
{
|
{
|
||||||
@ -28,7 +28,7 @@ std::string ParsedCsvRow::GetValue(const std::string& header, bool required) con
|
|||||||
return value;
|
return value;
|
||||||
}
|
}
|
||||||
|
|
||||||
float ParsedCsvRow::GetValueFloat(const std::string& header, bool required) const
|
float ParsedCsvRow::GetValueFloat(const std::string& header, const bool required) const
|
||||||
{
|
{
|
||||||
const auto& value = this->GetValue(header, required);
|
const auto& value = this->GetValue(header, required);
|
||||||
if (!value.empty())
|
if (!value.empty())
|
||||||
@ -42,7 +42,7 @@ float ParsedCsvRow::GetValueFloat(const std::string& header, bool required) cons
|
|||||||
return {};
|
return {};
|
||||||
}
|
}
|
||||||
|
|
||||||
ParsedCsv::ParsedCsv(const CsvInputStream& inputStream, bool hasHeaders)
|
ParsedCsv::ParsedCsv(const CsvInputStream& inputStream, const bool hasHeaders)
|
||||||
{
|
{
|
||||||
std::vector<std::vector<std::string>> csvLines;
|
std::vector<std::vector<std::string>> csvLines;
|
||||||
std::vector<std::string> currentLine;
|
std::vector<std::string> currentLine;
|
||||||
@ -55,7 +55,7 @@ ParsedCsv::ParsedCsv(const CsvInputStream& inputStream, bool hasHeaders)
|
|||||||
|
|
||||||
if (hasHeaders)
|
if (hasHeaders)
|
||||||
{
|
{
|
||||||
auto& headersRow = csvLines[0];
|
const auto& headersRow = csvLines[0];
|
||||||
for (auto i = 0u; i < headersRow.size(); i++)
|
for (auto i = 0u; i < headersRow.size(); i++)
|
||||||
{
|
{
|
||||||
this->headers[headersRow[i]] = i;
|
this->headers[headersRow[i]] = i;
|
||||||
@ -74,7 +74,7 @@ size_t ParsedCsv::Size() const
|
|||||||
return this->rows.size();
|
return this->rows.size();
|
||||||
}
|
}
|
||||||
|
|
||||||
ParsedCsvRow ParsedCsv::operator[](size_t index) const
|
ParsedCsvRow ParsedCsv::operator[](const size_t index) const
|
||||||
{
|
{
|
||||||
return this->rows.at(index);
|
return this->rows.at(index);
|
||||||
}
|
}
|
||||||
|
@ -1,5 +1,7 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include "Csv/CsvStream.h"
|
#include "Csv/CsvStream.h"
|
||||||
|
#include "Utils/ClassUtils.h"
|
||||||
|
|
||||||
#include <sstream>
|
#include <sstream>
|
||||||
#include <unordered_map>
|
#include <unordered_map>
|
||||||
@ -11,10 +13,10 @@ class ParsedCsvRow
|
|||||||
|
|
||||||
public:
|
public:
|
||||||
explicit ParsedCsvRow(std::unordered_map<std::string, size_t>& headers, std::vector<std::string> row);
|
explicit ParsedCsvRow(std::unordered_map<std::string, size_t>& headers, std::vector<std::string> row);
|
||||||
std::string GetValue(const std::string& header, bool required = false) const;
|
_NODISCARD std::string GetValue(const std::string& header, bool required = false) const;
|
||||||
float GetValueFloat(const std::string& header, bool required = false) const;
|
_NODISCARD float GetValueFloat(const std::string& header, bool required = false) const;
|
||||||
|
|
||||||
template<typename T> T GetValueInt(const std::string& header, bool required = false) const
|
template<typename T> T GetValueInt(const std::string& header, const bool required = false) const
|
||||||
{
|
{
|
||||||
const auto& value = this->GetValue(header, required);
|
const auto& value = this->GetValue(header, required);
|
||||||
if (!value.empty())
|
if (!value.empty())
|
||||||
@ -37,7 +39,7 @@ class ParsedCsv
|
|||||||
public:
|
public:
|
||||||
explicit ParsedCsv(const CsvInputStream& inputStream, bool hasHeaders = true);
|
explicit ParsedCsv(const CsvInputStream& inputStream, bool hasHeaders = true);
|
||||||
|
|
||||||
size_t Size() const;
|
_NODISCARD size_t Size() const;
|
||||||
|
|
||||||
ParsedCsvRow operator[](size_t index) const;
|
ParsedCsvRow operator[](size_t index) const;
|
||||||
};
|
};
|
||||||
|
@ -1,6 +1,4 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
#include <array>
|
|
||||||
#include <string>
|
|
||||||
|
|
||||||
namespace T6
|
namespace T6
|
||||||
{
|
{
|
||||||
|
@ -6,13 +6,12 @@
|
|||||||
#include "Game/T6/T6.h"
|
#include "Game/T6/T6.h"
|
||||||
#include "ObjContainer/SoundBank/SoundBankWriter.h"
|
#include "ObjContainer/SoundBank/SoundBankWriter.h"
|
||||||
#include "Pool/GlobalAssetPool.h"
|
#include "Pool/GlobalAssetPool.h"
|
||||||
#include "nlohmann/json.hpp"
|
#include "Utils/StringUtils.h"
|
||||||
|
|
||||||
#include <Utils/StringUtils.h>
|
|
||||||
#include <climits>
|
|
||||||
#include <cstring>
|
#include <cstring>
|
||||||
#include <fstream>
|
#include <fstream>
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
|
#include <nlohmann/json.hpp>
|
||||||
|
|
||||||
using namespace T6;
|
using namespace T6;
|
||||||
namespace fs = std::filesystem;
|
namespace fs = std::filesystem;
|
||||||
@ -24,7 +23,7 @@ namespace
|
|||||||
"devraw/",
|
"devraw/",
|
||||||
};
|
};
|
||||||
|
|
||||||
_NODISCARD std::string GetSoundFilePath(SndAlias* sndAlias)
|
_NODISCARD std::string GetSoundFilePath(const SndAlias* sndAlias)
|
||||||
{
|
{
|
||||||
std::string soundFilePath(sndAlias->assetFileName);
|
std::string soundFilePath(sndAlias->assetFileName);
|
||||||
|
|
||||||
@ -88,7 +87,7 @@ size_t GetValueIndex(const std::string& value, const std::string* lookupTable, s
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
unsigned int GetAliasSubListCount(unsigned int startRow, const ParsedCsv& csv)
|
unsigned int GetAliasSubListCount(const unsigned int startRow, const ParsedCsv& csv)
|
||||||
{
|
{
|
||||||
auto count = 1u;
|
auto count = 1u;
|
||||||
|
|
||||||
@ -132,11 +131,11 @@ bool LoadSoundAlias(MemoryManager* memory, SndAlias* alias, const ParsedCsvRow&
|
|||||||
alias->assetFileName = memory->Dup(aliasFileName.data());
|
alias->assetFileName = memory->Dup(aliasFileName.data());
|
||||||
alias->assetId = Common::SND_HashName(aliasFileName.data());
|
alias->assetId = Common::SND_HashName(aliasFileName.data());
|
||||||
|
|
||||||
auto secondaryName = row.GetValue("secondary");
|
const auto secondaryName = row.GetValue("secondary");
|
||||||
if (!secondaryName.empty())
|
if (!secondaryName.empty())
|
||||||
alias->secondaryname = memory->Dup(secondaryName.data());
|
alias->secondaryname = memory->Dup(secondaryName.data());
|
||||||
|
|
||||||
auto subtitle = row.GetValue("subtitle");
|
const auto subtitle = row.GetValue("subtitle");
|
||||||
if (!subtitle.empty())
|
if (!subtitle.empty())
|
||||||
alias->subtitle = memory->Dup(subtitle.data());
|
alias->subtitle = memory->Dup(subtitle.data());
|
||||||
|
|
||||||
@ -206,7 +205,7 @@ bool LoadSoundAliasIndexList(MemoryManager* memory, SndBank* sndBank)
|
|||||||
|
|
||||||
for (auto i = 0u; i < sndBank->aliasCount; i++)
|
for (auto i = 0u; i < sndBank->aliasCount; i++)
|
||||||
{
|
{
|
||||||
auto idx = sndBank->alias[i].id % sndBank->aliasCount;
|
const auto idx = sndBank->alias[i].id % sndBank->aliasCount;
|
||||||
if (sndBank->aliasIndex[idx].value == std::numeric_limits<unsigned short>::max())
|
if (sndBank->aliasIndex[idx].value == std::numeric_limits<unsigned short>::max())
|
||||||
{
|
{
|
||||||
sndBank->aliasIndex[idx].value = i;
|
sndBank->aliasIndex[idx].value = i;
|
||||||
@ -280,7 +279,7 @@ bool LoadSoundAliasList(
|
|||||||
{
|
{
|
||||||
// count how many of the next rows should be in the sound alias sub-list. Aliases are part of the same sub list if they have the same name for a
|
// count how many of the next rows should be in the sound alias sub-list. Aliases are part of the same sub list if they have the same name for a
|
||||||
// different file
|
// different file
|
||||||
auto subListCount = GetAliasSubListCount(row, aliasCsv);
|
const auto subListCount = GetAliasSubListCount(row, aliasCsv);
|
||||||
if (subListCount < 1)
|
if (subListCount < 1)
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
@ -297,7 +296,7 @@ bool LoadSoundAliasList(
|
|||||||
return false;
|
return false;
|
||||||
|
|
||||||
// if this asset is loaded instead of stream, increment the loaded count for later
|
// if this asset is loaded instead of stream, increment the loaded count for later
|
||||||
if (sndBank->alias[listIndex].head[i].flags.loadType == T6::SA_LOADED)
|
if (sndBank->alias[listIndex].head[i].flags.loadType == SA_LOADED)
|
||||||
(*loadedEntryCount)++;
|
(*loadedEntryCount)++;
|
||||||
else
|
else
|
||||||
(*streamedEntryCount)++;
|
(*streamedEntryCount)++;
|
||||||
@ -457,7 +456,7 @@ bool AssetLoaderSoundBank::LoadFromRaw(
|
|||||||
memset(sndBank, 0, sizeof(SndBank));
|
memset(sndBank, 0, sizeof(SndBank));
|
||||||
|
|
||||||
sndBank->name = memory->Dup(assetName.c_str());
|
sndBank->name = memory->Dup(assetName.c_str());
|
||||||
auto sndBankLocalization = utils::StringSplit(assetName, '.');
|
const auto sndBankLocalization = utils::StringSplit(assetName, '.');
|
||||||
|
|
||||||
// load the soundbank aliases
|
// load the soundbank aliases
|
||||||
unsigned int loadedEntryCount = 0u, streamedEntryCount = 0u;
|
unsigned int loadedEntryCount = 0u, streamedEntryCount = 0u;
|
||||||
@ -525,12 +524,12 @@ bool AssetLoaderSoundBank::LoadFromRaw(
|
|||||||
// add aliases to the correct sound bank writer
|
// add aliases to the correct sound bank writer
|
||||||
for (auto i = 0u; i < sndBank->aliasCount; i++)
|
for (auto i = 0u; i < sndBank->aliasCount; i++)
|
||||||
{
|
{
|
||||||
auto* aliasList = &sndBank->alias[i];
|
const auto* aliasList = &sndBank->alias[i];
|
||||||
for (auto j = 0; j < aliasList->count; j++)
|
for (auto j = 0; j < aliasList->count; j++)
|
||||||
{
|
{
|
||||||
auto* alias = &aliasList->head[j];
|
const auto* alias = &aliasList->head[j];
|
||||||
|
|
||||||
if (sabsWriter && alias->flags.loadType == T6::SA_STREAMED)
|
if (sabsWriter && alias->flags.loadType == SA_STREAMED)
|
||||||
sabsWriter->AddSound(GetSoundFilePath(alias), alias->assetId, alias->flags.looping, true);
|
sabsWriter->AddSound(GetSoundFilePath(alias), alias->assetId, alias->flags.looping, true);
|
||||||
else if (sablWriter)
|
else if (sablWriter)
|
||||||
sablWriter->AddSound(GetSoundFilePath(alias), alias->assetId, alias->flags.looping);
|
sablWriter->AddSound(GetSoundFilePath(alias), alias->assetId, alias->flags.looping);
|
||||||
@ -541,7 +540,7 @@ bool AssetLoaderSoundBank::LoadFromRaw(
|
|||||||
if (sablWriter)
|
if (sablWriter)
|
||||||
{
|
{
|
||||||
size_t dataSize = 0u;
|
size_t dataSize = 0u;
|
||||||
auto result = sablWriter->Write(dataSize);
|
const auto result = sablWriter->Write(dataSize);
|
||||||
sablStream->close();
|
sablStream->close();
|
||||||
|
|
||||||
if (result)
|
if (result)
|
||||||
@ -561,7 +560,7 @@ bool AssetLoaderSoundBank::LoadFromRaw(
|
|||||||
if (sabsWriter)
|
if (sabsWriter)
|
||||||
{
|
{
|
||||||
size_t dataSize = 0u;
|
size_t dataSize = 0u;
|
||||||
auto result = sabsWriter->Write(dataSize);
|
const auto result = sabsWriter->Write(dataSize);
|
||||||
sabsStream->close();
|
sabsStream->close();
|
||||||
|
|
||||||
if (!result)
|
if (!result)
|
||||||
|
@ -4,7 +4,6 @@
|
|||||||
#include "ObjContainer/SoundBank/SoundBankTypes.h"
|
#include "ObjContainer/SoundBank/SoundBankTypes.h"
|
||||||
#include "Sound/FlacDecoder.h"
|
#include "Sound/FlacDecoder.h"
|
||||||
#include "Sound/WavTypes.h"
|
#include "Sound/WavTypes.h"
|
||||||
#include "Utils/Alignment.h"
|
|
||||||
#include "Utils/FileUtils.h"
|
#include "Utils/FileUtils.h"
|
||||||
|
|
||||||
#include <cstring>
|
#include <cstring>
|
||||||
@ -34,8 +33,8 @@ class SoundBankWriterImpl : public SoundBankWriter
|
|||||||
inline static const std::string PAD_DATA = std::string(16, '\x00');
|
inline static const std::string PAD_DATA = std::string(16, '\x00');
|
||||||
|
|
||||||
public:
|
public:
|
||||||
explicit SoundBankWriterImpl(const std::string& fileName, std::ostream& stream, ISearchPath* assetSearchPath)
|
explicit SoundBankWriterImpl(std::string fileName, std::ostream& stream, ISearchPath* assetSearchPath)
|
||||||
: m_file_name(fileName),
|
: m_file_name(std::move(fileName)),
|
||||||
m_stream(stream),
|
m_stream(stream),
|
||||||
m_asset_search_path(assetSearchPath),
|
m_asset_search_path(assetSearchPath),
|
||||||
m_current_offset(0),
|
m_current_offset(0),
|
||||||
@ -102,6 +101,7 @@ public:
|
|||||||
m_entry_section_offset,
|
m_entry_section_offset,
|
||||||
m_checksum_section_offset,
|
m_checksum_section_offset,
|
||||||
checksum,
|
checksum,
|
||||||
|
{},
|
||||||
};
|
};
|
||||||
|
|
||||||
strncpy(header.dependencies, m_file_name.data(), header.dependencySize);
|
strncpy(header.dependencies, m_file_name.data(), header.dependencySize);
|
||||||
@ -118,7 +118,7 @@ public:
|
|||||||
const auto& soundFilePath = sound.m_file_path;
|
const auto& soundFilePath = sound.m_file_path;
|
||||||
const auto soundId = sound.m_sound_id;
|
const auto soundId = sound.m_sound_id;
|
||||||
|
|
||||||
size_t soundSize = -1;
|
size_t soundSize;
|
||||||
std::unique_ptr<char[]> soundData;
|
std::unique_ptr<char[]> soundData;
|
||||||
|
|
||||||
// try to find a wav file for the sound path
|
// try to find a wav file for the sound path
|
||||||
@ -129,8 +129,8 @@ public:
|
|||||||
wavFile.m_stream->read(reinterpret_cast<char*>(&header), sizeof(WavHeader));
|
wavFile.m_stream->read(reinterpret_cast<char*>(&header), sizeof(WavHeader));
|
||||||
|
|
||||||
soundSize = static_cast<size_t>(wavFile.m_length - sizeof(WavHeader));
|
soundSize = static_cast<size_t>(wavFile.m_length - sizeof(WavHeader));
|
||||||
auto frameCount = soundSize / (header.formatChunk.nChannels * (header.formatChunk.wBitsPerSample / 8));
|
const auto frameCount = soundSize / (header.formatChunk.nChannels * (header.formatChunk.wBitsPerSample / 8));
|
||||||
auto frameRateIndex = INDEX_FOR_FRAMERATE[header.formatChunk.nSamplesPerSec];
|
const auto frameRateIndex = INDEX_FOR_FRAMERATE[header.formatChunk.nSamplesPerSec];
|
||||||
|
|
||||||
SoundAssetBankEntry entry{
|
SoundAssetBankEntry entry{
|
||||||
soundId,
|
soundId,
|
||||||
@ -159,10 +159,10 @@ public:
|
|||||||
soundData = std::make_unique<char[]>(soundSize);
|
soundData = std::make_unique<char[]>(soundSize);
|
||||||
flacFile.m_stream->read(soundData.get(), soundSize);
|
flacFile.m_stream->read(soundData.get(), soundSize);
|
||||||
|
|
||||||
auto decoder = FlacDecoder::Create(soundData.get(), soundSize);
|
const auto decoder = FlacDecoder::Create(soundData.get(), soundSize);
|
||||||
if (decoder->Decode())
|
if (decoder->Decode())
|
||||||
{
|
{
|
||||||
auto frameRateIndex = INDEX_FOR_FRAMERATE[decoder->GetFrameRate()];
|
const auto frameRateIndex = INDEX_FOR_FRAMERATE[decoder->GetFrameRate()];
|
||||||
SoundAssetBankEntry entry{
|
SoundAssetBankEntry entry{
|
||||||
soundId,
|
soundId,
|
||||||
soundSize,
|
soundSize,
|
||||||
@ -189,7 +189,7 @@ public:
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
auto lastEntry = m_entries.rbegin();
|
const auto lastEntry = m_entries.rbegin();
|
||||||
if (!sound.m_streamed && lastEntry->frameRateIndex != 6)
|
if (!sound.m_streamed && lastEntry->frameRateIndex != 6)
|
||||||
{
|
{
|
||||||
std::cout << "WARNING: Loaded sound \"" << soundFilePath
|
std::cout << "WARNING: Loaded sound \"" << soundFilePath
|
||||||
@ -245,7 +245,7 @@ public:
|
|||||||
{
|
{
|
||||||
if (!WriteEntries())
|
if (!WriteEntries())
|
||||||
{
|
{
|
||||||
std::cerr << "An error occurred writing the sound bank entires. Please check output." << std::endl;
|
std::cerr << "An error occurred writing the sound bank entries. Please check output." << std::endl;
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user