Merge branch 'master' of github.com:highfidelity/hifi into avatar-entities-3

This commit is contained in:
Seth Alves 2016-05-10 12:08:45 -07:00
commit f90b9ec65d
44 changed files with 138 additions and 152 deletions

View file

@ -23,7 +23,7 @@ AssignmentAction::AssignmentAction(EntityActionType type, const QUuid& id, Entit
AssignmentAction::~AssignmentAction() { AssignmentAction::~AssignmentAction() {
} }
void AssignmentAction::removeFromSimulation(EntitySimulation* simulation) const { void AssignmentAction::removeFromSimulation(EntitySimulationPointer simulation) const {
withReadLock([&]{ withReadLock([&]{
simulation->removeAction(_id); simulation->removeAction(_id);
simulation->applyActionChanges(); simulation->applyActionChanges();

View file

@ -24,7 +24,7 @@ public:
AssignmentAction(EntityActionType type, const QUuid& id, EntityItemPointer ownerEntity); AssignmentAction(EntityActionType type, const QUuid& id, EntityItemPointer ownerEntity);
virtual ~AssignmentAction(); virtual ~AssignmentAction();
virtual void removeFromSimulation(EntitySimulation* simulation) const; virtual void removeFromSimulation(EntitySimulationPointer simulation) const;
virtual EntityItemWeakPointer getOwnerEntity() const { return _ownerEntity; } virtual EntityItemWeakPointer getOwnerEntity() const { return _ownerEntity; }
virtual void setOwnerEntity(const EntityItemPointer ownerEntity) { _ownerEntity = ownerEntity; } virtual void setOwnerEntity(const EntityItemPointer ownerEntity) { _ownerEntity = ownerEntity; }
virtual bool updateArguments(QVariantMap arguments); virtual bool updateArguments(QVariantMap arguments);

View file

@ -56,7 +56,7 @@ OctreePointer EntityServer::createTree() {
tree->createRootElement(); tree->createRootElement();
tree->addNewlyCreatedHook(this); tree->addNewlyCreatedHook(this);
if (!_entitySimulation) { if (!_entitySimulation) {
SimpleEntitySimulation* simpleSimulation = new SimpleEntitySimulation(); SimpleEntitySimulationPointer simpleSimulation { new SimpleEntitySimulation() };
simpleSimulation->setEntityTree(tree); simpleSimulation->setEntityTree(tree);
tree->setSimulation(simpleSimulation); tree->setSimulation(simpleSimulation);
_entitySimulation = simpleSimulation; _entitySimulation = simpleSimulation;

View file

@ -28,6 +28,8 @@ struct ViewerSendingStats {
}; };
class SimpleEntitySimulation; class SimpleEntitySimulation;
using SimpleEntitySimulationPointer = std::shared_ptr<SimpleEntitySimulation>;
class EntityServer : public OctreeServer, public NewlyCreatedEntityHook { class EntityServer : public OctreeServer, public NewlyCreatedEntityHook {
Q_OBJECT Q_OBJECT
@ -69,7 +71,7 @@ private slots:
void handleEntityPacket(QSharedPointer<ReceivedMessage> message, SharedNodePointer senderNode); void handleEntityPacket(QSharedPointer<ReceivedMessage> message, SharedNodePointer senderNode);
private: private:
SimpleEntitySimulation* _entitySimulation; SimpleEntitySimulationPointer _entitySimulation;
QTimer* _pruneDeletedEntitiesTimer = nullptr; QTimer* _pruneDeletedEntitiesTimer = nullptr;
QReadWriteLock _viewerSendingStatsLock; QReadWriteLock _viewerSendingStatsLock;

View file

@ -274,7 +274,7 @@
}, },
{ {
"id": "walkFwd", "id": "walkFwd",
"interpTarget": 15, "interpTarget": 16,
"interpDuration": 6, "interpDuration": 6,
"transitions": [ "transitions": [
{ "var": "isNotMoving", "state": "idle" }, { "var": "isNotMoving", "state": "idle" },
@ -497,7 +497,7 @@
"data": { "data": {
"url": "animations/idle.fbx", "url": "animations/idle.fbx",
"startFrame": 0.0, "startFrame": 0.0,
"endFrame": 90.0, "endFrame": 300.0,
"timeScale": 1.0, "timeScale": 1.0,
"loopFlag": true "loopFlag": true
}, },
@ -509,7 +509,7 @@
"data": { "data": {
"url": "animations/talk.fbx", "url": "animations/talk.fbx",
"startFrame": 0.0, "startFrame": 0.0,
"endFrame": 801.0, "endFrame": 800.0,
"timeScale": 1.0, "timeScale": 1.0,
"loopFlag": true "loopFlag": true
}, },
@ -572,7 +572,7 @@
"data": { "data": {
"url": "animations/idle_to_walk.fbx", "url": "animations/idle_to_walk.fbx",
"startFrame": 1.0, "startFrame": 1.0,
"endFrame": 19.0, "endFrame": 13.0,
"timeScale": 1.0, "timeScale": 1.0,
"loopFlag": false "loopFlag": false
}, },
@ -631,11 +631,12 @@
"id": "turnRight", "id": "turnRight",
"type": "clip", "type": "clip",
"data": { "data": {
"url": "animations/turn_right.fbx", "url": "animations/turn_left.fbx",
"startFrame": 0.0, "startFrame": 0.0,
"endFrame": 30.0, "endFrame": 30.0,
"timeScale": 1.0, "timeScale": 1.0,
"loopFlag": true "loopFlag": true,
"mirrorFlag": true
}, },
"children": [] "children": []
}, },

View file

@ -485,6 +485,7 @@ Application::Application(int& argc, char** argv, QElapsedTimer& startupTimer) :
_sessionRunTimer(startupTimer), _sessionRunTimer(startupTimer),
_previousSessionCrashed(setupEssentials(argc, argv)), _previousSessionCrashed(setupEssentials(argc, argv)),
_undoStackScriptingInterface(&_undoStack), _undoStackScriptingInterface(&_undoStack),
_entitySimulation(new PhysicalEntitySimulation()),
_physicsEngine(new PhysicsEngine(Vectors::ZERO)), _physicsEngine(new PhysicsEngine(Vectors::ZERO)),
_entityClipboardRenderer(false, this, this), _entityClipboardRenderer(false, this, this),
_entityClipboard(new EntityTree()), _entityClipboard(new EntityTree()),
@ -560,12 +561,6 @@ Application::Application(int& argc, char** argv, QElapsedTimer& startupTimer) :
// put the NodeList and datagram processing on the node thread // put the NodeList and datagram processing on the node thread
nodeList->moveToThread(nodeThread); nodeList->moveToThread(nodeThread);
// Model background downloads need to happen on the Datagram Processor Thread. The idle loop will
// emit checkBackgroundDownloads to cause the ModelCache to check it's queue for requested background
// downloads.
auto modelCache = DependencyManager::get<ModelCache>();
connect(this, &Application::checkBackgroundDownloads, modelCache.data(), &ModelCache::checkAsynchronousGets);
// put the audio processing on a separate thread // put the audio processing on a separate thread
QThread* audioThread = new QThread(); QThread* audioThread = new QThread();
audioThread->setObjectName("Audio Thread"); audioThread->setObjectName("Audio Thread");
@ -2739,9 +2734,6 @@ void Application::idle(uint64_t now) {
} }
_overlayConductor.update(secondsSinceLastUpdate); _overlayConductor.update(secondsSinceLastUpdate);
// check for any requested background downloads.
emit checkBackgroundDownloads();
} }
void Application::setLowVelocityFilter(bool lowVelocityFilter) { void Application::setLowVelocityFilter(bool lowVelocityFilter) {
@ -2991,13 +2983,13 @@ void Application::init() {
_physicsEngine->init(); _physicsEngine->init();
EntityTreePointer tree = getEntities()->getTree(); EntityTreePointer tree = getEntities()->getTree();
_entitySimulation.init(tree, _physicsEngine, &_entityEditSender); _entitySimulation->init(tree, _physicsEngine, &_entityEditSender);
tree->setSimulation(&_entitySimulation); tree->setSimulation(_entitySimulation);
auto entityScriptingInterface = DependencyManager::get<EntityScriptingInterface>(); auto entityScriptingInterface = DependencyManager::get<EntityScriptingInterface>();
// connect the _entityCollisionSystem to our EntityTreeRenderer since that's what handles running entity scripts // connect the _entityCollisionSystem to our EntityTreeRenderer since that's what handles running entity scripts
connect(&_entitySimulation, &EntitySimulation::entityCollisionWithEntity, connect(_entitySimulation.get(), &EntitySimulation::entityCollisionWithEntity,
getEntities(), &EntityTreeRenderer::entityCollisionWithEntity); getEntities(), &EntityTreeRenderer::entityCollisionWithEntity);
// connect the _entities (EntityTreeRenderer) to our script engine's EntityScriptingInterface for firing // connect the _entities (EntityTreeRenderer) to our script engine's EntityScriptingInterface for firing
@ -3417,22 +3409,22 @@ void Application::update(float deltaTime) {
PerformanceTimer perfTimer("updateStates)"); PerformanceTimer perfTimer("updateStates)");
static VectorOfMotionStates motionStates; static VectorOfMotionStates motionStates;
_entitySimulation.getObjectsToRemoveFromPhysics(motionStates); _entitySimulation->getObjectsToRemoveFromPhysics(motionStates);
_physicsEngine->removeObjects(motionStates); _physicsEngine->removeObjects(motionStates);
_entitySimulation.deleteObjectsRemovedFromPhysics(); _entitySimulation->deleteObjectsRemovedFromPhysics();
getEntities()->getTree()->withReadLock([&] { getEntities()->getTree()->withReadLock([&] {
_entitySimulation.getObjectsToAddToPhysics(motionStates); _entitySimulation->getObjectsToAddToPhysics(motionStates);
_physicsEngine->addObjects(motionStates); _physicsEngine->addObjects(motionStates);
}); });
getEntities()->getTree()->withReadLock([&] { getEntities()->getTree()->withReadLock([&] {
_entitySimulation.getObjectsToChange(motionStates); _entitySimulation->getObjectsToChange(motionStates);
VectorOfMotionStates stillNeedChange = _physicsEngine->changeObjects(motionStates); VectorOfMotionStates stillNeedChange = _physicsEngine->changeObjects(motionStates);
_entitySimulation.setObjectsToChange(stillNeedChange); _entitySimulation->setObjectsToChange(stillNeedChange);
}); });
_entitySimulation.applyActionChanges(); _entitySimulation->applyActionChanges();
avatarManager->getObjectsToRemoveFromPhysics(motionStates); avatarManager->getObjectsToRemoveFromPhysics(motionStates);
_physicsEngine->removeObjects(motionStates); _physicsEngine->removeObjects(motionStates);
@ -3460,7 +3452,7 @@ void Application::update(float deltaTime) {
getEntities()->getTree()->withWriteLock([&] { getEntities()->getTree()->withWriteLock([&] {
PerformanceTimer perfTimer("handleOutgoingChanges"); PerformanceTimer perfTimer("handleOutgoingChanges");
const VectorOfMotionStates& outgoingChanges = _physicsEngine->getOutgoingChanges(); const VectorOfMotionStates& outgoingChanges = _physicsEngine->getOutgoingChanges();
_entitySimulation.handleOutgoingChanges(outgoingChanges); _entitySimulation->handleOutgoingChanges(outgoingChanges);
avatarManager->handleOutgoingChanges(outgoingChanges); avatarManager->handleOutgoingChanges(outgoingChanges);
}); });
@ -3473,7 +3465,7 @@ void Application::update(float deltaTime) {
PerformanceTimer perfTimer("entities"); PerformanceTimer perfTimer("entities");
// Collision events (and their scripts) must not be handled when we're locked, above. (That would risk // Collision events (and their scripts) must not be handled when we're locked, above. (That would risk
// deadlock.) // deadlock.)
_entitySimulation.handleCollisionEvents(collisionEvents); _entitySimulation->handleCollisionEvents(collisionEvents);
// NOTE: the getEntities()->update() call below will wait for lock // NOTE: the getEntities()->update() call below will wait for lock
// and will simulate entity motion (the EntityTree has been given an EntitySimulation). // and will simulate entity motion (the EntityTree has been given an EntitySimulation).

View file

@ -222,8 +222,6 @@ public:
signals: signals:
void svoImportRequested(const QString& url); void svoImportRequested(const QString& url);
void checkBackgroundDownloads();
void fullAvatarURLChanged(const QString& newValue, const QString& modelName); void fullAvatarURLChanged(const QString& newValue, const QString& modelName);
void beforeAboutToQuit(); void beforeAboutToQuit();
@ -405,7 +403,7 @@ private:
QElapsedTimer _lastTimeUpdated; QElapsedTimer _lastTimeUpdated;
ShapeManager _shapeManager; ShapeManager _shapeManager;
PhysicalEntitySimulation _entitySimulation; PhysicalEntitySimulationPointer _entitySimulation;
PhysicsEnginePointer _physicsEngine; PhysicsEnginePointer _physicsEngine;
EntityTreeRenderer _entityClipboardRenderer; EntityTreeRenderer _entityClipboardRenderer;

View file

@ -36,7 +36,7 @@ AnimationPointer AnimationCache::getAnimation(const QUrl& url) {
} }
QSharedPointer<Resource> AnimationCache::createResource(const QUrl& url, const QSharedPointer<Resource>& fallback, QSharedPointer<Resource> AnimationCache::createResource(const QUrl& url, const QSharedPointer<Resource>& fallback,
bool delayLoad, const void* extra) { const void* extra) {
return QSharedPointer<Resource>(new Animation(url), &Resource::deleter); return QSharedPointer<Resource>(new Animation(url), &Resource::deleter);
} }

View file

@ -35,8 +35,8 @@ public:
protected: protected:
virtual QSharedPointer<Resource> createResource(const QUrl& url, virtual QSharedPointer<Resource> createResource(const QUrl& url, const QSharedPointer<Resource>& fallback,
const QSharedPointer<Resource>& fallback, bool delayLoad, const void* extra); const void* extra);
private: private:
explicit AnimationCache(QObject* parent = NULL); explicit AnimationCache(QObject* parent = NULL);
virtual ~AnimationCache() { } virtual ~AnimationCache() { }

View file

@ -35,7 +35,7 @@ SharedSoundPointer SoundCache::getSound(const QUrl& url) {
} }
QSharedPointer<Resource> SoundCache::createResource(const QUrl& url, const QSharedPointer<Resource>& fallback, QSharedPointer<Resource> SoundCache::createResource(const QUrl& url, const QSharedPointer<Resource>& fallback,
bool delayLoad, const void* extra) { const void* extra) {
qCDebug(audio) << "Requesting sound at" << url.toString(); qCDebug(audio) << "Requesting sound at" << url.toString();
return QSharedPointer<Resource>(new Sound(url), &Resource::deleter); return QSharedPointer<Resource>(new Sound(url), &Resource::deleter);
} }

View file

@ -25,8 +25,8 @@ public:
Q_INVOKABLE SharedSoundPointer getSound(const QUrl& url); Q_INVOKABLE SharedSoundPointer getSound(const QUrl& url);
protected: protected:
virtual QSharedPointer<Resource> createResource(const QUrl& url, virtual QSharedPointer<Resource> createResource(const QUrl& url, const QSharedPointer<Resource>& fallback,
const QSharedPointer<Resource>& fallback, bool delayLoad, const void* extra); const void* extra);
private: private:
SoundCache(QObject* parent = NULL); SoundCache(QObject* parent = NULL);
}; };

View file

@ -977,8 +977,8 @@ void RenderablePolyVoxEntityItem::compressVolumeDataAndSendEditPacket() {
properties.setVoxelDataDirty(); properties.setVoxelDataDirty();
properties.setLastEdited(now); properties.setLastEdited(now);
EntitySimulation* simulation = tree ? tree->getSimulation() : nullptr; EntitySimulationPointer simulation = tree ? tree->getSimulation() : nullptr;
PhysicalEntitySimulation* peSimulation = static_cast<PhysicalEntitySimulation*>(simulation); PhysicalEntitySimulationPointer peSimulation = std::static_pointer_cast<PhysicalEntitySimulation>(simulation);
EntityEditPacketSender* packetSender = peSimulation ? peSimulation->getPacketSender() : nullptr; EntityEditPacketSender* packetSender = peSimulation ? peSimulation->getPacketSender() : nullptr;
if (packetSender) { if (packetSender) {
packetSender->queueEditEntityMessage(PacketType::EntityEdit, tree, entity->getID(), properties); packetSender->queueEditEntityMessage(PacketType::EntityEdit, tree, entity->getID(), properties);

View file

@ -20,6 +20,8 @@ class EntityItem;
class EntitySimulation; class EntitySimulation;
using EntityItemPointer = std::shared_ptr<EntityItem>; using EntityItemPointer = std::shared_ptr<EntityItem>;
using EntityItemWeakPointer = std::weak_ptr<EntityItem>; using EntityItemWeakPointer = std::weak_ptr<EntityItem>;
class EntitySimulation;
using EntitySimulationPointer = std::shared_ptr<EntitySimulation>;
enum EntityActionType { enum EntityActionType {
// keep these synchronized with actionTypeFromString and actionTypeToString // keep these synchronized with actionTypeFromString and actionTypeToString
@ -39,7 +41,7 @@ public:
bool isActive() { return _active; } bool isActive() { return _active; }
virtual void removeFromSimulation(EntitySimulation* simulation) const = 0; virtual void removeFromSimulation(EntitySimulationPointer simulation) const = 0;
virtual EntityItemWeakPointer getOwnerEntity() const = 0; virtual EntityItemWeakPointer getOwnerEntity() const = 0;
virtual void setOwnerEntity(const EntityItemPointer ownerEntity) = 0; virtual void setOwnerEntity(const EntityItemPointer ownerEntity) = 0;
virtual bool updateArguments(QVariantMap arguments) = 0; virtual bool updateArguments(QVariantMap arguments) = 0;

View file

@ -89,7 +89,7 @@ EntityItem::EntityItem(const EntityItemID& entityItemID) :
EntityItem::~EntityItem() { EntityItem::~EntityItem() {
// clear out any left-over actions // clear out any left-over actions
EntityTreePointer entityTree = _element ? _element->getTree() : nullptr; EntityTreePointer entityTree = _element ? _element->getTree() : nullptr;
EntitySimulation* simulation = entityTree ? entityTree->getSimulation() : nullptr; EntitySimulationPointer simulation = entityTree ? entityTree->getSimulation() : nullptr;
if (simulation) { if (simulation) {
clearActions(simulation); clearActions(simulation);
} }
@ -1736,7 +1736,7 @@ QString EntityItem::actionsToDebugString() {
return result; return result;
} }
bool EntityItem::addAction(EntitySimulation* simulation, EntityActionPointer action) { bool EntityItem::addAction(EntitySimulationPointer simulation, EntityActionPointer action) {
bool result; bool result;
withWriteLock([&] { withWriteLock([&] {
checkWaitingToRemove(simulation); checkWaitingToRemove(simulation);
@ -1753,7 +1753,7 @@ bool EntityItem::addAction(EntitySimulation* simulation, EntityActionPointer act
return result; return result;
} }
bool EntityItem::addActionInternal(EntitySimulation* simulation, EntityActionPointer action) { bool EntityItem::addActionInternal(EntitySimulationPointer simulation, EntityActionPointer action) {
assert(action); assert(action);
assert(simulation); assert(simulation);
auto actionOwnerEntity = action->getOwnerEntity().lock(); auto actionOwnerEntity = action->getOwnerEntity().lock();
@ -1777,7 +1777,7 @@ bool EntityItem::addActionInternal(EntitySimulation* simulation, EntityActionPoi
return success; return success;
} }
bool EntityItem::updateAction(EntitySimulation* simulation, const QUuid& actionID, const QVariantMap& arguments) { bool EntityItem::updateAction(EntitySimulationPointer simulation, const QUuid& actionID, const QVariantMap& arguments) {
bool success = false; bool success = false;
withWriteLock([&] { withWriteLock([&] {
checkWaitingToRemove(simulation); checkWaitingToRemove(simulation);
@ -1800,7 +1800,7 @@ bool EntityItem::updateAction(EntitySimulation* simulation, const QUuid& actionI
return success; return success;
} }
bool EntityItem::removeAction(EntitySimulation* simulation, const QUuid& actionID) { bool EntityItem::removeAction(EntitySimulationPointer simulation, const QUuid& actionID) {
bool success = false; bool success = false;
withWriteLock([&] { withWriteLock([&] {
checkWaitingToRemove(simulation); checkWaitingToRemove(simulation);
@ -1809,7 +1809,7 @@ bool EntityItem::removeAction(EntitySimulation* simulation, const QUuid& actionI
return success; return success;
} }
bool EntityItem::removeActionInternal(const QUuid& actionID, EntitySimulation* simulation) { bool EntityItem::removeActionInternal(const QUuid& actionID, EntitySimulationPointer simulation) {
_previouslyDeletedActions.insert(actionID, usecTimestampNow()); _previouslyDeletedActions.insert(actionID, usecTimestampNow());
if (_objectActions.contains(actionID)) { if (_objectActions.contains(actionID)) {
if (!simulation) { if (!simulation) {
@ -1836,7 +1836,7 @@ bool EntityItem::removeActionInternal(const QUuid& actionID, EntitySimulation* s
return false; return false;
} }
bool EntityItem::clearActions(EntitySimulation* simulation) { bool EntityItem::clearActions(EntitySimulationPointer simulation) {
withWriteLock([&] { withWriteLock([&] {
QHash<QUuid, EntityActionPointer>::iterator i = _objectActions.begin(); QHash<QUuid, EntityActionPointer>::iterator i = _objectActions.begin();
while (i != _objectActions.end()) { while (i != _objectActions.end()) {
@ -1872,7 +1872,7 @@ void EntityItem::deserializeActionsInternal() {
EntityTreePointer entityTree = getTree(); EntityTreePointer entityTree = getTree();
assert(entityTree); assert(entityTree);
EntitySimulation* simulation = entityTree ? entityTree->getSimulation() : nullptr; EntitySimulationPointer simulation = entityTree ? entityTree->getSimulation() : nullptr;
assert(simulation); assert(simulation);
QVector<QByteArray> serializedActions; QVector<QByteArray> serializedActions;
@ -1952,7 +1952,7 @@ void EntityItem::deserializeActionsInternal() {
return; return;
} }
void EntityItem::checkWaitingToRemove(EntitySimulation* simulation) { void EntityItem::checkWaitingToRemove(EntitySimulationPointer simulation) {
foreach(QUuid actionID, _actionsToRemove) { foreach(QUuid actionID, _actionsToRemove) {
removeActionInternal(actionID, simulation); removeActionInternal(actionID, simulation);
} }

View file

@ -383,10 +383,10 @@ public:
void flagForMotionStateChange() { _dirtyFlags |= Simulation::DIRTY_MOTION_TYPE; } void flagForMotionStateChange() { _dirtyFlags |= Simulation::DIRTY_MOTION_TYPE; }
QString actionsToDebugString(); QString actionsToDebugString();
bool addAction(EntitySimulation* simulation, EntityActionPointer action); bool addAction(EntitySimulationPointer simulation, EntityActionPointer action);
bool updateAction(EntitySimulation* simulation, const QUuid& actionID, const QVariantMap& arguments); bool updateAction(EntitySimulationPointer simulation, const QUuid& actionID, const QVariantMap& arguments);
bool removeAction(EntitySimulation* simulation, const QUuid& actionID); bool removeAction(EntitySimulationPointer simulation, const QUuid& actionID);
bool clearActions(EntitySimulation* simulation); bool clearActions(EntitySimulationPointer simulation);
void setActionData(QByteArray actionData); void setActionData(QByteArray actionData);
const QByteArray getActionData() const; const QByteArray getActionData() const;
bool hasActions() const { return !_objectActions.empty(); } bool hasActions() const { return !_objectActions.empty(); }
@ -529,8 +529,8 @@ protected:
void* _physicsInfo = nullptr; // set by EntitySimulation void* _physicsInfo = nullptr; // set by EntitySimulation
bool _simulated; // set by EntitySimulation bool _simulated; // set by EntitySimulation
bool addActionInternal(EntitySimulation* simulation, EntityActionPointer action); bool addActionInternal(EntitySimulationPointer simulation, EntityActionPointer action);
bool removeActionInternal(const QUuid& actionID, EntitySimulation* simulation = nullptr); bool removeActionInternal(const QUuid& actionID, EntitySimulationPointer simulation = nullptr);
void deserializeActionsInternal(); void deserializeActionsInternal();
void serializeActions(bool& success, QByteArray& result) const; void serializeActions(bool& success, QByteArray& result) const;
QHash<QUuid, EntityActionPointer> _objectActions; QHash<QUuid, EntityActionPointer> _objectActions;
@ -541,7 +541,7 @@ protected:
// when an entity-server starts up, EntityItem::setActionData is called before the entity-tree is // when an entity-server starts up, EntityItem::setActionData is called before the entity-tree is
// ready. This means we can't find our EntityItemPointer or add the action to the simulation. These // ready. This means we can't find our EntityItemPointer or add the action to the simulation. These
// are used to keep track of and work around this situation. // are used to keep track of and work around this situation.
void checkWaitingToRemove(EntitySimulation* simulation = nullptr); void checkWaitingToRemove(EntitySimulationPointer simulation = nullptr);
mutable QSet<QUuid> _actionsToRemove; mutable QSet<QUuid> _actionsToRemove;
mutable bool _actionDataDirty = false; mutable bool _actionDataDirty = false;
mutable bool _actionDataNeedsTransmit = false; mutable bool _actionDataNeedsTransmit = false;

View file

@ -777,7 +777,7 @@ bool EntityScriptingInterface::appendPoint(QUuid entityID, const glm::vec3& poin
bool EntityScriptingInterface::actionWorker(const QUuid& entityID, bool EntityScriptingInterface::actionWorker(const QUuid& entityID,
std::function<bool(EntitySimulation*, EntityItemPointer)> actor) { std::function<bool(EntitySimulationPointer, EntityItemPointer)> actor) {
if (!_entityTree) { if (!_entityTree) {
return false; return false;
} }
@ -785,7 +785,7 @@ bool EntityScriptingInterface::actionWorker(const QUuid& entityID,
EntityItemPointer entity; EntityItemPointer entity;
bool doTransmit = false; bool doTransmit = false;
_entityTree->withWriteLock([&] { _entityTree->withWriteLock([&] {
EntitySimulation* simulation = _entityTree->getSimulation(); EntitySimulationPointer simulation = _entityTree->getSimulation();
entity = _entityTree->findEntityByEntityItemID(entityID); entity = _entityTree->findEntityByEntityItemID(entityID);
if (!entity) { if (!entity) {
qDebug() << "actionWorker -- unknown entity" << entityID; qDebug() << "actionWorker -- unknown entity" << entityID;
@ -826,7 +826,7 @@ QUuid EntityScriptingInterface::addAction(const QString& actionTypeString,
QUuid actionID = QUuid::createUuid(); QUuid actionID = QUuid::createUuid();
auto actionFactory = DependencyManager::get<EntityActionFactoryInterface>(); auto actionFactory = DependencyManager::get<EntityActionFactoryInterface>();
bool success = false; bool success = false;
actionWorker(entityID, [&](EntitySimulation* simulation, EntityItemPointer entity) { actionWorker(entityID, [&](EntitySimulationPointer simulation, EntityItemPointer entity) {
// create this action even if the entity doesn't have physics info. it will often be the // create this action even if the entity doesn't have physics info. it will often be the
// case that a script adds an action immediately after an object is created, and the physicsInfo // case that a script adds an action immediately after an object is created, and the physicsInfo
// is computed asynchronously. // is computed asynchronously.
@ -854,7 +854,7 @@ QUuid EntityScriptingInterface::addAction(const QString& actionTypeString,
bool EntityScriptingInterface::updateAction(const QUuid& entityID, const QUuid& actionID, const QVariantMap& arguments) { bool EntityScriptingInterface::updateAction(const QUuid& entityID, const QUuid& actionID, const QVariantMap& arguments) {
return actionWorker(entityID, [&](EntitySimulation* simulation, EntityItemPointer entity) { return actionWorker(entityID, [&](EntitySimulationPointer simulation, EntityItemPointer entity) {
bool success = entity->updateAction(simulation, actionID, arguments); bool success = entity->updateAction(simulation, actionID, arguments);
if (success) { if (success) {
entity->grabSimulationOwnership(); entity->grabSimulationOwnership();
@ -865,7 +865,7 @@ bool EntityScriptingInterface::updateAction(const QUuid& entityID, const QUuid&
bool EntityScriptingInterface::deleteAction(const QUuid& entityID, const QUuid& actionID) { bool EntityScriptingInterface::deleteAction(const QUuid& entityID, const QUuid& actionID) {
bool success = false; bool success = false;
actionWorker(entityID, [&](EntitySimulation* simulation, EntityItemPointer entity) { actionWorker(entityID, [&](EntitySimulationPointer simulation, EntityItemPointer entity) {
success = entity->removeAction(simulation, actionID); success = entity->removeAction(simulation, actionID);
if (success) { if (success) {
// reduce from grab to poke // reduce from grab to poke
@ -878,7 +878,7 @@ bool EntityScriptingInterface::deleteAction(const QUuid& entityID, const QUuid&
QVector<QUuid> EntityScriptingInterface::getActionIDs(const QUuid& entityID) { QVector<QUuid> EntityScriptingInterface::getActionIDs(const QUuid& entityID) {
QVector<QUuid> result; QVector<QUuid> result;
actionWorker(entityID, [&](EntitySimulation* simulation, EntityItemPointer entity) { actionWorker(entityID, [&](EntitySimulationPointer simulation, EntityItemPointer entity) {
QList<QUuid> actionIDs = entity->getActionIDs(); QList<QUuid> actionIDs = entity->getActionIDs();
result = QVector<QUuid>::fromList(actionIDs); result = QVector<QUuid>::fromList(actionIDs);
return false; // don't send an edit packet return false; // don't send an edit packet
@ -888,7 +888,7 @@ QVector<QUuid> EntityScriptingInterface::getActionIDs(const QUuid& entityID) {
QVariantMap EntityScriptingInterface::getActionArguments(const QUuid& entityID, const QUuid& actionID) { QVariantMap EntityScriptingInterface::getActionArguments(const QUuid& entityID, const QUuid& actionID) {
QVariantMap result; QVariantMap result;
actionWorker(entityID, [&](EntitySimulation* simulation, EntityItemPointer entity) { actionWorker(entityID, [&](EntitySimulationPointer simulation, EntityItemPointer entity) {
result = entity->getActionArguments(actionID); result = entity->getActionArguments(actionID);
return false; // don't send an edit packet return false; // don't send an edit packet
}); });

View file

@ -200,11 +200,11 @@ signals:
void debitEnergySource(float value); void debitEnergySource(float value);
private: private:
bool actionWorker(const QUuid& entityID, std::function<bool(EntitySimulation*, EntityItemPointer)> actor); bool actionWorker(const QUuid& entityID, std::function<bool(EntitySimulationPointer, EntityItemPointer)> actor);
bool setVoxels(QUuid entityID, std::function<bool(PolyVoxEntityItem&)> actor); bool setVoxels(QUuid entityID, std::function<bool(PolyVoxEntityItem&)> actor);
bool setPoints(QUuid entityID, std::function<bool(LineEntityItem&)> actor); bool setPoints(QUuid entityID, std::function<bool(LineEntityItem&)> actor);
void queueEntityMessage(PacketType packetType, EntityItemID entityID, const EntityItemProperties& properties); void queueEntityMessage(PacketType packetType, EntityItemID entityID, const EntityItemProperties& properties);
EntityItemPointer checkForTreeEntityAndTypeMatch(const QUuid& entityID, EntityItemPointer checkForTreeEntityAndTypeMatch(const QUuid& entityID,
EntityTypes::EntityType entityType = EntityTypes::Unknown); EntityTypes::EntityType entityType = EntityTypes::Unknown);

View file

@ -64,7 +64,7 @@ void EntitySimulation::prepareEntityForDelete(EntityItemPointer entity) {
assert(entity->isDead()); assert(entity->isDead());
if (entity->isSimulated()) { if (entity->isSimulated()) {
QMutexLocker lock(&_mutex); QMutexLocker lock(&_mutex);
entity->clearActions(this); entity->clearActions(getThisPointer());
removeEntityInternal(entity); removeEntityInternal(entity);
_entitiesToDelete.insert(entity); _entitiesToDelete.insert(entity);
} }

View file

@ -22,8 +22,9 @@
#include "EntityItem.h" #include "EntityItem.h"
#include "EntityTree.h" #include "EntityTree.h"
typedef QSet<EntityItemPointer> SetOfEntities; using EntitySimulationPointer = std::shared_ptr<EntitySimulation>;
typedef QVector<EntityItemPointer> VectorOfEntities; using SetOfEntities = QSet<EntityItemPointer>;
using VectorOfEntities = QVector<EntityItemPointer>;
// the EntitySimulation needs to know when these things change on an entity, // the EntitySimulation needs to know when these things change on an entity,
// so it can sort EntityItem or relay its state to the PhysicsEngine. // so it can sort EntityItem or relay its state to the PhysicsEngine.
@ -41,12 +42,16 @@ const int DIRTY_SIMULATION_FLAGS =
Simulation::DIRTY_MATERIAL | Simulation::DIRTY_MATERIAL |
Simulation::DIRTY_SIMULATOR_ID; Simulation::DIRTY_SIMULATOR_ID;
class EntitySimulation : public QObject { class EntitySimulation : public QObject, public std::enable_shared_from_this<EntitySimulation> {
Q_OBJECT Q_OBJECT
public: public:
EntitySimulation() : _mutex(QMutex::Recursive), _entityTree(NULL), _nextExpiry(quint64(-1)) { } EntitySimulation() : _mutex(QMutex::Recursive), _entityTree(NULL), _nextExpiry(quint64(-1)) { }
virtual ~EntitySimulation() { setEntityTree(NULL); } virtual ~EntitySimulation() { setEntityTree(NULL); }
inline EntitySimulationPointer getThisPointer() const {
return std::const_pointer_cast<EntitySimulation>(shared_from_this());
}
/// \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);

View file

@ -365,7 +365,7 @@ void EntityTree::notifyNewCollisionSoundURL(const QString& newURL, const EntityI
emit newCollisionSoundURL(QUrl(newURL), entityID); emit newCollisionSoundURL(QUrl(newURL), entityID);
} }
void EntityTree::setSimulation(EntitySimulation* simulation) { void EntityTree::setSimulation(EntitySimulationPointer simulation) {
this->withWriteLock([&] { this->withWriteLock([&] {
if (simulation) { if (simulation) {
// assert that the simulation's backpointer has already been properly connected // assert that the simulation's backpointer has already been properly connected

View file

@ -194,8 +194,8 @@ public:
void emitEntityScriptChanging(const EntityItemID& entityItemID, const bool reload); void emitEntityScriptChanging(const EntityItemID& entityItemID, const bool reload);
void setSimulation(EntitySimulation* simulation); void setSimulation(EntitySimulationPointer simulation);
EntitySimulation* getSimulation() const { return _simulation; } EntitySimulationPointer getSimulation() const { return _simulation; }
bool wantEditLogging() const { return _wantEditLogging; } bool wantEditLogging() const { return _wantEditLogging; }
void setWantEditLogging(bool value) { _wantEditLogging = value; } void setWantEditLogging(bool value) { _wantEditLogging = value; }
@ -299,7 +299,7 @@ protected:
mutable QReadWriteLock _entityToElementLock; mutable QReadWriteLock _entityToElementLock;
QHash<EntityItemID, EntityTreeElementPointer> _entityToElementMap; QHash<EntityItemID, EntityTreeElementPointer> _entityToElementMap;
EntitySimulation* _simulation; EntitySimulationPointer _simulation;
bool _wantEditLogging = false; bool _wantEditLogging = false;
bool _wantTerseEditLogging = false; bool _wantTerseEditLogging = false;

View file

@ -22,7 +22,7 @@ EntityTreeHeadlessViewer::~EntityTreeHeadlessViewer() {
void EntityTreeHeadlessViewer::init() { void EntityTreeHeadlessViewer::init() {
OctreeHeadlessViewer::init(); OctreeHeadlessViewer::init();
if (!_simulation) { if (!_simulation) {
SimpleEntitySimulation* simpleSimulation = new SimpleEntitySimulation(); SimpleEntitySimulationPointer simpleSimulation { new SimpleEntitySimulation() };
EntityTreePointer entityTree = std::static_pointer_cast<EntityTree>(_tree); EntityTreePointer entityTree = std::static_pointer_cast<EntityTree>(_tree);
simpleSimulation->setEntityTree(entityTree); simpleSimulation->setEntityTree(entityTree);
entityTree->setSimulation(simpleSimulation); entityTree->setSimulation(simpleSimulation);

View file

@ -49,7 +49,7 @@ protected:
return newTree; return newTree;
} }
EntitySimulation* _simulation; EntitySimulationPointer _simulation;
}; };
#endif // hifi_EntityTreeHeadlessViewer_h #endif // hifi_EntityTreeHeadlessViewer_h

View file

@ -14,6 +14,10 @@
#include "EntitySimulation.h" #include "EntitySimulation.h"
class SimpleEntitySimulation;
using SimpleEntitySimulationPointer = std::shared_ptr<SimpleEntitySimulation>;
/// provides simple velocity + gravity extrapolation of EntityItem's /// provides simple velocity + gravity extrapolation of EntityItem's
class SimpleEntitySimulation : public EntitySimulation { class SimpleEntitySimulation : public EntitySimulation {

View file

@ -71,7 +71,7 @@ void GeometryMappingResource::downloadFinished(const QByteArray& data) {
GeometryExtra extra{ mapping, _textureBaseUrl }; GeometryExtra extra{ mapping, _textureBaseUrl };
// Get the raw GeometryResource, not the wrapped NetworkGeometry // Get the raw GeometryResource, not the wrapped NetworkGeometry
_geometryResource = modelCache->getResource(url, QUrl(), false, &extra).staticCast<GeometryResource>(); _geometryResource = modelCache->getResource(url, QUrl(), &extra).staticCast<GeometryResource>();
// Avoid caching nested resources - their references will be held by the parent // Avoid caching nested resources - their references will be held by the parent
_geometryResource->_isCacheable = false; _geometryResource->_isCacheable = false;
@ -236,7 +236,7 @@ ModelCache::ModelCache() {
} }
QSharedPointer<Resource> ModelCache::createResource(const QUrl& url, const QSharedPointer<Resource>& fallback, QSharedPointer<Resource> ModelCache::createResource(const QUrl& url, const QSharedPointer<Resource>& fallback,
bool delayLoad, const void* extra) { const void* extra) {
Resource* resource = nullptr; Resource* resource = nullptr;
if (url.path().toLower().endsWith(".fst")) { if (url.path().toLower().endsWith(".fst")) {
resource = new GeometryMappingResource(url); resource = new GeometryMappingResource(url);
@ -252,7 +252,7 @@ QSharedPointer<Resource> ModelCache::createResource(const QUrl& url, const QShar
std::shared_ptr<NetworkGeometry> ModelCache::getGeometry(const QUrl& url, const QVariantHash& mapping, const QUrl& textureBaseUrl) { std::shared_ptr<NetworkGeometry> ModelCache::getGeometry(const QUrl& url, const QVariantHash& mapping, const QUrl& textureBaseUrl) {
GeometryExtra geometryExtra = { mapping, textureBaseUrl }; GeometryExtra geometryExtra = { mapping, textureBaseUrl };
GeometryResource::Pointer resource = getResource(url, QUrl(), true, &geometryExtra).staticCast<GeometryResource>(); GeometryResource::Pointer resource = getResource(url, QUrl(), &geometryExtra).staticCast<GeometryResource>();
if (resource) { if (resource) {
if (resource->isLoaded() && resource->shouldSetTextures()) { if (resource->isLoaded() && resource->shouldSetTextures()) {
resource->setTextures(); resource->setTextures();

View file

@ -44,8 +44,8 @@ public:
protected: protected:
friend class GeometryMappingResource; friend class GeometryMappingResource;
virtual QSharedPointer<Resource> createResource(const QUrl& url, virtual QSharedPointer<Resource> createResource(const QUrl& url, const QSharedPointer<Resource>& fallback,
const QSharedPointer<Resource>& fallback, bool delayLoad, const void* extra); const void* extra);
private: private:
ModelCache(); ModelCache();

View file

@ -7,11 +7,8 @@
// //
#include "ShaderCache.h" #include "ShaderCache.h"
NetworkShader::NetworkShader(const QUrl& url, bool delayLoad) NetworkShader::NetworkShader(const QUrl& url) :
: Resource(url, delayLoad) Resource(url) {}
{
}
void NetworkShader::downloadFinished(const QByteArray& data) { void NetworkShader::downloadFinished(const QByteArray& data) {
_source = QString::fromUtf8(data); _source = QString::fromUtf8(data);
@ -24,10 +21,11 @@ ShaderCache& ShaderCache::instance() {
} }
NetworkShaderPointer ShaderCache::getShader(const QUrl& url) { NetworkShaderPointer ShaderCache::getShader(const QUrl& url) {
return ResourceCache::getResource(url, QUrl(), false, nullptr).staticCast<NetworkShader>(); return ResourceCache::getResource(url, QUrl(), nullptr).staticCast<NetworkShader>();
} }
QSharedPointer<Resource> ShaderCache::createResource(const QUrl& url, const QSharedPointer<Resource>& fallback, bool delayLoad, const void* extra) { QSharedPointer<Resource> ShaderCache::createResource(const QUrl& url, const QSharedPointer<Resource>& fallback,
return QSharedPointer<Resource>(new NetworkShader(url, delayLoad), &Resource::deleter); const void* extra) {
return QSharedPointer<Resource>(new NetworkShader(url), &Resource::deleter);
} }

View file

@ -13,7 +13,7 @@
class NetworkShader : public Resource { class NetworkShader : public Resource {
public: public:
NetworkShader(const QUrl& url, bool delayLoad); NetworkShader(const QUrl& url);
virtual void downloadFinished(const QByteArray& data) override; virtual void downloadFinished(const QByteArray& data) override;
QString _source; QString _source;
@ -28,7 +28,8 @@ public:
NetworkShaderPointer getShader(const QUrl& url); NetworkShaderPointer getShader(const QUrl& url);
protected: protected:
virtual QSharedPointer<Resource> createResource(const QUrl& url, const QSharedPointer<Resource>& fallback, bool delayLoad, const void* extra) override; virtual QSharedPointer<Resource> createResource(const QUrl& url, const QSharedPointer<Resource>& fallback,
const void* extra) override;
}; };
#endif #endif

View file

@ -167,7 +167,7 @@ ScriptableResource* TextureCache::prefetch(const QUrl& url, int type) {
NetworkTexturePointer TextureCache::getTexture(const QUrl& url, Type type, const QByteArray& content) { NetworkTexturePointer TextureCache::getTexture(const QUrl& url, Type type, const QByteArray& content) {
TextureExtra extra = { type, content }; TextureExtra extra = { type, content };
return ResourceCache::getResource(url, QUrl(), content.isEmpty(), &extra).staticCast<NetworkTexture>(); return ResourceCache::getResource(url, QUrl(), &extra).staticCast<NetworkTexture>();
} }
@ -231,8 +231,8 @@ gpu::TexturePointer TextureCache::getImageTexture(const QString& path, Type type
return gpu::TexturePointer(loader(image, QUrl::fromLocalFile(path).fileName().toStdString())); return gpu::TexturePointer(loader(image, QUrl::fromLocalFile(path).fileName().toStdString()));
} }
QSharedPointer<Resource> TextureCache::createResource(const QUrl& url, QSharedPointer<Resource> TextureCache::createResource(const QUrl& url, const QSharedPointer<Resource>& fallback,
const QSharedPointer<Resource>& fallback, bool delayLoad, const void* extra) { const void* extra) {
const TextureExtra* textureExtra = static_cast<const TextureExtra*>(extra); const TextureExtra* textureExtra = static_cast<const TextureExtra*>(extra);
auto type = textureExtra ? textureExtra->type : Type::DEFAULT_TEXTURE; auto type = textureExtra ? textureExtra->type : Type::DEFAULT_TEXTURE;
auto content = textureExtra ? textureExtra->content : QByteArray(); auto content = textureExtra ? textureExtra->content : QByteArray();
@ -241,7 +241,7 @@ QSharedPointer<Resource> TextureCache::createResource(const QUrl& url,
} }
NetworkTexture::NetworkTexture(const QUrl& url, Type type, const QByteArray& content) : NetworkTexture::NetworkTexture(const QUrl& url, Type type, const QByteArray& content) :
Resource(url, !content.isEmpty()), Resource(url),
_type(type) _type(type)
{ {
_textureSource = std::make_shared<gpu::TextureSource>(); _textureSource = std::make_shared<gpu::TextureSource>();

View file

@ -131,8 +131,8 @@ protected:
// Overload ResourceCache::prefetch to allow specifying texture type for loads // Overload ResourceCache::prefetch to allow specifying texture type for loads
Q_INVOKABLE ScriptableResource* prefetch(const QUrl& url, int type); Q_INVOKABLE ScriptableResource* prefetch(const QUrl& url, int type);
virtual QSharedPointer<Resource> createResource(const QUrl& url, virtual QSharedPointer<Resource> createResource(const QUrl& url, const QSharedPointer<Resource>& fallback,
const QSharedPointer<Resource>& fallback, bool delayLoad, const void* extra); const void* extra);
private: private:
TextureCache(); TextureCache();

View file

@ -179,7 +179,7 @@ ScriptableResource* ResourceCache::prefetch(const QUrl& url, void* extra) {
result = new ScriptableResource(url); result = new ScriptableResource(url);
auto resource = getResource(url, QUrl(), false, extra); auto resource = getResource(url, QUrl(), extra);
result->_resource = resource; result->_resource = resource;
result->setObjectName(url.toString()); result->setObjectName(url.toString());
@ -316,25 +316,7 @@ void ResourceCache::setRequestLimit(int limit) {
} }
} }
void ResourceCache::getResourceAsynchronously(const QUrl& url) { QSharedPointer<Resource> ResourceCache::getResource(const QUrl& url, const QUrl& fallback, void* extra) {
qCDebug(networking) << "ResourceCache::getResourceAsynchronously" << url.toString();
QWriteLocker locker(&_resourcesToBeGottenLock);
_resourcesToBeGotten.enqueue(QUrl(url));
}
void ResourceCache::checkAsynchronousGets() {
assert(QThread::currentThread() == thread());
QWriteLocker locker(&_resourcesToBeGottenLock);
if (!_resourcesToBeGotten.isEmpty()) {
QUrl url = _resourcesToBeGotten.dequeue();
locker.unlock();
getResource(url);
}
}
QSharedPointer<Resource> ResourceCache::getResource(const QUrl& url, const QUrl& fallback,
bool delayLoad, void* extra) {
QSharedPointer<Resource> resource; QSharedPointer<Resource> resource;
{ {
QReadLocker locker(&_resourcesLock); QReadLocker locker(&_resourcesLock);
@ -346,17 +328,21 @@ QSharedPointer<Resource> ResourceCache::getResource(const QUrl& url, const QUrl&
} }
if (QThread::currentThread() != thread()) { if (QThread::currentThread() != thread()) {
assert(delayLoad); qCDebug(networking) << "Fetching asynchronously:" << url;
getResourceAsynchronously(url); QMetaObject::invokeMethod(this, "getResource",
Q_ARG(QUrl, url), Q_ARG(QUrl, fallback));
// Cannot use extra parameter as it might be freed before the invocation
return QSharedPointer<Resource>(); return QSharedPointer<Resource>();
} }
if (!url.isValid() && !url.isEmpty() && fallback.isValid()) { if (!url.isValid() && !url.isEmpty() && fallback.isValid()) {
return getResource(fallback, QUrl(), delayLoad); return getResource(fallback, QUrl());
} }
resource = createResource(url, fallback.isValid() ? resource = createResource(
getResource(fallback, QUrl(), true) : QSharedPointer<Resource>(), delayLoad, extra); url,
fallback.isValid() ? getResource(fallback, QUrl()) : QSharedPointer<Resource>(),
extra);
resource->setSelf(resource); resource->setSelf(resource);
resource->setCache(this); resource->setCache(this);
connect(resource.data(), &Resource::updateSize, this, &ResourceCache::updateTotalSize); connect(resource.data(), &Resource::updateSize, this, &ResourceCache::updateTotalSize);
@ -508,7 +494,7 @@ const int DEFAULT_REQUEST_LIMIT = 10;
int ResourceCache::_requestLimit = DEFAULT_REQUEST_LIMIT; int ResourceCache::_requestLimit = DEFAULT_REQUEST_LIMIT;
int ResourceCache::_requestsActive = 0; int ResourceCache::_requestsActive = 0;
Resource::Resource(const QUrl& url, bool delayLoad) : Resource::Resource(const QUrl& url) :
_url(url), _url(url),
_activeUrl(url), _activeUrl(url),
_request(nullptr) { _request(nullptr) {

View file

@ -179,9 +179,6 @@ public:
signals: signals:
void dirty(); void dirty();
public slots:
void checkAsynchronousGets();
protected slots: protected slots:
void updateTotalSize(const qint64& deltaSize); void updateTotalSize(const qint64& deltaSize);
@ -190,6 +187,14 @@ protected slots:
// and delegate to it (see TextureCache::prefetch(const QUrl&, int). // and delegate to it (see TextureCache::prefetch(const QUrl&, int).
ScriptableResource* prefetch(const QUrl& url, void* extra); ScriptableResource* prefetch(const QUrl& url, void* extra);
/// Loads a resource from the specified URL and returns it.
/// If the caller is on a different thread than the ResourceCache,
/// returns an empty smart pointer and loads its asynchronously.
/// \param fallback a fallback URL to load if the desired one is unavailable
/// \param extra extra data to pass to the creator, if appropriate
QSharedPointer<Resource> getResource(const QUrl& url, const QUrl& fallback = QUrl(),
void* extra = NULL);
private slots: private slots:
void clearATPAssets(); void clearATPAssets();
@ -200,16 +205,9 @@ protected:
// the QScriptEngine will delete the pointer when it is garbage collected. // the QScriptEngine will delete the pointer when it is garbage collected.
Q_INVOKABLE ScriptableResource* prefetch(const QUrl& url) { return prefetch(url, nullptr); } Q_INVOKABLE ScriptableResource* prefetch(const QUrl& url) { return prefetch(url, nullptr); }
/// Loads a resource from the specified URL.
/// \param fallback a fallback URL to load if the desired one is unavailable
/// \param delayLoad if true, don't load the resource immediately; wait until load is first requested
/// \param extra extra data to pass to the creator, if appropriate
QSharedPointer<Resource> getResource(const QUrl& url, const QUrl& fallback = QUrl(),
bool delayLoad = false, void* extra = NULL);
/// Creates a new resource. /// Creates a new resource.
virtual QSharedPointer<Resource> createResource(const QUrl& url, virtual QSharedPointer<Resource> createResource(const QUrl& url, const QSharedPointer<Resource>& fallback,
const QSharedPointer<Resource>& fallback, bool delayLoad, const void* extra) = 0; const void* extra) = 0;
void addUnusedResource(const QSharedPointer<Resource>& resource); void addUnusedResource(const QSharedPointer<Resource>& resource);
void removeUnusedResource(const QSharedPointer<Resource>& resource); void removeUnusedResource(const QSharedPointer<Resource>& resource);
@ -260,7 +258,7 @@ class Resource : public QObject {
public: public:
Resource(const QUrl& url, bool delayLoad = false); Resource(const QUrl& url);
~Resource(); ~Resource();
/// Returns the key last used to identify this resource in the unused map. /// Returns the key last used to identify this resource in the unused map.

View file

@ -138,7 +138,7 @@ QVariantMap ObjectAction::getArguments() {
void ObjectAction::debugDraw(btIDebugDraw* debugDrawer) { void ObjectAction::debugDraw(btIDebugDraw* debugDrawer) {
} }
void ObjectAction::removeFromSimulation(EntitySimulation* simulation) const { void ObjectAction::removeFromSimulation(EntitySimulationPointer simulation) const {
QUuid myID; QUuid myID;
withReadLock([&]{ withReadLock([&]{
myID = _id; myID = _id;

View file

@ -29,7 +29,7 @@ public:
ObjectAction(EntityActionType type, const QUuid& id, EntityItemPointer ownerEntity); ObjectAction(EntityActionType type, const QUuid& id, EntityItemPointer ownerEntity);
virtual ~ObjectAction(); virtual ~ObjectAction();
virtual void removeFromSimulation(EntitySimulation* simulation) const override; virtual void removeFromSimulation(EntitySimulationPointer simulation) const override;
virtual EntityItemWeakPointer getOwnerEntity() const override { return _ownerEntity; } virtual EntityItemWeakPointer getOwnerEntity() const override { return _ownerEntity; }
virtual void setOwnerEntity(const EntityItemPointer ownerEntity) override { _ownerEntity = ownerEntity; } virtual void setOwnerEntity(const EntityItemPointer ownerEntity) override { _ownerEntity = ownerEntity; }

View file

@ -156,7 +156,7 @@ void PhysicalEntitySimulation::clearEntitiesInternal() {
void PhysicalEntitySimulation::prepareEntityForDelete(EntityItemPointer entity) { void PhysicalEntitySimulation::prepareEntityForDelete(EntityItemPointer entity) {
assert(entity); assert(entity);
assert(entity->isDead()); assert(entity->isDead());
entity->clearActions(this); entity->clearActions(getThisPointer());
removeEntityInternal(entity); removeEntityInternal(entity);
} }
// end EntitySimulation overrides // end EntitySimulation overrides

View file

@ -23,7 +23,9 @@
#include "PhysicsEngine.h" #include "PhysicsEngine.h"
#include "EntityMotionState.h" #include "EntityMotionState.h"
typedef QSet<EntityMotionState*> SetOfEntityMotionStates; class PhysicalEntitySimulation;
using PhysicalEntitySimulationPointer = std::shared_ptr<PhysicalEntitySimulation>;
using SetOfEntityMotionStates = QSet<EntityMotionState*>;
class PhysicalEntitySimulation :public EntitySimulation { class PhysicalEntitySimulation :public EntitySimulation {
public: public:

View file

@ -9,12 +9,9 @@
#include "impl/PointerClip.h" #include "impl/PointerClip.h"
using namespace recording; using namespace recording;
NetworkClipLoader::NetworkClipLoader(const QUrl& url, bool delayLoad) NetworkClipLoader::NetworkClipLoader(const QUrl& url) :
: Resource(url, delayLoad), _clip(std::make_shared<NetworkClip>(url)) Resource(url),
{ _clip(std::make_shared<NetworkClip>(url)) {}
}
void NetworkClip::init(const QByteArray& clipData) { void NetworkClip::init(const QByteArray& clipData) {
_clipData = clipData; _clipData = clipData;
@ -32,10 +29,10 @@ ClipCache& ClipCache::instance() {
} }
NetworkClipLoaderPointer ClipCache::getClipLoader(const QUrl& url) { NetworkClipLoaderPointer ClipCache::getClipLoader(const QUrl& url) {
return ResourceCache::getResource(url, QUrl(), false, nullptr).staticCast<NetworkClipLoader>(); return ResourceCache::getResource(url, QUrl(), nullptr).staticCast<NetworkClipLoader>();
} }
QSharedPointer<Resource> ClipCache::createResource(const QUrl& url, const QSharedPointer<Resource>& fallback, bool delayLoad, const void* extra) { QSharedPointer<Resource> ClipCache::createResource(const QUrl& url, const QSharedPointer<Resource>& fallback, const void* extra) {
return QSharedPointer<Resource>(new NetworkClipLoader(url, delayLoad), &Resource::deleter); return QSharedPointer<Resource>(new NetworkClipLoader(url), &Resource::deleter);
} }

View file

@ -31,7 +31,7 @@ private:
class NetworkClipLoader : public Resource { class NetworkClipLoader : public Resource {
public: public:
NetworkClipLoader(const QUrl& url, bool delayLoad); NetworkClipLoader(const QUrl& url);
virtual void downloadFinished(const QByteArray& data) override; virtual void downloadFinished(const QByteArray& data) override;
ClipPointer getClip() { return _clip; } ClipPointer getClip() { return _clip; }
bool completed() { return _failedToLoad || isLoaded(); } bool completed() { return _failedToLoad || isLoaded(); }
@ -49,7 +49,7 @@ public:
NetworkClipLoaderPointer getClipLoader(const QUrl& url); NetworkClipLoaderPointer getClipLoader(const QUrl& url);
protected: protected:
virtual QSharedPointer<Resource> createResource(const QUrl& url, const QSharedPointer<Resource>& fallback, bool delayLoad, const void* extra) override; virtual QSharedPointer<Resource> createResource(const QUrl& url, const QSharedPointer<Resource>& fallback, const void* extra) override;
}; };
} }