vsg  1.1.0
VulkanSceneGraph library
PagedLOD.h
1 #pragma once
2 
3 /* <editor-fold desc="MIT License">
4 
5 Copyright(c) 2018 Robert Osfield
6 
7 Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
8 
9 The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
10 
11 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
12 
13 </editor-fold> */
14 
15 #include <vsg/io/FileSystem.h>
16 #include <vsg/io/Options.h>
17 #include <vsg/nodes/Node.h>
18 #include <vsg/vk/Semaphore.h>
19 
20 #include <array>
21 
22 namespace vsg
23 {
24 
25  // forward declare
26  class PagedLODList;
27 
35  class VSG_DECLSPEC PagedLOD : public Inherit<Node, PagedLOD>
36  {
37  public:
38  PagedLOD();
39 
40  template<class N, class V>
41  static void t_traverse(N& node, V& visitor)
42  {
43  for (auto& child : node.children)
44  {
45  if (child.node) child.node->accept(visitor);
46  }
47  }
48 
49  void traverse(Visitor& visitor) override { t_traverse(*this, visitor); }
50  void traverse(ConstVisitor& visitor) const override { t_traverse(*this, visitor); }
51  void traverse(RecordTraversal& visitor) const override { t_traverse(*this, visitor); }
52 
53  int compare(const Object& rhs) const override;
54 
55  void read(Input& input) override;
56  void write(Output& output) const override;
57 
58  struct Child
59  {
60  double minimumScreenHeightRatio = 0.0; // 0.0 is always visible
61  ref_ptr<Node> node;
62  };
63 
64  // external file to load when child 0 is null.
65  Path filename;
66 
67  dsphere bound;
68 
69  using Children = std::array<Child, 2>;
70  Children children;
71 
72  bool highResActive(uint64_t frameCount, uint64_t inactiveAge = 3) const
73  {
74  return (frameCount - frameHighResLastUsed.load()) <= inactiveAge;
75  }
76 
77  protected:
78  virtual ~PagedLOD();
79 
80  public:
81  ref_ptr<Options> options;
82 
83  // priority value assigned by record traversal as a guide to how important the external child is for loading.
84  mutable std::atomic<double> priority{0.0};
85 
86  mutable std::atomic_uint64_t frameHighResLastUsed{0};
87  mutable std::atomic_uint requestCount{0};
88 
89  enum RequestStatus : unsigned int
90  {
91  NoRequest = 0,
92  ReadRequest = 1,
93  Reading = 2,
94  Compiling = 3,
95  MergeRequest = 4,
96  Merging = 5,
97  DeleteRequest = 6,
98  Deleting = 7
99  };
100 
101  mutable std::atomic<RequestStatus> requestStatus{NoRequest};
102  mutable uint32_t index = 0;
103 
104  ref_ptr<Node> pending;
105  };
106  VSG_type_name(vsg::PagedLOD);
107 
108  struct PagedLODContainer : public Inherit<Object, PagedLODContainer>
109  {
110  PagedLODContainer(uint32_t maxNumPagedLOD = 10000);
111 
112  struct List
113  {
114  uint32_t head = 0;
115  uint32_t tail = 0;
116  uint32_t count = 0;
117  std::string name;
118  };
119 
120  struct Element
121  {
122  uint32_t previous = 0;
123  uint32_t next = 0;
124  ref_ptr<PagedLOD> plod;
125  List* list = nullptr;
126  };
127 
128  using Elements = std::vector<Element>;
129 
130  Elements elements;
131  List availableList;
132  List inactiveList;
133  List activeList;
134 
135  void resize(uint32_t new_size);
136  void resize();
137  void inactive(const PagedLOD* plod);
138  void active(const PagedLOD* plod);
139  void remove(PagedLOD* plod);
140 
141  void _move(const PagedLOD* plod, List* targetList);
142 
143  bool check();
144  bool check(const List& list);
145 
146  void print(std::ostream& out);
147  };
148 
149 } // namespace vsg
Definition: ConstVisitor.h:147
Definition: Inherit.h:28
Definition: Input.h:44
Definition: Object.h:42
Definition: Output.h:41
Definition: PagedLOD.h:36
int compare(const Object &rhs) const override
compare two objects, return -1 if this object is less than rhs, return 0 if it's equal,...
Definition: Path.h:32
RecordTraversal traverses a scene graph doing view frustum culling and invoking state/commands to rec...
Definition: RecordTraversal.h:61
Definition: Visitor.h:147
Definition: ref_ptr.h:22
Definition: PagedLOD.h:121
Definition: PagedLOD.h:113
Definition: PagedLOD.h:109
Definition: PagedLOD.h:59