1 #include <msp/datafile/collection.h>
2 #include <msp/fs/utils.h>
3 #include <msp/strings/format.h>
5 #include "instancearray.h"
6 #include "objectinstance.h"
7 #include "occludedscene.h"
8 #include "orderedscene.h"
11 #include "simplescene.h"
12 #include "zsortedscene.h"
19 Scene::GenericLoader::TypeRegistry &Scene::get_scene_registry()
21 static Scene::GenericLoader::TypeRegistry registry;
22 static bool initialized = false;
26 register_type<SimpleScene>("simple");
27 register_type<ZSortedScene>("zsorted");
28 register_type<OrderedScene>("ordered");
29 register_type<OccludedScene>("occluded");
35 unsigned Scene::Loader::inline_counter = 0;
37 Scene::Loader::Loader(Scene &s, Collection &c, ContentMap *m):
38 DataFile::CollectionObjectLoader<Scene>(s, &c),
41 add("array", &Loader::array);
42 add("object", &Loader::object);
43 add("object", &Loader::object_tagged);
44 add("scene", &Loader::scene);
45 add("scene", &Loader::scene_inline);
48 void Scene::Loader::array(const string &n)
50 RefPtr<InstanceArray<> > arr = new InstanceArray<>(get_collection().get<GL::Object>(n));
52 get_collection().add(format("_scene_array_%d.array", ++inline_counter), arr.get());
53 obj.add(*arr.release());
56 void Scene::Loader::object(const string &n)
58 object_tagged(n, string());
61 void Scene::Loader::object_tagged(const string &n, const string &t)
63 RefPtr<ObjectInstance> inst = new ObjectInstance(get_collection().get<GL::Object>(n));
65 get_collection().add(format("_scene_object_%d.inst", ++inline_counter), inst.get());
66 if(content && !t.empty())
67 (*content)[t] = inst.get();
68 obj.add(*inst.release());
71 void Scene::Loader::scene(const string &n)
73 obj.add(get_collection().get<Scene>(n));
76 void Scene::Loader::scene_inline()
78 GenericLoader ldr(get_collection());
80 Scene *scene = ldr.store_object(get_collection(), format("_scene_%d.scene", ++inline_counter));