mirror of
https://github.com/lubosz/overte.git
synced 2025-04-23 13:33:38 +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;
|
||||
}
|
||||
|
||||
DependencyManager::get<EntityTreeRenderer>()->cameraPosition = getMyAvatar()->getPosition();
|
||||
|
||||
_inPaint = true;
|
||||
Finally clearFlag([this] { _inPaint = false; });
|
||||
|
||||
|
@ -3249,6 +3247,13 @@ void Application::init() {
|
|||
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);
|
||||
_physicsEngine->init();
|
||||
|
||||
|
|
|
@ -28,11 +28,14 @@ class AbstractViewStateInterface;
|
|||
class Model;
|
||||
class ScriptEngine;
|
||||
class ZoneEntityItem;
|
||||
class EntityItem;
|
||||
|
||||
class Model;
|
||||
using ModelPointer = std::shared_ptr<Model>;
|
||||
using ModelWeakPointer = std::weak_ptr<Model>;
|
||||
|
||||
using CalculateEntityLoadingPriority = std::function<float(const EntityItem& item)>;
|
||||
|
||||
// Generic client side Octree renderer class.
|
||||
class EntityTreeRenderer : public OctreeRenderer, public EntityItemFBXService, public Dependency {
|
||||
Q_OBJECT
|
||||
|
@ -46,7 +49,9 @@ public:
|
|||
virtual PacketType getExpectedPacketType() const { return PacketType::EntityData; }
|
||||
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 update();
|
||||
|
@ -204,6 +209,10 @@ private:
|
|||
QList<EntityItemID> _entityIDsLastInScene;
|
||||
|
||||
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 we don't have a model, allocate one *immediately*
|
||||
if (!_model) {
|
||||
auto dims = this->getDimensions();
|
||||
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);
|
||||
_model = _myRenderer->allocateModel(getModelURL(), getCompoundShapeURL(), renderer->getEntityLoadingPriority(*this));
|
||||
_needsInitialSimulation = true;
|
||||
// If we need to change URLs, update it *after rendering* (to avoid access violations)
|
||||
} else if ((QUrl(getModelURL()) != _model->getURL() || QUrl(getCompoundShapeURL()) != _model->getCollisionURL())) {
|
||||
|
|
|
@ -52,7 +52,6 @@ public:
|
|||
bool& keepSearching, OctreeElementPointer& element, float& distance,
|
||||
BoxFace& face, glm::vec3& surfaceNormal,
|
||||
void** intersectedObject, bool precisionPicking) const override;
|
||||
|
||||
ModelPointer getModel(EntityTreeRenderer* renderer);
|
||||
|
||||
virtual bool needsToCallUpdate() const override;
|
||||
|
|
Loading…
Reference in a new issue