1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
|
#include "UnityPrefix.h"
#include "SubstanceArchive.h"
#include "SubstanceSystem.h"
#if UNITY_EDITOR
#include "Editor/Src/AssetPipeline/SubstanceImporter.h"
#include "Editor/Src/AssetPipeline/SubstanceCache.h"
#include "Editor/Src/EditorUserBuildSettings.h"
#endif
using namespace std;
IMPLEMENT_CLASS_HAS_POSTINIT( SubstanceArchive )
IMPLEMENT_OBJECT_SERIALIZE( SubstanceArchive )
SubstanceArchive::SubstanceArchive( MemLabelId label, ObjectCreationMode mode )
: Super( label, mode )
{
#if ENABLE_SUBSTANCE
m_isPushed = false;
m_generatedGraphs.clear();
m_linkedBinaryData.clear();
#endif
}
SubstanceArchive::~SubstanceArchive()
{
#if ENABLE_SUBSTANCE
GetSubstanceSystem().NotifyPackageDestruction(this);
for (std::map< UnityStr, UInt8* >::iterator i=m_linkedBinaryData.begin() ; i != m_linkedBinaryData.end() ; ++i)
{
UNITY_FREE(kMemSubstance, i->second);
}
m_linkedBinaryData.clear();
#endif
}
void SubstanceArchive::AwakeFromLoad( AwakeFromLoadMode awakeMode )
{
Super::AwakeFromLoad( awakeMode );
}
UInt8* SubstanceArchive::GetBufferData ()
{
return &m_PackageData[0];
}
unsigned SubstanceArchive::GetBufferSize ()
{
return m_PackageData.size();
}
#if ENABLE_SUBSTANCE
bool SubstanceArchive::SaveLinkedBinaryData( const UnityStr& prototypeName, const UInt8* data, const int size)
{
if (IsCloneDataAvailable(prototypeName))
{
WarningStringMsg("Trying to save linked substance data to a package that already has it");
return false;
}
UInt8* linkedBinaryData = (UInt8*) UNITY_MALLOC_ALIGNED_NULL(kMemSubstance, size, 32);
if (!linkedBinaryData)
{
WarningStringMsg("Could not allocate memory for a Substance package linked data");
return false;
}
memcpy( (void *) linkedBinaryData, (const void *) data, size);
m_linkedBinaryData[prototypeName] = linkedBinaryData;
return true;
}
UInt8* SubstanceArchive::GetLinkedBinaryData( const UnityStr& prototypeName ) const
{
return (m_linkedBinaryData.find(prototypeName)->second);
}
bool SubstanceArchive::IsCloneDataAvailable( const UnityStr& prototypeName ) const
{
return (m_linkedBinaryData.count(prototypeName) == 1);
}
#endif
#if UNITY_EDITOR
void SubstanceArchive::Init( const UInt8* _pPackage, unsigned int _PackageLength )
{
// Copy the package content
m_PackageData.assign( _pPackage, _pPackage + _PackageLength );
AwakeFromLoad(kDefaultAwakeFromLoad);
}
#endif
template<class T>
void SubstanceArchive::Transfer( T& transfer )
{
Super::Transfer( transfer );
transfer.Transfer( m_PackageData, "m_PackageData" );
transfer.Align();
}
void SubstanceArchive::PostInitializeClass ()
{
#if ENABLE_SUBSTANCE
g_SubstanceSystem = new SubstanceSystem();
#endif
}
void SubstanceArchive::CleanupClass ()
{
#if ENABLE_SUBSTANCE
delete g_SubstanceSystem;
#endif
}
#if ENABLE_SUBSTANCE
SubstanceSystem* SubstanceArchive::g_SubstanceSystem = NULL;
#endif
|