From c753695b4e75b6e90539e4e82564c32974bccea5 Mon Sep 17 00:00:00 2001 From: "alexey.lysiuk" Date: Thu, 10 Jun 2021 11:54:26 +0300 Subject: [PATCH] - fixed initialization of model frames Replaced loop arrays initialization and obvious comments with something more readable, I hope https://forum.zdoom.org/viewtopic.php?t=72523 --- src/r_data/models.cpp | 29 +++++++++++------------------ 1 file changed, 11 insertions(+), 18 deletions(-) diff --git a/src/r_data/models.cpp b/src/r_data/models.cpp index 0564099b6ac..d970d523959 100644 --- a/src/r_data/models.cpp +++ b/src/r_data/models.cpp @@ -413,25 +413,18 @@ static void ParseModelDefLump(int Lump) { smf.modelsAmount = MIN_MODELS; } - //Allocate TArrays - smf.modelIDs.Alloc(smf.modelsAmount); - smf.skinIDs.Alloc(smf.modelsAmount); - smf.surfaceskinIDs.Alloc(smf.modelsAmount * MD3_MAX_SURFACES); - smf.modelframes.Alloc(smf.modelsAmount); - //Make sure all modelIDs are -1 by default - for (auto& modelID : smf.modelIDs) - { - modelID = -1; - } - //Make sure no TArray elements of type FTextureID are null. These elements will have a textureid (FTextureID.texnum) of 0. - for (auto& skinID : smf.skinIDs) - { - skinID = FTextureID(FNullTextureID()); - } - for (auto& surfaceskinID : smf.surfaceskinIDs) + + const auto initArray = [](auto& array, const unsigned count, const auto value) { - surfaceskinID = FTextureID(FNullTextureID()); - } + array.Alloc(count); + std::fill(array.begin(), array.end(), value); + }; + + initArray(smf.modelIDs, smf.modelsAmount, -1); + initArray(smf.skinIDs, smf.modelsAmount, FNullTextureID()); + initArray(smf.surfaceskinIDs, smf.modelsAmount * MD3_MAX_SURFACES, FNullTextureID()); + initArray(smf.modelframes, smf.modelsAmount, 0); + sc.RestorePos(scPos); sc.MustGetStringName("{"); while (!sc.CheckString("}"))