mirror of
https://github.com/overte-org/overte.git
synced 2025-08-09 08:21:24 +02:00
Clean up priority loading implementation
This commit is contained in:
parent
d48bc96cf9
commit
d367583426
4 changed files with 18 additions and 9 deletions
|
@ -1642,8 +1642,6 @@ void Application::paintGL() {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
DependencyManager::get<EntityTreeRenderer>()->cameraPosition = getMyAvatar()->getPosition();
|
|
||||||
|
|
||||||
_inPaint = true;
|
_inPaint = true;
|
||||||
Finally clearFlag([this] { _inPaint = false; });
|
Finally clearFlag([this] { _inPaint = false; });
|
||||||
|
|
||||||
|
@ -3249,6 +3247,13 @@ void Application::init() {
|
||||||
getEntities()->setViewFrustum(_viewFrustum);
|
getEntities()->setViewFrustum(_viewFrustum);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
getEntities()->setEntityLoadingPriorityFunction([this](const EntityItem& item) {
|
||||||
|
auto dims = item.getDimensions();
|
||||||
|
auto maxSize = glm::max(dims.x, dims.y, dims.z);
|
||||||
|
auto distance = glm::distance(getMyAvatar()->getPosition(), item.getPosition());
|
||||||
|
return atan2(maxSize, distance);
|
||||||
|
});
|
||||||
|
|
||||||
ObjectMotionState::setShapeManager(&_shapeManager);
|
ObjectMotionState::setShapeManager(&_shapeManager);
|
||||||
_physicsEngine->init();
|
_physicsEngine->init();
|
||||||
|
|
||||||
|
|
|
@ -28,11 +28,14 @@ class AbstractViewStateInterface;
|
||||||
class Model;
|
class Model;
|
||||||
class ScriptEngine;
|
class ScriptEngine;
|
||||||
class ZoneEntityItem;
|
class ZoneEntityItem;
|
||||||
|
class EntityItem;
|
||||||
|
|
||||||
class Model;
|
class Model;
|
||||||
using ModelPointer = std::shared_ptr<Model>;
|
using ModelPointer = std::shared_ptr<Model>;
|
||||||
using ModelWeakPointer = std::weak_ptr<Model>;
|
using ModelWeakPointer = std::weak_ptr<Model>;
|
||||||
|
|
||||||
|
using CalculateEntityLoadingPriority = std::function<float(const EntityItem& item)>;
|
||||||
|
|
||||||
// Generic client side Octree renderer class.
|
// Generic client side Octree renderer class.
|
||||||
class EntityTreeRenderer : public OctreeRenderer, public EntityItemFBXService, public Dependency {
|
class EntityTreeRenderer : public OctreeRenderer, public EntityItemFBXService, public Dependency {
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
|
@ -46,7 +49,9 @@ public:
|
||||||
virtual PacketType getExpectedPacketType() const { return PacketType::EntityData; }
|
virtual PacketType getExpectedPacketType() const { return PacketType::EntityData; }
|
||||||
virtual void setTree(OctreePointer newTree);
|
virtual void setTree(OctreePointer newTree);
|
||||||
|
|
||||||
glm::vec3 cameraPosition {};
|
// Returns the priority at which an entity should be loaded. Higher values indicate higher priority.
|
||||||
|
float getEntityLoadingPriority(const EntityItem& item) const { return _calculateEntityLoadingPriorityFunc(item); }
|
||||||
|
void setEntityLoadingPriorityFunction(CalculateEntityLoadingPriority fn) { this->_calculateEntityLoadingPriorityFunc = fn; }
|
||||||
|
|
||||||
void shutdown();
|
void shutdown();
|
||||||
void update();
|
void update();
|
||||||
|
@ -204,6 +209,10 @@ private:
|
||||||
QList<EntityItemID> _entityIDsLastInScene;
|
QList<EntityItemID> _entityIDsLastInScene;
|
||||||
|
|
||||||
static int _entitiesScriptEngineCount;
|
static int _entitiesScriptEngineCount;
|
||||||
|
|
||||||
|
CalculateEntityLoadingPriority _calculateEntityLoadingPriorityFunc = [](const EntityItem& item) -> float {
|
||||||
|
return 0.0f;
|
||||||
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -484,11 +484,7 @@ ModelPointer RenderableModelEntityItem::getModel(EntityTreeRenderer* renderer) {
|
||||||
if (!getModelURL().isEmpty()) {
|
if (!getModelURL().isEmpty()) {
|
||||||
// If we don't have a model, allocate one *immediately*
|
// If we don't have a model, allocate one *immediately*
|
||||||
if (!_model) {
|
if (!_model) {
|
||||||
auto dims = this->getDimensions();
|
_model = _myRenderer->allocateModel(getModelURL(), getCompoundShapeURL(), renderer->getEntityLoadingPriority(*this));
|
||||||
auto maxSize = glm::max(dims.x, dims.y, dims.z);
|
|
||||||
auto distance = glm::distance(renderer->cameraPosition, getPosition());
|
|
||||||
float priority = atan2(maxSize / 2, distance);
|
|
||||||
_model = _myRenderer->allocateModel(getModelURL(), getCompoundShapeURL(), priority);
|
|
||||||
_needsInitialSimulation = true;
|
_needsInitialSimulation = true;
|
||||||
// If we need to change URLs, update it *after rendering* (to avoid access violations)
|
// If we need to change URLs, update it *after rendering* (to avoid access violations)
|
||||||
} else if ((QUrl(getModelURL()) != _model->getURL() || QUrl(getCompoundShapeURL()) != _model->getCollisionURL())) {
|
} else if ((QUrl(getModelURL()) != _model->getURL() || QUrl(getCompoundShapeURL()) != _model->getCollisionURL())) {
|
||||||
|
|
|
@ -52,7 +52,6 @@ public:
|
||||||
bool& keepSearching, OctreeElementPointer& element, float& distance,
|
bool& keepSearching, OctreeElementPointer& element, float& distance,
|
||||||
BoxFace& face, glm::vec3& surfaceNormal,
|
BoxFace& face, glm::vec3& surfaceNormal,
|
||||||
void** intersectedObject, bool precisionPicking) const override;
|
void** intersectedObject, bool precisionPicking) const override;
|
||||||
|
|
||||||
ModelPointer getModel(EntityTreeRenderer* renderer);
|
ModelPointer getModel(EntityTreeRenderer* renderer);
|
||||||
|
|
||||||
virtual bool needsToCallUpdate() const override;
|
virtual bool needsToCallUpdate() const override;
|
||||||
|
|
Loading…
Reference in a new issue