forked from Laupetin/OpenAssetTools
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request Laupetin#91 from Laupetin/iw3-stringtable
feat: add StringTable loading for IW3
- Loading branch information
Showing
14 changed files
with
522 additions
and
213 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,28 +1,36 @@ | ||
#pragma once | ||
#include "Utils/MemoryManager.h" | ||
|
||
#include <functional> | ||
#include <iostream> | ||
#include <string> | ||
#include <vector> | ||
|
||
class CsvInputStream | ||
{ | ||
std::istream& m_stream; | ||
|
||
public: | ||
explicit CsvInputStream(std::istream& stream); | ||
|
||
bool NextRow(std::vector<std::string>& out) const; | ||
bool NextRow(std::vector<const char*>& out, MemoryManager& memory) const; | ||
|
||
private: | ||
bool EmitNextRow(const std::function<void(std::string)>& cb) const; | ||
|
||
std::istream& m_stream; | ||
}; | ||
|
||
class CsvOutputStream | ||
{ | ||
std::ostream& m_stream; | ||
unsigned m_column_count; | ||
unsigned m_current_column; | ||
bool m_first_row; | ||
|
||
public: | ||
explicit CsvOutputStream(std::ostream& stream); | ||
|
||
void WriteColumn(const std::string& value); | ||
void NextRow(); | ||
|
||
private: | ||
std::ostream& m_stream; | ||
unsigned m_column_count; | ||
unsigned m_current_column; | ||
bool m_first_row; | ||
}; |
39 changes: 39 additions & 0 deletions
39
src/ObjLoading/Game/IW3/AssetLoaders/AssetLoaderStringTable.cpp
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
#include "AssetLoaderStringTable.h" | ||
|
||
#include "Csv/CsvStream.h" | ||
#include "Game/IW3/CommonIW3.h" | ||
#include "ObjLoading.h" | ||
#include "Pool/GlobalAssetPool.h" | ||
#include "StringTable/StringTableLoader.h" | ||
|
||
#include <cstring> | ||
|
||
using namespace IW3; | ||
|
||
void* AssetLoaderStringTable::CreateEmptyAsset(const std::string& assetName, MemoryManager* memory) | ||
{ | ||
auto* stringTable = memory->Create<StringTable>(); | ||
memset(stringTable, 0, sizeof(StringTable)); | ||
stringTable->name = memory->Dup(assetName.c_str()); | ||
return stringTable; | ||
} | ||
|
||
bool AssetLoaderStringTable::CanLoadFromRaw() const | ||
{ | ||
return true; | ||
} | ||
|
||
bool AssetLoaderStringTable::LoadFromRaw( | ||
const std::string& assetName, ISearchPath* searchPath, MemoryManager* memory, IAssetLoadingManager* manager, Zone* zone) const | ||
{ | ||
const auto file = searchPath->Open(assetName); | ||
if (!file.IsOpen()) | ||
return false; | ||
|
||
string_table::StringTableLoaderV1<StringTable> loader; | ||
auto* stringTable = loader.LoadFromStream(assetName, *memory, *file.m_stream); | ||
|
||
manager->AddAsset(ASSET_TYPE_STRINGTABLE, assetName, stringTable); | ||
|
||
return true; | ||
} |
17 changes: 17 additions & 0 deletions
17
src/ObjLoading/Game/IW3/AssetLoaders/AssetLoaderStringTable.h
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
#pragma once | ||
|
||
#include "AssetLoading/BasicAssetLoader.h" | ||
#include "Game/IW3/IW3.h" | ||
#include "SearchPath/ISearchPath.h" | ||
|
||
namespace IW3 | ||
{ | ||
class AssetLoaderStringTable final : public BasicAssetLoader<ASSET_TYPE_STRINGTABLE, StringTable> | ||
{ | ||
public: | ||
_NODISCARD void* CreateEmptyAsset(const std::string& assetName, MemoryManager* memory) override; | ||
_NODISCARD bool CanLoadFromRaw() const override; | ||
bool | ||
LoadFromRaw(const std::string& assetName, ISearchPath* searchPath, MemoryManager* memory, IAssetLoadingManager* manager, Zone* zone) const override; | ||
}; | ||
} // namespace IW3 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.