[ZoneBuilder] Nested assets work now (but it doesn't fix the clip map bug)

This commit is contained in:
TheApadayo 2016-12-23 08:43:37 -05:00
parent 2903444e89
commit e87ce9938d
3 changed files with 23 additions and 26 deletions

View File

@ -13,7 +13,6 @@ namespace Assets
buffer->save(asset);
buffer->pushBlock(Game::XFILE_BLOCK_VIRTUAL);
builder->pushAliasBase();
if (asset->name)
{
@ -51,20 +50,16 @@ namespace Assets
// xmodel is already stored
buffer->align(Utils::Stream::ALIGN_4);
Game::cStaticModel_t* destStaticModelList = buffer->dest<Game::cStaticModel_t>();
builder->pushAliasBase();
buffer->saveArray(asset->staticModelList, asset->numStaticModels);
for (int i = 0; i < asset->numStaticModels; ++i)
{
if (asset->staticModelList[i].xmodel)
{
destStaticModelList[i].xmodel = builder->saveSubAsset(Game::XAssetType::ASSET_TYPE_XMODEL, asset->staticModelList[i].xmodel,
offsetof(Game::cStaticModel_t, xmodel) + (sizeof(Game::cStaticModel_t) * i)).model;
destStaticModelList[i].xmodel = builder->saveSubAsset(Game::XAssetType::ASSET_TYPE_XMODEL, asset->staticModelList[i].xmodel).model;
}
}
builder->popAliasBase();
Utils::Stream::ClearPointer(&dest->staticModelList);
SaveLogExit();
}
@ -432,7 +427,7 @@ namespace Assets
if (asset->mapEnts)
{
dest->mapEnts = builder->saveSubAsset(Game::XAssetType::ASSET_TYPE_MAP_ENTS, asset->mapEnts, offsetof(Game::clipMap_t, mapEnts)).mapEnts;
dest->mapEnts = builder->saveSubAsset(Game::XAssetType::ASSET_TYPE_MAP_ENTS, asset->mapEnts).mapEnts;
}
for (int i = 0; i < 2; ++i)
@ -443,7 +438,6 @@ namespace Assets
buffer->align(Utils::Stream::ALIGN_4);
Game::DynEntityDef* dynEntDest = buffer->dest<Game::DynEntityDef>();
builder->pushAliasBase();
buffer->saveArray(asset->dynEntDefList[i], asset->dynEntCount[i]);
Game::DynEntityDef* dynEnt = asset->dynEntDefList[i];
@ -451,25 +445,20 @@ namespace Assets
{
if (dynEnt[j].xModel)
{
dynEntDest[j].xModel = builder->saveSubAsset(Game::XAssetType::ASSET_TYPE_XMODEL, dynEnt[j].xModel,
GET_ALIAS_OFFSET_ARRAY(Game::DynEntityDef, xModel, j)).model;
dynEntDest[j].xModel = builder->saveSubAsset(Game::XAssetType::ASSET_TYPE_XMODEL, dynEnt[j].xModel).model;
}
if (dynEnt[j].destroyFx)
{
dynEntDest[j].destroyFx = builder->saveSubAsset(Game::XAssetType::ASSET_TYPE_FX, dynEnt[j].destroyFx,
GET_ALIAS_OFFSET_ARRAY(Game::DynEntityDef, xModel, j)).fx;
dynEntDest[j].destroyFx = builder->saveSubAsset(Game::XAssetType::ASSET_TYPE_FX, dynEnt[j].destroyFx).fx;
}
if (dynEnt[j].physPreset)
{
dynEntDest[j].physPreset = builder->saveSubAsset(Game::XAssetType::ASSET_TYPE_PHYSPRESET, dynEnt[j].physPreset,
GET_ALIAS_OFFSET_ARRAY(Game::DynEntityDef, xModel, j)).physPreset;
dynEntDest[j].physPreset = builder->saveSubAsset(Game::XAssetType::ASSET_TYPE_PHYSPRESET, dynEnt[j].physPreset).physPreset;
}
}
builder->popAliasBase();
Utils::Stream::ClearPointer(&dest->dynEntDefList[i]);
}
}
@ -515,7 +504,6 @@ namespace Assets
buffer->popBlock();
buffer->popBlock();
builder->popAliasBase();
SaveLogExit();
}

View File

@ -204,7 +204,7 @@ namespace Components
offset.offset = (this->indexStart + (index * sizeof(Game::XAsset)) + 4);
return offset.getPackedOffset();
}
/*
void ZoneBuilder::Zone::pushAliasBase()
{
this->aliasBaseStack.push_back(this->buffer.getBlockSize(Game::XFILE_BLOCK_VIRTUAL));
@ -222,8 +222,9 @@ namespace Components
{
return this->aliasBaseStack.back();
}
*/
Game::XAssetHeader ZoneBuilder::Zone::saveSubAsset(Game::XAssetType type, void* ptr, unsigned int aliasOffset)
Game::XAssetHeader ZoneBuilder::Zone::saveSubAsset(Game::XAssetType type, void* ptr)
{
Game::XAssetHeader header;
header.data = ptr;
@ -253,13 +254,18 @@ namespace Components
assetToSave.header = header;
assetToSave.type = type;
this->storeAlias(ptr, this->getAliasBase() + aliasOffset);
// we alias the next 4 (aligned) bytes of the stream b/c DB_InsertPointer gives us a nice pointer to use as the alias
// otherwise it would be a fuckfest trying to figure out where the alias is in the stream
this->buffer.align(Utils::Stream::ALIGN_4);
this->storeAlias(ptr, this->buffer.getBlockSize(Game::XFILE_BLOCK_VIRTUAL));
this->buffer.increaseBlockSize(Game::XFILE_BLOCK_VIRTUAL, 4);
this->buffer.pushBlock(Game::XFILE_BLOCK_TEMP);
AssetHandler::ZoneSave(assetToSave, this);
this->buffer.popBlock();
this->savedAssets.push_back(header);
Utils::Stream::ClearPointer(&header.data);
header.data = reinterpret_cast<void*>(-2); // DB_InsertPointer marker
}
}
else
@ -445,6 +451,11 @@ namespace Components
return NULL;
}
void ZoneBuilder::Zone::storePointer(const void* pointer)
{
this->pointerMap[pointer] = this->buffer.getPackedOffset();
}
void ZoneBuilder::Zone::storeAlias(const void* ptr, unsigned int alias)
{
this->aliasMap[ptr] = alias;
@ -456,6 +467,7 @@ namespace Components
{
return this->aliasMap[ptr];
}
Logger::Print("Warning: Missing Alias for pointer! Export will almost certainly fail!\n");
return 0;
}

View File

@ -23,6 +23,7 @@ namespace Components
bool hasPointer(const void* pointer);
void storePointer(const void* pointer);
void storePointer(const void* pointer, Utils::Stream::Offset offset);
template<typename T>
inline T* getPointer(const T* pointer) { return reinterpret_cast<T*>(this->safeGetPointer(pointer)); }
@ -30,7 +31,7 @@ namespace Components
int findAsset(Game::XAssetType type, std::string name);
Game::XAsset* getAsset(int index);
uint32_t getAssetTableOffset(int index);
Game::XAssetHeader saveSubAsset(Game::XAssetType type, void* ptr, unsigned int aliasOffset);
Game::XAssetHeader saveSubAsset(Game::XAssetType type, void* ptr);
bool loadAsset(Game::XAssetType type, std::string name);
void markAsset(Game::XAssetType type, void* ptr);
@ -47,10 +48,6 @@ namespace Components
void incrementExternalSize(unsigned int size);
void pushAliasBase();
void popAliasBase();
unsigned int getAliasBase();
private:
void loadFastFiles();