Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor: sound bank loading dumping #277

Merged
merged 5 commits into from
Oct 6, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 6 additions & 4 deletions src/Common/Game/T6/T6_Assets.h
Original file line number Diff line number Diff line change
Expand Up @@ -6228,9 +6228,9 @@ namespace T6
unsigned int distanceLpf : 1; // 2
unsigned int doppler : 1; // 3
unsigned int isBig : 1; // 4
unsigned int pauseable : 1; // 5
unsigned int pausable : 1; // 5
unsigned int isMusic : 1; // 6
unsigned int stopOnDeath : 1; // 7
unsigned int stopOnEntDeath : 1; // 7
unsigned int timescale : 1; // 8
unsigned int voiceLimit : 1; // 9
unsigned int ignoreMaxDist : 1; // 10
Expand All @@ -6249,15 +6249,17 @@ namespace T6
unsigned int reverbFalloffCurve : 6; // 8-13
unsigned int volumeMinFalloffCurve : 6; // 14-19
unsigned int reverbMinFalloffCurve : 6; // 20-25
unsigned int unknown1_1 : 6; // 26-31
unsigned int unknown1_1 : 1; // 26
unsigned int isCinematic : 1; // 27
unsigned int unknown1_2 : 4; // 28-31
};

struct SndAlias
{
const char* name;
unsigned int id;
const char* subtitle;
const char* secondaryname;
const char* secondaryName;
unsigned int assetId;
const char* assetFileName;
SndAliasFlags flags;
Expand Down
34 changes: 34 additions & 0 deletions src/ObjCommon/Csv/CsvHeaderRow.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
#include "Csv/CsvHeaderRow.h"

CsvHeaderRow::CsvHeaderRow() = default;

bool CsvHeaderRow::Read(const CsvInputStream& inputStream)
{
if (!m_header_row.empty())
return false;

return inputStream.NextRow(m_header_row);
}

const std::string& CsvHeaderRow::HeaderNameForColumn(const unsigned columnIndex) const
{
return m_header_row[columnIndex];
}

bool CsvHeaderRow::RequireIndexForHeader(const std::string& headerName, unsigned& out) const
{
const auto existingHeader = std::ranges::find(m_header_row, headerName);
if (existingHeader == m_header_row.end())
return false;

out = std::distance(m_header_row.begin(), existingHeader);
return true;
}

std::optional<unsigned> CsvHeaderRow::GetIndexForHeader(const std::string& headerName) const
{
unsigned result;
if (!RequireIndexForHeader(headerName, result))
return std::nullopt;
return result;
}
22 changes: 22 additions & 0 deletions src/ObjCommon/Csv/CsvHeaderRow.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
#pragma once

#include "Csv/CsvStream.h"

#include <optional>
#include <string>
#include <vector>

class CsvHeaderRow
{
public:
CsvHeaderRow();

bool Read(const CsvInputStream& inputStream);

const std::string& HeaderNameForColumn(unsigned columnIndex) const;
bool RequireIndexForHeader(const std::string& headerName, unsigned& out) const;
[[nodiscard]] std::optional<unsigned> GetIndexForHeader(const std::string& headerName) const;

private:
std::vector<std::string> m_header_row;
};
90 changes: 88 additions & 2 deletions src/ObjCommon/Csv/CsvStream.cpp
Original file line number Diff line number Diff line change
@@ -1,14 +1,88 @@
#include "CsvStream.h"

#include "Utils/StringUtils.h"

#include <cstdlib>
#include <sstream>

constexpr char CSV_SEPARATOR = ',';

CsvCell::CsvCell(std::string value)
: m_value(std::move(value))
{
}

bool CsvCell::AsFloat(float& out) const
{
const char* startPtr = m_value.c_str();
char* endPtr;
out = std::strtof(startPtr, &endPtr);

if (endPtr == startPtr)
return false;

for (const auto* c = endPtr; *c; c++)
{
if (!isspace(*c))
return false;
}

return true;
}

bool CsvCell::AsInt32(int32_t& out) const
{
const char* startPtr = m_value.c_str();
char* endPtr;
out = std::strtol(startPtr, &endPtr, 0);

if (endPtr == startPtr)
return false;

for (const auto* c = endPtr; *c; c++)
{
if (!isspace(*c))
return false;
}

return true;
}

bool CsvCell::AsUInt32(uint32_t& out) const
{
const char* startPtr = m_value.c_str();
char* endPtr;
out = std::strtoul(startPtr, &endPtr, 0);

if (endPtr == startPtr)
return false;

for (const auto* c = endPtr; *c; c++)
{
if (!isspace(*c))
return false;
}

return true;
}

CsvInputStream::CsvInputStream(std::istream& stream)
: m_stream(stream)
{
}

bool CsvInputStream::NextRow(std::vector<CsvCell>& out) const
{
if (!out.empty())
out.clear();

return EmitNextRow(
[&out](std::string value)
{
out.emplace_back(std::move(value));
});
}

bool CsvInputStream::NextRow(std::vector<std::string>& out) const
{
if (!out.empty())
Expand Down Expand Up @@ -38,13 +112,17 @@ bool CsvInputStream::EmitNextRow(const std::function<void(std::string)>& cb) con
auto c = m_stream.get();
const auto isEof = c == EOF;
std::ostringstream col;
auto content = false;
while (c != EOF)
{
if (c == CSV_SEPARATOR)
{
cb(col.str());
auto value = col.str();
utils::StringTrimR(value);
cb(std::move(value));
col.clear();
col.str(std::string());
content = false;
}
else if (c == '\r')
{
Expand All @@ -57,8 +135,14 @@ bool CsvInputStream::EmitNextRow(const std::function<void(std::string)>& cb) con
{
break;
}
else if (isspace(c))
{
if (content)
col << static_cast<char>(c);
}
else
{
content = true;
col << static_cast<char>(c);
}

Expand All @@ -67,7 +151,9 @@ bool CsvInputStream::EmitNextRow(const std::function<void(std::string)>& cb) con

if (!isEof)
{
cb(col.str());
auto value = col.str();
utils::StringTrimR(value);
cb(std::move(value));
}

return !isEof;
Expand Down
14 changes: 14 additions & 0 deletions src/ObjCommon/Csv/CsvStream.h
Original file line number Diff line number Diff line change
@@ -1,16 +1,30 @@
#pragma once
#include "Utils/MemoryManager.h"

#include <cstdint>
#include <functional>
#include <iostream>
#include <string>
#include <vector>

class CsvCell
{
public:
explicit CsvCell(std::string value);

bool AsFloat(float& out) const;
bool AsInt32(int32_t& out) const;
bool AsUInt32(uint32_t& out) const;

std::string m_value;
};

class CsvInputStream
{
public:
explicit CsvInputStream(std::istream& stream);

bool NextRow(std::vector<CsvCell>& out) const;
bool NextRow(std::vector<std::string>& out) const;
bool NextRow(std::vector<const char*>& out, MemoryManager& memory) const;

Expand Down
80 changes: 0 additions & 80 deletions src/ObjCommon/Csv/ParsedCsv.cpp

This file was deleted.

45 changes: 0 additions & 45 deletions src/ObjCommon/Csv/ParsedCsv.h

This file was deleted.

Loading