[IMaterial] Correct loading order
This commit is contained in:
parent
e909329910
commit
cb4f4a8321
@ -5,17 +5,19 @@
|
|||||||
namespace Assets
|
namespace Assets
|
||||||
{
|
{
|
||||||
void IMaterial::load(Game::XAssetHeader* header, std::string name, Components::ZoneBuilder::Zone* builder)
|
void IMaterial::load(Game::XAssetHeader* header, std::string name, Components::ZoneBuilder::Zone* builder)
|
||||||
|
{
|
||||||
|
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
|
||||||
|
}
|
||||||
|
|
||||||
|
void IMaterial::loadBinary(Game::XAssetHeader* header, std::string name, Components::ZoneBuilder::Zone* builder)
|
||||||
{
|
{
|
||||||
Components::FileSystem::File materialFile(fmt::sprintf("materials/%s.iw4xMaterial", name.data()));
|
Components::FileSystem::File materialFile(fmt::sprintf("materials/%s.iw4xMaterial", name.data()));
|
||||||
if(!materialFile.exists())
|
if (!materialFile.exists()) return;
|
||||||
{
|
|
||||||
this->loadJson(header, name, builder);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
Game::Material* material = builder->getAllocator()->allocate<Game::Material>();
|
Game::Material* material = builder->getAllocator()->allocate<Game::Material>();
|
||||||
|
if (!material)
|
||||||
if(!material)
|
|
||||||
{
|
{
|
||||||
Components::Logger::Print("Error allocating memory for material structure!\n");
|
Components::Logger::Print("Error allocating memory for material structure!\n");
|
||||||
return;
|
return;
|
||||||
@ -56,7 +58,7 @@ namespace Assets
|
|||||||
material->constantTable = builder->getAllocator()->allocateArray<Game::MaterialConstantDef>(material->constantCount & 0xFF);
|
material->constantTable = builder->getAllocator()->allocateArray<Game::MaterialConstantDef>(material->constantCount & 0xFF);
|
||||||
material->stateBitTable = builder->getAllocator()->allocateArray<Game::GfxStateBits>(material->stateBitsCount & 0xFF);
|
material->stateBitTable = builder->getAllocator()->allocateArray<Game::GfxStateBits>(material->stateBitsCount & 0xFF);
|
||||||
|
|
||||||
if(!material->textureTable || !material->constantTable || !material->stateBitTable)
|
if (!material->textureTable || !material->constantTable || !material->stateBitTable)
|
||||||
{
|
{
|
||||||
Components::Logger::Print("Error allocating memory for material structure!\n");
|
Components::Logger::Print("Error allocating memory for material structure!\n");
|
||||||
return;
|
return;
|
||||||
@ -130,6 +132,11 @@ namespace Assets
|
|||||||
}, material, false);
|
}, 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)
|
void IMaterial::loadJson(Game::XAssetHeader* header, std::string name, Components::ZoneBuilder::Zone* builder)
|
||||||
{
|
{
|
||||||
Components::FileSystem::File materialInfo(fmt::sprintf("materials/%s.json", name.data()));
|
Components::FileSystem::File materialInfo(fmt::sprintf("materials/%s.json", name.data()));
|
||||||
|
@ -9,5 +9,7 @@ namespace Assets
|
|||||||
virtual void mark(Game::XAssetHeader header, Components::ZoneBuilder::Zone* builder) override;
|
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;
|
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 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);
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user