2
0
mirror of https://github.com/Laupetin/OpenAssetTools.git synced 2025-11-30 16:27:47 +00:00

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

@@ -83,7 +83,7 @@ namespace IW5
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

@@ -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,11 +65,11 @@ bool AssetLoaderScriptFile::LoadFromRaw(
return false;
}
scriptFile->buffer = static_cast<char*>(memory->Alloc(scriptFile->compressedLen));
scriptFile->buffer = memory->Alloc<char>(scriptFile->compressedLen);
memcpy(const_cast<char*>(scriptFile->buffer), fileBuffer.get() + offset, scriptFile->compressedLen);
offset += scriptFile->compressedLen;
scriptFile->bytecode = static_cast<unsigned char*>(memory->Alloc(scriptFile->bytecodeLen));
scriptFile->bytecode = memory->Alloc<unsigned char>(scriptFile->bytecodeLen);
memcpy(scriptFile->bytecode, fileBuffer.get() + offset, scriptFile->bytecodeLen);
manager->AddAsset(ASSET_TYPE_SCRIPTFILE, assetName, scriptFile);

View File

@@ -68,12 +68,12 @@ namespace
return true;
}
*perSurfaceTypeSound = static_cast<SndAliasCustom*>(m_memory->Alloc(sizeof(SndAliasCustom) * SURF_TYPE_COUNT));
*perSurfaceTypeSound = m_memory->Alloc<SndAliasCustom>(SURF_TYPE_COUNT);
for (auto i = 0u; i < SURF_TYPE_COUNT; i++)
{
const auto currentPerSurfaceTypeSound = value + surfaceTypeSoundSuffixes[i];
(*perSurfaceTypeSound)[i].name = static_cast<snd_alias_list_name*>(m_memory->Alloc(sizeof(snd_alias_list_name)));
(*perSurfaceTypeSound)[i].name = m_memory->Alloc<snd_alias_list_name>();
(*perSurfaceTypeSound)[i].name->soundName = m_memory->Dup(currentPerSurfaceTypeSound.c_str());
}
@@ -207,7 +207,7 @@ namespace
return false;
}
auto* animOverrides = static_cast<AnimOverrideEntry*>(m_memory->Alloc(sizeof(AnimOverrideEntry) * valueArray.size()));
auto* animOverrides = m_memory->Alloc<AnimOverrideEntry>(valueArray.size());
auto i = 0u;
for (const auto& overrideValues : valueArray)
@@ -248,7 +248,7 @@ namespace
return false;
}
auto* soundOverrides = static_cast<SoundOverrideEntry*>(m_memory->Alloc(sizeof(SoundOverrideEntry) * valueArray.size()));
auto* soundOverrides = m_memory->Alloc<SoundOverrideEntry>(valueArray.size());
auto i = 0u;
for (const auto& overrideValues : valueArray)
@@ -283,7 +283,7 @@ namespace
return false;
}
auto* fxOverrides = static_cast<FxOverrideEntry*>(m_memory->Alloc(sizeof(FxOverrideEntry) * valueArray.size()));
auto* fxOverrides = m_memory->Alloc<FxOverrideEntry>(valueArray.size());
auto i = 0u;
for (const auto& overrideValues : valueArray)
@@ -321,7 +321,7 @@ namespace
return false;
}
auto* reloadOverrides = static_cast<ReloadStateTimerEntry*>(m_memory->Alloc(sizeof(ReloadStateTimerEntry) * valueArray.size()));
auto* reloadOverrides = m_memory->Alloc<ReloadStateTimerEntry>(valueArray.size());
auto i = 0u;
for (const auto& overrideValues : valueArray)
@@ -372,10 +372,8 @@ namespace
if (!ParseSingleWeaponAttachment(overrideValues[0], currentOverride.attachment))
return false;
currentOverride.notetrackSoundMapKeys = static_cast<ScriptString*>(m_memory->Alloc(sizeof(ScriptString) * 24u));
memset(currentOverride.notetrackSoundMapKeys, 0u, sizeof(ScriptString) * 24u);
currentOverride.notetrackSoundMapValues = static_cast<ScriptString*>(m_memory->Alloc(sizeof(ScriptString) * 24u));
memset(currentOverride.notetrackSoundMapValues, 0u, sizeof(ScriptString) * 24u);
currentOverride.notetrackSoundMapKeys = m_memory->Alloc<ScriptString>(24u);
currentOverride.notetrackSoundMapValues = m_memory->Alloc<ScriptString>(24u);
lastAttachment = overrideValues[0];
currentOverrideKeyOffset = 0u;
}
@@ -394,8 +392,7 @@ namespace
if (currentOverrideKeyOffset > 0u)
overrideVector.emplace_back(currentOverride);
m_weapon->weapCompleteDef.notetrackOverrides =
static_cast<NoteTrackToSoundEntry*>(m_memory->Alloc(sizeof(NoteTrackToSoundEntry) * overrideVector.size()));
m_weapon->weapCompleteDef.notetrackOverrides = m_memory->Alloc<NoteTrackToSoundEntry>(overrideVector.size());
memcpy(m_weapon->weapCompleteDef.notetrackOverrides, overrideVector.data(), sizeof(NoteTrackToSoundEntry) * overrideVector.size());
m_weapon->weapCompleteDef.numNotetrackOverrides = overrideVector.size();
@@ -462,7 +459,7 @@ namespace
return;
}
soundAlias.name = static_cast<snd_alias_list_name*>(m_memory->Alloc(sizeof(snd_alias_list_name)));
soundAlias.name = m_memory->Alloc<snd_alias_list_name>();
soundAlias.name->soundName = m_memory->Dup(value.c_str());
m_indirect_asset_references.emplace(m_loading_manager->LoadIndirectAssetReference(ASSET_TYPE_SOUND, value));
}
@@ -698,13 +695,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

@@ -31,8 +31,7 @@ bool AssetLoaderWeaponAttachment::LoadFromRaw(
if (!file.IsOpen())
return false;
auto* attachment = static_cast<WeaponAttachment*>(memory->Alloc(sizeof(WeaponAttachment)));
memset(attachment, 0, sizeof(Material));
auto* attachment = memory->Alloc<WeaponAttachment>();
attachment->szInternalName = memory->Dup(assetName.c_str());
std::vector<XAssetInfoGeneric*> dependencies;