diff --git a/src/playsim/actor.h b/src/playsim/actor.h index 63ce2691d..a2a525089 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 791a33a50..56d61451d 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 875e1d6fe..3bc5e2248 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);