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)

View File

@ -182,7 +182,7 @@ bool InfoStringToStructConverter::ConvertBaseField(const cspField_t& field, cons
return true;
}
auto* name = static_cast<snd_alias_list_name*>(m_memory->Alloc(sizeof(snd_alias_list_name)));
auto* name = m_memory->Alloc<snd_alias_list_name>();
name->soundName = m_memory->Dup(value.c_str());
reinterpret_cast<SndAliasCustom*>(reinterpret_cast<uintptr_t>(m_structure) + field.iOffset)->name = name;

View File

@ -45,7 +45,7 @@ size_t MenuConversionZoneState::AddStaticDvar(const std::string& dvarName)
return foundDvar->second;
auto* memory = m_zone->GetMemory();
auto* staticDvar = static_cast<StaticDvar*>(memory->Alloc(sizeof(StaticDvar)));
auto* staticDvar = memory->Alloc<StaticDvar>();
staticDvar->dvarName = memory->Dup(dvarName.c_str());
staticDvar->dvar = nullptr;
@ -97,24 +97,24 @@ void MenuConversionZoneState::FinalizeSupportingData() const
if (!m_functions.empty())
{
m_supporting_data->uifunctions.functions = static_cast<Statement_s**>(memory->Alloc(sizeof(void*) * m_functions.size()));
memcpy(m_supporting_data->uifunctions.functions, &m_functions[0], sizeof(void*) * m_functions.size());
m_supporting_data->uifunctions.functions = memory->Alloc<Statement_s*>(m_functions.size());
memcpy(m_supporting_data->uifunctions.functions, m_functions.data(), sizeof(void*) * m_functions.size());
}
else
m_supporting_data->uifunctions.functions = nullptr;
if (!m_static_dvars.empty())
{
m_supporting_data->staticDvarList.staticDvars = static_cast<StaticDvar**>(memory->Alloc(sizeof(void*) * m_static_dvars.size()));
memcpy(m_supporting_data->staticDvarList.staticDvars, &m_static_dvars[0], sizeof(void*) * m_static_dvars.size());
m_supporting_data->staticDvarList.staticDvars = memory->Alloc<StaticDvar*>(m_static_dvars.size());
memcpy(m_supporting_data->staticDvarList.staticDvars, m_static_dvars.data(), sizeof(void*) * m_static_dvars.size());
}
else
m_supporting_data->staticDvarList.staticDvars = nullptr;
if (!m_strings.empty())
{
m_supporting_data->uiStrings.strings = static_cast<const char**>(memory->Alloc(sizeof(void*) * m_strings.size()));
memcpy(m_supporting_data->uiStrings.strings, &m_strings[0], sizeof(void*) * m_strings.size());
m_supporting_data->uiStrings.strings = memory->Alloc<const char*>(m_strings.size());
memcpy(m_supporting_data->uiStrings.strings, m_strings.data(), sizeof(void*) * m_strings.size());
}
else
m_supporting_data->uiStrings.strings = nullptr;

View File

@ -424,7 +424,7 @@ namespace IW4
std::vector<expressionEntry> expressionEntries;
ConvertExpressionEntry(statement, expressionEntries, expression, menu, item);
auto* outputExpressionEntries = static_cast<expressionEntry*>(m_memory->Alloc(sizeof(expressionEntry) * expressionEntries.size()));
auto* outputExpressionEntries = m_memory->Alloc<expressionEntry>(expressionEntries.size());
memcpy(outputExpressionEntries, expressionEntries.data(), sizeof(expressionEntry) * expressionEntries.size());
statement->entries = outputExpressionEntries;
@ -586,8 +586,8 @@ namespace IW4
if (!setLocalVar)
return;
auto* outputHandler = static_cast<MenuEventHandler*>(m_memory->Alloc(sizeof(MenuEventHandler) + sizeof(SetLocalVarData)));
auto* outputSetLocalVar = reinterpret_cast<SetLocalVarData*>(reinterpret_cast<int8_t*>(outputHandler) + sizeof(MenuEventHandler));
auto* outputHandler = m_memory->Alloc<MenuEventHandler>();
auto* outputSetLocalVar = m_memory->Alloc<SetLocalVarData>();
outputHandler->eventType = SetLocalVarTypeToEventType(setLocalVar->m_type);
outputHandler->eventData.setLocalVarData = outputSetLocalVar;
@ -631,8 +631,8 @@ namespace IW4
}
else
{
auto* outputHandler = static_cast<MenuEventHandler*>(m_memory->Alloc(sizeof(MenuEventHandler) + sizeof(ConditionalScript)));
auto* outputCondition = reinterpret_cast<ConditionalScript*>(reinterpret_cast<int8_t*>(outputHandler) + sizeof(MenuEventHandler));
auto* outputHandler = m_memory->Alloc<MenuEventHandler>();
auto* outputCondition = m_memory->Alloc<ConditionalScript>();
outputHandler->eventType = EVENT_IF;
outputHandler->eventData.conditionalScript = outputCondition;
@ -699,9 +699,9 @@ namespace IW4
if (elements.empty())
return nullptr;
auto* outputSet = static_cast<MenuEventHandlerSet*>(m_memory->Alloc(sizeof(MenuEventHandlerSet) + sizeof(void*) * elements.size()));
auto* outputElements = reinterpret_cast<MenuEventHandler**>(reinterpret_cast<int8_t*>(outputSet) + sizeof(MenuEventHandlerSet));
memcpy(outputElements, &elements[0], sizeof(void*) * elements.size());
auto* outputSet = m_memory->Alloc<MenuEventHandlerSet>();
auto* outputElements = m_memory->Alloc<MenuEventHandler*>(elements.size());
memcpy(outputElements, elements.data(), sizeof(void*) * elements.size());
outputSet->eventHandlerCount = static_cast<int>(elements.size());
outputSet->eventHandlers = outputElements;
@ -717,7 +717,7 @@ namespace IW4
return nullptr;
const auto keyHandlerCount = keyHandlers.size();
auto* output = static_cast<ItemKeyHandler*>(m_memory->Alloc(sizeof(ItemKeyHandler) * keyHandlerCount));
auto* output = m_memory->Alloc<ItemKeyHandler>(keyHandlerCount);
auto currentKeyHandler = keyHandlers.cbegin();
for (auto i = 0u; i < keyHandlerCount; i++)
{
@ -829,7 +829,7 @@ namespace IW4
if (floatExpressionCount <= 0)
return nullptr;
auto* floatExpressions = static_cast<ItemFloatExpression*>(m_memory->Alloc(sizeof(ItemFloatExpression) * floatExpressionCount));
auto* floatExpressions = m_memory->Alloc<ItemFloatExpression>(floatExpressionCount);
auto floatExpressionIndex = 0;
for (const auto& [expression, expressionIsStatic, target, staticValue, staticValueArraySize, dynamicFlagsToSet] : locations)
{
@ -903,9 +903,7 @@ namespace IW4
if (commonListBox == nullptr)
return nullptr;
auto* listBox = static_cast<listBoxDef_s*>(m_memory->Alloc(sizeof(listBoxDef_s)));
memset(listBox, 0, sizeof(listBoxDef_s));
auto* listBox = m_memory->Alloc<listBoxDef_s>();
listBox->notselectable = commonListBox->m_not_selectable ? 1 : 0;
listBox->noScrollBars = commonListBox->m_no_scrollbars ? 1 : 0;
listBox->usePaging = commonListBox->m_use_paging ? 1 : 0;
@ -940,9 +938,7 @@ namespace IW4
if (commonEditField == nullptr)
return nullptr;
auto* editField = static_cast<editFieldDef_s*>(m_memory->Alloc(sizeof(editFieldDef_s)));
memset(editField, 0, sizeof(editFieldDef_s));
auto* editField = m_memory->Alloc<editFieldDef_s>();
editField->defVal = static_cast<float>(commonEditField->m_def_val);
editField->minVal = static_cast<float>(commonEditField->m_min_val);
editField->maxVal = static_cast<float>(commonEditField->m_max_val);
@ -962,9 +958,7 @@ namespace IW4
if (commonMultiValue == nullptr)
return nullptr;
auto* multiValue = static_cast<multiDef_s*>(m_memory->Alloc(sizeof(multiDef_s)));
memset(multiValue, 0, sizeof(multiDef_s));
auto* multiValue = m_memory->Alloc<multiDef_s>();
multiValue->count = static_cast<int>(std::min(std::extent_v<decltype(multiDef_s::dvarList)>, commonMultiValue->m_step_names.size()));
multiValue->strDef = !commonMultiValue->m_string_values.empty() ? 1 : 0;
@ -995,9 +989,7 @@ namespace IW4
if (commonNewsTicker == nullptr)
return nullptr;
auto* newsTicker = static_cast<newsTickerDef_s*>(m_memory->Alloc(sizeof(newsTickerDef_s)));
memset(newsTicker, 0, sizeof(newsTickerDef_s));
auto* newsTicker = m_memory->Alloc<newsTickerDef_s>();
newsTicker->spacing = commonNewsTicker->m_spacing;
newsTicker->speed = commonNewsTicker->m_speed;
newsTicker->feedId = commonNewsTicker->m_news_feed_id;
@ -1095,10 +1087,8 @@ namespace IW4
case CommonItemFeatureType::NONE:
default:
if (item->type == ITEM_TYPE_TEXT_SCROLL)
{
item->typeData.scroll = static_cast<textScrollDef_s*>(m_memory->Alloc(sizeof(textScrollDef_s)));
memset(item->typeData.scroll, 0, sizeof(textScrollDef_s));
}
item->typeData.scroll = m_memory->Alloc<textScrollDef_s>();
break;
}
@ -1113,9 +1103,7 @@ namespace IW4
return nullptr;
}
auto* items = static_cast<itemDef_s**>(m_memory->Alloc(sizeof(void*) * commonMenu.m_items.size()));
memset(items, 0, sizeof(void*) * commonMenu.m_items.size());
auto* items = m_memory->Alloc<itemDef_s*>(commonMenu.m_items.size());
for (auto i = 0u; i < commonMenu.m_items.size(); i++)
items[i] = ConvertItem(commonMenu, *commonMenu.m_items[i]);