datamap object passed around while loading
[laserbrain_demo] / src / scene.h
1 #ifndef SCENE_H_
2 #define SCENE_H_
3
4 #include <vector>
5 #include <list>
6 #include "mesh.h"
7 #include "snode.h"
8 #include "texture.h"
9 #include "dataset.h"
10 #include "datamap.h"
11
12 enum {
13         SCNLOAD_FLIPYZ = 1,
14         SCNLOAD_FLIPTEX = 2,
15
16         SCNLOAD_STAGE_IO = 0x4000,
17         SCNLOAD_STAGE_GL = 0x8000
18 };
19
20 class MetaScene;
21
22 class Scene {
23 private:
24         bool own_texset;
25
26 public:
27         MetaScene *metascn;
28         DataMap datamap;
29
30         // meshes objects and nodes are owned by Scene
31         std::vector<Mesh*> meshes;
32         std::vector<Object*> objects;
33         SceneNode *nodes;
34
35         Mesh *walk_mesh;
36
37         TextureSet *texset;     // only owned by Scene if own_texset is true
38         void *loader_data;
39
40         explicit Scene(TextureSet *tset = 0);
41         ~Scene();
42
43         Scene(const Scene &rhs) = delete;
44         Scene &operator =(const Scene &rhs) = delete;
45
46         void destroy();
47
48         bool load(const char *fname, unsigned int flags = 0);
49
50         // merge scn into this scene, leaving scn empty and safe to destroy
51         bool merge(Scene *scn);
52
53         void add_object(Object *obj);
54         bool remove_object(Object *obj);
55         bool have_object(Object *obj) const;
56
57         void add_mesh(Mesh *m);
58         bool remove_mesh(Mesh *m);
59         bool have_mesh(Mesh *m) const;
60
61         void add_node(SceneNode *n);
62         bool remove_node(SceneNode *n);
63         bool have_node(SceneNode *n) const;
64
65         /* find and remove all nodes whose names match the regexp
66          * XXX at the moment this has the effect of flattening the hierarchy in the
67          * result scene. If we ever need verbatim extraction of whole subtrees we'll
68          * need to change the algorithm.
69          */
70         Scene *extract_nodes(const char *qstr);
71
72         /* bake all node transformations to their respective meshes and make the
73          * node transformations identity.
74          * XXX this assumes no mesh is shared by two nodes.
75          */
76         void apply_xform();
77
78         void update(float dt);
79         void draw() const;
80 };
81
82 class SceneSet : public DataSet<Scene*> {
83 private:
84         static Scene *create_scene();
85         static bool load_scene(Scene *scn, const char *fname);
86         static bool done_scene(Scene *scn);
87         static void free_scene(Scene *scn);
88
89 public:
90         SceneSet();
91 };
92
93 #endif  // SCENE_H_