vsg: include/vsg/nodes/PagedLOD.h Source File

vsg 1.1.13 VulkanSceneGraph library

Loading...
Searching...
No Matches
PagedLOD.h
1#pragma once
2
3/* <editor-fold desc="MIT License">
4
5Copyright(c) 2018 Robert Osfield
6
7Permission 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
9The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
10
11THE 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
22namespace 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 PagedLOD(const PagedLOD& rhs, const CopyOp& copyop = {});
40
41 struct Child
42 {
43 double minimumScreenHeightRatio = 0.0; // 0.0 is always visible
44 ref_ptr<Node> node;
45 };
46
47 // external file to load when child 0 is null.
48 Path filename;
49
50 dsphere bound;
51
52 using Children = std::array<Child, 2>;
53 Children children;
54
55 bool highResActive(uint64_t frameCount, uint64_t inactiveAge = 3) const
56 {
57 return (frameCount - frameHighResLastUsed.load()) <= inactiveAge;
58 }
59
60 public:
61 ref_ptr<Object> clone(const CopyOp& copyop = {}) const override { return PagedLOD::create(*this, copyop); }
62 int compare(const Object& rhs) const override;
63
64 template<class N, class V>
65 static void t_traverse(N& node, V& visitor)
66 {
67 for (auto& child : node.children)
68 {
69 if (child.node) child.node->accept(visitor);
70 }
71 }
72
73 void traverse(Visitor& visitor) override { t_traverse(*this, visitor); }
74 void traverse(ConstVisitor& visitor) const override { t_traverse(*this, visitor); }
75 void traverse(RecordTraversal& visitor) const override { t_traverse(*this, visitor); }
76
77 void read(Input& input) override;
78 void write(Output& output) const override;
79
80 protected:
81 virtual ~PagedLOD();
82
83 public:
84 ref_ptr<Options> options;
85
86 // priority value assigned by record traversal as a guide to how important the external child is for loading.
87 mutable std::atomic<double> priority{0.0};
88
89 mutable std::atomic_uint64_t frameHighResLastUsed{0};
90 mutable std::atomic_uint requestCount{0};
91
92 enum RequestStatus : unsigned int
93 {
94 NoRequest = 0,
95 ReadRequest = 1,
96 Reading = 2,
97 Compiling = 3,
98 MergeRequest = 4,
99 Merging = 5,
100 DeleteRequest = 6,
101 Deleting = 7
102 };
103
104 mutable std::atomic<RequestStatus> requestStatus{NoRequest};
105 mutable uint32_t index = 0;
106
107 ref_ptr<Node> pending;
108 };
109 VSG_type_name(vsg::PagedLOD);
110
111 struct PagedLODContainer : public Inherit<Object, PagedLODContainer>
112 {
113 explicit PagedLODContainer(uint32_t maxNumPagedLOD = 10000);
114
115 struct List
116 {
117 uint32_t head = 0;
118 uint32_t tail = 0;
119 uint32_t count = 0;
120 std::string name;
121 };
122
123 struct Element
124 {
125 uint32_t previous = 0;
126 uint32_t next = 0;
127 ref_ptr<PagedLOD> plod;
128 List* list = nullptr;
129 };
130
131 using Elements = std::vector<Element>;
132
133 Elements elements;
134 List availableList;
135 List inactiveList;
136 List activeList;
137
138 void resize(uint32_t new_size);
139 void resize();
140 void inactive(const PagedLOD* plod);
141 void active(const PagedLOD* plod);
142 void remove(PagedLOD* plod);
143
144 void _move(const PagedLOD* plod, List* targetList);
145
146 bool check();
147 bool check(const List& list);
148
149 void print(std::ostream& out);
150 };
151
152} // namespace vsg
vsg::CopyOp
Definition Object.h:42
vsg::Object
Definition Object.h:60
vsg::PagedLOD
Definition PagedLOD.h:36
vsg::PagedLOD::clone
ref_ptr< Object > clone(const CopyOp &copyop={}) const override
Definition PagedLOD.h:61
vsg::PagedLOD::compare
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,...
vsg::Path
Definition Path.h:34
vsg::ref_ptr
Definition ref_ptr.h:22
vsg::PagedLOD::Child
Definition PagedLOD.h:42
vsg::PagedLODContainer::Element
Definition PagedLOD.h:124
vsg::PagedLODContainer::List
Definition PagedLOD.h:116