mirror of
https://github.com/overte-org/overte.git
synced 2025-08-09 11:28:03 +02:00
time budget and raw pointer key for entitiesToSend
This commit is contained in:
parent
b6818c4369
commit
b85a5507e0
3 changed files with 22 additions and 16 deletions
|
@ -39,9 +39,10 @@ private:
|
||||||
// PrioritizedEntity is a placeholder in a sorted queue.
|
// PrioritizedEntity is a placeholder in a sorted queue.
|
||||||
class PrioritizedEntity {
|
class PrioritizedEntity {
|
||||||
public:
|
public:
|
||||||
PrioritizedEntity(EntityItemPointer entity, float priority) : _weakEntity(entity), _priority(priority) { }
|
PrioritizedEntity(EntityItemPointer entity, float priority) : _weakEntity(entity), _rawEntityPointer(entity.get()), _priority(priority) {}
|
||||||
float updatePriority(const ConicalView& view);
|
float updatePriority(const ConicalView& view);
|
||||||
EntityItemPointer getEntity() const { return _weakEntity.lock(); }
|
EntityItemPointer getEntity() const { return _weakEntity.lock(); }
|
||||||
|
EntityItem* getRawEntityPointer() const { return _rawEntityPointer; }
|
||||||
float getPriority() const { return _priority; }
|
float getPriority() const { return _priority; }
|
||||||
|
|
||||||
class Compare {
|
class Compare {
|
||||||
|
@ -52,6 +53,7 @@ public:
|
||||||
|
|
||||||
private:
|
private:
|
||||||
EntityItemWeakPointer _weakEntity;
|
EntityItemWeakPointer _weakEntity;
|
||||||
|
EntityItem* _rawEntityPointer;
|
||||||
float _priority;
|
float _priority;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -122,14 +122,14 @@ void EntityTreeSendThread::traverseTreeAndSendContents(SharedNodePointer node, O
|
||||||
// Only send entities if they are large enough to see
|
// Only send entities if they are large enough to see
|
||||||
if (renderAccuracy > 0.0f) {
|
if (renderAccuracy > 0.0f) {
|
||||||
_sendQueue.push(PrioritizedEntity(entity, priority));
|
_sendQueue.push(PrioritizedEntity(entity, priority));
|
||||||
_entitiesToSend.insert(entity);
|
_entitiesToSend.insert(entity.get());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
const float WHEN_IN_DOUBT_PRIORITY = 1.0f;
|
const float WHEN_IN_DOUBT_PRIORITY = 1.0f;
|
||||||
_sendQueue.push(PrioritizedEntity(entity, WHEN_IN_DOUBT_PRIORITY));
|
_sendQueue.push(PrioritizedEntity(entity, WHEN_IN_DOUBT_PRIORITY));
|
||||||
_entitiesToSend.insert(entity);
|
_entitiesToSend.insert(entity.get());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -140,7 +140,11 @@ void EntityTreeSendThread::traverseTreeAndSendContents(SharedNodePointer node, O
|
||||||
if (!_traversal.finished()) {
|
if (!_traversal.finished()) {
|
||||||
uint64_t startTime = usecTimestampNow();
|
uint64_t startTime = usecTimestampNow();
|
||||||
|
|
||||||
const uint64_t TIME_BUDGET = 100000; // usec
|
#ifdef DEBUG
|
||||||
|
const uint64_t TIME_BUDGET = 400; // usec
|
||||||
|
#else
|
||||||
|
const uint64_t TIME_BUDGET = 200; // usec
|
||||||
|
#endif
|
||||||
_traversal.traverse(TIME_BUDGET);
|
_traversal.traverse(TIME_BUDGET);
|
||||||
|
|
||||||
uint64_t dt = usecTimestampNow() - startTime;
|
uint64_t dt = usecTimestampNow() - startTime;
|
||||||
|
@ -157,7 +161,7 @@ void EntityTreeSendThread::traverseTreeAndSendContents(SharedNodePointer node, O
|
||||||
std::cout << "adebug send '" << entity->getName().toStdString() << "'" << " : " << entry.getPriority() << std::endl; // adebug
|
std::cout << "adebug send '" << entity->getName().toStdString() << "'" << " : " << entry.getPriority() << std::endl; // adebug
|
||||||
}
|
}
|
||||||
_sendQueue.pop();
|
_sendQueue.pop();
|
||||||
_entitiesToSend.erase(entity);
|
_entitiesToSend.erase(entry.getRawEntityPointer());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
#endif // SEND_SORTED_ENTITIES
|
#endif // SEND_SORTED_ENTITIES
|
||||||
|
@ -235,7 +239,7 @@ void EntityTreeSendThread::startNewTraversal(const ViewFrustum& view, EntityTree
|
||||||
_traversal.setScanCallback([&] (DiffTraversal::VisibleElement& next) {
|
_traversal.setScanCallback([&] (DiffTraversal::VisibleElement& next) {
|
||||||
next.element->forEachEntity([&](EntityItemPointer entity) {
|
next.element->forEachEntity([&](EntityItemPointer entity) {
|
||||||
// Bail early if we've already checked this entity this frame
|
// Bail early if we've already checked this entity this frame
|
||||||
if (_entitiesToSend.find(entity) != _entitiesToSend.end()) {
|
if (_entitiesToSend.find(entity.get()) != _entitiesToSend.end()) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
bool success = false;
|
bool success = false;
|
||||||
|
@ -255,13 +259,13 @@ void EntityTreeSendThread::startNewTraversal(const ViewFrustum& view, EntityTree
|
||||||
if (renderAccuracy > 0.0f) {
|
if (renderAccuracy > 0.0f) {
|
||||||
float priority = _conicalView.computePriority(cube);
|
float priority = _conicalView.computePriority(cube);
|
||||||
_sendQueue.push(PrioritizedEntity(entity, priority));
|
_sendQueue.push(PrioritizedEntity(entity, priority));
|
||||||
_entitiesToSend.insert(entity);
|
_entitiesToSend.insert(entity.get());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
const float WHEN_IN_DOUBT_PRIORITY = 1.0f;
|
const float WHEN_IN_DOUBT_PRIORITY = 1.0f;
|
||||||
_sendQueue.push(PrioritizedEntity(entity, WHEN_IN_DOUBT_PRIORITY));
|
_sendQueue.push(PrioritizedEntity(entity, WHEN_IN_DOUBT_PRIORITY));
|
||||||
_entitiesToSend.insert(entity);
|
_entitiesToSend.insert(entity.get());
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
@ -272,7 +276,7 @@ void EntityTreeSendThread::startNewTraversal(const ViewFrustum& view, EntityTree
|
||||||
uint64_t timestamp = _traversal.getStartOfCompletedTraversal();
|
uint64_t timestamp = _traversal.getStartOfCompletedTraversal();
|
||||||
next.element->forEachEntity([&](EntityItemPointer entity) {
|
next.element->forEachEntity([&](EntityItemPointer entity) {
|
||||||
// Bail early if we've already checked this entity this frame
|
// Bail early if we've already checked this entity this frame
|
||||||
if (_entitiesToSend.find(entity) != _entitiesToSend.end()) {
|
if (_entitiesToSend.find(entity.get()) != _entitiesToSend.end()) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (entity->getLastEdited() > timestamp) {
|
if (entity->getLastEdited() > timestamp) {
|
||||||
|
@ -290,13 +294,13 @@ void EntityTreeSendThread::startNewTraversal(const ViewFrustum& view, EntityTree
|
||||||
if (renderAccuracy > 0.0f) {
|
if (renderAccuracy > 0.0f) {
|
||||||
float priority = _conicalView.computePriority(cube);
|
float priority = _conicalView.computePriority(cube);
|
||||||
_sendQueue.push(PrioritizedEntity(entity, priority));
|
_sendQueue.push(PrioritizedEntity(entity, priority));
|
||||||
_entitiesToSend.insert(entity);
|
_entitiesToSend.insert(entity.get());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
const float WHEN_IN_DOUBT_PRIORITY = 1.0f;
|
const float WHEN_IN_DOUBT_PRIORITY = 1.0f;
|
||||||
_sendQueue.push(PrioritizedEntity(entity, WHEN_IN_DOUBT_PRIORITY));
|
_sendQueue.push(PrioritizedEntity(entity, WHEN_IN_DOUBT_PRIORITY));
|
||||||
_entitiesToSend.insert(entity);
|
_entitiesToSend.insert(entity.get());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
@ -310,7 +314,7 @@ void EntityTreeSendThread::startNewTraversal(const ViewFrustum& view, EntityTree
|
||||||
if (next.element->getLastChangedContent() > timestamp || next.intersection != ViewFrustum::INSIDE) {
|
if (next.element->getLastChangedContent() > timestamp || next.intersection != ViewFrustum::INSIDE) {
|
||||||
next.element->forEachEntity([&](EntityItemPointer entity) {
|
next.element->forEachEntity([&](EntityItemPointer entity) {
|
||||||
// Bail early if we've already checked this entity this frame
|
// Bail early if we've already checked this entity this frame
|
||||||
if (_entitiesToSend.find(entity) != _entitiesToSend.end()) {
|
if (_entitiesToSend.find(entity.get()) != _entitiesToSend.end()) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
bool success = false;
|
bool success = false;
|
||||||
|
@ -328,7 +332,7 @@ void EntityTreeSendThread::startNewTraversal(const ViewFrustum& view, EntityTree
|
||||||
if (entity->getLastEdited() > timestamp || !_traversal.getCompletedView().cubeIntersectsKeyhole(cube)) {
|
if (entity->getLastEdited() > timestamp || !_traversal.getCompletedView().cubeIntersectsKeyhole(cube)) {
|
||||||
float priority = _conicalView.computePriority(cube);
|
float priority = _conicalView.computePriority(cube);
|
||||||
_sendQueue.push(PrioritizedEntity(entity, priority));
|
_sendQueue.push(PrioritizedEntity(entity, priority));
|
||||||
_entitiesToSend.insert(entity);
|
_entitiesToSend.insert(entity.get());
|
||||||
} else {
|
} else {
|
||||||
// If this entity was skipped last time because it was too small, we still need to send it
|
// If this entity was skipped last time because it was too small, we still need to send it
|
||||||
float lastRenderAccuracy = calculateRenderAccuracy(_traversal.getCompletedView().getPosition(),
|
float lastRenderAccuracy = calculateRenderAccuracy(_traversal.getCompletedView().getPosition(),
|
||||||
|
@ -339,7 +343,7 @@ void EntityTreeSendThread::startNewTraversal(const ViewFrustum& view, EntityTree
|
||||||
if (lastRenderAccuracy <= 0.0f) {
|
if (lastRenderAccuracy <= 0.0f) {
|
||||||
float priority = _conicalView.computePriority(cube);
|
float priority = _conicalView.computePriority(cube);
|
||||||
_sendQueue.push(PrioritizedEntity(entity, priority));
|
_sendQueue.push(PrioritizedEntity(entity, priority));
|
||||||
_entitiesToSend.insert(entity);
|
_entitiesToSend.insert(entity.get());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -347,7 +351,7 @@ void EntityTreeSendThread::startNewTraversal(const ViewFrustum& view, EntityTree
|
||||||
} else {
|
} else {
|
||||||
const float WHEN_IN_DOUBT_PRIORITY = 1.0f;
|
const float WHEN_IN_DOUBT_PRIORITY = 1.0f;
|
||||||
_sendQueue.push(PrioritizedEntity(entity, WHEN_IN_DOUBT_PRIORITY));
|
_sendQueue.push(PrioritizedEntity(entity, WHEN_IN_DOUBT_PRIORITY));
|
||||||
_entitiesToSend.insert(entity);
|
_entitiesToSend.insert(entity.get());
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
|
@ -43,7 +43,7 @@ private:
|
||||||
|
|
||||||
DiffTraversal _traversal;
|
DiffTraversal _traversal;
|
||||||
EntityPriorityQueue _sendQueue;
|
EntityPriorityQueue _sendQueue;
|
||||||
std::unordered_set<EntityItemPointer> _entitiesToSend;
|
std::unordered_set<EntityItem*> _entitiesToSend;
|
||||||
ConicalView _conicalView; // cached optimized view for fast priority calculations
|
ConicalView _conicalView; // cached optimized view for fast priority calculations
|
||||||
|
|
||||||
// packet construction stuff
|
// packet construction stuff
|
||||||
|
|
Loading…
Reference in a new issue