hkVersionPatchManager.h
上传用户:yisoukefu
上传日期:2020-08-09
资源大小:39506k
文件大小:7k
源码类别:

其他游戏

开发平台:

Visual C++

  1. /* 
  2.  * 
  3.  * Confidential Information of Telekinesys Research Limited (t/a Havok). Not for disclosure or distribution without Havok's
  4.  * prior written consent. This software contains code, techniques and know-how which is confidential and proprietary to Havok.
  5.  * Level 2 and Level 3 source code contains trade secrets of Havok. Havok Software (C) Copyright 1999-2009 Telekinesys Research Limited t/a Havok. All Rights Reserved. Use of this software is subject to the terms of an end user license agreement.
  6.  * 
  7.  */
  8. #ifndef HK_SERIALIZE_PATCH_MANAGER_H
  9. #define HK_SERIALIZE_PATCH_MANAGER_H
  10. #include <Common/Base/Types/hkTypedUnion.h>
  11. #include <Common/Base/Container/StringMap/hkStringMap.h>
  12. #include <Common/Serialize/Data/hkDataObject.h>
  13. class hkClassNameRegistry;
  14. class hkDataClassDict;
  15. class hkDataWorldDict;
  16. /// Class defining and managing versions of classes using patches.
  17. /// You should hkVersionPatchManager::getInstance() to access instance
  18. /// of the manager.
  19. class hkVersionPatchManager : public hkReferencedObject, public hkSingleton<hkVersionPatchManager>
  20. {
  21. public:
  22. /// Supported patch component types.
  23. enum PatchType
  24. {
  25. PATCH_INVALID,
  26. PATCH_MEMBER_ADDED,
  27. PATCH_MEMBER_REMOVED,
  28. PATCH_MEMBER_RENAMED,
  29. PATCH_FUNCTION,
  30. PATCH_CAST,
  31. PATCH_DEPENDS,
  32. PATCH_PARENT_SET,
  33. PATCH_END
  34. };
  35. /// Class defining a versioning patch for reflected class.
  36. struct PatchInfo
  37. {
  38. /// Class defining a component of the versioning patch, e.g. add and/or remove class member.
  39. struct Component
  40. {
  41. PatchType type;
  42. const void* patch;
  43. private:
  44. HK_DECLARE_NONVIRTUAL_CLASS_ALLOCATOR(HK_MEMORY_CLASS_SERIALIZE, Component);
  45. };
  46. const char* oldName;
  47. const char* newName;
  48. hkInt32 oldVersion;
  49. hkInt32 newVersion;
  50. const Component* component;
  51. hkInt32 numComponent;
  52. private:
  53. HK_DECLARE_NONVIRTUAL_CLASS_ALLOCATOR(HK_MEMORY_CLASS_SERIALIZE, PatchInfo);
  54. };
  55. typedef void (*Function)(hkDataObject& o);
  56. typedef hkStringMap<hkDataClassDict*> ClassImplFromName;
  57. /// hkVersionPatchManager constructor.
  58. hkVersionPatchManager();
  59. /// hkVersionPatchManager destructor.
  60. ~hkVersionPatchManager();
  61. /// Set class version dependency in patch.
  62. struct DependsPatch
  63. {
  64. enum { PATCH_TYPE=PATCH_DEPENDS };
  65. const char* name;
  66. hkInt32 version;
  67. private:
  68. HK_DECLARE_NONVIRTUAL_CLASS_ALLOCATOR(HK_MEMORY_CLASS_SERIALIZE, DependsPatch);
  69. };
  70. /// Define class member renamed in patch.
  71. struct MemberRenamedPatch
  72. {
  73. enum { PATCH_TYPE=PATCH_MEMBER_RENAMED};
  74. const char* oldName;
  75. const char* newName;
  76. private:
  77. HK_DECLARE_NONVIRTUAL_CLASS_ALLOCATOR(HK_MEMORY_CLASS_SERIALIZE, MemberRenamedPatch);
  78. };
  79. /// Define class member added in patch.
  80. struct MemberAddedPatch
  81. {
  82. enum { PATCH_TYPE=PATCH_MEMBER_ADDED};
  83. const char* name;
  84. hkDataObject::Type type;
  85. const char* typeName;
  86. hkInt32 tuples;
  87. private:
  88. HK_DECLARE_NONVIRTUAL_CLASS_ALLOCATOR(HK_MEMORY_CLASS_SERIALIZE, MemberAddedPatch);
  89. };
  90. /// Define class member removed in patch.
  91. struct MemberRemovedPatch
  92. {
  93. enum { PATCH_TYPE=PATCH_MEMBER_REMOVED};
  94. const char* name;
  95. hkDataObject::Type type;
  96. const char* typeName;
  97. hkInt32 tuples;
  98. private:
  99. HK_DECLARE_NONVIRTUAL_CLASS_ALLOCATOR(HK_MEMORY_CLASS_SERIALIZE, MemberRemovedPatch);
  100. };
  101. /// Set class parent in patch.
  102.   struct SetParentPatch
  103. {
  104. enum { PATCH_TYPE=PATCH_PARENT_SET };
  105. const char* oldParent;
  106. const char* newParent;
  107. private:
  108. HK_DECLARE_NONVIRTUAL_CLASS_ALLOCATOR(HK_MEMORY_CLASS_SERIALIZE, SetParentPatch);
  109. };
  110. /// Set function to be called in patch.
  111. struct FunctionPatch
  112. {
  113. enum { PATCH_TYPE=PATCH_FUNCTION };
  114. const char* name;
  115. Function function;
  116. private:
  117. HK_DECLARE_NONVIRTUAL_CLASS_ALLOCATOR(HK_MEMORY_CLASS_SERIALIZE, FunctionPatch);
  118. };
  119. /// Set cast to class in patch.
  120. struct CastPatch
  121. {
  122. enum { PATCH_TYPE=PATCH_CAST };
  123. const char* name;
  124. private:
  125. HK_DECLARE_NONVIRTUAL_CLASS_ALLOCATOR(HK_MEMORY_CLASS_SERIALIZE, CastPatch);
  126. };
  127. /// Apply registered patches to the 'world'.
  128. /// The function optionally takes custom class name registry specifying final classes
  129. /// for versioning data in 'world'. By default, the hkBuiltinTypeRegistry is used.
  130. /// This function already calls hkVersionPatchManager::recomputePatchDependencies().
  131. hkResult applyPatches(hkDataWorldDict& world, const hkClassNameRegistry* finalClassesReg = HK_NULL) const;
  132. /// Register individual patch with the version patch manager.
  133. /// The patch dependencies must be recomputed to guarantee proper sequence
  134. /// of patches when applied to classes in a dictionary world.
  135. void addPatch(const PatchInfo* p);
  136. /// Recompute all patch dependencies and set them in proper order,
  137. /// so classes can be updated accordingly.
  138. hkResult recomputePatchDependencies() const;
  139. // Used internally.
  140. hkResult applyPatchesDebug(hkDataWorldDict& world) const;
  141. // Used internally.
  142. // Return all registered patches.
  143. // The order of the patches may not be set according to dependencies,
  144. // you should call hkVersionPatchManager::recomputePatchDependencies()
  145. // to guarantee it.
  146. const hkArray<const PatchInfo*>& getPatches() const;
  147. // Used internally.
  148. // Generate uid, an unique 64-bit value, from class name and version.
  149. hkUint64 getUid( const char* name, hkInt32 ver ) const;
  150. // Used internally.
  151. // Get class name from uid.
  152. const char* getClassName( hkUint64 uid ) const;
  153. // Used internally.
  154. // Get class version from uid.
  155. hkInt32 getClassVersion( hkUint64 uid ) const;
  156. // Used internally.
  157. // Get update patch index from uid, if any.
  158. // Return -1 if no update patch found.
  159. HK_FORCE_INLINE hkInt32 getPatchIndex( hkUint64 uid ) const;
  160. // Used internally.
  161. // Get patch by index.
  162. HK_FORCE_INLINE const PatchInfo* getPatch( hkInt32 patchIndex ) const;
  163. // Used internally.
  164. // Find last registered patch index for given uid.
  165. // The patches should be recomputed before calling this function
  166. // (see hkVersionPatchManager::recomputePatchDependencies() for details).
  167. int findLastPatchIndexForUid(hkUint64 uid, hkBool32 allowRenames = false) const;
  168. private:
  169. class UidFromClassVersion;
  170. UidFromClassVersion* m_uidFromClassVersion;
  171. // all patches
  172. mutable hkArray<const PatchInfo*> m_patchInfos;
  173. mutable hkPointerMap<hkUint64, hkInt32> m_patchIndexFromUid;
  174. private:
  175. hkResult preparePatches(hkDataWorldDict& worldToUpdate, const hkClassNameRegistry& finalClassesReg, hkArray<const PatchInfo*>& patchInfosOut) const;
  176. };
  177. #include <Common/Serialize/Version/hkVersionPatchManager.inl>
  178. #endif // HK_SERIALIZE_PATCH_MANAGER_H
  179. /*
  180. * Havok SDK - NO SOURCE PC DOWNLOAD, BUILD(#20090216)
  181. * Confidential Information of Havok.  (C) Copyright 1999-2009
  182. * Telekinesys Research Limited t/a Havok. All Rights Reserved. The Havok
  183. * Logo, and the Havok buzzsaw logo are trademarks of Havok.  Title, ownership
  184. * rights, and intellectual property rights in the Havok software remain in
  185. * Havok and/or its suppliers.
  186. * Use of this software for evaluation purposes is subject to and indicates
  187. * acceptance of the End User licence Agreement for this product. A copy of
  188. * the license is included with this software and is also available at www.havok.com/tryhavok.
  189. */