Linux multi-monitor fullscreen support
[ryzomcore.git] / nel / tools / 3d / pipeline_max / builtin / reference_maker.cpp
blob4b684d543f92134566d0a027385e221bc363b6eb
1 /**
2 * \file reference_maker.cpp
3 * \brief CReferenceMaker
4 * \date 2012-08-22 08:52GMT
5 * \author Jan Boon (Kaetemi)
6 * CReferenceMaker
7 */
9 /*
10 * Copyright (C) 2012 by authors
12 * This file is part of RYZOM CORE PIPELINE.
13 * RYZOM CORE PIPELINE is free software: you can redistribute it
14 * and/or modify it under the terms of the GNU Affero General Public
15 * License as published by the Free Software Foundation, either
16 * version 3 of the License, or (at your option) any later version.
18 * RYZOM CORE PIPELINE is distributed in the hope that it will be
19 * useful, but WITHOUT ANY WARRANTY; without even the implied warranty
20 * of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Affero General Public License for more details.
23 * You should have received a copy of the GNU Affero General Public
24 * License along with RYZOM CORE PIPELINE. If not, see
25 * <http://www.gnu.org/licenses/>.
28 #include <nel/misc/types_nl.h>
29 #include "reference_maker.h"
31 // STL includes
32 #include <iomanip>
34 // NeL includes
35 // #include <nel/misc/debug.h>
37 // Project includes
39 using namespace std;
40 // using namespace NLMISC;
42 namespace PIPELINE {
43 namespace MAX {
44 namespace BUILTIN {
46 ////////////////////////////////////////////////////////////////////////
47 ////////////////////////////////////////////////////////////////////////
48 ////////////////////////////////////////////////////////////////////////
50 // Elevate warnings to errors in this file for stricter reading
51 #undef nlwarning
52 #define nlwarning nlerror
54 // Elevate debug to error in this file for debugging
55 // #undef nldebug
56 // #define nldebug nlerror
58 // Chunk identifiers
59 #define PMB_REFERENCES_2034_CHUNK_ID 0x2034
60 #define PMB_REFERENCES_2035_CHUNK_ID 0x2035
61 #define PMB_204B_EQUALS_2E_CHUNK_ID 0x204B
62 #define PMB_UNKNOWN2045_CHUNK_ID 0x2045
63 #define PMB_UNKNOWN2047_CHUNK_ID 0x2047
64 #define PMB_UNKNOWN21B0_CHUNK_ID 0x21B0
66 ////////////////////////////////////////////////////////////////////////
67 ////////////////////////////////////////////////////////////////////////
68 ////////////////////////////////////////////////////////////////////////
70 CReferenceMaker::CReferenceMaker(CScene *scene) : CAnimatable(scene), m_ReferenceMap(false), m_204B_Equals_2E(NULL), m_References2035Value0(0), m_Unknown2045(NULL), m_Unknown2047(NULL), m_Unknown21B0(NULL)
75 CReferenceMaker::~CReferenceMaker()
77 if (!m_ChunksOwnsPointers)
79 delete m_204B_Equals_2E;
80 m_204B_Equals_2E = NULL;
81 delete m_Unknown2045;
82 m_Unknown2045 = NULL;
83 delete m_Unknown2047;
84 m_Unknown2047 = NULL;
85 delete m_Unknown21B0;
86 m_Unknown21B0 = NULL;
90 const ucstring CReferenceMaker::DisplayName = ucstring("ReferenceMaker");
91 const char *CReferenceMaker::InternalName = "ReferenceMaker";
92 const char *CReferenceMaker::InternalNameUnknown = "ReferenceMakerUnknown";
93 const NLMISC::CClassId CReferenceMaker::ClassId = NLMISC::CClassId(0x2ec43d15, 0x10a270ad); /* Not official, please correct */
94 const TSClassId CReferenceMaker::SuperClassId = 0x00000100;
95 const CReferenceMakerClassDesc ReferenceMakerClassDesc(&DllPluginDescBuiltin);
96 const CReferenceMakerSuperClassDesc ReferenceMakerSuperClassDesc(&ReferenceMakerClassDesc);
98 void CReferenceMaker::parse(uint16 version, uint filter)
100 CAnimatable::parse(version);
101 if (!m_ChunksOwnsPointers)
103 CStorageArray<sint32> *references2034 = static_cast<CStorageArray<sint32> *>(getChunk(PMB_REFERENCES_2034_CHUNK_ID));
104 CStorageArray<sint32> *references2035 = static_cast<CStorageArray<sint32> *>(getChunk(PMB_REFERENCES_2035_CHUNK_ID));
105 if (references2034) nlassert(references2035 == NULL); // Apparently, there can be only one.
106 if (references2035) nlassert(references2034 == NULL);
107 m_204B_Equals_2E = static_cast<CStorageValue<uint8> *>(getChunk(PMB_204B_EQUALS_2E_CHUNK_ID));
108 if (m_204B_Equals_2E) nlassert(m_204B_Equals_2E->Value == 0x2e); // Really, let me know when it has another value.
110 // Parse contents
111 if (references2034)
113 m_ReferenceMap = false; // NOTE: Plugins may check after parse if they parsed with the correct type, to find a pattern
114 m_ArchivedChunks.push_back(references2034);
115 for (std::vector<sint32>::size_type i = 0; i < references2034->Value.size(); ++i)
117 if (references2034->Value[i] > 0)
119 CReferenceMaker *referenceMaker = dynamic_cast<CReferenceMaker *>(container()->getByStorageIndex(references2034->Value[i]));
120 if (!referenceMaker) nlerror("Reference maker %s %s, 0x%x is not a reference maker", ucstring(container()->getByStorageIndex(references2034->Value[i])->classDesc()->displayName()).toUtf8().c_str(), container()->getByStorageIndex(references2034->Value[i])->classDesc()->classId().toString().c_str(), container()->getByStorageIndex(references2034->Value[i])->classDesc()->superClassId());
121 setReference(i, referenceMaker);
125 if (references2035)
127 m_ReferenceMap = true;
128 m_ArchivedChunks.push_back(references2035);
129 std::vector<sint32>::iterator it = references2035->Value.begin();
130 m_References2035Value0 = (*it);
131 ++it;
132 std::vector<sint32>::iterator end = references2035->Value.end();
133 while (it != end)
135 sint32 index = (*it);
136 ++it;
137 sint32 referenceindex = (*it);
138 ++it;
139 CReferenceMaker *referenceMaker = dynamic_cast<CReferenceMaker *>(container()->getByStorageIndex(referenceindex));
140 if (!referenceMaker) nlerror("Reference maker %s, 0x%x is not a reference maker", container()->getByStorageIndex(referenceindex)->classDesc()->classId().toString().c_str(), container()->getByStorageIndex(referenceindex)->classDesc()->superClassId());
141 setReference(index, referenceMaker);
145 m_Unknown2045 = static_cast<CStorageRaw *>(getChunk(PMB_UNKNOWN2045_CHUNK_ID)); // not sure if this is part of maker or target
146 m_Unknown2047 = static_cast<CStorageRaw *>(getChunk(PMB_UNKNOWN2047_CHUNK_ID)); // not sure if this is part of maker or target
147 m_Unknown21B0 = static_cast<CStorageRaw *>(getChunk(PMB_UNKNOWN21B0_CHUNK_ID)); // not sure if this is part of maker or target
151 void CReferenceMaker::clean()
153 CAnimatable::clean(); // Nothing to do here, m_ArchivedChunks is cleaned (deleted) for us!
156 void CReferenceMaker::build(uint16 version, uint filter)
158 CAnimatable::build(version);
159 // TODO: Build contents
160 //if (m_References2034) putChunk(PMB_REFERENCES_2034_CHUNK_ID, m_References2034);
161 //if (m_References2035) putChunk(PMB_REFERENCES_2035_CHUNK_ID, m_References2035);
162 if (!m_ReferenceMap)
164 CStorageArray<sint32> *references2034 = new CStorageArray<sint32>();
165 uint nb = nbReferences();
166 references2034->Value.resize(nb);
167 for (uint i = 0; i < nb; ++i)
169 CReferenceMaker *referenceMaker = getReference(i);
170 if (referenceMaker) references2034->Value[i] = container()->getOrCreateStorageIndex(referenceMaker);
171 else references2034->Value[i] = -1;
173 putChunk(PMB_REFERENCES_2034_CHUNK_ID, references2034);
174 m_ArchivedChunks.push_back(references2034);
176 else
178 CStorageArray<sint32> *references2035 = new CStorageArray<sint32>();
179 uint nb = nbReferences();
180 references2035->Value.push_back(m_References2035Value0);
181 for (uint i = 0; i < nb; ++i)
183 CReferenceMaker *referenceMaker = getReference(i);
184 if (referenceMaker)
186 references2035->Value.push_back(i);
187 references2035->Value.push_back(container()->getOrCreateStorageIndex(referenceMaker));
190 putChunk(PMB_REFERENCES_2035_CHUNK_ID, references2035);
191 m_ArchivedChunks.push_back(references2035);
193 if (m_204B_Equals_2E) putChunk(PMB_204B_EQUALS_2E_CHUNK_ID, m_204B_Equals_2E);
194 if (m_Unknown2045) putChunk(PMB_UNKNOWN2045_CHUNK_ID, m_Unknown2045);
195 if (m_Unknown2047) putChunk(PMB_UNKNOWN2047_CHUNK_ID, m_Unknown2047);
196 if (m_Unknown21B0) putChunk(PMB_UNKNOWN21B0_CHUNK_ID, m_Unknown21B0);
199 void CReferenceMaker::disown()
201 m_References.clear();
202 m_ReferenceMap = false;
203 m_References2035Value0 = 0;
204 m_204B_Equals_2E = NULL;
205 m_Unknown2045 = NULL;
206 m_Unknown2047 = NULL;
207 m_Unknown21B0 = NULL;
208 CAnimatable::disown();
211 void CReferenceMaker::init()
213 CAnimatable::init();
216 bool CReferenceMaker::inherits(const NLMISC::CClassId classId) const
218 if (classId == classDesc()->classId()) return true;
219 return CAnimatable::inherits(classId);
222 const ISceneClassDesc *CReferenceMaker::classDesc() const
224 return &ReferenceMakerClassDesc;
227 void CReferenceMaker::toStringLocal(std::ostream &ostream, const std::string &pad, uint filter) const
229 CAnimatable::toStringLocal(ostream, pad);
230 uint nb = nbReferences();
231 if (nb)
233 if (!m_ReferenceMap) ostream << "\n" << pad << "References 0x2034: ";
234 else ostream << "\n" << pad << "References 0x2035: ";
235 std::string padpad = pad + "\t";
236 ostream << "PARSED ";
237 if (!m_References.size()) ostream << "VIRTUAL ";
238 ostream << "{ ";
239 for (uint i = 0; i < nb; ++i)
241 CReferenceMaker *referenceMaker = getReference(i);
242 if (referenceMaker)
244 ostream << "\n" << padpad << i << ": <ptr=0x";
246 std::stringstream ss;
247 ss << std::hex << std::setfill('0');
248 ss << std::setw(16) << (uint64)(void *)referenceMaker;
249 ostream << ss.str();
251 ostream << "> ";
252 ostream << "(" << ucstring(referenceMaker->classDesc()->displayName()).toUtf8() << ", " << referenceMaker->classDesc()->classId().toString() << ") ";
255 ostream << "} ";
257 if (m_204B_Equals_2E)
259 ostream << "\n" << pad << "0x204B Equals 0x2E (46): ";
260 m_204B_Equals_2E->toString(ostream, pad + "\t");
262 if (m_Unknown2045)
264 ostream << "\n" << pad << "Unknown 0x2045: ";
265 m_Unknown2045->toString(ostream, pad + "\t");
267 if (m_Unknown2047)
269 ostream << "\n" << pad << "Unknown 0x2047: ";
270 m_Unknown2047->toString(ostream, pad + "\t");
272 if (m_Unknown21B0)
274 ostream << "\n" << pad << "Unknown 0x21B0: ";
275 m_Unknown21B0->toString(ostream, pad + "\t");
279 CReferenceMaker *CReferenceMaker::getReference(uint index) const
281 if (m_References.size() <= index) return NULL;
282 return m_References[index];
285 void CReferenceMaker::setReference(uint index, CReferenceMaker *reference)
287 if (m_References.size() <= index) m_References.resize(index + 1);
288 m_References[index] = reference;
291 uint CReferenceMaker::nbReferences() const
293 return m_References.size();
296 IStorageObject *CReferenceMaker::createChunkById(uint16 id, bool container)
298 switch (id)
300 case PMB_REFERENCES_2034_CHUNK_ID:
301 return new CStorageArray<sint32>();
302 case PMB_REFERENCES_2035_CHUNK_ID:
303 return new CStorageArray<sint32>();
304 case PMB_204B_EQUALS_2E_CHUNK_ID:
305 return new CStorageValue<uint8>();
306 case PMB_UNKNOWN21B0_CHUNK_ID:
307 return new CStorageRaw();
309 return CAnimatable::createChunkById(id, container);
312 ////////////////////////////////////////////////////////////////////////
313 ////////////////////////////////////////////////////////////////////////
314 ////////////////////////////////////////////////////////////////////////
316 } /* namespace BUILTIN */
317 } /* namespace MAX */
318 } /* namespace PIPELINE */
320 /* end of file */