|
|
@ -33,7 +33,7 @@ namespace Assets
|
|
|
|
material->sortKey = reader.readByte();
|
|
|
|
material->sortKey = reader.readByte();
|
|
|
|
material->textureAtlasRowCount = reader.readByte();
|
|
|
|
material->textureAtlasRowCount = reader.readByte();
|
|
|
|
material->textureAtlasColumnCount = reader.readByte();
|
|
|
|
material->textureAtlasColumnCount = reader.readByte();
|
|
|
|
material->drawSurf.packed = reader.read<__int16>();
|
|
|
|
material->drawSurf.packed = reader.read<__int64>();
|
|
|
|
material->surfaceTypeBits = reader.read<int>();
|
|
|
|
material->surfaceTypeBits = reader.read<int>();
|
|
|
|
material->hashIndex = reader.read<unsigned __int16>();
|
|
|
|
material->hashIndex = reader.read<unsigned __int16>();
|
|
|
|
char* stateBitsEntry = reader.readArray<char>(48);
|
|
|
|
char* stateBitsEntry = reader.readArray<char>(48);
|
|
|
@ -43,27 +43,29 @@ namespace Assets
|
|
|
|
material->stateBitsCount = reader.readByte();
|
|
|
|
material->stateBitsCount = reader.readByte();
|
|
|
|
material->stateFlags = reader.readByte();
|
|
|
|
material->stateFlags = reader.readByte();
|
|
|
|
material->cameraRegion = reader.readByte();
|
|
|
|
material->cameraRegion = reader.readByte();
|
|
|
|
material->techniqueSet = Components::AssetHandler::FindOriginalAsset(Game::XAssetType::ASSET_TYPE_TECHSET, reader.readCString()).techniqueSet;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
material->textureTable = builder->getAllocator()->allocateArray<Game::MaterialTextureDef>(material->textureCount);
|
|
|
|
std::string techset = reader.readString();
|
|
|
|
material->constantTable = builder->getAllocator()->allocateArray<Game::MaterialConstantDef>(material->constantCount);
|
|
|
|
material->techniqueSet = Components::AssetHandler::FindOriginalAsset(Game::XAssetType::ASSET_TYPE_TECHSET, techset.data()).techniqueSet;
|
|
|
|
material->stateBitTable = builder->getAllocator()->allocateArray<Game::GfxStateBits>(material->stateBitsCount);
|
|
|
|
|
|
|
|
|
|
|
|
material->textureTable = builder->getAllocator()->allocateArray<Game::MaterialTextureDef>(material->textureCount & 0xFF);
|
|
|
|
|
|
|
|
material->constantTable = builder->getAllocator()->allocateArray<Game::MaterialConstantDef>(material->constantCount & 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");
|
|
|
|
builder->getAllocator()->free(material); // cleanup
|
|
|
|
|
|
|
|
return;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
for (int i = 0; i < material->textureCount; ++i)
|
|
|
|
for (char i = 0; i < material->textureCount; ++i)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
const char* mapName = reader.readCString();
|
|
|
|
std::string mapName = reader.readString();
|
|
|
|
material->textureTable[i].nameStart = mapName[0];
|
|
|
|
material->textureTable[i].nameStart = mapName.front();
|
|
|
|
material->textureTable[i].nameEnd = mapName[strlen(mapName) - 1];
|
|
|
|
material->textureTable[i].nameEnd = mapName.back();
|
|
|
|
material->textureTable[i].nameHash = Game::R_HashString(mapName);
|
|
|
|
material->textureTable[i].nameHash = Game::R_HashString(mapName.data());
|
|
|
|
material->textureTable[i].sampleState = reader.readByte();
|
|
|
|
material->textureTable[i].sampleState = reader.readByte();
|
|
|
|
material->textureTable[i].semantic = reader.readByte();
|
|
|
|
material->textureTable[i].semantic = reader.readByte();
|
|
|
|
|
|
|
|
|
|
|
|
if (material->textureTable[i].semantic == SEMANTIC_WATER_MAP)
|
|
|
|
if (material->textureTable[i].semantic == SEMANTIC_WATER_MAP)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
material->textureTable[i].info.water->floatTime = reader.read<float>();
|
|
|
|
material->textureTable[i].info.water->floatTime = reader.read<float>();
|
|
|
@ -90,36 +92,23 @@ namespace Assets
|
|
|
|
{
|
|
|
|
{
|
|
|
|
material->textureTable[i].info.image = Components::AssetHandler::FindOriginalAsset(Game::XAssetType::ASSET_TYPE_IMAGE, reader.readCString()).image;
|
|
|
|
material->textureTable[i].info.image = Components::AssetHandler::FindOriginalAsset(Game::XAssetType::ASSET_TYPE_IMAGE, reader.readCString()).image;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
builder->getAllocator()->free(mapName);
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
for (int i = 0; i < material->constantCount; ++i)
|
|
|
|
for (char i = 0; i < material->constantCount; ++i)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
const char* constName = reader.readCString();
|
|
|
|
std::string constName = reader.readString();
|
|
|
|
const char* ptr = constName;
|
|
|
|
strncpy_s(material->constantTable[i].name, 12, constName.data(), 12);
|
|
|
|
int j = 0;
|
|
|
|
|
|
|
|
// its late and msbuild wont stop bitching about strncpy being unsafe and i really dont care enough to fix it any other way
|
|
|
|
material->constantTable[i].nameHash = Game::R_HashString(constName.data());
|
|
|
|
// this will do for now
|
|
|
|
|
|
|
|
// strncpy(materialConstantTable[i].name, constName, 12);
|
|
|
|
|
|
|
|
while(j < 12 && *ptr)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
material->constantTable[i].name[j] = *ptr;
|
|
|
|
|
|
|
|
++ptr;
|
|
|
|
|
|
|
|
++j;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
material->constantTable[i].nameHash = Game::R_HashString(constName);
|
|
|
|
|
|
|
|
float* literal = reader.readArray<float>(4);
|
|
|
|
float* literal = reader.readArray<float>(4);
|
|
|
|
material->constantTable[i].literal[0] = literal[0];
|
|
|
|
material->constantTable[i].literal[0] = literal[0];
|
|
|
|
material->constantTable[i].literal[1] = literal[1];
|
|
|
|
material->constantTable[i].literal[1] = literal[1];
|
|
|
|
material->constantTable[i].literal[2] = literal[2];
|
|
|
|
material->constantTable[i].literal[2] = literal[2];
|
|
|
|
material->constantTable[i].literal[3] = literal[3];
|
|
|
|
material->constantTable[i].literal[3] = literal[3];
|
|
|
|
|
|
|
|
|
|
|
|
builder->getAllocator()->free(constName);
|
|
|
|
|
|
|
|
builder->getAllocator()->free(literal);
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
material->stateBitTable = reader.readArray<Game::GfxStateBits>(material->stateBitsCount);
|
|
|
|
material->stateBitTable = reader.readArray<Game::GfxStateBits>(material->stateBitsCount);
|
|
|
|
|
|
|
|
header->material = 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)
|
|
|
|