BVB Source Codes

CRYENGINE Show GameSerialize.h Source code

Return Download CRYENGINE: download GameSerialize.h Source code - Download CRYENGINE Source code - Type:.h
  1. // Copyright 2001-2016 Crytek GmbH / Crytek Group. All rights reserved.
  2.  
  3. #ifndef __GAME_SERIALIZE_H__
  4. #define __GAME_SERIALIZE_H__
  5.  
  6. #pragma once
  7.  
  8. #include "ISaveGame.h"
  9. #include "ILoadGame.h"
  10. #include "ILevelSystem.h"
  11. #include "GameSerializeHelpers.h"
  12.  
  13. class CCryAction;
  14. class CSaveGameHolder;
  15. class CLoadGameHolder;
  16. struct Checkpoint;
  17. struct IGameFramework;
  18. struct SGameStartParams;
  19. struct ISaveGame;
  20. struct SBasicEntityData;
  21. struct STempAutoResourcesLock;
  22.  
  23. typedef DynArray<SBasicEntityData, int, NArray::SmallDynStorage<NAlloc::GeneralHeapAlloc>> TBasicEntityDatas;
  24. typedef std::vector<IEntity*>                                                              TEntitiesToSerialize;
  25. typedef ISaveGame* (*                                                                      SaveGameFactory)();
  26. typedef ILoadGame* (*                                                                      LoadGameFactory)();
  27.  
  28. //struct to save the state during a save game process
  29. struct SSaveEnvironment
  30. {
  31.         CCryAction*     m_pCryAction;
  32.         const char*     m_checkPointName;
  33.         Checkpoint&     m_checkpoint;
  34.         CSaveGameHolder m_pSaveGame;
  35.         const char*     m_saveMethod;
  36.  
  37.         SSaveEnvironment(CCryAction* pCryAction, const char* checkPointName, const char* method, Checkpoint& checkpoint, const std::map<string, SaveGameFactory>& saveGameFactories) :
  38.                 m_pCryAction(pCryAction),
  39.                 m_checkPointName(checkPointName),
  40.                 m_checkpoint(checkpoint),
  41.                 m_pSaveGame(stl::find_in_map(saveGameFactories, CONST_TEMP_STRING(method), CSaveGameHolder::ReturnNull)()),
  42.                 m_saveMethod(method)
  43.         {
  44.         }
  45.  
  46.         bool InitSave(const char* name, ESaveGameReason reason);
  47. };
  48.  
  49. //struct to save the state during a load game process
  50. struct SLoadEnvironment
  51. {
  52.         CCryAction*                 m_pCryAction;
  53.         CLoadGameHolder             m_pLoadGame;
  54.         std::unique_ptr<TSerialize> m_pSer;
  55.         Checkpoint&                 m_checkpoint;
  56.         TBasicEntityDatas           m_basicEntityData;
  57.  
  58.         bool                        m_bLoadingErrors;
  59.         bool                        m_bHaveReserved;
  60.         ELoadGameResult             m_failure;
  61.  
  62.         SLoadEnvironment(CCryAction* pCryAction, Checkpoint& checkpoint, const char* method, const std::map<string, LoadGameFactory>& loadGameFactories) :
  63.                 m_pCryAction(pCryAction),
  64.                 m_pLoadGame(stl::find_in_map(loadGameFactories, method, CLoadGameHolder::ReturnNull)()),
  65.                 m_pSer(nullptr),
  66.                 m_checkpoint(checkpoint),
  67.                 m_basicEntityData(NAlloc::GeneralHeapAlloc(m_pLoadGame->GetHeap())),
  68.                 m_bLoadingErrors(false),
  69.                 m_bHaveReserved(false),
  70.                 m_failure(eLGR_Failed)
  71.         {}
  72.  
  73.         bool InitLoad(bool requireQuickLoad, const char* path);
  74. };
  75.  
  76. class CGameSerialize : public IEntitySystemSink, ILevelSystemListener
  77. {
  78. public:
  79.         CGameSerialize();
  80.         ~CGameSerialize();
  81.  
  82.         void RegisterSaveGameFactory(const char* name, SaveGameFactory factory);
  83.         void RegisterLoadGameFactory(const char* name, LoadGameFactory factory);
  84.         void GetMemoryStatistics(ICrySizer* s)
  85.         {
  86.                 //[AlexMcC|19.04.10]: Avoid infinite recursion caused by passing function pointers to AddObject()
  87.                 //s->AddObject(m_saveGameFactories);
  88.                 //s->AddObject(m_loadGameFactories);
  89.         }
  90.  
  91.         bool            SaveGame(CCryAction* pCryAction, const char* method, const char* name, ESaveGameReason reason = eSGR_QuickSave, const char* checkPointName = NULL);
  92.         ELoadGameResult LoadGame(CCryAction* pCryAction, const char* method, const char* path, SGameStartParams& params, bool requireQuickLoad);
  93.  
  94.         void            RegisterFactories(IGameFramework* pFW);
  95.  
  96.         // IEntitySystemSink
  97.         virtual bool OnBeforeSpawn(SEntitySpawnParams&) { return true; }
  98.         virtual void OnSpawn(IEntity* pEntity, SEntitySpawnParams&);
  99.         virtual bool OnRemove(IEntity* pEntity);
  100.         virtual void OnReused(IEntity* pEntity, SEntitySpawnParams& entitySpawnParams) {}
  101.         virtual void OnEvent(IEntity* pEntity, SEntityEvent& entityEvent)              {}
  102.         // ~IEntitySystemSink
  103.  
  104.         // ILevelSystemListener
  105.         virtual void OnLevelNotFound(const char* levelName)                    {}
  106.         virtual void OnLoadingStart(ILevelInfo* pLevel);
  107.         virtual void OnLoadingLevelEntitiesStart(ILevelInfo* pLevel)           {};
  108.         virtual void OnLoadingComplete(ILevelInfo* pLevel)                     {}
  109.         virtual void OnLoadingError(ILevelInfo* pLevel, const char* error)     {}
  110.         virtual void OnLoadingProgress(ILevelInfo* pLevel, int progressAmount) {}
  111.         virtual void OnUnloadComplete(ILevelInfo* pLevel);
  112.         // ~ILevelSystemListener
  113.  
  114. private:
  115.  
  116.         //save process steps
  117.         bool SaveMetaData(SSaveEnvironment& savEnv);
  118.         void SaveEngineSystems(SSaveEnvironment& savEnv);
  119.         bool SaveEntities(SSaveEnvironment& savEnv);
  120.         bool SaveGameData(SSaveEnvironment& savEnv, TSerialize& gameState, TEntitiesToSerialize& entities);
  121.  
  122.         //load process steps
  123.         void LoadEngineSystems(SLoadEnvironment& loadEnv);
  124.         bool LoadLevel(SLoadEnvironment& loadEnv, SGameStartParams& startParams, STempAutoResourcesLock& autoResourcesLock, bool bIsQuickLoading, bool requireQuickLoad);
  125.         bool LoadEntities(SLoadEnvironment& loadEnv, std::unique_ptr<TSerialize> pGameStateSer);
  126.         void LoadBasicEntityData(SLoadEnvironment& loadEnv);
  127.         void LoadGameData(SLoadEnvironment& loadEnv);
  128.  
  129.         //helper functions
  130.         void Clean();
  131.         void ReserveEntityIds(const TBasicEntityDatas& basicEntityData);
  132.         void FlushActivatableGameObjectExtensions();
  133.         bool RepositionEntities(const TBasicEntityDatas& basicEntityData, bool insistOnAllEntitiesBeingThere);
  134.         void DeleteDynamicEntities(const TBasicEntityDatas& basicEntityData);
  135.         void DumpEntities();
  136.         bool IsUserSignedIn(CCryAction* pCryAction) const;
  137.  
  138. #ifndef _RELEASE
  139.         struct DebugSaveParts;
  140.  
  141.         void DebugPrintMemoryUsage(const DebugSaveParts& debugSaveParts) const;
  142. #endif
  143.  
  144. private:
  145.         std::map<string, SaveGameFactory> m_saveGameFactories;
  146.         std::map<string, LoadGameFactory> m_loadGameFactories;
  147.  
  148.         typedef std::vector<EntityId> TEntityVector;
  149.         typedef std::set<EntityId>    TEntitySet;
  150.         TEntityVector m_serializeEntities;
  151.         TEntitySet    m_dynamicEntities;
  152. };
  153.  
  154. #endif
  155.  
downloadGameSerialize.h Source code - Download CRYENGINE Source code
Related Source Codes/Software:
postal - 2017-06-11
reactide - Reactide is the first dedicated IDE for React web ... 2017-06-11
rkt - rkt is a pod-native container engine for Linux. It... 2017-06-11
uWebSockets - Tiny WebSockets https://for... 2017-06-11
realworld - TodoMVC for the RealWorld - Exemplary fullstack Me... 2017-06-11
CRYENGINE - CRYENGINE is a powerful real-time game development... 2017-06-11
goreplay - GoReplay is an open-source tool for capturing and ... 2017-06-10
pyenv - Simple Python version management 2017-06-10
redux-saga - An alternative side effect model for Redux apps ... 2017-06-10
angular-starter - 2017-06-10

 Back to top