backported changes from museum project
[ld37_one_room] / 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 public:
24         MetaScene *metascn;
25         DataMap datamap;
26
27         // meshes objects and nodes are owned by Scene
28         std::vector<Mesh*> meshes;
29         std::vector<Object*> objects;
30         SceneNode *nodes;
31
32         Mesh *walk_mesh;
33
34         TextureSet *texset;
35         void *loader_data;
36
37         explicit Scene();
38         ~Scene();
39
40         Scene(const Scene &rhs) = delete;
41         Scene &operator =(const Scene &rhs) = delete;
42
43         void destroy();
44         void clear();   // clear all contents (meshes, objects, and nodes)
45
46         bool load(const char *fname, unsigned int flags = 0);
47
48         // merge scn into this scene, leaving scn empty and safe to destroy
49         bool merge(Scene *scn);
50
51         void add_object(Object *obj);
52         bool remove_object(Object *obj);
53         bool have_object(Object *obj) const;
54
55         void add_mesh(Mesh *m);
56         bool remove_mesh(Mesh *m);
57         bool have_mesh(Mesh *m) const;
58
59         void add_node(SceneNode *n);
60         bool remove_node(SceneNode *n);
61         bool have_node(SceneNode *n) const;
62
63         /* find and remove all nodes whose names match the regexp
64          * XXX at the moment this has the effect of flattening the hierarchy in the
65          * result scene. If we ever need verbatim extraction of whole subtrees we'll
66          * need to change the algorithm.
67          */
68         Scene *extract_nodes(const char *qstr);
69
70         /* bake all node transformations to their respective meshes and make the
71          * node transformations identity.
72          * XXX this assumes no mesh is shared by two nodes.
73          */
74         void apply_xform();
75
76         void update(float dt);
77         void draw() const;
78 };
79
80 class SceneSet : public DataSet<Scene*> {
81 private:
82         static Scene *create_scene();
83         static bool load_scene(Scene *scn, const char *fname);
84         static bool done_scene(Scene *scn);
85         static void free_scene(Scene *scn);
86
87 public:
88         SceneSet();
89 };
90
91 #endif  // SCENE_H_