-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathWrappers.h
200 lines (157 loc) · 6.8 KB
/
Wrappers.h
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
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
#pragma once
#include "[BGSEEBase]\Wrappers.h"
namespace cse
{
class TESFormWrapper : public bgsee::FormWrapper
{
protected:
TESForm* WrappedForm;
public:
TESFormWrapper(TESForm* Form);
virtual ~TESFormWrapper();
virtual UInt32 GetFormID(void) const;
virtual const char* GetEditorID(void) const;
virtual UInt8 GetType(void) const;
virtual const char* GetTypeString(void) const;
virtual UInt32 GetFlags(void) const;
virtual bool GetIsDeleted(void) const;
TESForm* GetWrappedForm(void) const;
};
class TESFileWrapper : public bgsee::PluginFileWrapper
{
protected:
TESFile* WrappedPlugin;
std::string PluginPath;
void CreateTempFile(void);
public:
TESFileWrapper();
virtual ~TESFileWrapper();
virtual bool Construct(const char* FileName, bool OverwriteExisting);
virtual void Purge(void);
virtual bool Open(bool ForWriting);
virtual bool SaveHeader(void);
virtual bool CorrectHeader(UInt32 RecordCount);
virtual bool Close(void);
virtual UInt8 GetRecordType(void);
virtual bool GetNextRecord(bool SkipIgnoredRecords);
virtual int GetErrorState(void) const;
virtual const char* GetFileName(void) const;
virtual void Delete(void);
TESFile* GetWrappedPlugin(void) const;
};
class IFormCollectionSerializer : public bgsee::FormCollectionSerializer
{
static const char* kSigilDefaultForm;
static const char* kSigilObjectRef;
protected:
TESFormArrayT LoadedFormBuffer; // stores loaded forms for deferred linking
void FreeBuffer(void);
virtual bool LoadForm(bgsee::PluginFileWrapper* File) = 0; // returns false if an error was encountered
virtual void SaveForm(bgsee::PluginFileWrapper* File, bgsee::FormWrapper* Form);
bool GetFormInBuffer(TESForm* Form) const;
public:
IFormCollectionSerializer();
virtual ~IFormCollectionSerializer();
enum
{
kSerializer_Unknown = 0,
kSerializer_DefaultForm,
kSerializer_ObjectRef,
kSerializer__MAX
};
static UInt8 GetFileSerializerType(bgsee::PluginFileWrapper* File); // returns the type of serializer used to create the file
static void SetFileSerializerType(bgsee::PluginFileWrapper* File, UInt8 Type); // tags the file with the serializer type
virtual UInt8 GetType() = 0;
};
class IFormCollectionInstantiator
{
public:
virtual ~IFormCollectionInstantiator() = 0
{
;//
}
virtual bool Instantiate(IFormCollectionSerializer* Data, bool FreeTempData) = 0; // returns false if an error occurred
};
// creates non-temp copies of the loaded forms and adds them to the datahandler
class DefaultFormCollectionInstantiator : public IFormCollectionInstantiator
{
public:
virtual ~DefaultFormCollectionInstantiator();
virtual bool Instantiate(IFormCollectionSerializer* Data, bool FreeTempData = true);
};
// for non-TESObjectREFR forms
class DefaultFormCollectionSerializer : public IFormCollectionSerializer
{
friend class DefaultFormCollectionInstantiator;
protected:
virtual bool LoadForm(bgsee::PluginFileWrapper* File); // returns false if an error was encountered
public:
virtual ~DefaultFormCollectionSerializer();
virtual bool Serialize(bgsee::FormListT& Forms, bgsee::PluginFileWrapper* OutputStream);
virtual bool Deserialize(bgsee::PluginFileWrapper* InputStream, int& OutDeserializedFormCount);
virtual UInt8 GetType();
};
class ObjectRefCollectionSerializer;
class ObjectRefCollectionInstantiator : public IFormCollectionInstantiator
{
protected:
void GetPositionOffset(TESObjectREFRArrayT& InData, NiNode* CameraNode, Vector3& OutOffset);
TESObject* InstantiateBaseForm(TESObjectREFR* Ref);
public:
virtual ~ObjectRefCollectionInstantiator();
// creates references at the render window camera position
virtual bool Instantiate(IFormCollectionSerializer* Data, bool FreeTempData = true);
// generates 3D data for the loaded refs, returns false on error
// caller takes ownership of the output
bool CreatePreviewNode(ObjectRefCollectionSerializer* Data,
TESPreviewControl* PreviewControl,
TESFormArrayT& OutPreviewBaseForms,
TESObjectREFRArrayT& OutPreviewRefs,
NiNode** OutPreviewNode);
};
// describes a object ref in a collection
struct ObjectRefDescriptor
{
std::string FormID;
std::string EditorID;
std::string Position;
std::string Rotation;
std::string Scale;
std::string BaseFormEditorID;
std::string BaseFormType;
bool TemporaryBaseForm;
bool HasEnableStateParent;
std::string EnableStateParentFormID;
std::string EnableStateParentEditorID;
bool ParentOppositeState;
};
typedef std::shared_ptr<ObjectRefDescriptor> ObjectRefDescriptorHandleT;
typedef std::vector<ObjectRefDescriptorHandleT> ObjectRefCollectionDescriptorArrayT;
// includes a shallow copy of the refs' baseforms (dependencies are ignored)
class ObjectRefCollectionSerializer : public IFormCollectionSerializer
{
friend class ObjectRefCollectionInstantiator;
protected:
typedef std::map<TESObjectREFR*, TESObjectREFR*> RefParentTableT;
typedef std::map<TESObjectREFR*, bool> RefParentStateTableT;
TESFormArrayT BaseFormDeserializatonBuffer;
RefParentTableT ParentDeserializationBuffer; // maps (loaded) refs to their parents
RefParentStateTableT ParentStateDeserializationBuffer; // maps (loaded) refs to their ESP opposite state
bool StrictBaseFormResolution; // if true, loaded refs' baseforms must resolve to an existing form; if not, they are discarded
// if false, loaded refs are allowed dependencies on the deserialized baseforms; new baseform instances must be created and linked during the instantiation
virtual bool LoadForm(bgsee::PluginFileWrapper* File);
void FreeDeserializationBuffers();
bool IsBaseFormTemporary(TESForm* Form) const; // returns true if the form is found in the deserialization buffer
bool IsBaseFormTemporary(UInt32 FormID) const;
bool ResolveBaseForms(); // returns false if the resolution wasn't successful
ObjectRefDescriptor* GetDescriptor(TESForm* Form) const;
public:
ObjectRefCollectionSerializer(bool StrictBaseFormResolution);
virtual ~ObjectRefCollectionSerializer();
virtual bool Serialize(bgsee::FormListT& Forms, bgsee::PluginFileWrapper* OutputStream);
virtual bool Deserialize(bgsee::PluginFileWrapper* InputStream, int& OutDeserializedFormCount);
virtual UInt8 GetType();
bool GetHasTemporaryBaseForms() const; // returns true if any of the loaded refs are dependent on a temp baseform
void GetDescription(ObjectRefCollectionDescriptorArrayT& Out) const;
};
}