From c304a8f9747320a9209f8eadea12e96c4bef4f38 Mon Sep 17 00:00:00 2001 From: Shiny Metagross <30511800+ShinyMetagross@users.noreply.github.com> Date: Tue, 28 Jun 2022 12:04:10 -0700 Subject: [PATCH] Changed static arrays to TArrays - Made the models and skins arrays TArrays - The issue I described with models not always reverting to default properly was caused by the fact I was unintentionally overwriting smf data. Now intermediate TArrays store the data before the loop instead of overwriting anything --- src/playsim/actor.h | 4 ++-- src/playsim/p_actionfunctions.cpp | 9 +++++++-- src/r_data/models.cpp | 23 +++++++++++++++++------ 3 files changed, 26 insertions(+), 10 deletions(-) diff --git a/src/playsim/actor.h b/src/playsim/actor.h index 63ce2691d1..a2a5250894 100644 --- a/src/playsim/actor.h +++ b/src/playsim/actor.h @@ -1069,8 +1069,8 @@ public: double Speed; double FloatSpeed; FName modelDef; - int models[16] = { -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1 }; //[SM] - I hate this solution, but it get's the job done - FTextureID skins[16]; + TArray models; + TArray skins; // interaction info FBlockNode *BlockNode; // links in blocks (if needed) diff --git a/src/playsim/p_actionfunctions.cpp b/src/playsim/p_actionfunctions.cpp index 791a33a501..56d61451d2 100644 --- a/src/playsim/p_actionfunctions.cpp +++ b/src/playsim/p_actionfunctions.cpp @@ -5055,8 +5055,13 @@ DEFINE_ACTION_FUNCTION(AActor, A_ChangeModel) mobj->hasmodel = modeldef == nullptr && !mobj->hasmodel ? 1 : 0; mobj->modelDef = modeldef; - mobj->models[modelindex] = model != nullptr ? FindModel(modelpath.GetChars(), model.GetChars()) : -1; - mobj->skins[skinindex] = skin != nullptr ? LoadSkin(skinpath.GetChars(), skin.GetChars()) : mobj->skins[skinindex] = FNullTextureID(); + + mobj->models.Delete(modelindex); + mobj->skins.Delete(skinindex); + if(model != nullptr) mobj->models.Insert(modelindex, FindModel(modelpath.GetChars(), model.GetChars())); + else mobj->models.Insert(modelindex, -1); + if(skin != nullptr) mobj->skins.Insert(skinindex, LoadSkin(skinpath.GetChars(), skin.GetChars())); + else mobj->skins.Insert(skinindex, FNullTextureID()); return 0; } diff --git a/src/r_data/models.cpp b/src/r_data/models.cpp index 875e1d6fe5..3bc5e22487 100644 --- a/src/r_data/models.cpp +++ b/src/r_data/models.cpp @@ -276,14 +276,25 @@ void RenderFrameModels(FModelRenderer *renderer, FLevelLocals *Level, const FSpr } } + //[SM] - these temporary arrays prevent actual smf data from being overwritten, which was the source of my problems + TArray tempModelIDs = smf->modelIDs; + TArray tempSkinIDs = smf->skinIDs; for (int i = 0; i < smf->modelsAmount; i++) - { - if (actor->models[i] != -1) - smf->modelIDs[i] = actor->models[i]; - if (smf->modelIDs[i] != -1) + { + if (i < actor->models.Size()) { - FModel * mdl = Models[smf->modelIDs[i]]; - auto tex = actor->skins[i].isValid() ? TexMan.GetGameTexture(actor->skins[i], true) : smf->skinIDs[i].isValid() ? TexMan.GetGameTexture(smf->skinIDs[i], true) : nullptr; + if (actor->models[i] >= 0) + tempModelIDs[i] = actor->models[i]; + } + if (tempModelIDs[i] != -1) + { + FModel * mdl = Models[tempModelIDs[i]]; + if (i < actor->skins.Size()) + { + if (actor->skins[i].isValid()) + tempSkinIDs[i] = actor->skins[i]; + } + auto tex = tempSkinIDs[i].isValid() ? TexMan.GetGameTexture(tempSkinIDs[i], true) : nullptr; mdl->BuildVertexBuffer(renderer); mdl->PushSpriteMDLFrame(smf, i);