Plasma Engine  2.0
Loading...
Searching...
No Matches
GraphVersioning.h
1#pragma once
2
4
5#include <Foundation/Algorithm/HashingUtils.h>
6#include <Foundation/Basics.h>
7#include <Foundation/Configuration/Singleton.h>
8#include <Foundation/Configuration/Startup.h>
9#include <Foundation/Containers/HashTable.h>
10#include <Foundation/Reflection/Reflection.h>
11#include <Foundation/Serialization/GraphPatch.h>
12#include <Foundation/Strings/HashedString.h>
13
14class plRTTI;
17class plGraphPatch;
20
23{
24 plVersionKey() = default;
25 plVersionKey(plStringView sType, plUInt32 uiTypeVersion)
26 {
27 m_sType.Assign(sType);
28 m_uiTypeVersion = uiTypeVersion;
29 }
30 PL_DECLARE_POD_TYPE();
31 plHashedString m_sType;
32 plUInt32 m_uiTypeVersion;
33};
34
37{
38 PL_FORCE_INLINE static plUInt32 Hash(const plVersionKey& a)
39 {
40 auto typeNameHash = a.m_sType.GetHash();
41 plUInt32 uiHash = plHashingUtils::xxHash32(&typeNameHash, sizeof(typeNameHash));
42 uiHash = plHashingUtils::xxHash32(&a.m_uiTypeVersion, sizeof(a.m_uiTypeVersion), uiHash);
43 return uiHash;
44 }
45
46 PL_ALWAYS_INLINE static bool Equal(const plVersionKey& a, const plVersionKey& b)
47 {
48 return a.m_sType == b.m_sType && a.m_uiTypeVersion == b.m_uiTypeVersion;
49 }
50};
51
53struct PL_FOUNDATION_DLL plTypeVersionInfo
54{
55 const char* GetTypeName() const;
56 void SetTypeName(const char* szName);
57 const char* GetParentTypeName() const;
58 void SetParentTypeName(const char* szName);
59
60 plHashedString m_sTypeName;
61 plHashedString m_sParentTypeName;
62 plUInt32 m_uiTypeVersion;
63};
64PL_DECLARE_REFLECTABLE_TYPE(PL_FOUNDATION_DLL, plTypeVersionInfo);
65
68class PL_FOUNDATION_DLL plGraphPatchContext
69{
70public:
75 void PatchBaseClass(const char* szType, plUInt32 uiTypeVersion, bool bForcePatch = false); // [tested]
76
78 void RenameClass(const char* szTypeName); // [tested]
79
81 void RenameClass(const char* szTypeName, plUInt32 uiVersion);
82
84 void ChangeBaseClass(plArrayPtr<plVersionKey> baseClasses); // [tested]
85
86private:
87 friend class plGraphVersioning;
89 void Patch(plAbstractObjectNode* pNode);
90 void Patch(plUInt32 uiBaseClassIndex, plUInt32 uiTypeVersion, bool bForcePatch);
91 void UpdateBaseClasses();
92
93private:
94 plGraphVersioning* m_pParent = nullptr;
95 plAbstractObjectGraph* m_pGraph = nullptr;
96 plAbstractObjectNode* m_pNode = nullptr;
97 plDynamicArray<plVersionKey> m_BaseClasses;
98 plUInt32 m_uiBaseClassIndex = 0;
100};
101
105class PL_FOUNDATION_DLL plGraphVersioning
106{
107 PL_DECLARE_SINGLETON(plGraphVersioning);
108
109public:
112
115 void PatchGraph(plAbstractObjectGraph* pGraph, plAbstractObjectGraph* pTypesGraph = nullptr);
116
117private:
118 friend class plGraphPatchContext;
119
120 PL_MAKE_SUBSYSTEM_STARTUP_FRIEND(Foundation, GraphVersioning);
121
122 void PluginEventHandler(const plPluginEvent& EventData);
123 void UpdatePatches();
124 plUInt32 GetMaxPatchVersion(const plHashedString& sType) const;
125
126 plHashTable<plHashedString, plUInt32> m_MaxPatchVersion;
129};
Definition AbstractObjectGraph.h:115
Definition AbstractObjectGraph.h:17
This class encapsulates an array and it's size. It is recommended to use this class instead of plain ...
Definition ArrayPtr.h:37
Definition DynamicArray.h:81
Handles the patching of a node. Is passed into the patch classes to provide utility functions and tra...
Definition GraphVersioning.h:69
Patch base class for plAbstractObjectGraph patches.
Definition GraphPatch.h:20
Singleton that allows version patching of plAbstractObjectGraph.
Definition GraphVersioning.h:106
Definition HashTable.h:333
This class is optimized to take nearly no memory (sizeof(void*)) and to allow very fast checks whethe...
Definition HashedString.h:25
void Assign(const char(&string)[N])
Assigning a new string from a string constant is a slow operation, but the hash computation can happe...
plUInt64 GetHash() const
Returns the hash of the stored string.
Definition HashedString_inl.h:115
static plUInt32 xxHash32(const void *pKey, size_t uiSizeInByte, plUInt32 uiSeed=0)
Calculates the 32bit xxHash of the given key.
Definition HashingUtils.cpp:209
This class holds information about reflected types. Each instance represents one type that is known t...
Definition RTTI.h:30
plStringView represent a read-only sub-string of a larger string, as it can store a dedicated string ...
Definition StringView.h:34
Hash helper class for plVersionKey.
Definition GraphVersioning.h:37
The data that is broadcast whenever a plugin is (un-) loaded.
Definition Plugin.h:11
A class that overlaps plReflectedTypeDescriptor with the properties needed for patching.
Definition GraphVersioning.h:54
Tuple used for identifying patches and tracking patch progression.
Definition GraphVersioning.h:23