mirror of
https://github.com/overte-org/overte.git
synced 2025-07-23 14:04:23 +02:00
Merge pull request #10846 from sethalves/fix-server-scripts-more
make ResourceManager be owned by DependencyManager
This commit is contained in:
commit
e781f97ddc
23 changed files with 68 additions and 63 deletions
|
@ -62,7 +62,7 @@ Agent::Agent(ReceivedMessage& message) :
|
||||||
_entityEditSender.setPacketsPerSecond(DEFAULT_ENTITY_PPS_PER_SCRIPT);
|
_entityEditSender.setPacketsPerSecond(DEFAULT_ENTITY_PPS_PER_SCRIPT);
|
||||||
DependencyManager::get<EntityScriptingInterface>()->setPacketSender(&_entityEditSender);
|
DependencyManager::get<EntityScriptingInterface>()->setPacketSender(&_entityEditSender);
|
||||||
|
|
||||||
ResourceManager::init();
|
DependencyManager::set<ResourceManager>();
|
||||||
|
|
||||||
DependencyManager::registerInheritance<SpatialParentFinder, AssignmentParentFinder>();
|
DependencyManager::registerInheritance<SpatialParentFinder, AssignmentParentFinder>();
|
||||||
|
|
||||||
|
@ -199,7 +199,7 @@ void Agent::requestScript() {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
auto request = ResourceManager::createResourceRequest(this, scriptURL);
|
auto request = DependencyManager::get<ResourceManager>()->createResourceRequest(this, scriptURL);
|
||||||
|
|
||||||
if (!request) {
|
if (!request) {
|
||||||
qWarning() << "Could not create ResourceRequest for Agent script at" << scriptURL.toString();
|
qWarning() << "Could not create ResourceRequest for Agent script at" << scriptURL.toString();
|
||||||
|
@ -779,7 +779,7 @@ void Agent::aboutToFinish() {
|
||||||
// our entity tree is going to go away so tell that to the EntityScriptingInterface
|
// our entity tree is going to go away so tell that to the EntityScriptingInterface
|
||||||
DependencyManager::get<EntityScriptingInterface>()->setEntityTree(nullptr);
|
DependencyManager::get<EntityScriptingInterface>()->setEntityTree(nullptr);
|
||||||
|
|
||||||
ResourceManager::cleanup();
|
DependencyManager::get<ResourceManager>()->cleanup();
|
||||||
|
|
||||||
// cleanup the AudioInjectorManager (and any still running injectors)
|
// cleanup the AudioInjectorManager (and any still running injectors)
|
||||||
DependencyManager::destroy<AudioInjectorManager>();
|
DependencyManager::destroy<AudioInjectorManager>();
|
||||||
|
|
|
@ -31,7 +31,7 @@ EntityServer::EntityServer(ReceivedMessage& message) :
|
||||||
OctreeServer(message),
|
OctreeServer(message),
|
||||||
_entitySimulation(NULL)
|
_entitySimulation(NULL)
|
||||||
{
|
{
|
||||||
ResourceManager::init();
|
DependencyManager::set<ResourceManager>();
|
||||||
DependencyManager::set<ResourceCacheSharedItems>();
|
DependencyManager::set<ResourceCacheSharedItems>();
|
||||||
DependencyManager::set<ScriptCache>();
|
DependencyManager::set<ScriptCache>();
|
||||||
|
|
||||||
|
|
|
@ -54,7 +54,7 @@ EntityScriptServer::EntityScriptServer(ReceivedMessage& message) : ThreadedAssig
|
||||||
|
|
||||||
DependencyManager::get<EntityScriptingInterface>()->setPacketSender(&_entityEditSender);
|
DependencyManager::get<EntityScriptingInterface>()->setPacketSender(&_entityEditSender);
|
||||||
|
|
||||||
ResourceManager::init();
|
DependencyManager::set<ResourceManager>();
|
||||||
|
|
||||||
DependencyManager::registerInheritance<SpatialParentFinder, AssignmentParentFinder>();
|
DependencyManager::registerInheritance<SpatialParentFinder, AssignmentParentFinder>();
|
||||||
|
|
||||||
|
@ -67,7 +67,6 @@ EntityScriptServer::EntityScriptServer(ReceivedMessage& message) : ThreadedAssig
|
||||||
DependencyManager::set<ScriptCache>();
|
DependencyManager::set<ScriptCache>();
|
||||||
DependencyManager::set<ScriptEngines>(ScriptEngine::ENTITY_SERVER_SCRIPT);
|
DependencyManager::set<ScriptEngines>(ScriptEngine::ENTITY_SERVER_SCRIPT);
|
||||||
|
|
||||||
|
|
||||||
auto& packetReceiver = DependencyManager::get<NodeList>()->getPacketReceiver();
|
auto& packetReceiver = DependencyManager::get<NodeList>()->getPacketReceiver();
|
||||||
packetReceiver.registerListenerForTypes({ PacketType::OctreeStats, PacketType::EntityData, PacketType::EntityErase },
|
packetReceiver.registerListenerForTypes({ PacketType::OctreeStats, PacketType::EntityData, PacketType::EntityErase },
|
||||||
this, "handleOctreePacket");
|
this, "handleOctreePacket");
|
||||||
|
@ -493,7 +492,7 @@ void EntityScriptServer::checkAndCallPreload(const EntityItemID& entityID, bool
|
||||||
if (entity && (reload || notRunning || details.scriptText != entity->getServerScripts())) {
|
if (entity && (reload || notRunning || details.scriptText != entity->getServerScripts())) {
|
||||||
QString scriptUrl = entity->getServerScripts();
|
QString scriptUrl = entity->getServerScripts();
|
||||||
if (!scriptUrl.isEmpty()) {
|
if (!scriptUrl.isEmpty()) {
|
||||||
scriptUrl = ResourceManager::normalizeURL(scriptUrl);
|
scriptUrl = DependencyManager::get<ResourceManager>()->normalizeURL(scriptUrl);
|
||||||
qCDebug(entity_script_server) << "Loading entity server script" << scriptUrl << "for" << entityID;
|
qCDebug(entity_script_server) << "Loading entity server script" << scriptUrl << "for" << entityID;
|
||||||
_entitiesScriptEngine->loadEntityScript(entityID, scriptUrl, reload);
|
_entitiesScriptEngine->loadEntityScript(entityID, scriptUrl, reload);
|
||||||
}
|
}
|
||||||
|
@ -551,7 +550,7 @@ void EntityScriptServer::aboutToFinish() {
|
||||||
// our entity tree is going to go away so tell that to the EntityScriptingInterface
|
// our entity tree is going to go away so tell that to the EntityScriptingInterface
|
||||||
DependencyManager::get<EntityScriptingInterface>()->setEntityTree(nullptr);
|
DependencyManager::get<EntityScriptingInterface>()->setEntityTree(nullptr);
|
||||||
|
|
||||||
ResourceManager::cleanup();
|
DependencyManager::get<ResourceManager>()->cleanup();
|
||||||
|
|
||||||
// cleanup the AudioInjectorManager (and any still running injectors)
|
// cleanup the AudioInjectorManager (and any still running injectors)
|
||||||
DependencyManager::destroy<AudioInjectorManager>();
|
DependencyManager::destroy<AudioInjectorManager>();
|
||||||
|
|
|
@ -582,6 +582,7 @@ bool setupEssentials(int& argc, char** argv, bool runningMarkerExisted) {
|
||||||
DependencyManager::set<LocationBookmarks>();
|
DependencyManager::set<LocationBookmarks>();
|
||||||
DependencyManager::set<Snapshot>();
|
DependencyManager::set<Snapshot>();
|
||||||
DependencyManager::set<CloseEventSender>();
|
DependencyManager::set<CloseEventSender>();
|
||||||
|
DependencyManager::set<ResourceManager>();
|
||||||
|
|
||||||
return previousSessionCrashed;
|
return previousSessionCrashed;
|
||||||
}
|
}
|
||||||
|
@ -776,7 +777,6 @@ Application::Application(int& argc, char** argv, QElapsedTimer& startupTimer, bo
|
||||||
connect(this, &Application::activeDisplayPluginChanged,
|
connect(this, &Application::activeDisplayPluginChanged,
|
||||||
reinterpret_cast<scripting::Audio*>(audioScriptingInterface.data()), &scripting::Audio::onContextChanged);
|
reinterpret_cast<scripting::Audio*>(audioScriptingInterface.data()), &scripting::Audio::onContextChanged);
|
||||||
|
|
||||||
ResourceManager::init();
|
|
||||||
// Make sure we don't time out during slow operations at startup
|
// Make sure we don't time out during slow operations at startup
|
||||||
updateHeartbeat();
|
updateHeartbeat();
|
||||||
|
|
||||||
|
@ -1881,7 +1881,7 @@ Application::~Application() {
|
||||||
DependencyManager::destroy<SoundCache>();
|
DependencyManager::destroy<SoundCache>();
|
||||||
DependencyManager::destroy<OctreeStatsProvider>();
|
DependencyManager::destroy<OctreeStatsProvider>();
|
||||||
|
|
||||||
ResourceManager::cleanup();
|
DependencyManager::get<ResourceManager>()->cleanup();
|
||||||
|
|
||||||
// remove the NodeList from the DependencyManager
|
// remove the NodeList from the DependencyManager
|
||||||
DependencyManager::destroy<NodeList>();
|
DependencyManager::destroy<NodeList>();
|
||||||
|
@ -5941,7 +5941,7 @@ void Application::addAssetToWorldFromURL(QString url) {
|
||||||
|
|
||||||
addAssetToWorldInfo(filename, "Downloading model file " + filename + ".");
|
addAssetToWorldInfo(filename, "Downloading model file " + filename + ".");
|
||||||
|
|
||||||
auto request = ResourceManager::createResourceRequest(nullptr, QUrl(url));
|
auto request = DependencyManager::get<ResourceManager>()->createResourceRequest(nullptr, QUrl(url));
|
||||||
connect(request, &ResourceRequest::finished, this, &Application::addAssetToWorldFromURLRequestFinished);
|
connect(request, &ResourceRequest::finished, this, &Application::addAssetToWorldFromURLRequestFinished);
|
||||||
request->send();
|
request->send();
|
||||||
}
|
}
|
||||||
|
|
|
@ -106,7 +106,8 @@ void ATPAssetMigrator::loadEntityServerFile() {
|
||||||
|
|
||||||
jsonValue = entityObject;
|
jsonValue = entityObject;
|
||||||
} else if (wantsToMigrateResource(migrationURL)) {
|
} else if (wantsToMigrateResource(migrationURL)) {
|
||||||
auto request = ResourceManager::createResourceRequest(this, migrationURL);
|
auto request =
|
||||||
|
DependencyManager::get<ResourceManager>()->createResourceRequest(this, migrationURL);
|
||||||
|
|
||||||
if (request) {
|
if (request) {
|
||||||
qCDebug(asset_migrator) << "Requesting" << migrationURL << "for ATP asset migration";
|
qCDebug(asset_migrator) << "Requesting" << migrationURL << "for ATP asset migration";
|
||||||
|
|
|
@ -118,7 +118,7 @@ int main(int argc, const char* argv[]) {
|
||||||
// tell everyone to use the right cache location
|
// tell everyone to use the right cache location
|
||||||
//
|
//
|
||||||
// this handles data8 and prepared
|
// this handles data8 and prepared
|
||||||
ResourceManager::setCacheDir(cacheDir);
|
DependencyManager::get<ResourceManager>()->setCacheDir(cacheDir);
|
||||||
|
|
||||||
// this does the ktx_cache
|
// this does the ktx_cache
|
||||||
PathUtils::getAppLocalDataPath(cacheDir);
|
PathUtils::getAppLocalDataPath(cacheDir);
|
||||||
|
|
|
@ -62,7 +62,7 @@ bool TestScriptingInterface::loadTestScene(QString scene) {
|
||||||
static const QString TEST_SCRIPTS_ROOT = TEST_ROOT + "scripts/";
|
static const QString TEST_SCRIPTS_ROOT = TEST_ROOT + "scripts/";
|
||||||
static const QString TEST_SCENES_ROOT = TEST_ROOT + "scenes/";
|
static const QString TEST_SCENES_ROOT = TEST_ROOT + "scenes/";
|
||||||
return DependencyManager::get<OffscreenUi>()->returnFromUiThread([scene]()->QVariant {
|
return DependencyManager::get<OffscreenUi>()->returnFromUiThread([scene]()->QVariant {
|
||||||
ResourceManager::setUrlPrefixOverride("atp:/", TEST_BINARY_ROOT + scene + ".atp/");
|
DependencyManager::get<ResourceManager>()->setUrlPrefixOverride("atp:/", TEST_BINARY_ROOT + scene + ".atp/");
|
||||||
auto tree = qApp->getEntities()->getTree();
|
auto tree = qApp->getEntities()->getTree();
|
||||||
auto treeIsClient = tree->getIsClient();
|
auto treeIsClient = tree->getIsClient();
|
||||||
// Force the tree to accept the load regardless of permissions
|
// Force the tree to accept the load regardless of permissions
|
||||||
|
|
|
@ -853,7 +853,7 @@ void EntityTreeRenderer::checkAndCallPreload(const EntityItemID& entityID, bool
|
||||||
entity->scriptHasUnloaded();
|
entity->scriptHasUnloaded();
|
||||||
}
|
}
|
||||||
if (shouldLoad) {
|
if (shouldLoad) {
|
||||||
scriptUrl = ResourceManager::normalizeURL(scriptUrl);
|
scriptUrl = DependencyManager::get<ResourceManager>()->normalizeURL(scriptUrl);
|
||||||
_entitiesScriptEngine->loadEntityScript(entityID, scriptUrl, reload);
|
_entitiesScriptEngine->loadEntityScript(entityID, scriptUrl, reload);
|
||||||
entity->scriptHasPreloaded();
|
entity->scriptHasPreloaded();
|
||||||
}
|
}
|
||||||
|
|
|
@ -132,7 +132,7 @@ void EntityEditFilters::addFilter(EntityItemID entityID, QString filterURL) {
|
||||||
_filterDataMap.insert(entityID, filterData);
|
_filterDataMap.insert(entityID, filterData);
|
||||||
_lock.unlock();
|
_lock.unlock();
|
||||||
|
|
||||||
auto scriptRequest = ResourceManager::createResourceRequest(this, scriptURL);
|
auto scriptRequest = DependencyManager::get<ResourceManager>()->createResourceRequest(this, scriptURL);
|
||||||
if (!scriptRequest) {
|
if (!scriptRequest) {
|
||||||
qWarning() << "Could not create ResourceRequest for Entity Edit filter script at" << scriptURL.toString();
|
qWarning() << "Could not create ResourceRequest for Entity Edit filter script at" << scriptURL.toString();
|
||||||
scriptRequestFinished(entityID);
|
scriptRequestFinished(entityID);
|
||||||
|
|
|
@ -202,7 +202,7 @@ bool OBJReader::isValidTexture(const QByteArray &filename) {
|
||||||
}
|
}
|
||||||
QUrl candidateUrl = _url.resolved(QUrl(filename));
|
QUrl candidateUrl = _url.resolved(QUrl(filename));
|
||||||
|
|
||||||
return ResourceManager::resourceExists(candidateUrl);
|
return DependencyManager::get<ResourceManager>()->resourceExists(candidateUrl);
|
||||||
}
|
}
|
||||||
|
|
||||||
void OBJReader::parseMaterialLibrary(QIODevice* device) {
|
void OBJReader::parseMaterialLibrary(QIODevice* device) {
|
||||||
|
@ -267,7 +267,7 @@ void OBJReader::parseMaterialLibrary(QIODevice* device) {
|
||||||
}
|
}
|
||||||
|
|
||||||
std::tuple<bool, QByteArray> requestData(QUrl& url) {
|
std::tuple<bool, QByteArray> requestData(QUrl& url) {
|
||||||
auto request = ResourceManager::createResourceRequest(nullptr, url);
|
auto request = DependencyManager::get<ResourceManager>()->createResourceRequest(nullptr, url);
|
||||||
|
|
||||||
if (!request) {
|
if (!request) {
|
||||||
return std::make_tuple(false, QByteArray());
|
return std::make_tuple(false, QByteArray());
|
||||||
|
|
|
@ -384,7 +384,7 @@ void NetworkTexture::makeRequest() {
|
||||||
// Add a fragment to the base url so we can identify the section of the ktx being requested when debugging
|
// Add a fragment to the base url so we can identify the section of the ktx being requested when debugging
|
||||||
// The actual requested url is _activeUrl and will not contain the fragment
|
// The actual requested url is _activeUrl and will not contain the fragment
|
||||||
_url.setFragment("head");
|
_url.setFragment("head");
|
||||||
_ktxHeaderRequest = ResourceManager::createResourceRequest(this, _activeUrl);
|
_ktxHeaderRequest = DependencyManager::get<ResourceManager>()->createResourceRequest(this, _activeUrl);
|
||||||
|
|
||||||
if (!_ktxHeaderRequest) {
|
if (!_ktxHeaderRequest) {
|
||||||
qCDebug(networking).noquote() << "Failed to get request for" << _url.toDisplayString();
|
qCDebug(networking).noquote() << "Failed to get request for" << _url.toDisplayString();
|
||||||
|
@ -454,7 +454,7 @@ void NetworkTexture::startMipRangeRequest(uint16_t low, uint16_t high) {
|
||||||
|
|
||||||
bool isHighMipRequest = low == NULL_MIP_LEVEL && high == NULL_MIP_LEVEL;
|
bool isHighMipRequest = low == NULL_MIP_LEVEL && high == NULL_MIP_LEVEL;
|
||||||
|
|
||||||
_ktxMipRequest = ResourceManager::createResourceRequest(this, _activeUrl);
|
_ktxMipRequest = DependencyManager::get<ResourceManager>()->createResourceRequest(this, _activeUrl);
|
||||||
|
|
||||||
if (!_ktxMipRequest) {
|
if (!_ktxMipRequest) {
|
||||||
qCWarning(networking).noquote() << "Failed to get request for" << _url.toDisplayString();
|
qCWarning(networking).noquote() << "Failed to get request for" << _url.toDisplayString();
|
||||||
|
|
|
@ -13,7 +13,7 @@
|
||||||
#include "AtpReply.h"
|
#include "AtpReply.h"
|
||||||
|
|
||||||
AtpReply::AtpReply(const QUrl& url, QObject* parent) :
|
AtpReply::AtpReply(const QUrl& url, QObject* parent) :
|
||||||
_resourceRequest(ResourceManager::createResourceRequest(parent, url)) {
|
_resourceRequest(DependencyManager::get<ResourceManager>()->createResourceRequest(parent, url)) {
|
||||||
setOperation(QNetworkAccessManager::GetOperation);
|
setOperation(QNetworkAccessManager::GetOperation);
|
||||||
|
|
||||||
connect(_resourceRequest, &AssetResourceRequest::progress, this, &AtpReply::downloadProgress);
|
connect(_resourceRequest, &AssetResourceRequest::progress, this, &AtpReply::downloadProgress);
|
||||||
|
|
|
@ -672,7 +672,7 @@ void Resource::makeRequest() {
|
||||||
|
|
||||||
PROFILE_ASYNC_BEGIN(resource, "Resource:" + getType(), QString::number(_requestID), { { "url", _url.toString() }, { "activeURL", _activeUrl.toString() } });
|
PROFILE_ASYNC_BEGIN(resource, "Resource:" + getType(), QString::number(_requestID), { { "url", _url.toString() }, { "activeURL", _activeUrl.toString() } });
|
||||||
|
|
||||||
_request = ResourceManager::createResourceRequest(this, _activeUrl);
|
_request = DependencyManager::get<ResourceManager>()->createResourceRequest(this, _activeUrl);
|
||||||
|
|
||||||
if (!_request) {
|
if (!_request) {
|
||||||
qCDebug(networking).noquote() << "Failed to get request for" << _url.toDisplayString();
|
qCDebug(networking).noquote() << "Failed to get request for" << _url.toDisplayString();
|
||||||
|
|
|
@ -24,10 +24,16 @@
|
||||||
#include "NetworkAccessManager.h"
|
#include "NetworkAccessManager.h"
|
||||||
#include "NetworkLogging.h"
|
#include "NetworkLogging.h"
|
||||||
|
|
||||||
QThread ResourceManager::_thread;
|
|
||||||
ResourceManager::PrefixMap ResourceManager::_prefixMap;
|
ResourceManager::ResourceManager() {
|
||||||
QMutex ResourceManager::_prefixMapLock;
|
_thread.setObjectName("Resource Manager Thread");
|
||||||
QString ResourceManager::_cacheDir;
|
|
||||||
|
auto assetClient = DependencyManager::set<AssetClient>(_cacheDir);
|
||||||
|
assetClient->moveToThread(&_thread);
|
||||||
|
QObject::connect(&_thread, &QThread::started, assetClient.data(), &AssetClient::init);
|
||||||
|
|
||||||
|
_thread.start();
|
||||||
|
}
|
||||||
|
|
||||||
void ResourceManager::setUrlPrefixOverride(const QString& prefix, const QString& replacement) {
|
void ResourceManager::setUrlPrefixOverride(const QString& prefix, const QString& replacement) {
|
||||||
QMutexLocker locker(&_prefixMapLock);
|
QMutexLocker locker(&_prefixMapLock);
|
||||||
|
@ -75,16 +81,6 @@ QUrl ResourceManager::normalizeURL(const QUrl& originalUrl) {
|
||||||
return url;
|
return url;
|
||||||
}
|
}
|
||||||
|
|
||||||
void ResourceManager::init() {
|
|
||||||
_thread.setObjectName("Resource Manager Thread");
|
|
||||||
|
|
||||||
auto assetClient = DependencyManager::set<AssetClient>(_cacheDir);
|
|
||||||
assetClient->moveToThread(&_thread);
|
|
||||||
QObject::connect(&_thread, &QThread::started, assetClient.data(), &AssetClient::init);
|
|
||||||
|
|
||||||
_thread.start();
|
|
||||||
}
|
|
||||||
|
|
||||||
void ResourceManager::cleanup() {
|
void ResourceManager::cleanup() {
|
||||||
// cleanup the AssetClient thread
|
// cleanup the AssetClient thread
|
||||||
DependencyManager::destroy<AssetClient>();
|
DependencyManager::destroy<AssetClient>();
|
||||||
|
|
|
@ -14,7 +14,11 @@
|
||||||
|
|
||||||
#include <functional>
|
#include <functional>
|
||||||
|
|
||||||
|
#include <QObject>
|
||||||
#include <QtCore/QMutex>
|
#include <QtCore/QMutex>
|
||||||
|
#include <QThread>
|
||||||
|
|
||||||
|
#include <DependencyManager.h>
|
||||||
|
|
||||||
#include "ResourceRequest.h"
|
#include "ResourceRequest.h"
|
||||||
|
|
||||||
|
@ -24,34 +28,38 @@ const QString URL_SCHEME_HTTPS = "https";
|
||||||
const QString URL_SCHEME_FTP = "ftp";
|
const QString URL_SCHEME_FTP = "ftp";
|
||||||
const QString URL_SCHEME_ATP = "atp";
|
const QString URL_SCHEME_ATP = "atp";
|
||||||
|
|
||||||
class ResourceManager {
|
class ResourceManager: public QObject, public Dependency {
|
||||||
|
Q_OBJECT
|
||||||
|
SINGLETON_DEPENDENCY
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
ResourceManager();
|
||||||
|
|
||||||
static void setUrlPrefixOverride(const QString& prefix, const QString& replacement);
|
void setUrlPrefixOverride(const QString& prefix, const QString& replacement);
|
||||||
static QString normalizeURL(const QString& urlString);
|
QString normalizeURL(const QString& urlString);
|
||||||
static QUrl normalizeURL(const QUrl& url);
|
QUrl normalizeURL(const QUrl& url);
|
||||||
|
|
||||||
static ResourceRequest* createResourceRequest(QObject* parent, const QUrl& url);
|
ResourceRequest* createResourceRequest(QObject* parent, const QUrl& url);
|
||||||
|
|
||||||
static void init();
|
void init();
|
||||||
static void cleanup();
|
void cleanup();
|
||||||
|
|
||||||
// Blocking call to check if a resource exists. This function uses a QEventLoop internally
|
// Blocking call to check if a resource exists. This function uses a QEventLoop internally
|
||||||
// to return to the calling thread so that events can still be processed.
|
// to return to the calling thread so that events can still be processed.
|
||||||
static bool resourceExists(const QUrl& url);
|
bool resourceExists(const QUrl& url);
|
||||||
|
|
||||||
// adjust where we persist the cache
|
// adjust where we persist the cache
|
||||||
static void setCacheDir(const QString& cacheDir);
|
void setCacheDir(const QString& cacheDir);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
static QThread _thread;
|
QThread _thread;
|
||||||
|
|
||||||
using PrefixMap = std::map<QString, QString>;
|
using PrefixMap = std::map<QString, QString>;
|
||||||
|
|
||||||
static PrefixMap _prefixMap;
|
PrefixMap _prefixMap;
|
||||||
static QMutex _prefixMapLock;
|
QMutex _prefixMapLock;
|
||||||
|
|
||||||
static QString _cacheDir;
|
QString _cacheDir;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -11,5 +11,5 @@
|
||||||
#include "ResourceManager.h"
|
#include "ResourceManager.h"
|
||||||
|
|
||||||
void ResourceScriptingInterface::overrideUrlPrefix(const QString& prefix, const QString& replacement) {
|
void ResourceScriptingInterface::overrideUrlPrefix(const QString& prefix, const QString& replacement) {
|
||||||
ResourceManager::setUrlPrefixOverride(prefix, replacement);
|
DependencyManager::get<ResourceManager>()->setUrlPrefixOverride(prefix, replacement);
|
||||||
}
|
}
|
||||||
|
|
|
@ -1668,7 +1668,8 @@ bool Octree::readJSONFromGzippedFile(QString qFileName) {
|
||||||
}
|
}
|
||||||
|
|
||||||
bool Octree::readFromURL(const QString& urlString) {
|
bool Octree::readFromURL(const QString& urlString) {
|
||||||
auto request = std::unique_ptr<ResourceRequest>(ResourceManager::createResourceRequest(this, urlString));
|
auto request =
|
||||||
|
std::unique_ptr<ResourceRequest>(DependencyManager::get<ResourceManager>()->createResourceRequest(this, urlString));
|
||||||
|
|
||||||
if (!request) {
|
if (!request) {
|
||||||
return false;
|
return false;
|
||||||
|
|
|
@ -103,7 +103,7 @@ bool Procedural::parseVersion(const QJsonValue& version) {
|
||||||
}
|
}
|
||||||
|
|
||||||
bool Procedural::parseShader(const QUrl& shaderPath) {
|
bool Procedural::parseShader(const QUrl& shaderPath) {
|
||||||
auto shaderUrl = ResourceManager::normalizeURL(shaderPath);
|
auto shaderUrl = DependencyManager::get<ResourceManager>()->normalizeURL(shaderPath);
|
||||||
|
|
||||||
if (!shaderUrl.isValid()) {
|
if (!shaderUrl.isValid()) {
|
||||||
if (!shaderUrl.isEmpty()) {
|
if (!shaderUrl.isEmpty()) {
|
||||||
|
|
|
@ -85,7 +85,7 @@ QString FileScriptingInterface::convertUrlToPath(QUrl url) {
|
||||||
// this function is not in use
|
// this function is not in use
|
||||||
void FileScriptingInterface::downloadZip(QString path, const QString link) {
|
void FileScriptingInterface::downloadZip(QString path, const QString link) {
|
||||||
QUrl url = QUrl(link);
|
QUrl url = QUrl(link);
|
||||||
auto request = ResourceManager::createResourceRequest(nullptr, url);
|
auto request = DependencyManager::get<ResourceManager>()->createResourceRequest(nullptr, url);
|
||||||
connect(request, &ResourceRequest::finished, this, [this, path]{
|
connect(request, &ResourceRequest::finished, this, [this, path]{
|
||||||
unzipFile(path, ""); // so intellisense isn't mad
|
unzipFile(path, ""); // so intellisense isn't mad
|
||||||
});
|
});
|
||||||
|
|
|
@ -57,7 +57,7 @@ void ScriptCache::clearATPScriptsFromCache() {
|
||||||
}
|
}
|
||||||
|
|
||||||
void ScriptCache::deleteScript(const QUrl& unnormalizedURL) {
|
void ScriptCache::deleteScript(const QUrl& unnormalizedURL) {
|
||||||
QUrl url = ResourceManager::normalizeURL(unnormalizedURL);
|
QUrl url = DependencyManager::get<ResourceManager>()->normalizeURL(unnormalizedURL);
|
||||||
Lock lock(_containerLock);
|
Lock lock(_containerLock);
|
||||||
if (_scriptCache.contains(url)) {
|
if (_scriptCache.contains(url)) {
|
||||||
qCDebug(scriptengine) << "Delete script from cache:" << url.toString();
|
qCDebug(scriptengine) << "Delete script from cache:" << url.toString();
|
||||||
|
@ -70,7 +70,7 @@ void ScriptCache::getScriptContents(const QString& scriptOrURL, contentAvailable
|
||||||
qCDebug(scriptengine) << "ScriptCache::getScriptContents() on thread [" << QThread::currentThread() << "] expected thread [" << thread() << "]";
|
qCDebug(scriptengine) << "ScriptCache::getScriptContents() on thread [" << QThread::currentThread() << "] expected thread [" << thread() << "]";
|
||||||
#endif
|
#endif
|
||||||
QUrl unnormalizedURL(scriptOrURL);
|
QUrl unnormalizedURL(scriptOrURL);
|
||||||
QUrl url = ResourceManager::normalizeURL(unnormalizedURL);
|
QUrl url = DependencyManager::get<ResourceManager>()->normalizeURL(unnormalizedURL);
|
||||||
|
|
||||||
// attempt to determine if this is a URL to a script, or if this is actually a script itself (which is valid in the
|
// attempt to determine if this is a URL to a script, or if this is actually a script itself (which is valid in the
|
||||||
// entityScript use case)
|
// entityScript use case)
|
||||||
|
@ -109,7 +109,7 @@ void ScriptCache::getScriptContents(const QString& scriptOrURL, contentAvailable
|
||||||
#ifdef THREAD_DEBUGGING
|
#ifdef THREAD_DEBUGGING
|
||||||
qCDebug(scriptengine) << "about to call: ResourceManager::createResourceRequest(this, url); on thread [" << QThread::currentThread() << "] expected thread [" << thread() << "]";
|
qCDebug(scriptengine) << "about to call: ResourceManager::createResourceRequest(this, url); on thread [" << QThread::currentThread() << "] expected thread [" << thread() << "]";
|
||||||
#endif
|
#endif
|
||||||
auto request = ResourceManager::createResourceRequest(nullptr, url);
|
auto request = DependencyManager::get<ResourceManager>()->createResourceRequest(nullptr, url);
|
||||||
Q_ASSERT(request);
|
Q_ASSERT(request);
|
||||||
request->setCacheEnabled(!forceDownload);
|
request->setCacheEnabled(!forceDownload);
|
||||||
connect(request, &ResourceRequest::finished, this, [=]{ scriptContentAvailable(maxRetries); });
|
connect(request, &ResourceRequest::finished, this, [=]{ scriptContentAvailable(maxRetries); });
|
||||||
|
@ -166,7 +166,7 @@ void ScriptCache::scriptContentAvailable(int maxRetries) {
|
||||||
qCDebug(scriptengine) << QString("Retrying script request [%1 / %2]: %3")
|
qCDebug(scriptengine) << QString("Retrying script request [%1 / %2]: %3")
|
||||||
.arg(attempt).arg(maxRetries).arg(url.toString());
|
.arg(attempt).arg(maxRetries).arg(url.toString());
|
||||||
|
|
||||||
auto request = ResourceManager::createResourceRequest(nullptr, url);
|
auto request = DependencyManager::get<ResourceManager>()->createResourceRequest(nullptr, url);
|
||||||
Q_ASSERT(request);
|
Q_ASSERT(request);
|
||||||
|
|
||||||
// We've already made a request, so the cache must be disabled or it wasn't there, so enabling
|
// We've already made a request, so the cache must be disabled or it wasn't there, so enabling
|
||||||
|
|
|
@ -1762,7 +1762,7 @@ void ScriptEngine::include(const QStringList& includeFiles, QScriptValue callbac
|
||||||
QList<QUrl> urls;
|
QList<QUrl> urls;
|
||||||
|
|
||||||
for (QString includeFile : includeFiles) {
|
for (QString includeFile : includeFiles) {
|
||||||
QString file = ResourceManager::normalizeURL(includeFile);
|
QString file = DependencyManager::get<ResourceManager>()->normalizeURL(includeFile);
|
||||||
QUrl thisURL;
|
QUrl thisURL;
|
||||||
bool isStandardLibrary = false;
|
bool isStandardLibrary = false;
|
||||||
if (file.startsWith("/~/")) {
|
if (file.startsWith("/~/")) {
|
||||||
|
|
|
@ -520,7 +520,7 @@ public:
|
||||||
_entitySimulation = simpleSimulation;
|
_entitySimulation = simpleSimulation;
|
||||||
}
|
}
|
||||||
|
|
||||||
ResourceManager::init();
|
DependencyManager::set<ResourceManager>();
|
||||||
|
|
||||||
setFlags(Qt::MSWindowsOwnDC | Qt::Window | Qt::Dialog | Qt::WindowMinMaxButtonsHint | Qt::WindowTitleHint);
|
setFlags(Qt::MSWindowsOwnDC | Qt::Window | Qt::Dialog | Qt::WindowMinMaxButtonsHint | Qt::WindowTitleHint);
|
||||||
_size = QSize(800, 600);
|
_size = QSize(800, 600);
|
||||||
|
@ -575,7 +575,7 @@ public:
|
||||||
DependencyManager::destroy<ModelCache>();
|
DependencyManager::destroy<ModelCache>();
|
||||||
DependencyManager::destroy<GeometryCache>();
|
DependencyManager::destroy<GeometryCache>();
|
||||||
DependencyManager::destroy<ScriptCache>();
|
DependencyManager::destroy<ScriptCache>();
|
||||||
ResourceManager::cleanup();
|
DependencyManager::get<ResourceManager>()->cleanup();
|
||||||
// remove the NodeList from the DependencyManager
|
// remove the NodeList from the DependencyManager
|
||||||
DependencyManager::destroy<NodeList>();
|
DependencyManager::destroy<NodeList>();
|
||||||
}
|
}
|
||||||
|
@ -998,7 +998,7 @@ private:
|
||||||
QFileInfo atpPathInfo(atpPath);
|
QFileInfo atpPathInfo(atpPath);
|
||||||
if (atpPathInfo.exists()) {
|
if (atpPathInfo.exists()) {
|
||||||
QString atpUrl = QUrl::fromLocalFile(atpPath).toString();
|
QString atpUrl = QUrl::fromLocalFile(atpPath).toString();
|
||||||
ResourceManager::setUrlPrefixOverride("atp:/", atpUrl + "/");
|
DependencyManager::get<ResourceManager>()->setUrlPrefixOverride("atp:/", atpUrl + "/");
|
||||||
}
|
}
|
||||||
_octree->clear();
|
_octree->clear();
|
||||||
_octree->getTree()->readFromURL(fileName);
|
_octree->getTree()->readFromURL(fileName);
|
||||||
|
|
|
@ -329,7 +329,7 @@ public:
|
||||||
installEventFilter(this);
|
installEventFilter(this);
|
||||||
QThreadPool::globalInstance()->setMaxThreadCount(2);
|
QThreadPool::globalInstance()->setMaxThreadCount(2);
|
||||||
QThread::currentThread()->setPriority(QThread::HighestPriority);
|
QThread::currentThread()->setPriority(QThread::HighestPriority);
|
||||||
ResourceManager::init();
|
DependencyManager::set<ResourceManager>();
|
||||||
setFlags(Qt::MSWindowsOwnDC | Qt::Window | Qt::Dialog | Qt::WindowMinMaxButtonsHint | Qt::WindowTitleHint);
|
setFlags(Qt::MSWindowsOwnDC | Qt::Window | Qt::Dialog | Qt::WindowMinMaxButtonsHint | Qt::WindowTitleHint);
|
||||||
_size = QSize(800, 600);
|
_size = QSize(800, 600);
|
||||||
_renderThread._size = _size;
|
_renderThread._size = _size;
|
||||||
|
@ -369,7 +369,7 @@ public:
|
||||||
DependencyManager::destroy<TextureCache>();
|
DependencyManager::destroy<TextureCache>();
|
||||||
DependencyManager::destroy<ModelCache>();
|
DependencyManager::destroy<ModelCache>();
|
||||||
DependencyManager::destroy<GeometryCache>();
|
DependencyManager::destroy<GeometryCache>();
|
||||||
ResourceManager::cleanup();
|
DependencyManager::get<ResourceManager>()->cleanup();
|
||||||
}
|
}
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
|
|
Loading…
Reference in a new issue