]> git.tdb.fi Git - libs/gltk.git/blob - source/partcache.h
Make sure classes follow the rule of 0/3/5
[libs/gltk.git] / source / partcache.h
1 #ifndef MSP_GLTK_PARTCACHE_H_
2 #define MSP_GLTK_PARTCACHE_H_
3
4 #include <msp/gl/mesh.h>
5 #include <msp/gl/texture2d.h>
6 #include "mspgltk_api.h"
7
8 namespace Msp {
9 namespace GLtk {
10
11 class Part;
12
13 struct CachedPart
14 {
15         const Part *part = nullptr;
16         const GL::Texture2D *texture = nullptr;
17         GL::Mesh *mesh = nullptr;
18
19         CachedPart() = default;
20         CachedPart(CachedPart &&);
21         CachedPart &operator=(CachedPart &&);
22         ~CachedPart();
23 };
24
25 class MSPGLTK_API PartCache
26 {
27 public:
28         class Rebuild
29         {
30         private:
31                 PartCache &cache;
32
33         public:
34                 Rebuild(PartCache &c): cache(c) { cache.begin_rebuild(); }
35                 ~Rebuild() { cache.end_rebuild(); }
36         };
37
38         typedef std::list<CachedPart> PartList;
39
40 private:
41         bool rebuilding = false;
42         PartList parts;
43         PartList::iterator next;
44         PartList::iterator current;
45
46 public:
47         void begin_rebuild();
48         void insert_special(const Part &);
49         GL::Mesh &create_mesh(const Part &, const GL::Texture2D &);
50         void end_rebuild();
51
52         const PartList &get_parts() const { return parts; }
53 };
54
55 } // namespace GLtk
56 } // namespace Msp
57
58 #endif