mirror of
https://github.com/ZDoom/qzdoom.git
synced 2024-11-10 14:51:51 +00:00
Finished serializing
- Implemented an FString TArray which goes into save files that saves a model file and path, and when the game is loaded, spits back out the model to be Loaded when loading a save file
This commit is contained in:
parent
5b8789977a
commit
6d00e4a3f3
5 changed files with 30 additions and 3 deletions
|
@ -42,6 +42,7 @@
|
|||
#include "modelrenderer.h"
|
||||
|
||||
|
||||
TArray<FString> savedModelFiles;
|
||||
TDeletingArray<FModel*> Models;
|
||||
TArray<FSpriteModelFrame> SpriteModelFrames;
|
||||
|
||||
|
|
|
@ -12,6 +12,7 @@ struct FSpriteModelFrame;
|
|||
|
||||
FTextureID LoadSkin(const char* path, const char* fn);
|
||||
void FlushModels();
|
||||
extern TArray<FString> savedModelFiles;
|
||||
extern TDeletingArray<FModel*> Models;
|
||||
extern TArray<FSpriteModelFrame> SpriteModelFrames;
|
||||
|
||||
|
|
|
@ -78,6 +78,7 @@
|
|||
#include "s_music.h"
|
||||
#include "p_setup.h"
|
||||
#include "d_event.h"
|
||||
#include "model.h"
|
||||
|
||||
#include "v_video.h"
|
||||
#include "g_hub.h"
|
||||
|
@ -2119,6 +2120,14 @@ void G_DoLoadGame ()
|
|||
|
||||
BackupSaveName = savename;
|
||||
|
||||
//Push any added models from A_ChangeModel
|
||||
for (int i = 0; i < savedModelFiles.Size(); i++)
|
||||
{
|
||||
FString modelFilePath = savedModelFiles[i].Left(savedModelFiles[i].LastIndexOf("/")+1);
|
||||
FString modelFileName = savedModelFiles[i].Right(savedModelFiles[i].Len() - savedModelFiles[i].Left(savedModelFiles[i].LastIndexOf("/") + 1).Len());
|
||||
FindModel(modelFilePath, modelFileName);
|
||||
}
|
||||
|
||||
// At this point, the GC threshold is likely a lot higher than the
|
||||
// amount of memory in use, so bring it down now by starting a
|
||||
// collection.
|
||||
|
|
|
@ -61,6 +61,7 @@
|
|||
#include "version.h"
|
||||
#include "fragglescript/t_script.h"
|
||||
#include "s_music.h"
|
||||
#include "model.h"
|
||||
|
||||
EXTERN_CVAR(Bool, save_formatted)
|
||||
|
||||
|
@ -996,7 +997,8 @@ void FLevelLocals::Serialize(FSerializer &arc, bool hubload)
|
|||
("scrolls", Scrolls)
|
||||
("automap", automap)
|
||||
("interpolator", interpolator)
|
||||
("frozenstate", frozenstate);
|
||||
("frozenstate", frozenstate)
|
||||
("savedModelFiles", savedModelFiles);
|
||||
|
||||
|
||||
// Hub transitions must keep the current total time
|
||||
|
|
|
@ -5067,13 +5067,27 @@ DEFINE_ACTION_FUNCTION(AActor, A_ChangeModel)
|
|||
int maxModels = mobj->modelData->modelIDs.Size();
|
||||
int maxSkins = mobj->modelData->skinIDs.Size();
|
||||
|
||||
int queryModel = model != NAME_None ? FindModel(modelpath.GetChars(), model.GetChars()) : -1;
|
||||
|
||||
mobj->modelData->modelDef = modeldef;
|
||||
if (maxModels > index) mobj->modelData->modelIDs.Pop(mobj->modelData->modelIDs[index]);
|
||||
if(maxModels > index) mobj->modelData->modelIDs.Pop(mobj->modelData->modelIDs[index]);
|
||||
if(maxSkins > index) mobj->modelData->skinIDs.Pop(mobj->modelData->skinIDs[index]);
|
||||
|
||||
mobj->modelData->modelIDs.Insert(index, model != NAME_None ? FindModel(modelpath.GetChars(), model.GetChars()) : -1);
|
||||
mobj->modelData->modelIDs.Insert(index, queryModel);
|
||||
mobj->modelData->skinIDs.Insert(index, skin != NAME_None ? LoadSkin(skinpath.GetChars(), skin.GetChars()) : FNullTextureID());
|
||||
|
||||
//[SM] - We need to serialize file paths and model names so that they are pushed on loading save files.
|
||||
if (model != NAME_None)
|
||||
{
|
||||
FString fullName;
|
||||
fullName.Format("%s%s", modelpath, model.GetChars());
|
||||
bool allowPush = true;
|
||||
for (unsigned i = 0; i < savedModelFiles.Size(); i++)
|
||||
if (!savedModelFiles[i].CompareNoCase(fullName)) allowPush = false;
|
||||
|
||||
if(allowPush) savedModelFiles.Push(fullName);
|
||||
}
|
||||
|
||||
//[SM] - if an indice of modelIDs or skinIDs comes up blank and it's the last one, just delete it. For using very large amounts of indices, common sense says to just not run this repeatedly.
|
||||
int i = 0;
|
||||
|
||||
|
|
Loading…
Reference in a new issue