]> git.mxchange.org Git - flightgear.git/blob - src/Scenery/SceneryPager.cxx
Clear chat messages when an aircraft becomes inactive in the property tree.
[flightgear.git] / src / Scenery / SceneryPager.cxx
1 // SceneryPager.hxx -- Interface to OSG database pager
2 //
3 // Copyright (C) 2007 Tim Moore timoore@redhat.com
4 //
5 // This program is free software; you can redistribute it and/or
6 // modify it under the terms of the GNU General Public License as
7 // published by the Free Software Foundation; either version 2 of the
8 // License, or (at your option) any later version.
9 //
10 // This program is distributed in the hope that it will be useful, but
11 // WITHOUT ANY WARRANTY; without even the implied warranty of
12 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
13 // General Public License for more details.
14 //
15 // You should have received a copy of the GNU General Public License
16 // along with this program; if not, write to the Free Software
17 // Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
18
19 #include "SceneryPager.hxx"
20 #include <algorithm>
21 #include <functional>
22
23 using namespace flightgear;
24 using osg::ref_ptr;
25 using osg::Node;
26
27 SceneryPager::SceneryPager()
28 {
29     _pagerRequests.reserve(48);
30     _deleteRequests.reserve(16);
31 }
32
33 SceneryPager::SceneryPager(const SceneryPager& rhs) :
34     DatabasePager(rhs)
35 {
36 }
37
38 SceneryPager::~SceneryPager()
39 {
40 }
41
42 void SceneryPager::queueRequest(const std::string& fileName, osg::Group* group,
43                                 float priority, osg::FrameStamp* frameStamp)
44 {
45     _pagerRequests.push_back(PagerRequest(fileName, group, priority,
46                                           frameStamp));
47 }
48
49 void SceneryPager::queueDeleteRequest(osg::ref_ptr<osg::Object>& objptr)
50 {
51     _deleteRequests.push_back(objptr);
52     objptr = 0;
53 }
54 void SceneryPager::signalEndFrame()
55 {
56     using namespace std;
57     bool areDeleteRequests = false;
58     bool arePagerRequests = false;
59     if (!_deleteRequests.empty()) {
60         areDeleteRequests = true;
61         OpenThreads::ScopedLock<OpenThreads::Mutex>
62             lock(_childrenToDeleteListMutex);
63         _childrenToDeleteList.insert(_childrenToDeleteList.end(),
64                                      _deleteRequests.begin(),
65                                      _deleteRequests.end());
66         _deleteRequests.clear();
67     }
68     if (!_pagerRequests.empty()) {
69         arePagerRequests = true;
70         for_each(_pagerRequests.begin(), _pagerRequests.end(),
71                  bind2nd(mem_fun_ref(&PagerRequest::doRequest), this));
72         _pagerRequests.clear();
73     }
74     if (areDeleteRequests && !arePagerRequests)
75         updateDatabasePagerThreadBlock();
76     DatabasePager::signalEndFrame();
77 }
78