chore: update all usages of memory manager allocation

This commit is contained in:
Jan
2024-04-22 21:21:31 +02:00
parent 0845cccd12
commit a3acba8bc0
51 changed files with 149 additions and 211 deletions

View File

@ -1287,7 +1287,7 @@ namespace IW4
{
if (!m_textures.empty())
{
m_material->textureTable = static_cast<MaterialTextureDef*>(m_memory->Alloc(sizeof(MaterialTextureDef) * m_textures.size()));
m_material->textureTable = m_memory->Alloc<MaterialTextureDef>(m_textures.size());
m_material->textureCount = static_cast<unsigned char>(m_textures.size());
memcpy(m_material->textureTable, m_textures.data(), sizeof(MaterialTextureDef) * m_textures.size());
}
@ -1299,7 +1299,7 @@ namespace IW4
if (!m_constants.empty())
{
m_material->constantTable = static_cast<MaterialConstantDef*>(m_memory->Alloc(sizeof(MaterialConstantDef) * m_constants.size()));
m_material->constantTable = m_memory->Alloc<MaterialConstantDef>(m_constants.size());
m_material->constantCount = static_cast<unsigned char>(m_constants.size());
memcpy(m_material->constantTable, m_constants.data(), sizeof(MaterialConstantDef) * m_constants.size());
}
@ -1311,7 +1311,7 @@ namespace IW4
if (!m_state_bits.empty())
{
m_material->stateBitsTable = static_cast<GfxStateBits*>(m_memory->Alloc(sizeof(GfxStateBits) * m_state_bits.size()));
m_material->stateBitsTable = m_memory->Alloc<GfxStateBits>(m_state_bits.size());
m_material->stateBitsCount = static_cast<unsigned char>(m_state_bits.size());
memcpy(m_material->stateBitsTable, m_state_bits.data(), sizeof(GfxStateBits) * m_state_bits.size());
}

View File

@ -83,7 +83,7 @@ namespace IW4
if (menuListAsset->menuCount > 0)
{
menuListAsset->menus = static_cast<menuDef_t**>(memory->Alloc(sizeof(uintptr_t) * menuListAsset->menuCount));
menuListAsset->menus = memory->Alloc<menuDef_t*>(menuListAsset->menuCount);
for (auto i = 0; i < menuListAsset->menuCount; i++)
menuListAsset->menus[i] = menus[i];
}

View File

@ -51,12 +51,12 @@ bool AssetLoaderPixelShader::LoadFromRaw(
pixelShader->prog.loadDef.loadForRenderer = 0;
pixelShader->prog.ps = nullptr;
auto* fileBuffer = static_cast<char*>(memory->Alloc(pixelShader->prog.loadDef.programSize * sizeof(uint32_t)));
file.m_stream->read(fileBuffer, static_cast<std::streamsize>(pixelShader->prog.loadDef.programSize) * sizeof(uint32_t));
auto* fileBuffer = memory->Alloc<uint32_t>(pixelShader->prog.loadDef.programSize);
file.m_stream->read(reinterpret_cast<char*>(fileBuffer), static_cast<std::streamsize>(pixelShader->prog.loadDef.programSize) * sizeof(uint32_t));
if (file.m_stream->gcount() != file.m_length)
return false;
pixelShader->prog.loadDef.program = reinterpret_cast<uint32_t*>(fileBuffer);
pixelShader->prog.loadDef.program = fileBuffer;
manager->AddAsset(ASSET_TYPE_PIXELSHADER, assetName, pixelShader);
return true;

View File

@ -36,7 +36,7 @@ bool AssetLoaderRawFile::LoadFromRaw(
return false;
const auto compressionBufferSize = static_cast<size_t>(file.m_length + COMPRESSED_BUFFER_SIZE_PADDING);
auto* compressedBuffer = static_cast<char*>(memory->Alloc(compressionBufferSize));
auto* compressedBuffer = memory->Alloc<char>(compressionBufferSize);
z_stream_s zs{};

View File

@ -65,7 +65,7 @@ void AssetLoaderStructuredDataDefSet::ConvertEnum(StructuredDataEnum* outputEnum
inputEnum->SortEntriesByName();
if (!inputEnum->m_entries.empty())
{
outputEnum->entries = static_cast<StructuredDataEnumEntry*>(memory->Alloc(sizeof(StructuredDataEnumEntry) * inputEnum->m_entries.size()));
outputEnum->entries = memory->Alloc<StructuredDataEnumEntry>(inputEnum->m_entries.size());
for (auto entryIndex = 0u; entryIndex < inputEnum->m_entries.size(); entryIndex++)
{
auto& outputEntry = outputEnum->entries[entryIndex];
@ -88,8 +88,7 @@ void AssetLoaderStructuredDataDefSet::ConvertStruct(StructuredDataStruct* output
inputStruct->SortPropertiesByName();
if (!inputStruct->m_properties.empty())
{
outputStruct->properties =
static_cast<StructuredDataStructProperty*>(memory->Alloc(sizeof(StructuredDataStructProperty) * inputStruct->m_properties.size()));
outputStruct->properties = memory->Alloc<StructuredDataStructProperty>(inputStruct->m_properties.size());
for (auto propertyIndex = 0u; propertyIndex < inputStruct->m_properties.size(); propertyIndex++)
{
auto& outputProperty = outputStruct->properties[propertyIndex];
@ -137,7 +136,7 @@ void AssetLoaderStructuredDataDefSet::ConvertDef(StructuredDataDef* outputDef, c
outputDef->enumCount = static_cast<int>(inputDef->m_enums.size());
if (!inputDef->m_enums.empty())
{
outputDef->enums = static_cast<StructuredDataEnum*>(memory->Alloc(sizeof(StructuredDataEnum) * inputDef->m_enums.size()));
outputDef->enums = memory->Alloc<StructuredDataEnum>(inputDef->m_enums.size());
for (auto enumIndex = 0u; enumIndex < inputDef->m_enums.size(); enumIndex++)
ConvertEnum(&outputDef->enums[enumIndex], inputDef->m_enums[enumIndex].get(), memory);
}
@ -147,7 +146,7 @@ void AssetLoaderStructuredDataDefSet::ConvertDef(StructuredDataDef* outputDef, c
outputDef->structCount = static_cast<int>(inputDef->m_structs.size());
if (!inputDef->m_structs.empty())
{
outputDef->structs = static_cast<StructuredDataStruct*>(memory->Alloc(sizeof(StructuredDataStruct) * inputDef->m_structs.size()));
outputDef->structs = memory->Alloc<StructuredDataStruct>(inputDef->m_structs.size());
for (auto structIndex = 0u; structIndex < inputDef->m_structs.size(); structIndex++)
ConvertStruct(&outputDef->structs[structIndex], inputDef->m_structs[structIndex].get(), memory);
}
@ -157,8 +156,7 @@ void AssetLoaderStructuredDataDefSet::ConvertDef(StructuredDataDef* outputDef, c
outputDef->indexedArrayCount = static_cast<int>(inputDef->m_indexed_arrays.size());
if (!inputDef->m_indexed_arrays.empty())
{
outputDef->indexedArrays =
static_cast<StructuredDataIndexedArray*>(memory->Alloc(sizeof(StructuredDataIndexedArray) * inputDef->m_indexed_arrays.size()));
outputDef->indexedArrays = memory->Alloc<StructuredDataIndexedArray>(inputDef->m_indexed_arrays.size());
for (auto indexedArrayIndex = 0u; indexedArrayIndex < inputDef->m_indexed_arrays.size(); indexedArrayIndex++)
ConvertIndexedArray(&outputDef->indexedArrays[indexedArrayIndex], &inputDef->m_indexed_arrays[indexedArrayIndex], memory);
}
@ -168,7 +166,7 @@ void AssetLoaderStructuredDataDefSet::ConvertDef(StructuredDataDef* outputDef, c
outputDef->enumedArrayCount = static_cast<int>(inputDef->m_enumed_arrays.size());
if (!inputDef->m_enumed_arrays.empty())
{
outputDef->enumedArrays = static_cast<StructuredDataEnumedArray*>(memory->Alloc(sizeof(StructuredDataEnumedArray) * inputDef->m_enumed_arrays.size()));
outputDef->enumedArrays = memory->Alloc<StructuredDataEnumedArray>(inputDef->m_enumed_arrays.size());
for (auto enumedArrayIndex = 0u; enumedArrayIndex < inputDef->m_enumed_arrays.size(); enumedArrayIndex++)
ConvertEnumedArray(&outputDef->enumedArrays[enumedArrayIndex], &inputDef->m_enumed_arrays[enumedArrayIndex], memory);
}
@ -186,7 +184,7 @@ StructuredDataDefSet* AssetLoaderStructuredDataDefSet::ConvertSet(const std::str
auto* set = memory->Create<StructuredDataDefSet>();
set->name = memory->Dup(assetName.c_str());
set->defCount = defs.size();
set->defs = static_cast<StructuredDataDef*>(memory->Alloc(sizeof(StructuredDataDef) * defs.size()));
set->defs = memory->Alloc<StructuredDataDef>(defs.size());
for (auto defIndex = 0u; defIndex < defs.size(); defIndex++)
ConvertDef(&set->defs[defIndex], defs[defIndex].get(), memory);

View File

@ -72,7 +72,7 @@ namespace IW4
if (existingEntry != m_allocated_literals.end())
return existingEntry->second;
auto* newLiteral = static_cast<float(*)[4]>(memory->Alloc(sizeof(float) * 4u));
auto* newLiteral = memory->Alloc<float[4]>();
(*newLiteral)[0] = source.m_value[0];
(*newLiteral)[1] = source.m_value[1];
(*newLiteral)[2] = source.m_value[2];
@ -1159,8 +1159,7 @@ namespace IW4
out.pixelShader = in.m_pixel_shader->Asset();
out.vertexDecl = in.m_vertex_decl_asset->Asset();
const auto argDataSize = sizeof(MaterialShaderArgument) * in.m_arguments.size();
out.args = static_cast<MaterialShaderArgument*>(m_memory->Alloc(argDataSize));
out.args = m_memory->Alloc<MaterialShaderArgument>(in.m_arguments.size());
size_t perObjArgCount = 0u;
size_t perPrimArgCount = 0u;
@ -1221,8 +1220,7 @@ namespace IW4
{
assert(!passes.empty());
const auto techniqueSize = sizeof(MaterialTechnique) + (passes.size() - 1u) * sizeof(MaterialPass);
auto* technique = static_cast<MaterialTechnique*>(m_memory->Alloc(techniqueSize));
memset(technique, 0, techniqueSize);
auto* technique = static_cast<MaterialTechnique*>(m_memory->AllocRaw(techniqueSize));
technique->name = m_memory->Dup(techniqueName.c_str());
technique->passCount = static_cast<uint16_t>(passes.size());

View File

@ -51,12 +51,12 @@ bool AssetLoaderVertexShader::LoadFromRaw(
vertexShader->prog.loadDef.loadForRenderer = 0;
vertexShader->prog.vs = nullptr;
auto* fileBuffer = static_cast<char*>(memory->Alloc(vertexShader->prog.loadDef.programSize * sizeof(uint32_t)));
file.m_stream->read(fileBuffer, static_cast<std::streamsize>(vertexShader->prog.loadDef.programSize) * sizeof(uint32_t));
auto* fileBuffer = memory->Alloc<uint32_t>(vertexShader->prog.loadDef.programSize);
file.m_stream->read(reinterpret_cast<char*>(fileBuffer), static_cast<std::streamsize>(vertexShader->prog.loadDef.programSize) * sizeof(uint32_t));
if (file.m_stream->gcount() != file.m_length)
return false;
vertexShader->prog.loadDef.program = reinterpret_cast<uint32_t*>(fileBuffer);
vertexShader->prog.loadDef.program = fileBuffer;
manager->AddAsset(ASSET_TYPE_VERTEXSHADER, assetName, vertexShader);
return true;

View File

@ -70,12 +70,12 @@ namespace
}
assert(std::extent_v<decltype(bounceSoundSuffixes)> == SURF_TYPE_NUM);
*bounceSound = static_cast<SndAliasCustom*>(m_memory->Alloc(sizeof(SndAliasCustom) * SURF_TYPE_NUM));
*bounceSound = m_memory->Alloc<SndAliasCustom>(SURF_TYPE_NUM);
for (auto i = 0u; i < SURF_TYPE_NUM; i++)
{
const auto currentBounceSound = value + bounceSoundSuffixes[i];
(*bounceSound)[i].name = static_cast<snd_alias_list_name*>(m_memory->Alloc(sizeof(snd_alias_list_name)));
(*bounceSound)[i].name = m_memory->Alloc<snd_alias_list_name>();
(*bounceSound)[i].name->soundName = m_memory->Dup(currentBounceSound.c_str());
}
@ -265,13 +265,6 @@ namespace
}
}
snd_alias_list_name* CreateSoundAliasListName(const char* value, MemoryManager* memory)
{
auto* name = static_cast<snd_alias_list_name*>(memory->Alloc(sizeof(snd_alias_list_name)));
name->soundName = memory->Dup(value);
return name;
}
void CheckProjectileValues(const WeaponCompleteDef& weaponCompleteDef, const WeaponDef& weaponDef)
{
if (weaponDef.iProjectileSpeed <= 0)