2
0
mirror of https://github.com/AxioDL/metaforce.git synced 2025-07-07 20:45:51 +00:00

Merge pull request #258 from lioncash/emplaced

General: Make use of emplace_back where applicable
This commit is contained in:
Phillip Stephens 2020-03-23 23:26:51 -07:00 committed by GitHub
commit 2e43266714
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
13 changed files with 38 additions and 33 deletions

View File

@ -30,12 +30,12 @@ bool CSaveWorldIntermediate::InitializePump() {
x4_strgId = wld.IGetStringTableAssetId(); x4_strgId = wld.IGetStringTableAssetId();
x8_savwId = wld.IGetSaveWorldAssetId(); x8_savwId = wld.IGetSaveWorldAssetId();
u32 areaCount = wld.IGetAreaCount(); const u32 areaCount = wld.IGetAreaCount();
xc_areaIds.reserve(areaCount); xc_areaIds.reserve(areaCount);
for (u32 i = 0; i < areaCount; ++i) { for (u32 i = 0; i < areaCount; ++i) {
const IGameArea* area = wld.IGetAreaAlways(i); const IGameArea* area = wld.IGetAreaAlways(i);
xc_areaIds.push_back(area->IGetAreaId()); xc_areaIds.emplace_back(area->IGetAreaId());
} }
CAssetId mlvlId = wld.IGetWorldAssetId(); CAssetId mlvlId = wld.IGetWorldAssetId();

View File

@ -14,13 +14,13 @@ CSaveWorld::CSaveWorld(CInputStream& in) {
const u32 cinematicCount = in.readUint32Big(); const u32 cinematicCount = in.readUint32Big();
x4_cinematics.reserve(cinematicCount); x4_cinematics.reserve(cinematicCount);
for (u32 i = 0; i < cinematicCount; ++i) { for (u32 i = 0; i < cinematicCount; ++i) {
x4_cinematics.push_back(in.readUint32Big()); x4_cinematics.emplace_back(in.readUint32Big());
} }
const u32 relayCount = in.readUint32Big(); const u32 relayCount = in.readUint32Big();
x14_relays.reserve(relayCount); x14_relays.reserve(relayCount);
for (u32 i = 0; i < relayCount; ++i) { for (u32 i = 0; i < relayCount; ++i) {
x14_relays.push_back(in.readUint32Big()); x14_relays.emplace_back(in.readUint32Big());
} }
} }
@ -35,7 +35,7 @@ CSaveWorld::CSaveWorld(CInputStream& in) {
const u32 doorCount = in.readUint32Big(); const u32 doorCount = in.readUint32Big();
x34_doors.reserve(doorCount); x34_doors.reserve(doorCount);
for (u32 i = 0; i < doorCount; ++i) { for (u32 i = 0; i < doorCount; ++i) {
x34_doors.push_back(in.readUint32Big()); x34_doors.emplace_back(in.readUint32Big());
} }
if (version <= 0) { if (version <= 0) {

View File

@ -475,7 +475,7 @@ CHudDecoInterfaceThermal::CHudDecoInterfaceThermal(CGuiFrame& selHud) {
if (CGuiWidget* w = selHud.FindWidget("basewidget_lock")) { if (CGuiWidget* w = selHud.FindWidget("basewidget_lock")) {
for (CGuiWidget* c = static_cast<CGuiWidget*>(w->GetChildObject()); c; for (CGuiWidget* c = static_cast<CGuiWidget*>(w->GetChildObject()); c;
c = static_cast<CGuiWidget*>(c->GetNextSibling())) { c = static_cast<CGuiWidget*>(c->GetNextSibling())) {
x84_lockonWidgets.push_back({c, c->GetLocalTransform()}); x84_lockonWidgets.emplace_back(c, c->GetLocalTransform());
c->SetLocalTransform(c->GetLocalTransform() * zeus::CTransform::Scale(x68_lockonScale)); c->SetLocalTransform(c->GetLocalTransform() * zeus::CTransform::Scale(x68_lockonScale));
} }
} }

View File

@ -64,8 +64,8 @@ CRasterFont::CRasterFont(urde::CInputStream& in, urde::IObjectStore& store) {
baseline = in.readByte(); baseline = in.readByte();
kernStart = in.readInt16Big(); kernStart = in.readInt16Big();
} }
xc_glyphs.push_back(std::make_pair( xc_glyphs.emplace_back(
chr, CGlyph(a, b, c, startU, startV, endU, endV, cellWidth, cellHeight, baseline, kernStart, layer))); chr, CGlyph(a, b, c, startU, startV, endU, endV, cellWidth, cellHeight, baseline, kernStart, layer));
} }
std::sort(xc_glyphs.begin(), xc_glyphs.end(), [=](auto& a, auto& b) -> bool { return a.first < b.first; }); std::sort(xc_glyphs.begin(), xc_glyphs.end(), [=](auto& a, auto& b) -> bool { return a.first < b.first; });

View File

@ -188,7 +188,7 @@ CFontImageDef CTextParser::GetImage(const char16_t* str, int len,
texs.reserve(commaCount - 1); texs.reserve(commaCount - 1);
do { do {
AdvanceCommaPos(); AdvanceCommaPos();
texs.push_back(x0_store.GetObj({SBIG('TXTR'), GetAssetIdFromString(&iterable[tokenPos], len, txtrMap)})); texs.emplace_back(x0_store.GetObj({SBIG('TXTR'), GetAssetIdFromString(&iterable[tokenPos], len, txtrMap)}));
AdvanceTokenPos(); AdvanceTokenPos();
} while (commaPos != iterable.size()); } while (commaPos != iterable.size());
@ -211,7 +211,7 @@ CFontImageDef CTextParser::GetImage(const char16_t* str, int len,
texs.reserve(commaCount - 3); texs.reserve(commaCount - 3);
do { do {
AdvanceCommaPos(); AdvanceCommaPos();
texs.push_back(x0_store.GetObj({SBIG('TXTR'), GetAssetIdFromString(&iterable[tokenPos], len, txtrMap)})); texs.emplace_back(x0_store.GetObj({SBIG('TXTR'), GetAssetIdFromString(&iterable[tokenPos], len, txtrMap)}));
AdvanceTokenPos(); AdvanceTokenPos();
} while (commaPos != iterable.size()); } while (commaPos != iterable.size());

View File

@ -174,7 +174,7 @@ void CTextRenderBuffer::AddImage(const zeus::CVector2i& offset, const CFontImage
if (x0_mode == EMode::AllocTally) if (x0_mode == EMode::AllocTally)
m_primitiveMarks.push_back({Command::ImageRender, m_imagesCount++, 0}); m_primitiveMarks.push_back({Command::ImageRender, m_imagesCount++, 0});
else else
m_images.push_back({image, offset}); m_images.emplace_back(image, offset);
} }
void CTextRenderBuffer::AddCharacter(const zeus::CVector2i& offset, char16_t ch, const zeus::CColor& color) { void CTextRenderBuffer::AddCharacter(const zeus::CVector2i& offset, char16_t ch, const zeus::CColor& color) {
@ -209,7 +209,7 @@ void CTextRenderBuffer::AddFontChange(const TToken<CRasterFont>& font) {
} }
m_activeFontCh = m_fontCharacters.size(); m_activeFontCh = m_fontCharacters.size();
m_fontCharacters.push_back({font}); m_fontCharacters.emplace_back(font);
} }
bool CTextRenderBuffer::HasSpaceAvailable(const zeus::CVector2i& origin, const zeus::CVector2i& extent) const { bool CTextRenderBuffer::HasSpaceAvailable(const zeus::CVector2i& origin, const zeus::CVector2i& extent) const {

View File

@ -19,10 +19,11 @@ CCEKeyframeEmitter::CCEKeyframeEmitter(CInputStream& in) {
x10_loopEnd = in.readUint32Big(); x10_loopEnd = in.readUint32Big();
x14_loopStart = in.readUint32Big(); x14_loopStart = in.readUint32Big();
u32 count = in.readUint32Big(); const u32 count = in.readUint32Big();
x18_keys.reserve(count); x18_keys.reserve(count);
for (u32 i = 0; i < count; ++i) for (u32 i = 0; i < count; ++i) {
x18_keys.push_back(in.readVec4fBig()); x18_keys.emplace_back(in.readVec4fBig());
}
} }
bool CCEKeyframeEmitter::GetValue(int frame, zeus::CColor& valOut) const { bool CCEKeyframeEmitter::GetValue(int frame, zeus::CColor& valOut) const {

View File

@ -333,7 +333,7 @@ void CParticleElectric::CreateNewParticles(int count) {
if (CIntElement* slif = x1c_elecDesc->x4_SLIF.get()) if (CIntElement* slif = x1c_elecDesc->x4_SLIF.get())
slif->GetValue(x28_currentFrame, lifetime); slif->GetValue(x28_currentFrame, lifetime);
x3e8_electricManagers.push_back(CParticleElectricManager(allocIdx, lifetime, x28_currentFrame)); x3e8_electricManagers.emplace_back(allocIdx, lifetime, x28_currentFrame);
CParticleElectricManager& elec = x3e8_electricManagers.back(); CParticleElectricManager& elec = x3e8_electricManagers.back();
CParticleGlobals::instance()->SetParticleLifetime(elec.xc_endFrame - elec.x8_startFrame); CParticleGlobals::instance()->SetParticleLifetime(elec.xc_endFrame - elec.x8_startFrame);
int frame = x28_currentFrame - elec.x8_startFrame; int frame = x28_currentFrame - elec.x8_startFrame;

View File

@ -19,10 +19,11 @@ CVEKeyframeEmitter::CVEKeyframeEmitter(CInputStream& in) {
x10_loopEnd = in.readUint32Big(); x10_loopEnd = in.readUint32Big();
x14_loopStart = in.readUint32Big(); x14_loopStart = in.readUint32Big();
u32 count = in.readUint32Big(); const u32 count = in.readUint32Big();
x18_keys.reserve(count); x18_keys.reserve(count);
for (u32 i = 0; i < count; ++i) for (u32 i = 0; i < count; ++i) {
x18_keys.push_back(in.readVec3fBig()); x18_keys.emplace_back(in.readVec3fBig());
}
} }
bool CVEKeyframeEmitter::GetValue(int frame, zeus::CVector3f& valOut) const { bool CVEKeyframeEmitter::GetValue(int frame, zeus::CVector3f& valOut) const {

View File

@ -353,28 +353,31 @@ CGameArea::CGameArea(CInputStream& in, int idx, int mlvlVersion) : x4_selfIdx(id
else else
x88_areaId = -1; x88_areaId = -1;
u32 attachedCount = in.readUint32Big(); const u32 attachedCount = in.readUint32Big();
x8c_attachedAreaIndices.reserve(attachedCount); x8c_attachedAreaIndices.reserve(attachedCount);
for (u32 i = 0; i < attachedCount; ++i) for (u32 i = 0; i < attachedCount; ++i) {
x8c_attachedAreaIndices.push_back(in.readUint16Big()); x8c_attachedAreaIndices.emplace_back(in.readUint16Big());
}
x9c_deps1 = ::urde::ReadDependencyList(in); x9c_deps1 = ::urde::ReadDependencyList(in);
xac_deps2 = ::urde::ReadDependencyList(in); xac_deps2 = ::urde::ReadDependencyList(in);
zeus::CAABox aabb = x6c_aabb.getTransformedAABox(xc_transform); const zeus::CAABox aabb = x6c_aabb.getTransformedAABox(xc_transform);
x6c_aabb = aabb; x6c_aabb = aabb;
if (mlvlVersion > 13) { if (mlvlVersion > 13) {
u32 depCount = in.readUint32Big(); const u32 depCount = in.readUint32Big();
xbc_layerDepOffsets.reserve(depCount); xbc_layerDepOffsets.reserve(depCount);
for (u32 i = 0; i < depCount; ++i) for (u32 i = 0; i < depCount; ++i) {
xbc_layerDepOffsets.push_back(in.readUint32Big()); xbc_layerDepOffsets.emplace_back(in.readUint32Big());
}
} }
u32 dockCount = in.readUint32Big(); const u32 dockCount = in.readUint32Big();
xcc_docks.reserve(dockCount); xcc_docks.reserve(dockCount);
for (u32 i = 0; i < dockCount; ++i) for (u32 i = 0; i < dockCount; ++i) {
xcc_docks.push_back({in, xc_transform}); xcc_docks.emplace_back(in, xc_transform);
}
ClearTokenList(); ClearTokenList();

View File

@ -89,10 +89,10 @@ float CScriptPickupGenerator::GetPickupTemplates(CStateManager& mgr,
doAlways = true; doAlways = true;
break; break;
} }
bool thirtyPercTest = mgr.GetActiveRandom()->Float() < 0.3f; const bool thirtyPercTest = mgr.GetActiveRandom()->Float() < 0.3f;
if ((doAlways || (doThirtyPerc && thirtyPercTest)) && possibility > 0.f) { if ((doAlways || (doThirtyPerc && thirtyPercTest)) && possibility > 0.f) {
totalPossibility += possibility * multiplier; totalPossibility += possibility * multiplier;
idsOut.push_back(std::make_pair(possibility, conn.x8_objId)); idsOut.emplace_back(possibility, conn.x8_objId);
} }
} }
} }

View File

@ -254,7 +254,7 @@ void CScriptSpecialFunction::AcceptScriptMsg(EScriptObjectMessage msg, TUniqueId
auto search = mgr.GetIdListForScript(conn.x8_objId); auto search = mgr.GetIdListForScript(conn.x8_objId);
for (auto it = search.first; it != search.second; ++it) { for (auto it = search.first; it != search.second; ++it) {
if (TCastToPtr<CActor> act = mgr.ObjectById(it->second)) { if (TCastToPtr<CActor> act = mgr.ObjectById(it->second)) {
x198_ringControllers.push_back(SRingController(it->second, 0.f, false)); x198_ringControllers.emplace_back(it->second, 0.f, false);
act->RemoveMaterial(EMaterialTypes::Occluder, mgr); act->RemoveMaterial(EMaterialTypes::Occluder, mgr);
} }
} }

View File

@ -242,7 +242,7 @@ void CScriptTrigger::Touch(CActor& act, CStateManager& mgr) {
} }
if (True(testFlags & x12c_flags)) { if (True(testFlags & x12c_flags)) {
xe8_inhabitants.push_back(act.GetUniqueId()); xe8_inhabitants.emplace_back(act.GetUniqueId());
InhabitantAdded(act, mgr); InhabitantAdded(act, mgr);
if (pl) { if (pl) {