Skip to content

Commit

Permalink
Only store dev names if dev flag is set
Browse files Browse the repository at this point in the history
  • Loading branch information
Mauler125 committed Dec 16, 2024
1 parent 6ddca29 commit 7d7bb4c
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 16 deletions.
2 changes: 1 addition & 1 deletion src/assets/material.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -517,7 +517,7 @@ void Assets::AddMaterialAsset_v12(CPakFile* const pak, const PakGuid_t assetGuid
// !!!R2 SPECIFIC!!!
{
const size_t nameBufLen = matlAsset.name.length() + 1;
CPakDataChunk nameChunk = pak->CreateDataChunk(nameBufLen, SF_DEV | SF_CPU, 1);
CPakDataChunk nameChunk = pak->CreateDataChunk(nameBufLen, SF_CPU | SF_DEV, 1);

sprintf_s(nameChunk.Data(), nameBufLen, "%s", matlAsset.name.c_str());

Expand Down
17 changes: 10 additions & 7 deletions src/assets/shader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -142,15 +142,18 @@ static void Shader_InternalAddShader(CPakFile* const pak, const char* const asse
ShaderAssetHeader_t* const hdr = reinterpret_cast<ShaderAssetHeader_t*>(hdrChunk.Data());
Shader_SetupHeader(hdr, shader);

const size_t nameLen = shader->name.length();

if (nameLen > 0)
if (if (pak->IsFlagSet(PF_KEEP_DEV)))
{
CPakDataChunk nameChunk = pak->CreateDataChunk(nameLen + 1, SF_CPU | SF_DEV, 1);
strcpy_s(nameChunk.Data(), nameChunk.GetSize(), shader->name.c_str());
const size_t nameLen = shader->name.length();

if (nameLen > 0)
{
CPakDataChunk nameChunk = pak->CreateDataChunk(nameLen + 1, SF_CPU | SF_DEV, 1);
strcpy_s(nameChunk.Data(), nameChunk.GetSize(), shader->name.c_str());

hdr->name = nameChunk.GetPointer();
pak->AddPointer(hdrChunk.GetPointer(offsetof(ShaderAssetHeader_t, name)));
hdr->name = nameChunk.GetPointer();
pak->AddPointer(hdrChunk.GetPointer(offsetof(ShaderAssetHeader_t, name)));
}
}

CPakDataChunk dataChunk = {};
Expand Down
21 changes: 14 additions & 7 deletions src/assets/shaderset.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -65,17 +65,24 @@ void ShaderSet_InternalCreateSet(CPakFile* const pak, const char* const assetPat
std::vector<PakGuidRefHdr_t> guids{};

CPakDataChunk hdrChunk = pak->CreateDataChunk(sizeof(ShaderSetAssetHeader_t), SF_HEAD, 8);
ShaderSetAssetHeader_t* const hdr = reinterpret_cast<ShaderSetAssetHeader_t*>(hdrChunk.Data());

const std::string assetPathWithoutExtension = Utils::ChangeExtension(assetPath, "");

CPakDataChunk nameChunk = pak->CreateDataChunk(assetPathWithoutExtension.length() + 1, SF_CPU | SF_DEV, 1);
strcpy_s(nameChunk.Data(), nameChunk.GetSize(), assetPathWithoutExtension.c_str());
CPakDataChunk nameChunk;

ShaderSetAssetHeader_t* const hdr = reinterpret_cast<ShaderSetAssetHeader_t*>(hdrChunk.Data());
if (pak->IsFlagSet(PF_KEEP_DEV))
{
const std::string assetPathWithoutExtension = Utils::ChangeExtension(assetPath, "");
const size_t devNameLen = assetPathWithoutExtension.length();

hdr->name = nameChunk.GetPointer();
if (devNameLen > 0)
{
nameChunk = pak->CreateDataChunk(assetPathWithoutExtension.length() + 1, SF_CPU | SF_DEV, 1);
strcpy_s(nameChunk.Data(), nameChunk.GetSize(), assetPathWithoutExtension.c_str());

pak->AddPointer(hdrChunk.GetPointer(offsetof(ShaderSetAssetHeader_t, name)));
hdr->name = nameChunk.GetPointer();
pak->AddPointer(hdrChunk.GetPointer(offsetof(ShaderSetAssetHeader_t, name)));
}
}

// === Shader Inputs ===
hdr->vertexShader = shaderSet->vertexShaderGuid;
Expand Down
2 changes: 1 addition & 1 deletion src/assets/texture.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,7 @@ static void Texture_InternalAddTexture(CPakFile* const pak, const PakGuid_t asse

if (nameBufLen > 0)
{
CPakDataChunk nameChunk = pak->CreateDataChunk(nameBufLen + 1, SF_DEV | SF_CPU, 1);
CPakDataChunk nameChunk = pak->CreateDataChunk(nameBufLen + 1, SF_CPU | SF_DEV, 1);
memcpy(nameChunk.Data(), assetPath, nameBufLen + 1);

hdr->pName = nameChunk.GetPointer();
Expand Down

0 comments on commit 7d7bb4c

Please sign in to comment.