]> git.localhorst.tv Git - l2e.git/blobdiff - src/loader/Loader.cpp
initialize objects after loading
[l2e.git] / src / loader / Loader.cpp
index dbfbe3186fdd93e8a508110c082753197778cc3c..961ec7cff6d315dec5537338fe08ba8cfc0b9450 100644 (file)
@@ -61,6 +61,13 @@ void Loader::Load(const std::string &filePath) {
                LoadImages(header->ident,
                                header->ImagesBegin(),
                                header->ImagesEnd());
+
+               InitObjects(
+                               header->ObjectsBegin(),
+                               header->ObjectsEnd());
+               InitArrays(
+                               header->ArraysBegin(),
+                               header->ArraysEnd());
        } catch (...) {
                delete[] block;
                throw;
@@ -159,4 +166,42 @@ void Loader::LoadArrays(char *src, Array *begin, Array *end) {
        }
 }
 
+
+void Loader::InitObjects(Object *begin, Object *end) {
+       for (Object *i = begin; i < end; i = i->Next()) {
+               const TypeDescription &td =
+                               TypeDescription::Get(i->typeId);
+               InitObject(i->RawObject(), td);
+       }
+}
+
+void Loader::InitObject(char *object, const TypeDescription &td) {
+       td.Init(object);
+       td.Load(object);
+       for (TypeDescription::FieldIterator
+                       i(td.FieldsBegin()), end(td.FieldsEnd());
+                       i != end; ++i) {
+               const FieldDescription &field = i->second;
+               if (field.IsReferenced() || field.IsAggregate()) {
+                       continue;
+               }
+               const TypeDescription &nestedType
+                               = TypeDescription::Get(field.TypeId());
+               InitObject(object + field.Offset(), nestedType);
+       }
+}
+
+void Loader::InitArrays(Array *begin, Array *end) {
+       for (Array *i = begin; i < end; i = i->Next()) {
+               if (i->ref) {
+                       continue;
+               }
+               const TypeDescription &td = TypeDescription::Get(i->typeId);
+               for (char *j = i->Data(), *end = i->Data() + i->size;
+                               j < end; j += td.Size()) {
+                       InitObject(j, td);
+               }
+       }
+}
+
 }