mirror of
https://github.com/Laupetin/OpenAssetTools.git
synced 2025-04-20 00:02:55 +00:00
code review changes
This commit is contained in:
parent
42c4068d2a
commit
2478a1355f
@ -7,7 +7,7 @@ class AlgorithmMD5 : public IHashFunction
|
|||||||
AlgorithmMD5Impl* m_impl;
|
AlgorithmMD5Impl* m_impl;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
static const int HASH_SIZE = 20;
|
static const int HASH_SIZE = 16;
|
||||||
|
|
||||||
AlgorithmMD5();
|
AlgorithmMD5();
|
||||||
~AlgorithmMD5() override;
|
~AlgorithmMD5() override;
|
||||||
|
@ -1,19 +1,19 @@
|
|||||||
#include "Csv/ParsedCsv.h"
|
#include "Csv/ParsedCsv.h"
|
||||||
|
|
||||||
ParsedCsvRow::ParsedCsvRow(std::unordered_map<std::string, size_t>& headers, std::vector<std::string>& row)
|
ParsedCsvRow::ParsedCsvRow(std::unordered_map<std::string, size_t>& headers, std::vector<std::string> row)
|
||||||
: headers(headers),
|
: headers(headers),
|
||||||
values(row)
|
values(std::move(row))
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
const std::string ParsedCsvRow::GetValue(const std::string& header, bool required) const
|
std::string ParsedCsvRow::GetValue(const std::string& header, bool required) const
|
||||||
{
|
{
|
||||||
if (this->headers.find(header) == this->headers.end())
|
if (this->headers.find(header) == this->headers.end())
|
||||||
{
|
{
|
||||||
if (required)
|
if (required)
|
||||||
std::cerr << "ERROR: Required column \"" << header << "\" was not found";
|
std::cerr << "ERROR: Required column \"" << header << "\" was not found" << std::endl;
|
||||||
else
|
else
|
||||||
std::cerr << "WARNING: Expected column \"" << header << "\" was not found";
|
std::cerr << "WARNING: Expected column \"" << header << "\" was not found" << std::endl;
|
||||||
|
|
||||||
return {};
|
return {};
|
||||||
}
|
}
|
||||||
@ -21,14 +21,14 @@ const std::string ParsedCsvRow::GetValue(const std::string& header, bool require
|
|||||||
auto& value = this->values.at(this->headers[header]);
|
auto& value = this->values.at(this->headers[header]);
|
||||||
if (required && value.empty())
|
if (required && value.empty())
|
||||||
{
|
{
|
||||||
std::cerr << "ERROR: Required column \"" << header << "\" does not have a value";
|
std::cerr << "ERROR: Required column \"" << header << "\" does not have a value" << std::endl;
|
||||||
return {};
|
return {};
|
||||||
}
|
}
|
||||||
|
|
||||||
return value;
|
return value;
|
||||||
}
|
}
|
||||||
|
|
||||||
const float ParsedCsvRow::GetValueFloat(const std::string& header, bool required) const
|
float ParsedCsvRow::GetValueFloat(const std::string& header, bool required) const
|
||||||
{
|
{
|
||||||
const auto& value = this->GetValue(header, required);
|
const auto& value = this->GetValue(header, required);
|
||||||
if (!value.empty())
|
if (!value.empty())
|
||||||
@ -65,7 +65,7 @@ ParsedCsv::ParsedCsv(const CsvInputStream& inputStream, bool hasHeaders)
|
|||||||
for (auto i = hasHeaders ? 1u : 0u; i < csvLines.size(); i++)
|
for (auto i = hasHeaders ? 1u : 0u; i < csvLines.size(); i++)
|
||||||
{
|
{
|
||||||
auto& rowValues = csvLines[i];
|
auto& rowValues = csvLines[i];
|
||||||
this->rows.push_back(ParsedCsvRow(this->headers, rowValues));
|
this->rows.emplace_back(this->headers, std::move(rowValues));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
#include <Csv/CsvStream.h>
|
|
||||||
#include <sstream>
|
#include <sstream>
|
||||||
#include <unordered_map>
|
#include <unordered_map>
|
||||||
|
#include "Csv/CsvStream.h"
|
||||||
|
|
||||||
class ParsedCsvRow
|
class ParsedCsvRow
|
||||||
{
|
{
|
||||||
@ -9,9 +9,9 @@ class ParsedCsvRow
|
|||||||
std::vector<std::string> values;
|
std::vector<std::string> values;
|
||||||
|
|
||||||
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);
|
||||||
const std::string GetValue(const std::string& header, bool required = false) const;
|
std::string GetValue(const std::string& header, bool required = false) const;
|
||||||
const float GetValueFloat(const std::string& header, bool required = false) const;
|
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, bool required = false) const
|
||||||
{
|
{
|
||||||
|
@ -26,14 +26,5 @@ namespace T6
|
|||||||
static constexpr const char* GDF_FILENAME_WEAPON_ATTACHMENT = "attachment.gdf";
|
static constexpr const char* GDF_FILENAME_WEAPON_ATTACHMENT = "attachment.gdf";
|
||||||
static constexpr const char* GDF_FILENAME_WEAPON_ATTACHMENT_UNIQUE = "attachmentunique.gdf";
|
static constexpr const char* GDF_FILENAME_WEAPON_ATTACHMENT_UNIQUE = "attachmentunique.gdf";
|
||||||
static constexpr const char* GDF_FILENAME_ZBARRIER = "zbarrier.gdf";
|
static constexpr const char* GDF_FILENAME_ZBARRIER = "zbarrier.gdf";
|
||||||
|
|
||||||
static const std::array<std::string, 27> SOUND_GROUPS;
|
|
||||||
static const std::array<std::string, 18> SOUND_CURVES;
|
|
||||||
static const std::array<std::string, 32> SOUND_DUCK_GROUPS;
|
|
||||||
static const std::array<std::string, 4> SOUND_LIMIT_TYPES;
|
|
||||||
static const std::array<std::string, 8> SOUND_MOVE_TYPES;
|
|
||||||
static const std::array<std::string, 4> SOUND_LOAD_TYPES;
|
|
||||||
static const std::array<std::string, 11> SOUND_BUS_IDS;
|
|
||||||
static const std::array<std::string, 4> SOUND_RANDOMIZE_TYPES;
|
|
||||||
};
|
};
|
||||||
} // namespace T6
|
} // namespace T6
|
||||||
|
@ -1,8 +1,9 @@
|
|||||||
#include "ObjConstantsT6.h"
|
#pragma once
|
||||||
|
#include <string>
|
||||||
|
|
||||||
namespace T6
|
namespace T6
|
||||||
{
|
{
|
||||||
const std::array<std::string, 27> ObjConstants::SOUND_GROUPS{
|
inline const std::string SOUND_GROUPS[]{
|
||||||
"grp_reference",
|
"grp_reference",
|
||||||
"grp_master",
|
"grp_master",
|
||||||
"grp_wpn_lfe",
|
"grp_wpn_lfe",
|
||||||
@ -32,7 +33,7 @@ namespace T6
|
|||||||
"",
|
"",
|
||||||
};
|
};
|
||||||
|
|
||||||
const std::array<std::string, 18> ObjConstants::SOUND_CURVES{
|
inline const std::string SOUND_CURVES[]{
|
||||||
"default",
|
"default",
|
||||||
"defaultmin",
|
"defaultmin",
|
||||||
"allon",
|
"allon",
|
||||||
@ -53,7 +54,7 @@ namespace T6
|
|||||||
"",
|
"",
|
||||||
};
|
};
|
||||||
|
|
||||||
const std::array<std::string, 32> ObjConstants::SOUND_DUCK_GROUPS{
|
inline const std::string SOUND_DUCK_GROUPS[]{
|
||||||
"snp_alerts_gameplay",
|
"snp_alerts_gameplay",
|
||||||
"snp_ambience",
|
"snp_ambience",
|
||||||
"snp_claw",
|
"snp_claw",
|
||||||
@ -88,14 +89,14 @@ namespace T6
|
|||||||
"snp_x3",
|
"snp_x3",
|
||||||
};
|
};
|
||||||
|
|
||||||
const std::array<std::string, 4> ObjConstants::SOUND_LIMIT_TYPES{
|
inline const std::string SOUND_LIMIT_TYPES[]{
|
||||||
"none",
|
"none",
|
||||||
"oldest",
|
"oldest",
|
||||||
"reject",
|
"reject",
|
||||||
"priority",
|
"priority",
|
||||||
};
|
};
|
||||||
|
|
||||||
const std::array<std::string, 8> ObjConstants::SOUND_MOVE_TYPES{
|
inline const std::string SOUND_MOVE_TYPES[]{
|
||||||
"none",
|
"none",
|
||||||
"left_player",
|
"left_player",
|
||||||
"center_player",
|
"center_player",
|
||||||
@ -106,14 +107,14 @@ namespace T6
|
|||||||
"right_shot",
|
"right_shot",
|
||||||
};
|
};
|
||||||
|
|
||||||
const std::array<std::string, 4> ObjConstants::SOUND_LOAD_TYPES{
|
inline const std::string SOUND_LOAD_TYPES[]{
|
||||||
"unknown",
|
"unknown",
|
||||||
"loaded",
|
"loaded",
|
||||||
"streamed",
|
"streamed",
|
||||||
"primed",
|
"primed",
|
||||||
};
|
};
|
||||||
|
|
||||||
const std::array<std::string, 11> ObjConstants::SOUND_BUS_IDS{
|
inline const std::string SOUND_BUS_IDS[]{
|
||||||
"bus_reverb",
|
"bus_reverb",
|
||||||
"bus_fx",
|
"bus_fx",
|
||||||
"bus_voice",
|
"bus_voice",
|
||||||
@ -127,11 +128,10 @@ namespace T6
|
|||||||
"",
|
"",
|
||||||
};
|
};
|
||||||
|
|
||||||
const std::array<std::string, 4> ObjConstants::SOUND_RANDOMIZE_TYPES{
|
inline const std::string SOUND_RANDOMIZE_TYPES[]{
|
||||||
"volume",
|
"volume",
|
||||||
"pitch",
|
"pitch",
|
||||||
"variant",
|
"variant",
|
||||||
"",
|
"",
|
||||||
};
|
};
|
||||||
|
|
||||||
} // namespace T6
|
} // namespace T6
|
@ -2,7 +2,7 @@
|
|||||||
|
|
||||||
#include "Csv/ParsedCsv.h"
|
#include "Csv/ParsedCsv.h"
|
||||||
#include "Game/T6/CommonT6.h"
|
#include "Game/T6/CommonT6.h"
|
||||||
#include "Game/T6/ObjConstantsT6.h"
|
#include "Game/T6/SoundConstantsT6.h"
|
||||||
#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"
|
||||||
@ -180,24 +180,18 @@ bool LoadSoundAlias(MemoryManager* memory, SndAlias* alias, const ParsedCsvRow&
|
|||||||
alias->flags.pauseable = row.GetValue("pause") == "yes";
|
alias->flags.pauseable = row.GetValue("pause") == "yes";
|
||||||
alias->flags.stopOnDeath = row.GetValue("stop_on_death") == "yes";
|
alias->flags.stopOnDeath = row.GetValue("stop_on_death") == "yes";
|
||||||
|
|
||||||
alias->duckGroup =
|
alias->duckGroup = static_cast<char>(GetValueIndex(row.GetValue("duck_group"), SOUND_DUCK_GROUPS, std::extent_v<decltype(SOUND_DUCK_GROUPS)>));
|
||||||
static_cast<char>(GetValueIndex(row.GetValue("duck_group"), ObjConstants::SOUND_DUCK_GROUPS.data(), ObjConstants::SOUND_DUCK_GROUPS.size()));
|
alias->flags.volumeGroup = GetValueIndex(row.GetValue("group"), SOUND_GROUPS, std::extent_v<decltype(SOUND_GROUPS)>);
|
||||||
alias->flags.volumeGroup = GetValueIndex(row.GetValue("group"), ObjConstants::SOUND_GROUPS.data(), ObjConstants::SOUND_GROUPS.size());
|
alias->flags.fluxType = GetValueIndex(row.GetValue("move_type"), SOUND_MOVE_TYPES, std::extent_v<decltype(SOUND_MOVE_TYPES)>);
|
||||||
alias->flags.fluxType = GetValueIndex(row.GetValue("move_type"), ObjConstants::SOUND_MOVE_TYPES.data(), ObjConstants::SOUND_MOVE_TYPES.size());
|
alias->flags.loadType = GetValueIndex(row.GetValue("type"), SOUND_LOAD_TYPES, std::extent_v<decltype(SOUND_LOAD_TYPES)>);
|
||||||
alias->flags.loadType = GetValueIndex(row.GetValue("type"), ObjConstants::SOUND_LOAD_TYPES.data(), ObjConstants::SOUND_LOAD_TYPES.size());
|
alias->flags.busType = GetValueIndex(row.GetValue("bus"), SOUND_BUS_IDS, std::extent_v<decltype(SOUND_BUS_IDS)>);
|
||||||
alias->flags.busType = GetValueIndex(row.GetValue("bus"), ObjConstants::SOUND_BUS_IDS.data(), ObjConstants::SOUND_BUS_IDS.size());
|
alias->flags.limitType = GetValueIndex(row.GetValue("limit_type"), SOUND_LIMIT_TYPES, std::extent_v<decltype(SOUND_LIMIT_TYPES)>);
|
||||||
alias->flags.limitType = GetValueIndex(row.GetValue("limit_type"), ObjConstants::SOUND_LIMIT_TYPES.data(), ObjConstants::SOUND_LIMIT_TYPES.size());
|
alias->flags.volumeFalloffCurve = GetValueIndex(row.GetValue("volume_falloff_curve"), SOUND_CURVES, std::extent_v<decltype(SOUND_CURVES)>);
|
||||||
alias->flags.volumeFalloffCurve = GetValueIndex(row.GetValue("volume_falloff_curve"), ObjConstants::SOUND_CURVES.data(), ObjConstants::SOUND_CURVES.size());
|
alias->flags.reverbFalloffCurve = GetValueIndex(row.GetValue("reverb_falloff_curve"), SOUND_CURVES, std::extent_v<decltype(SOUND_CURVES)>);
|
||||||
alias->flags.reverbFalloffCurve = GetValueIndex(row.GetValue("reverb_falloff_curve"), ObjConstants::SOUND_CURVES.data(), ObjConstants::SOUND_CURVES.size());
|
alias->flags.entityLimitType = GetValueIndex(row.GetValue("entity_limit_type"), SOUND_LIMIT_TYPES, std::extent_v<decltype(SOUND_LIMIT_TYPES)>);
|
||||||
|
alias->flags.volumeMinFalloffCurve = GetValueIndex(row.GetValue("volume_min_falloff_curve"), SOUND_CURVES, std::extent_v<decltype(SOUND_CURVES)>);
|
||||||
alias->flags.entityLimitType =
|
alias->flags.reverbMinFalloffCurve = GetValueIndex(row.GetValue("reverb_min_falloff_curve"), SOUND_CURVES, std::extent_v<decltype(SOUND_CURVES)>);
|
||||||
GetValueIndex(row.GetValue("entity_limit_type"), ObjConstants::SOUND_LIMIT_TYPES.data(), ObjConstants::SOUND_LIMIT_TYPES.size());
|
alias->flags.randomizeType = GetValueIndex(row.GetValue("randomize_type"), SOUND_RANDOMIZE_TYPES, std::extent_v<decltype(SOUND_RANDOMIZE_TYPES)>);
|
||||||
alias->flags.volumeMinFalloffCurve =
|
|
||||||
GetValueIndex(row.GetValue("volume_min_falloff_curve"), ObjConstants::SOUND_CURVES.data(), ObjConstants::SOUND_CURVES.size());
|
|
||||||
alias->flags.reverbMinFalloffCurve =
|
|
||||||
GetValueIndex(row.GetValue("reverb_min_falloff_curve"), ObjConstants::SOUND_CURVES.data(), ObjConstants::SOUND_CURVES.size());
|
|
||||||
alias->flags.randomizeType =
|
|
||||||
GetValueIndex(row.GetValue("randomize_type"), ObjConstants::SOUND_RANDOMIZE_TYPES.data(), ObjConstants::SOUND_RANDOMIZE_TYPES.size());
|
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
@ -208,16 +202,15 @@ bool LoadSoundAliasIndexList(MemoryManager* memory, SndBank* sndBank)
|
|||||||
sndBank->aliasIndex = static_cast<SndIndexEntry*>(memory->Alloc(sizeof(SndIndexEntry) * sndBank->aliasCount));
|
sndBank->aliasIndex = static_cast<SndIndexEntry*>(memory->Alloc(sizeof(SndIndexEntry) * sndBank->aliasCount));
|
||||||
memset(sndBank->aliasIndex, 0xFF, sizeof(SndIndexEntry) * sndBank->aliasCount);
|
memset(sndBank->aliasIndex, 0xFF, sizeof(SndIndexEntry) * sndBank->aliasCount);
|
||||||
|
|
||||||
bool* setAliasIndexList = new bool[sndBank->aliasCount];
|
const auto setAliasIndexList = std::make_unique<bool[]>(sndBank->aliasCount);
|
||||||
memset(setAliasIndexList, false, sndBank->aliasCount);
|
|
||||||
|
|
||||||
for (auto i = 0u; i < sndBank->aliasCount; i++)
|
for (auto i = 0u; i < sndBank->aliasCount; i++)
|
||||||
{
|
{
|
||||||
auto idx = sndBank->alias[i].id % sndBank->aliasCount;
|
auto idx = sndBank->alias[i].id % sndBank->aliasCount;
|
||||||
if (sndBank->aliasIndex[idx].value == USHRT_MAX)
|
if (sndBank->aliasIndex[idx].value == std::numeric_limits<unsigned short>::max())
|
||||||
{
|
{
|
||||||
sndBank->aliasIndex[idx].value = i;
|
sndBank->aliasIndex[idx].value = i;
|
||||||
sndBank->aliasIndex[idx].next = USHRT_MAX;
|
sndBank->aliasIndex[idx].next = std::numeric_limits<unsigned short>::max();
|
||||||
setAliasIndexList[i] = true;
|
setAliasIndexList[i] = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -228,44 +221,42 @@ bool LoadSoundAliasIndexList(MemoryManager* memory, SndBank* sndBank)
|
|||||||
continue;
|
continue;
|
||||||
|
|
||||||
auto idx = sndBank->alias[i].id % sndBank->aliasCount;
|
auto idx = sndBank->alias[i].id % sndBank->aliasCount;
|
||||||
while (sndBank->aliasIndex[idx].next != USHRT_MAX)
|
while (sndBank->aliasIndex[idx].next != std::numeric_limits<unsigned short>::max())
|
||||||
{
|
{
|
||||||
idx = sndBank->aliasIndex[idx].next;
|
idx = sndBank->aliasIndex[idx].next;
|
||||||
}
|
}
|
||||||
|
|
||||||
auto offset = 1u;
|
auto offset = 1u;
|
||||||
auto freeIdx = USHRT_MAX;
|
auto freeIdx = std::numeric_limits<unsigned short>::max();
|
||||||
while (true)
|
while (true)
|
||||||
{
|
{
|
||||||
freeIdx = (idx + offset) % sndBank->aliasCount;
|
freeIdx = (idx + offset) % sndBank->aliasCount;
|
||||||
if (sndBank->aliasIndex[freeIdx].value == USHRT_MAX)
|
if (sndBank->aliasIndex[freeIdx].value == std::numeric_limits<unsigned short>::max())
|
||||||
break;
|
break;
|
||||||
|
|
||||||
freeIdx = (idx + sndBank->aliasCount - offset) % sndBank->aliasCount;
|
freeIdx = (idx + sndBank->aliasCount - offset) % sndBank->aliasCount;
|
||||||
if (sndBank->aliasIndex[freeIdx].value == USHRT_MAX)
|
if (sndBank->aliasIndex[freeIdx].value == std::numeric_limits<unsigned short>::max())
|
||||||
break;
|
break;
|
||||||
|
|
||||||
offset++;
|
offset++;
|
||||||
freeIdx = USHRT_MAX;
|
freeIdx = std::numeric_limits<unsigned short>::max();
|
||||||
|
|
||||||
if (offset >= sndBank->aliasCount)
|
if (offset >= sndBank->aliasCount)
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (freeIdx == USHRT_MAX)
|
if (freeIdx == std::numeric_limits<unsigned short>::max())
|
||||||
{
|
{
|
||||||
std::cerr << "Unable to allocate sound bank alias index list" << std::endl;
|
std::cerr << "Unable to allocate sound bank alias index list" << std::endl;
|
||||||
delete[] setAliasIndexList;
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
sndBank->aliasIndex[idx].next = freeIdx;
|
sndBank->aliasIndex[idx].next = freeIdx;
|
||||||
sndBank->aliasIndex[freeIdx].value = i;
|
sndBank->aliasIndex[freeIdx].value = i;
|
||||||
sndBank->aliasIndex[freeIdx].next = USHRT_MAX;
|
sndBank->aliasIndex[freeIdx].next = std::numeric_limits<unsigned short>::max();
|
||||||
setAliasIndexList[i] = true;
|
setAliasIndexList[i] = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
delete[] setAliasIndexList;
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -436,8 +427,7 @@ bool LoadSoundDuckList(ISearchPath* searchPath, MemoryManager* memory, SndBank*
|
|||||||
|
|
||||||
for (auto& valueJson : duckJson["values"])
|
for (auto& valueJson : duckJson["values"])
|
||||||
{
|
{
|
||||||
auto index =
|
auto index = GetValueIndex(valueJson["duckGroup"].get<std::string>(), SOUND_DUCK_GROUPS, std::extent_v<decltype(SOUND_DUCK_GROUPS)>);
|
||||||
GetValueIndex(valueJson["duckGroup"].get<std::string>(), ObjConstants::SOUND_DUCK_GROUPS.data(), ObjConstants::SOUND_DUCK_GROUPS.size());
|
|
||||||
|
|
||||||
duck->attenuation[index] = valueJson["attenuation"].get<float>();
|
duck->attenuation[index] = valueJson["attenuation"].get<float>();
|
||||||
duck->filter[index] = valueJson["filter"].get<float>();
|
duck->filter[index] = valueJson["filter"].get<float>();
|
||||||
@ -550,14 +540,15 @@ bool AssetLoaderSoundBank::LoadFromRaw(
|
|||||||
// write the output linked sound bank
|
// write the output linked sound bank
|
||||||
if (sablWriter)
|
if (sablWriter)
|
||||||
{
|
{
|
||||||
auto size = static_cast<size_t>(sablWriter->Write());
|
size_t dataSize = 0u;
|
||||||
|
auto result = sablWriter->Write(dataSize);
|
||||||
sablStream->close();
|
sablStream->close();
|
||||||
|
|
||||||
if (size != UINT32_MAX)
|
if (result)
|
||||||
{
|
{
|
||||||
sndBank->loadedAssets.dataSize = size;
|
sndBank->loadedAssets.dataSize = dataSize;
|
||||||
sndBank->loadedAssets.data = static_cast<SndChar2048*>(memory->Alloc(size));
|
sndBank->loadedAssets.data = static_cast<SndChar2048*>(memory->Alloc(dataSize));
|
||||||
memset(sndBank->loadedAssets.data, 0, size);
|
memset(sndBank->loadedAssets.data, 0, dataSize);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
@ -569,10 +560,11 @@ bool AssetLoaderSoundBank::LoadFromRaw(
|
|||||||
// write the output streamed sound bank
|
// write the output streamed sound bank
|
||||||
if (sabsWriter)
|
if (sabsWriter)
|
||||||
{
|
{
|
||||||
auto size = static_cast<size_t>(sabsWriter->Write());
|
size_t dataSize = 0u;
|
||||||
|
auto result = sabsWriter->Write(dataSize);
|
||||||
sabsStream->close();
|
sabsStream->close();
|
||||||
|
|
||||||
if (size == UINT32_MAX)
|
if (!result)
|
||||||
{
|
{
|
||||||
std::cerr << "Streamed Sound Bank for " << assetName << " failed to generate. Please check your build files." << std::endl;
|
std::cerr << "Streamed Sound Bank for " << assetName << " failed to generate. Please check your build files." << std::endl;
|
||||||
return false;
|
return false;
|
||||||
|
@ -2,12 +2,11 @@
|
|||||||
|
|
||||||
#include "Crypto.h"
|
#include "Crypto.h"
|
||||||
#include "ObjContainer/SoundBank/SoundBankTypes.h"
|
#include "ObjContainer/SoundBank/SoundBankTypes.h"
|
||||||
#include "Sound/WavTypes.h"
|
|
||||||
#include "Sound/FlacDecoder.h"
|
#include "Sound/FlacDecoder.h"
|
||||||
|
#include "Sound/WavTypes.h"
|
||||||
#include "Utils/Alignment.h"
|
#include "Utils/Alignment.h"
|
||||||
#include "Utils/FileUtils.h"
|
#include "Utils/FileUtils.h"
|
||||||
|
|
||||||
|
|
||||||
#include <cstring>
|
#include <cstring>
|
||||||
#include <filesystem>
|
#include <filesystem>
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
@ -78,8 +77,8 @@ public:
|
|||||||
|
|
||||||
void AlignToChunk()
|
void AlignToChunk()
|
||||||
{
|
{
|
||||||
if ((m_current_offset & 0xF) != 0)
|
if (m_current_offset % 16 != 0)
|
||||||
Pad(0x10 - (m_current_offset & 0xF));
|
Pad(16 - (m_current_offset % 16));
|
||||||
}
|
}
|
||||||
|
|
||||||
void WriteHeader()
|
void WriteHeader()
|
||||||
@ -91,7 +90,8 @@ public:
|
|||||||
SoundAssetBankChecksum checksum{};
|
SoundAssetBankChecksum checksum{};
|
||||||
memset(&checksum, 0xCC, sizeof(SoundAssetBankChecksum));
|
memset(&checksum, 0xCC, sizeof(SoundAssetBankChecksum));
|
||||||
|
|
||||||
SoundAssetBankHeader header{MAGIC,
|
SoundAssetBankHeader header{
|
||||||
|
MAGIC,
|
||||||
VERSION,
|
VERSION,
|
||||||
sizeof(SoundAssetBankEntry),
|
sizeof(SoundAssetBankEntry),
|
||||||
sizeof(SoundAssetBankChecksum),
|
sizeof(SoundAssetBankChecksum),
|
||||||
@ -102,7 +102,8 @@ public:
|
|||||||
m_total_size,
|
m_total_size,
|
||||||
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);
|
||||||
|
|
||||||
@ -169,7 +170,7 @@ public:
|
|||||||
static_cast<size_t>(m_current_offset),
|
static_cast<size_t>(m_current_offset),
|
||||||
decoder->GetFrameCount(),
|
decoder->GetFrameCount(),
|
||||||
frameRateIndex,
|
frameRateIndex,
|
||||||
decoder->GetNumChannels(),
|
static_cast<unsigned char>(decoder->GetNumChannels()),
|
||||||
sound.looping,
|
sound.looping,
|
||||||
8,
|
8,
|
||||||
};
|
};
|
||||||
@ -192,7 +193,8 @@ public:
|
|||||||
auto lastEntry = m_entries.rbegin();
|
auto lastEntry = m_entries.rbegin();
|
||||||
if (!sound.streamed && lastEntry->frameRateIndex != 6)
|
if (!sound.streamed && lastEntry->frameRateIndex != 6)
|
||||||
{
|
{
|
||||||
std::cout << "WARNING: Loaded sound \"" << soundFilePath << "\" should have a framerate of 48000 but doesn't. This sound may not work on all games!" << std::endl;
|
std::cout << "WARNING: Loaded sound \"" << soundFilePath
|
||||||
|
<< "\" should have a framerate of 48000 but doesn't. This sound may not work on all games!" << std::endl;
|
||||||
}
|
}
|
||||||
|
|
||||||
// calculate checksum
|
// calculate checksum
|
||||||
@ -240,12 +242,12 @@ public:
|
|||||||
AlignToChunk();
|
AlignToChunk();
|
||||||
}
|
}
|
||||||
|
|
||||||
std::int64_t Write() override
|
bool Write(size_t& dataSize) override
|
||||||
{
|
{
|
||||||
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 entires. Please check output." << std::endl;
|
||||||
return -1;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
WriteEntryList();
|
WriteEntryList();
|
||||||
@ -259,11 +261,12 @@ public:
|
|||||||
if (m_current_offset > UINT32_MAX)
|
if (m_current_offset > UINT32_MAX)
|
||||||
{
|
{
|
||||||
std::cerr << "Sound bank files must be under 4GB. Please reduce the number of sounds being written!" << std::endl;
|
std::cerr << "Sound bank files must be under 4GB. Please reduce the number of sounds being written!" << std::endl;
|
||||||
return -1;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
// return the total size for the sound asset data
|
// output the total size for the sound asset data
|
||||||
return m_entry_section_offset - DATA_OFFSET;
|
dataSize = static_cast<size_t>(m_entry_section_offset - DATA_OFFSET);
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
@ -17,7 +17,7 @@ public:
|
|||||||
SoundBankWriter& operator=(SoundBankWriter&& other) noexcept = default;
|
SoundBankWriter& operator=(SoundBankWriter&& other) noexcept = default;
|
||||||
|
|
||||||
virtual void AddSound(const std::string& soundFilePath, unsigned int soundId, bool looping = false, bool streamed = false) = 0;
|
virtual void AddSound(const std::string& soundFilePath, unsigned int soundId, bool looping = false, bool streamed = false) = 0;
|
||||||
virtual std::int64_t Write() = 0;
|
virtual bool Write(size_t& dataSize) = 0;
|
||||||
|
|
||||||
static std::unique_ptr<SoundBankWriter> Create(const std::string& fileName, std::ostream& stream, ISearchPath* assetSearchPath);
|
static std::unique_ptr<SoundBankWriter> Create(const std::string& fileName, std::ostream& stream, ISearchPath* assetSearchPath);
|
||||||
|
|
||||||
|
@ -2,7 +2,7 @@
|
|||||||
|
|
||||||
#include "Csv/CsvStream.h"
|
#include "Csv/CsvStream.h"
|
||||||
#include "Game/T6/CommonT6.h"
|
#include "Game/T6/CommonT6.h"
|
||||||
#include "Game/T6/ObjConstantsT6.h"
|
#include "Game/T6/SoundConstantsT6.h"
|
||||||
#include "ObjContainer/SoundBank/SoundBank.h"
|
#include "ObjContainer/SoundBank/SoundBank.h"
|
||||||
#include "Sound/WavWriter.h"
|
#include "Sound/WavWriter.h"
|
||||||
#include "nlohmann/json.hpp"
|
#include "nlohmann/json.hpp"
|
||||||
@ -123,8 +123,8 @@ namespace
|
|||||||
std::unordered_map<unsigned int, std::string> CreateCurvesMap()
|
std::unordered_map<unsigned int, std::string> CreateCurvesMap()
|
||||||
{
|
{
|
||||||
std::unordered_map<unsigned int, std::string> result;
|
std::unordered_map<unsigned int, std::string> result;
|
||||||
for (auto i = 0u; i < ObjConstants::SOUND_CURVES.size(); i++)
|
for (auto i = 0u; i < std::extent_v<decltype(SOUND_CURVES)>; i++)
|
||||||
result.emplace(T6::Common::SND_HashName(ObjConstants::SOUND_CURVES[i].data()), ObjConstants::SOUND_CURVES[i]);
|
result.emplace(T6::Common::SND_HashName(SOUND_CURVES[i].data()), SOUND_CURVES[i]);
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -226,7 +226,7 @@ class AssetDumperSndBank::Internal
|
|||||||
stream.WriteColumn((alias->secondaryname && *alias->secondaryname) ? alias->secondaryname : "");
|
stream.WriteColumn((alias->secondaryname && *alias->secondaryname) ? alias->secondaryname : "");
|
||||||
|
|
||||||
// group
|
// group
|
||||||
stream.WriteColumn(ObjConstants::SOUND_GROUPS[alias->flags.volumeGroup]);
|
stream.WriteColumn(SOUND_GROUPS[alias->flags.volumeGroup]);
|
||||||
|
|
||||||
// vol_min
|
// vol_min
|
||||||
stream.WriteColumn(std::to_string(alias->volMin));
|
stream.WriteColumn(std::to_string(alias->volMin));
|
||||||
@ -247,28 +247,28 @@ class AssetDumperSndBank::Internal
|
|||||||
stream.WriteColumn(std::to_string(alias->distReverbMax));
|
stream.WriteColumn(std::to_string(alias->distReverbMax));
|
||||||
|
|
||||||
// volume_falloff_curve
|
// volume_falloff_curve
|
||||||
stream.WriteColumn(ObjConstants::SOUND_CURVES[alias->flags.volumeFalloffCurve]);
|
stream.WriteColumn(SOUND_CURVES[alias->flags.volumeFalloffCurve]);
|
||||||
|
|
||||||
// reverb_falloff_curve
|
// reverb_falloff_curve
|
||||||
stream.WriteColumn(ObjConstants::SOUND_CURVES[alias->flags.reverbFalloffCurve]);
|
stream.WriteColumn(SOUND_CURVES[alias->flags.reverbFalloffCurve]);
|
||||||
|
|
||||||
// volume_min_falloff_curve
|
// volume_min_falloff_curve
|
||||||
stream.WriteColumn(ObjConstants::SOUND_CURVES[alias->flags.volumeMinFalloffCurve]);
|
stream.WriteColumn(SOUND_CURVES[alias->flags.volumeMinFalloffCurve]);
|
||||||
|
|
||||||
// reverb_min_falloff_curve"
|
// reverb_min_falloff_curve"
|
||||||
stream.WriteColumn(ObjConstants::SOUND_CURVES[alias->flags.reverbMinFalloffCurve]);
|
stream.WriteColumn(SOUND_CURVES[alias->flags.reverbMinFalloffCurve]);
|
||||||
|
|
||||||
// limit_count
|
// limit_count
|
||||||
stream.WriteColumn(std::to_string(alias->limitCount));
|
stream.WriteColumn(std::to_string(alias->limitCount));
|
||||||
|
|
||||||
// limit_type
|
// limit_type
|
||||||
stream.WriteColumn(ObjConstants::SOUND_LIMIT_TYPES[alias->flags.limitType]);
|
stream.WriteColumn(SOUND_LIMIT_TYPES[alias->flags.limitType]);
|
||||||
|
|
||||||
// entity_limit_count
|
// entity_limit_count
|
||||||
stream.WriteColumn(std::to_string(alias->entityLimitCount));
|
stream.WriteColumn(std::to_string(alias->entityLimitCount));
|
||||||
|
|
||||||
// entity_limit_type
|
// entity_limit_type
|
||||||
stream.WriteColumn(ObjConstants::SOUND_LIMIT_TYPES[alias->flags.entityLimitType]);
|
stream.WriteColumn(SOUND_LIMIT_TYPES[alias->flags.entityLimitType]);
|
||||||
|
|
||||||
// pitch_min
|
// pitch_min
|
||||||
stream.WriteColumn(std::to_string(alias->pitchMin));
|
stream.WriteColumn(std::to_string(alias->pitchMin));
|
||||||
@ -295,13 +295,13 @@ class AssetDumperSndBank::Internal
|
|||||||
stream.WriteColumn("");
|
stream.WriteColumn("");
|
||||||
|
|
||||||
// type
|
// type
|
||||||
stream.WriteColumn(ObjConstants::SOUND_LOAD_TYPES[alias->flags.loadType]);
|
stream.WriteColumn(SOUND_LOAD_TYPES[alias->flags.loadType]);
|
||||||
|
|
||||||
// loop
|
// loop
|
||||||
stream.WriteColumn(alias->flags.looping == T6::SA_NON_LOOPING ? "nonlooping" : "looping");
|
stream.WriteColumn(alias->flags.looping == T6::SA_NON_LOOPING ? "nonlooping" : "looping");
|
||||||
|
|
||||||
// randomize_type
|
// randomize_type
|
||||||
stream.WriteColumn(ObjConstants::SOUND_RANDOMIZE_TYPES[std::min(alias->flags.randomizeType, 3u)]);
|
stream.WriteColumn(SOUND_RANDOMIZE_TYPES[std::min(alias->flags.randomizeType, 3u)]);
|
||||||
|
|
||||||
// probability",
|
// probability",
|
||||||
stream.WriteColumn(std::to_string(alias->probability));
|
stream.WriteColumn(std::to_string(alias->probability));
|
||||||
@ -316,7 +316,7 @@ class AssetDumperSndBank::Internal
|
|||||||
stream.WriteColumn(FindNameForDuck(alias->duck, bank));
|
stream.WriteColumn(FindNameForDuck(alias->duck, bank));
|
||||||
|
|
||||||
// duck_group",
|
// duck_group",
|
||||||
stream.WriteColumn(ObjConstants::SOUND_DUCK_GROUPS[alias->duckGroup]);
|
stream.WriteColumn(SOUND_DUCK_GROUPS[alias->duckGroup]);
|
||||||
|
|
||||||
// pan",
|
// pan",
|
||||||
stream.WriteColumn(alias->flags.panType == SA_PAN_2D ? "2d" : "3d");
|
stream.WriteColumn(alias->flags.panType == SA_PAN_2D ? "2d" : "3d");
|
||||||
@ -346,7 +346,7 @@ class AssetDumperSndBank::Internal
|
|||||||
stream.WriteColumn(alias->flags.distanceLpf ? "yes" : "no");
|
stream.WriteColumn(alias->flags.distanceLpf ? "yes" : "no");
|
||||||
|
|
||||||
// move_type",
|
// move_type",
|
||||||
stream.WriteColumn(ObjConstants::SOUND_MOVE_TYPES[alias->flags.fluxType]);
|
stream.WriteColumn(SOUND_MOVE_TYPES[alias->flags.fluxType]);
|
||||||
|
|
||||||
// move_time",
|
// move_time",
|
||||||
stream.WriteColumn(std::to_string(alias->fluxTime));
|
stream.WriteColumn(std::to_string(alias->fluxTime));
|
||||||
@ -397,7 +397,7 @@ class AssetDumperSndBank::Internal
|
|||||||
stream.WriteColumn(alias->flags.stopOnDeath ? "yes" : "no");
|
stream.WriteColumn(alias->flags.stopOnDeath ? "yes" : "no");
|
||||||
|
|
||||||
// bus",
|
// bus",
|
||||||
stream.WriteColumn(ObjConstants::SOUND_BUS_IDS[alias->flags.busType]);
|
stream.WriteColumn(SOUND_BUS_IDS[alias->flags.busType]);
|
||||||
|
|
||||||
// snapshot",
|
// snapshot",
|
||||||
stream.WriteColumn("");
|
stream.WriteColumn("");
|
||||||
@ -630,7 +630,7 @@ class AssetDumperSndBank::Internal
|
|||||||
for (auto i = 0u; i < 32u; i++)
|
for (auto i = 0u; i < 32u; i++)
|
||||||
{
|
{
|
||||||
values.push_back({
|
values.push_back({
|
||||||
{"duckGroup", ObjConstants::SOUND_DUCK_GROUPS[i]},
|
{"duckGroup", SOUND_DUCK_GROUPS[i]},
|
||||||
{"attenuation", duck.attenuation[i] },
|
{"attenuation", duck.attenuation[i] },
|
||||||
{"filter", duck.filter[i] }
|
{"filter", duck.filter[i] }
|
||||||
});
|
});
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
#include <Sound/WavTypes.h>
|
|
||||||
#include <ostream>
|
#include <ostream>
|
||||||
|
#include "Sound/WavTypes.h"
|
||||||
|
|
||||||
class WavWriter
|
class WavWriter
|
||||||
{
|
{
|
||||||
|
@ -104,13 +104,13 @@ namespace utils
|
|||||||
|
|
||||||
std::vector<std::string> StringSplit(const std::string& str, const char delim)
|
std::vector<std::string> StringSplit(const std::string& str, const char delim)
|
||||||
{
|
{
|
||||||
std::vector<std::string> strings{};
|
std::vector<std::string> strings;
|
||||||
std::istringstream stream(str);
|
std::istringstream stream(str);
|
||||||
|
|
||||||
std::string s;
|
std::string s;
|
||||||
while (std::getline(stream, s, delim))
|
while (std::getline(stream, s, delim))
|
||||||
{
|
{
|
||||||
strings.push_back(s);
|
strings.emplace_back(std::move(s));
|
||||||
}
|
}
|
||||||
|
|
||||||
return strings;
|
return strings;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user