mirror of
https://github.com/overte-org/overte.git
synced 2025-08-07 18:10:37 +02:00
remove updateEntitiesInternal(), make updateEntities() virtual
This commit is contained in:
parent
9557ba80c9
commit
99d0579007
6 changed files with 27 additions and 33 deletions
|
@ -21,6 +21,7 @@ void EntitySimulation::setEntityTree(EntityTreePointer tree) {
|
||||||
if (_entityTree && _entityTree != tree) {
|
if (_entityTree && _entityTree != tree) {
|
||||||
_entitiesToSort.clear();
|
_entitiesToSort.clear();
|
||||||
_simpleKinematicEntities.clear();
|
_simpleKinematicEntities.clear();
|
||||||
|
_changedEntities.clear();
|
||||||
_entitiesToUpdate.clear();
|
_entitiesToUpdate.clear();
|
||||||
_mortalEntities.clear();
|
_mortalEntities.clear();
|
||||||
_nextExpiry = std::numeric_limits<uint64_t>::max();
|
_nextExpiry = std::numeric_limits<uint64_t>::max();
|
||||||
|
@ -29,15 +30,14 @@ void EntitySimulation::setEntityTree(EntityTreePointer tree) {
|
||||||
}
|
}
|
||||||
|
|
||||||
void EntitySimulation::updateEntities() {
|
void EntitySimulation::updateEntities() {
|
||||||
|
PerformanceTimer perfTimer("EntitySimulation::updateEntities");
|
||||||
QMutexLocker lock(&_mutex);
|
QMutexLocker lock(&_mutex);
|
||||||
uint64_t now = usecTimestampNow();
|
uint64_t now = usecTimestampNow();
|
||||||
PerformanceTimer perfTimer("EntitySimulation::updateEntities");
|
|
||||||
|
|
||||||
// these methods may accumulate entries in _entitiesToBeDeleted
|
// these methods may accumulate entries in _entitiesToBeDeleted
|
||||||
expireMortalEntities(now);
|
expireMortalEntities(now);
|
||||||
callUpdateOnEntitiesThatNeedIt(now);
|
callUpdateOnEntitiesThatNeedIt(now);
|
||||||
moveSimpleKinematics(now);
|
moveSimpleKinematics(now);
|
||||||
updateEntitiesInternal(now);
|
|
||||||
sortEntitiesThatMoved();
|
sortEntitiesThatMoved();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -220,14 +220,12 @@ void EntitySimulation::clearEntities() {
|
||||||
QMutexLocker lock(&_mutex);
|
QMutexLocker lock(&_mutex);
|
||||||
_entitiesToSort.clear();
|
_entitiesToSort.clear();
|
||||||
_simpleKinematicEntities.clear();
|
_simpleKinematicEntities.clear();
|
||||||
|
_changedEntities.clear();
|
||||||
|
_allEntities.clear();
|
||||||
|
_deadEntities.clear();
|
||||||
_entitiesToUpdate.clear();
|
_entitiesToUpdate.clear();
|
||||||
_mortalEntities.clear();
|
_mortalEntities.clear();
|
||||||
_nextExpiry = std::numeric_limits<uint64_t>::max();
|
_nextExpiry = std::numeric_limits<uint64_t>::max();
|
||||||
|
|
||||||
clearEntitiesInternal();
|
|
||||||
|
|
||||||
_allEntities.clear();
|
|
||||||
_deadEntities.clear();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void EntitySimulation::moveSimpleKinematics(uint64_t now) {
|
void EntitySimulation::moveSimpleKinematics(uint64_t now) {
|
||||||
|
|
|
@ -46,8 +46,8 @@ const int DIRTY_SIMULATION_FLAGS =
|
||||||
|
|
||||||
class EntitySimulation : public QObject, public std::enable_shared_from_this<EntitySimulation> {
|
class EntitySimulation : public QObject, public std::enable_shared_from_this<EntitySimulation> {
|
||||||
public:
|
public:
|
||||||
EntitySimulation() : _mutex(QMutex::Recursive), _entityTree(NULL), _nextExpiry(std::numeric_limits<uint64_t>::max()) { }
|
EntitySimulation() : _mutex(QMutex::Recursive), _nextExpiry(std::numeric_limits<uint64_t>::max()), _entityTree(nullptr) { }
|
||||||
virtual ~EntitySimulation() { setEntityTree(NULL); }
|
virtual ~EntitySimulation() { setEntityTree(nullptr); }
|
||||||
|
|
||||||
inline EntitySimulationPointer getThisPointer() const {
|
inline EntitySimulationPointer getThisPointer() const {
|
||||||
return std::const_pointer_cast<EntitySimulation>(shared_from_this());
|
return std::const_pointer_cast<EntitySimulation>(shared_from_this());
|
||||||
|
@ -56,7 +56,7 @@ public:
|
||||||
/// \param tree pointer to EntityTree which is stored internally
|
/// \param tree pointer to EntityTree which is stored internally
|
||||||
void setEntityTree(EntityTreePointer tree);
|
void setEntityTree(EntityTreePointer tree);
|
||||||
|
|
||||||
void updateEntities();
|
virtual void updateEntities();
|
||||||
|
|
||||||
// FIXME: remove these
|
// FIXME: remove these
|
||||||
virtual void addDynamic(EntityDynamicPointer dynamic) {}
|
virtual void addDynamic(EntityDynamicPointer dynamic) {}
|
||||||
|
@ -71,7 +71,7 @@ public:
|
||||||
/// call this whenever an entity was changed from some EXTERNAL event (NOT by the EntitySimulation itself)
|
/// call this whenever an entity was changed from some EXTERNAL event (NOT by the EntitySimulation itself)
|
||||||
void changeEntity(EntityItemPointer entity);
|
void changeEntity(EntityItemPointer entity);
|
||||||
|
|
||||||
void clearEntities();
|
virtual void clearEntities();
|
||||||
|
|
||||||
void moveSimpleKinematics(uint64_t now);
|
void moveSimpleKinematics(uint64_t now);
|
||||||
|
|
||||||
|
@ -79,19 +79,14 @@ public:
|
||||||
|
|
||||||
virtual void takeDeadEntities(SetOfEntities& entitiesToDelete);
|
virtual void takeDeadEntities(SetOfEntities& entitiesToDelete);
|
||||||
|
|
||||||
/// \param entity pointer to EntityItem that needs to be put on the entitiesToDelete list and removed from others.
|
|
||||||
virtual void prepareEntityForDelete(EntityItemPointer entity);
|
virtual void prepareEntityForDelete(EntityItemPointer entity);
|
||||||
|
|
||||||
void processChangedEntities();
|
void processChangedEntities();
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
// These pure virtual methods are protected because they are not to be called will-nilly. The base class
|
|
||||||
// calls them in the right places.
|
|
||||||
virtual void updateEntitiesInternal(uint64_t now) = 0;
|
|
||||||
virtual void addEntityToInternalLists(EntityItemPointer entity);
|
virtual void addEntityToInternalLists(EntityItemPointer entity);
|
||||||
virtual void removeEntityFromInternalLists(EntityItemPointer entity);
|
virtual void removeEntityFromInternalLists(EntityItemPointer entity);
|
||||||
virtual void processChangedEntity(const EntityItemPointer& entity);
|
virtual void processChangedEntity(const EntityItemPointer& entity);
|
||||||
virtual void clearEntitiesInternal() = 0;
|
|
||||||
|
|
||||||
void expireMortalEntities(uint64_t now);
|
void expireMortalEntities(uint64_t now);
|
||||||
void callUpdateOnEntitiesThatNeedIt(uint64_t now);
|
void callUpdateOnEntitiesThatNeedIt(uint64_t now);
|
||||||
|
@ -101,16 +96,11 @@ protected:
|
||||||
|
|
||||||
SetOfEntities _entitiesToSort; // entities moved by simulation (and might need resort in EntityTree)
|
SetOfEntities _entitiesToSort; // entities moved by simulation (and might need resort in EntityTree)
|
||||||
SetOfEntities _simpleKinematicEntities; // entities undergoing non-colliding kinematic motion
|
SetOfEntities _simpleKinematicEntities; // entities undergoing non-colliding kinematic motion
|
||||||
|
|
||||||
protected:
|
|
||||||
SetOfEntities _deadEntities; // dead entities that might still be in the _entityTree
|
SetOfEntities _deadEntities; // dead entities that might still be in the _entityTree
|
||||||
|
|
||||||
private:
|
private:
|
||||||
void moveSimpleKinematics();
|
void moveSimpleKinematics();
|
||||||
|
|
||||||
// back pointer to EntityTree structure
|
|
||||||
EntityTreePointer _entityTree;
|
|
||||||
|
|
||||||
// We maintain multiple lists, each for its distinct purpose.
|
// We maintain multiple lists, each for its distinct purpose.
|
||||||
// An entity may be in more than one list.
|
// An entity may be in more than one list.
|
||||||
std::unordered_set<EntityItemPointer> _changedEntities; // all changes this frame
|
std::unordered_set<EntityItemPointer> _changedEntities; // all changes this frame
|
||||||
|
@ -118,6 +108,9 @@ private:
|
||||||
SetOfEntities _entitiesToUpdate; // entities that need to call EntityItem::update()
|
SetOfEntities _entitiesToUpdate; // entities that need to call EntityItem::update()
|
||||||
SetOfEntities _mortalEntities; // entities that have an expiry
|
SetOfEntities _mortalEntities; // entities that have an expiry
|
||||||
uint64_t _nextExpiry;
|
uint64_t _nextExpiry;
|
||||||
|
|
||||||
|
// back pointer to EntityTree structure
|
||||||
|
EntityTreePointer _entityTree;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // hifi_EntitySimulation_h
|
#endif // hifi_EntitySimulation_h
|
||||||
|
|
|
@ -47,7 +47,10 @@ void SimpleEntitySimulation::clearOwnership(const QUuid& ownerID) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void SimpleEntitySimulation::updateEntitiesInternal(uint64_t now) {
|
void SimpleEntitySimulation::updateEntities() {
|
||||||
|
EntitySimulation::updateEntities();
|
||||||
|
QMutexLocker lock(&_mutex);
|
||||||
|
uint64_t now = usecTimestampNow();
|
||||||
expireStaleOwnerships(now);
|
expireStaleOwnerships(now);
|
||||||
stopOwnerlessEntities(now);
|
stopOwnerlessEntities(now);
|
||||||
}
|
}
|
||||||
|
@ -134,10 +137,11 @@ void SimpleEntitySimulation::processChangedEntity(const EntityItemPointer& entit
|
||||||
entity->clearDirtyFlags();
|
entity->clearDirtyFlags();
|
||||||
}
|
}
|
||||||
|
|
||||||
void SimpleEntitySimulation::clearEntitiesInternal() {
|
void SimpleEntitySimulation::clearEntities() {
|
||||||
QMutexLocker lock(&_mutex);
|
QMutexLocker lock(&_mutex);
|
||||||
_entitiesWithSimulationOwner.clear();
|
_entitiesWithSimulationOwner.clear();
|
||||||
_entitiesThatNeedSimulationOwner.clear();
|
_entitiesThatNeedSimulationOwner.clear();
|
||||||
|
EntitySimulation::clearEntities();
|
||||||
}
|
}
|
||||||
|
|
||||||
void SimpleEntitySimulation::sortEntitiesThatMoved() {
|
void SimpleEntitySimulation::sortEntitiesThatMoved() {
|
||||||
|
|
|
@ -23,16 +23,16 @@ using SimpleEntitySimulationPointer = std::shared_ptr<SimpleEntitySimulation>;
|
||||||
class SimpleEntitySimulation : public EntitySimulation {
|
class SimpleEntitySimulation : public EntitySimulation {
|
||||||
public:
|
public:
|
||||||
SimpleEntitySimulation() : EntitySimulation() { }
|
SimpleEntitySimulation() : EntitySimulation() { }
|
||||||
~SimpleEntitySimulation() { clearEntitiesInternal(); }
|
~SimpleEntitySimulation() { clearEntities(); }
|
||||||
|
|
||||||
void clearOwnership(const QUuid& ownerID);
|
void clearOwnership(const QUuid& ownerID);
|
||||||
|
void clearEntities() override;
|
||||||
|
void updateEntities() override;
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
void updateEntitiesInternal(uint64_t now) override;
|
|
||||||
void addEntityToInternalLists(EntityItemPointer entity) override;
|
void addEntityToInternalLists(EntityItemPointer entity) override;
|
||||||
void removeEntityFromInternalLists(EntityItemPointer entity) override;
|
void removeEntityFromInternalLists(EntityItemPointer entity) override;
|
||||||
void processChangedEntity(const EntityItemPointer& entity) override;
|
void processChangedEntity(const EntityItemPointer& entity) override;
|
||||||
void clearEntitiesInternal() override;
|
|
||||||
|
|
||||||
void sortEntitiesThatMoved() override;
|
void sortEntitiesThatMoved() override;
|
||||||
|
|
||||||
|
|
|
@ -40,10 +40,6 @@ void PhysicalEntitySimulation::init(
|
||||||
}
|
}
|
||||||
|
|
||||||
// begin EntitySimulation overrides
|
// begin EntitySimulation overrides
|
||||||
void PhysicalEntitySimulation::updateEntitiesInternal(uint64_t now) {
|
|
||||||
// Do nothing here because the "internal" update the PhysicsEngine::stepSimulation() which is done elsewhere.
|
|
||||||
}
|
|
||||||
|
|
||||||
void PhysicalEntitySimulation::addEntityToInternalLists(EntityItemPointer entity) {
|
void PhysicalEntitySimulation::addEntityToInternalLists(EntityItemPointer entity) {
|
||||||
EntitySimulation::addEntityToInternalLists(entity);
|
EntitySimulation::addEntityToInternalLists(entity);
|
||||||
entity->deserializeActions(); // TODO: do this elsewhere
|
entity->deserializeActions(); // TODO: do this elsewhere
|
||||||
|
@ -186,11 +182,12 @@ void PhysicalEntitySimulation::processChangedEntity(const EntityItemPointer& ent
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void PhysicalEntitySimulation::clearEntitiesInternal() {
|
void PhysicalEntitySimulation::clearEntities() {
|
||||||
// TODO: we should probably wait to lock the _physicsEngine so we don't mess up data structures
|
// TODO: we should probably wait to lock the _physicsEngine so we don't mess up data structures
|
||||||
// while it is in the middle of a simulation step. As it is, we're probably in shutdown mode
|
// while it is in the middle of a simulation step. As it is, we're probably in shutdown mode
|
||||||
// anyway, so maybe the simulation was already properly shutdown? Cross our fingers...
|
// anyway, so maybe the simulation was already properly shutdown? Cross our fingers...
|
||||||
|
|
||||||
|
QMutexLocker lock(&_mutex);
|
||||||
// remove the objects (aka MotionStates) from physics
|
// remove the objects (aka MotionStates) from physics
|
||||||
_physicsEngine->removeSetOfObjects(_physicalObjects);
|
_physicsEngine->removeSetOfObjects(_physicalObjects);
|
||||||
|
|
||||||
|
@ -212,6 +209,8 @@ void PhysicalEntitySimulation::clearEntitiesInternal() {
|
||||||
_entitiesToAddToPhysics.clear();
|
_entitiesToAddToPhysics.clear();
|
||||||
_incomingChanges.clear();
|
_incomingChanges.clear();
|
||||||
_entitiesToDeleteLater.clear();
|
_entitiesToDeleteLater.clear();
|
||||||
|
|
||||||
|
EntitySimulation::clearEntities();
|
||||||
}
|
}
|
||||||
|
|
||||||
// virtual
|
// virtual
|
||||||
|
|
|
@ -66,16 +66,16 @@ public:
|
||||||
virtual void takeDeadEntities(SetOfEntities& deadEntities) override;
|
virtual void takeDeadEntities(SetOfEntities& deadEntities) override;
|
||||||
void takeDeadAvatarEntities(SetOfEntities& deadEntities);
|
void takeDeadAvatarEntities(SetOfEntities& deadEntities);
|
||||||
|
|
||||||
|
virtual void clearEntities() override;
|
||||||
|
|
||||||
signals:
|
signals:
|
||||||
void entityCollisionWithEntity(const EntityItemID& idA, const EntityItemID& idB, const Collision& collision);
|
void entityCollisionWithEntity(const EntityItemID& idA, const EntityItemID& idB, const Collision& collision);
|
||||||
|
|
||||||
protected: // only called by EntitySimulation
|
protected: // only called by EntitySimulation
|
||||||
// overrides for EntitySimulation
|
// overrides for EntitySimulation
|
||||||
virtual void updateEntitiesInternal(uint64_t now) override;
|
|
||||||
virtual void addEntityToInternalLists(EntityItemPointer entity) override;
|
virtual void addEntityToInternalLists(EntityItemPointer entity) override;
|
||||||
virtual void removeEntityFromInternalLists(EntityItemPointer entity) override;
|
virtual void removeEntityFromInternalLists(EntityItemPointer entity) override;
|
||||||
void processChangedEntity(const EntityItemPointer& entity) override;
|
void processChangedEntity(const EntityItemPointer& entity) override;
|
||||||
virtual void clearEntitiesInternal() override;
|
|
||||||
|
|
||||||
void removeOwnershipData(EntityMotionState* motionState);
|
void removeOwnershipData(EntityMotionState* motionState);
|
||||||
void clearOwnershipData();
|
void clearOwnershipData();
|
||||||
|
|
Loading…
Reference in a new issue