Use observer_ptr in OrthophotoManager
This commit is contained in:
parent
023a3de5f1
commit
fee2c592c0
@ -347,9 +347,9 @@ namespace simgear {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void OrthophotoManager::registerOrthophoto(const long bucket_idx, const OrthophotoRef& orthophoto) {
|
void OrthophotoManager::registerOrthophoto(const long bucket_idx, const OrthophotoRef& orthophoto) {
|
||||||
OrthophotoRef& entry = _orthophotos[bucket_idx];
|
OrthophotoWeakRef& entry = _orthophotos[bucket_idx];
|
||||||
|
|
||||||
if (entry) {
|
if (entry.valid()) {
|
||||||
SG_LOG(SG_TERRAIN, SG_WARN, "OrthophotoManager::registerOrthophoto(): Bucket index " << bucket_idx << " already has a registered orthophoto.");
|
SG_LOG(SG_TERRAIN, SG_WARN, "OrthophotoManager::registerOrthophoto(): Bucket index " << bucket_idx << " already has a registered orthophoto.");
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -362,26 +362,13 @@ namespace simgear {
|
|||||||
SG_LOG(SG_TERRAIN, SG_INFO, "Registered orthophoto for bucket index " << bucket_idx);
|
SG_LOG(SG_TERRAIN, SG_INFO, "Registered orthophoto for bucket index " << bucket_idx);
|
||||||
}
|
}
|
||||||
|
|
||||||
void OrthophotoManager::unregisterOrthophoto(const long bucket_idx) {
|
|
||||||
if (_orthophotos[bucket_idx]) {
|
|
||||||
_orthophotos.erase(bucket_idx);
|
|
||||||
SG_LOG(SG_TERRAIN, SG_INFO, "Unregistered orthophoto with bucket index " << bucket_idx);
|
|
||||||
} else {
|
|
||||||
SG_LOG(SG_TERRAIN, SG_WARN, "OrthophotoManager::unregisterOrthophoto(): Attempted to unregister orthophoto with bucket index that is not currently registered.");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void OrthophotoManager::unregisterAll() {
|
|
||||||
_orthophotos.clear();
|
|
||||||
SG_LOG(SG_TERRAIN, SG_INFO, "Unregistered all orthophotos");
|
|
||||||
}
|
|
||||||
|
|
||||||
OrthophotoRef OrthophotoManager::getOrthophoto(const long bucket_idx) {
|
OrthophotoRef OrthophotoManager::getOrthophoto(const long bucket_idx) {
|
||||||
if (_orthophotos[bucket_idx]) {
|
OrthophotoWeakRef weak_ref = _orthophotos[bucket_idx];
|
||||||
return _orthophotos[bucket_idx];
|
OrthophotoRef ref;
|
||||||
} else {
|
if (weak_ref.valid()) {
|
||||||
return nullptr;
|
weak_ref.lock(ref);
|
||||||
}
|
}
|
||||||
|
return ref;
|
||||||
}
|
}
|
||||||
|
|
||||||
OrthophotoRef OrthophotoManager::getOrthophoto(const std::vector<SGVec3d>& nodes, const SGVec3d& center) {
|
OrthophotoRef OrthophotoManager::getOrthophoto(const std::vector<SGVec3d>& nodes, const SGVec3d& center) {
|
||||||
|
@ -22,9 +22,11 @@
|
|||||||
|
|
||||||
#include <unordered_map>
|
#include <unordered_map>
|
||||||
|
|
||||||
#include <osg/Referenced>
|
|
||||||
#include <osg/Image>
|
#include <osg/Image>
|
||||||
#include <osg/Texture2D>
|
#include <osg/Texture2D>
|
||||||
|
#include <osg/Referenced>
|
||||||
|
#include <osg/ref_ptr>
|
||||||
|
#include <osg/observer_ptr>
|
||||||
#include <osgDB/ReaderWriter>
|
#include <osgDB/ReaderWriter>
|
||||||
#include <osgDB/ReadFile>
|
#include <osgDB/ReadFile>
|
||||||
#include <simgear/misc/sg_dir.hxx>
|
#include <simgear/misc/sg_dir.hxx>
|
||||||
@ -41,6 +43,7 @@ namespace simgear {
|
|||||||
|
|
||||||
class Orthophoto;
|
class Orthophoto;
|
||||||
using OrthophotoRef = osg::ref_ptr<Orthophoto>;
|
using OrthophotoRef = osg::ref_ptr<Orthophoto>;
|
||||||
|
using OrthophotoWeakRef = osg::observer_ptr<Orthophoto>;
|
||||||
|
|
||||||
class OrthophotoBounds {
|
class OrthophotoBounds {
|
||||||
private:
|
private:
|
||||||
@ -85,13 +88,11 @@ namespace simgear {
|
|||||||
|
|
||||||
class OrthophotoManager : public osg::Referenced {
|
class OrthophotoManager : public osg::Referenced {
|
||||||
private:
|
private:
|
||||||
std::unordered_map<long, OrthophotoRef> _orthophotos;
|
std::unordered_map<long, OrthophotoWeakRef> _orthophotos;
|
||||||
public:
|
public:
|
||||||
static OrthophotoManager* instance();
|
static OrthophotoManager* instance();
|
||||||
|
|
||||||
void registerOrthophoto(const long bucket_idx, const OrthophotoRef& orthophoto);
|
void registerOrthophoto(const long bucket_idx, const OrthophotoRef& orthophoto);
|
||||||
void unregisterOrthophoto(const long bucket_idx);
|
|
||||||
void unregisterAll();
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get an orthophoto by bucket index
|
* Get an orthophoto by bucket index
|
||||||
|
Loading…
Reference in New Issue
Block a user