Stringtable tests

This commit is contained in:
momo5502 2016-08-16 13:58:45 +02:00
parent 405ae959f2
commit f6410370ac
9 changed files with 76 additions and 6 deletions

2
deps/mongoose vendored

@ -1 +1 @@
Subproject commit 2efc8598297de21d54ab52e383ed8adbb3325d3d
Subproject commit 8cdd19bcaed7f503de7902804d0d96ce51e95a34

2
deps/protobuf vendored

@ -1 +1 @@
Subproject commit d9ccf4d0b1fdfb55bdc41f49d42f37a6c4b5302a
Subproject commit 4763e64eb1e72e628ab75a9872f4146fdd2cf765

View File

@ -265,6 +265,7 @@ namespace Components
AssetHandler::RegisterInterface(new Assets::IPhysPreset());
AssetHandler::RegisterInterface(new Assets::IXAnimParts());
AssetHandler::RegisterInterface(new Assets::IPhysCollmap());
AssetHandler::RegisterInterface(new Assets::IStringTable());
//AssetHandler::RegisterInterface(new Assets::IXModelSurfs());
AssetHandler::RegisterInterface(new Assets::ILocalizedEntry());
AssetHandler::RegisterInterface(new Assets::IMaterialPixelShader());

View File

@ -68,6 +68,7 @@ namespace Components
#include "AssetInterfaces\IPhysPreset.hpp"
#include "AssetInterfaces\IXAnimParts.hpp"
#include "AssetInterfaces\IPhysCollmap.hpp"
#include "AssetInterfaces\IStringTable.hpp"
#include "AssetInterfaces\IXModelSurfs.hpp"
#include "AssetInterfaces\ILocalizedEntry.hpp"
#include "AssetInterfaces\IMaterialPixelShader.hpp"

View File

@ -94,7 +94,6 @@ namespace Assets
Game::Stage* stage = &asset->stages[i];
buffer->SaveString(stage->stageName);
Utils::Stream::ClearPointer(&destStage->stageName);
}

View File

@ -0,0 +1,51 @@
#include <STDInclude.hpp>
namespace Assets
{
void IStringTable::Save_StringTableCellArray(Components::ZoneBuilder::Zone* builder, Game::StringTableCell* values, int count)
{
Assert_Size(Game::StringTableCell, 8);
Utils::Stream* buffer = builder->GetBuffer();
Game::StringTableCell* destValues = buffer->Dest<Game::StringTableCell>();
buffer->SaveArray(destValues, count);
for (int i = 0; i < count; ++i)
{
Game::StringTableCell* destValue = &destValues[i];
Game::StringTableCell* value = &values[i];
buffer->SaveString(value->string);
Utils::Stream::ClearPointer(&destValue->string);
}
}
void IStringTable::Save(Game::XAssetHeader header, Components::ZoneBuilder::Zone* builder)
{
Assert_Size(Game::StringTable, 16);
Utils::Stream* buffer = builder->GetBuffer();
Game::StringTable* asset = header.stringTable;
Game::StringTable* dest = buffer->Dest<Game::StringTable>();
buffer->Save(asset, sizeof(Game::StringTable));
buffer->PushBlock(Game::XFILE_BLOCK_VIRTUAL);
if (asset->name)
{
buffer->SaveString(builder->GetAssetName(this->GetType(), asset->name));
Utils::Stream::ClearPointer(&dest->name);
}
if (asset->values)
{
buffer->Align(Utils::Stream::ALIGN_4);
IStringTable::Save_StringTableCellArray(builder, asset->values, asset->columnCount * asset->rowCount);
Utils::Stream::ClearPointer(&dest->values);
}
buffer->PopBlock();
}
}

View File

@ -0,0 +1,13 @@
namespace Assets
{
class IStringTable : public Components::AssetHandler::IAsset
{
public:
virtual Game::XAssetType GetType() override { return Game::XAssetType::ASSET_TYPE_STRINGTABLE; };
virtual void Save(Game::XAssetHeader header, Components::ZoneBuilder::Zone* builder) override;
private:
void Save_StringTableCellArray(Components::ZoneBuilder::Zone* builder, Game::StringTableCell* values, int count);
};
}

View File

@ -506,7 +506,10 @@ namespace Components
// Don't resize the console
Utils::Hook(0x64DC6B, 0x64DCC2, HOOK_JUMP).Install()->Quick();
Dedicated::OnFrame(Console::RefreshStatus);
if (Dedicated::IsEnabled() && !ZoneBuilder::IsEnabled())
{
Dedicated::OnFrame(Console::RefreshStatus);
}
// Code below is not necessary when performing unit tests!
if (Loader::PerformingUnitTests()) return;

View File

@ -47,9 +47,11 @@ namespace Components
{
for (int j = 0; j < table->columnCount; ++j)
{
std::string value = parsedTable.GetElementAt(i, j);
Game::StringTableCell* cell = &table->values[i * table->columnCount + j];
cell->hash = StringTable::Hash(parsedTable.GetElementAt(i, j).data());
cell->string = StringTable::MemAllocator.DuplicateString(parsedTable.GetElementAt(i, j));
cell->hash = StringTable::Hash(value.data());
cell->string = StringTable::MemAllocator.DuplicateString(value);
//if (!cell->string) cell->string = ""; // We have to assume it allocated successfully
}
}