mirror of
https://github.com/HifiExperiments/overte.git
synced 2025-06-25 19:18:47 +02:00
Merge pull request #13709 from thoys/fix/require-load-queue
MS17041: Fix for require fail when the same script loaded simultaneously from another entity script
This commit is contained in:
commit
7a635b6a57
6 changed files with 32 additions and 5 deletions
|
@ -40,7 +40,6 @@
|
||||||
|
|
||||||
#include <PointerManager.h>
|
#include <PointerManager.h>
|
||||||
|
|
||||||
size_t std::hash<EntityItemID>::operator()(const EntityItemID& id) const { return qHash(id); }
|
|
||||||
std::function<bool()> EntityTreeRenderer::_entitiesShouldFadeFunction;
|
std::function<bool()> EntityTreeRenderer::_entitiesShouldFadeFunction;
|
||||||
|
|
||||||
QString resolveScriptURL(const QString& scriptUrl) {
|
QString resolveScriptURL(const QString& scriptUrl) {
|
||||||
|
|
|
@ -40,9 +40,6 @@ namespace render { namespace entities {
|
||||||
|
|
||||||
} }
|
} }
|
||||||
|
|
||||||
// Allow the use of std::unordered_map with QUuid keys
|
|
||||||
namespace std { template<> struct hash<EntityItemID> { size_t operator()(const EntityItemID& id) const; }; }
|
|
||||||
|
|
||||||
using EntityRenderer = render::entities::EntityRenderer;
|
using EntityRenderer = render::entities::EntityRenderer;
|
||||||
using EntityRendererPointer = render::entities::EntityRendererPointer;
|
using EntityRendererPointer = render::entities::EntityRendererPointer;
|
||||||
using EntityRendererWeakPointer = render::entities::EntityRendererWeakPointer;
|
using EntityRendererWeakPointer = render::entities::EntityRendererWeakPointer;
|
||||||
|
|
|
@ -69,3 +69,4 @@ QVector<EntityItemID> qVectorEntityItemIDFromScriptValue(const QScriptValue& arr
|
||||||
return newVector;
|
return newVector;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
size_t std::hash<EntityItemID>::operator()(const EntityItemID& id) const { return qHash(id); }
|
||||||
|
|
|
@ -45,4 +45,7 @@ QScriptValue EntityItemIDtoScriptValue(QScriptEngine* engine, const EntityItemID
|
||||||
void EntityItemIDfromScriptValue(const QScriptValue &object, EntityItemID& properties);
|
void EntityItemIDfromScriptValue(const QScriptValue &object, EntityItemID& properties);
|
||||||
QVector<EntityItemID> qVectorEntityItemIDFromScriptValue(const QScriptValue& array);
|
QVector<EntityItemID> qVectorEntityItemIDFromScriptValue(const QScriptValue& array);
|
||||||
|
|
||||||
|
// Allow the use of std::unordered_map with QUuid keys
|
||||||
|
namespace std { template<> struct hash<EntityItemID> { size_t operator()(const EntityItemID& id) const; }; }
|
||||||
|
|
||||||
#endif // hifi_EntityItemID_h
|
#endif // hifi_EntityItemID_h
|
||||||
|
|
|
@ -219,6 +219,20 @@ ScriptEngine::ScriptEngine(Context context, const QString& scriptContents, const
|
||||||
}
|
}
|
||||||
logException(output);
|
logException(output);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
if (_type == Type::ENTITY_CLIENT || _type == Type::ENTITY_SERVER) {
|
||||||
|
QObject::connect(this, &ScriptEngine::update, this, [this]() {
|
||||||
|
// process pending entity script content
|
||||||
|
if (!_contentAvailableQueue.empty()) {
|
||||||
|
EntityScriptContentAvailableMap pending;
|
||||||
|
std::swap(_contentAvailableQueue, pending);
|
||||||
|
for (auto& pair : pending) {
|
||||||
|
auto& args = pair.second;
|
||||||
|
entityScriptContentAvailable(args.entityID, args.scriptOrURL, args.contents, args.isURL, args.success, args.status);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
QString ScriptEngine::getContext() const {
|
QString ScriptEngine::getContext() const {
|
||||||
|
@ -2181,7 +2195,7 @@ void ScriptEngine::loadEntityScript(const EntityItemID& entityID, const QString&
|
||||||
qCDebug(scriptengine) << "loadEntityScript.contentAvailable" << status << QUrl(url).fileName() << entityID.toString();
|
qCDebug(scriptengine) << "loadEntityScript.contentAvailable" << status << QUrl(url).fileName() << entityID.toString();
|
||||||
#endif
|
#endif
|
||||||
if (!isStopping() && _entityScripts.contains(entityID)) {
|
if (!isStopping() && _entityScripts.contains(entityID)) {
|
||||||
entityScriptContentAvailable(entityID, url, contents, isURL, success, status);
|
_contentAvailableQueue[entityID] = { entityID, url, contents, isURL, success, status };
|
||||||
} else {
|
} else {
|
||||||
#ifdef DEBUG_ENTITY_STATES
|
#ifdef DEBUG_ENTITY_STATES
|
||||||
qCDebug(scriptengine) << "loadEntityScript.contentAvailable -- aborting";
|
qCDebug(scriptengine) << "loadEntityScript.contentAvailable -- aborting";
|
||||||
|
|
|
@ -12,6 +12,7 @@
|
||||||
#ifndef hifi_ScriptEngine_h
|
#ifndef hifi_ScriptEngine_h
|
||||||
#define hifi_ScriptEngine_h
|
#define hifi_ScriptEngine_h
|
||||||
|
|
||||||
|
#include <unordered_map>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
|
|
||||||
#include <QtCore/QObject>
|
#include <QtCore/QObject>
|
||||||
|
@ -71,6 +72,17 @@ public:
|
||||||
//bool forceRedownload;
|
//bool forceRedownload;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
struct EntityScriptContentAvailable {
|
||||||
|
EntityItemID entityID;
|
||||||
|
QString scriptOrURL;
|
||||||
|
QString contents;
|
||||||
|
bool isURL;
|
||||||
|
bool success;
|
||||||
|
QString status;
|
||||||
|
};
|
||||||
|
|
||||||
|
typedef std::unordered_map<EntityItemID, EntityScriptContentAvailable> EntityScriptContentAvailableMap;
|
||||||
|
|
||||||
typedef QList<CallbackData> CallbackList;
|
typedef QList<CallbackData> CallbackList;
|
||||||
typedef QHash<QString, CallbackList> RegisteredEventHandlers;
|
typedef QHash<QString, CallbackList> RegisteredEventHandlers;
|
||||||
|
|
||||||
|
@ -762,6 +774,7 @@ protected:
|
||||||
QHash<EntityItemID, EntityScriptDetails> _entityScripts;
|
QHash<EntityItemID, EntityScriptDetails> _entityScripts;
|
||||||
QHash<QString, EntityItemID> _occupiedScriptURLs;
|
QHash<QString, EntityItemID> _occupiedScriptURLs;
|
||||||
QList<DeferredLoadEntity> _deferredEntityLoads;
|
QList<DeferredLoadEntity> _deferredEntityLoads;
|
||||||
|
EntityScriptContentAvailableMap _contentAvailableQueue;
|
||||||
|
|
||||||
bool _isThreaded { false };
|
bool _isThreaded { false };
|
||||||
QScriptEngineDebugger* _debugger { nullptr };
|
QScriptEngineDebugger* _debugger { nullptr };
|
||||||
|
|
Loading…
Reference in a new issue