[IMaterial] Correct loading order

This commit is contained in:
momo5502 2016-12-27 19:17:52 +01:00
parent e909329910
commit cb4f4a8321
2 changed files with 17 additions and 8 deletions

View File

@ -6,15 +6,17 @@ namespace Assets
{
void IMaterial::load(Game::XAssetHeader* header, std::string name, Components::ZoneBuilder::Zone* builder)
{
Components::FileSystem::File materialFile(fmt::sprintf("materials/%s.iw4xMaterial", name.data()));
if(!materialFile.exists())
{
this->loadJson(header, name, builder);
return;
if (!header->data) this->loadJson(header, name, builder); // Check if we want to override materials
if (!header->data) this->loadNative(header, name, builder); // Check if there is a native one
if (!header->data) this->loadBinary(header, name, builder); // Check if we need to import a new one into the game
}
Game::Material* material = builder->getAllocator()->allocate<Game::Material>();
void IMaterial::loadBinary(Game::XAssetHeader* header, std::string name, Components::ZoneBuilder::Zone* builder)
{
Components::FileSystem::File materialFile(fmt::sprintf("materials/%s.iw4xMaterial", name.data()));
if (!materialFile.exists()) return;
Game::Material* material = builder->getAllocator()->allocate<Game::Material>();
if (!material)
{
Components::Logger::Print("Error allocating memory for material structure!\n");
@ -130,6 +132,11 @@ namespace Assets
}, material, false);
}
void IMaterial::loadNative(Game::XAssetHeader* header, std::string name, Components::ZoneBuilder::Zone* builder)
{
header->material = Components::AssetHandler::FindOriginalAsset(this->getType(), name.data()).material;
}
void IMaterial::loadJson(Game::XAssetHeader* header, std::string name, Components::ZoneBuilder::Zone* builder)
{
Components::FileSystem::File materialInfo(fmt::sprintf("materials/%s.json", name.data()));

View File

@ -9,5 +9,7 @@ namespace Assets
virtual void mark(Game::XAssetHeader header, Components::ZoneBuilder::Zone* builder) override;
virtual void load(Game::XAssetHeader* header, std::string name, Components::ZoneBuilder::Zone* builder) override;
void loadJson(Game::XAssetHeader* header, std::string name, Components::ZoneBuilder::Zone* builder);
void loadNative(Game::XAssetHeader* header, std::string name, Components::ZoneBuilder::Zone* builder);
void loadBinary(Game::XAssetHeader* header, std::string name, Components::ZoneBuilder::Zone* builder);
};
}