Skip to content

Commit

Permalink
effectsloader: Disable file watchers
Browse files Browse the repository at this point in the history
Fix #63

TODO: write a new watcher in a future release
  • Loading branch information
rodlie committed Aug 21, 2023
1 parent c44339d commit 9c6e936
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 30 deletions.
40 changes: 12 additions & 28 deletions src/app/effectsloader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -261,7 +261,7 @@ void EffectsLoader::iniShaderEffects()
for (const auto &path : AppSupport::getFilesFromPath(AppSupport::getAppShaderPresetsPath(),
QStringList() << "*.gre")) {
try {
iniShaderEffectProgramExec(path, false);
iniShaderEffectProgramExec(path);
} catch(const std::exception& e) {
gPrintExceptionCritical(e);
}
Expand All @@ -277,7 +277,11 @@ void EffectsLoader::iniShaderEffects()
}
}

const auto newFileWatcher = QSharedPointer<QFileSystemModel>(
qDebug() << "Shaders paths" << mLoadedGREPaths;
qDebug() << "Shaders total" << mLoadedShaders.count();

// TODO: rewrite this
/*const auto newFileWatcher = QSharedPointer<QFileSystemModel>(
new QFileSystemModel);
newFileWatcher->setRootPath(dirPath);
connect(newFileWatcher.get(), &QFileSystemModel::directoryLoaded,
Expand Down Expand Up @@ -309,7 +313,7 @@ void EffectsLoader::iniShaderEffects()
iniSingleRasterEffectProgram(grePath);
}
});
});
});*/
doneCurrent();
}

Expand All @@ -325,10 +329,9 @@ void EffectsLoader::iniSingleRasterEffectProgram(const QString &grePath)
}
}

void EffectsLoader::iniShaderEffectProgramExec(const QString &grePath,
bool watch)
void EffectsLoader::iniShaderEffectProgramExec(const QString &grePath)
{
if (!QFile::exists(grePath)) { return; }
if (!QFile::exists(grePath) || mLoadedGREPaths.contains(grePath)) { return; }

const auto shaderID = AppSupport::getShaderID(grePath);
if (shaderID.first.isEmpty() || shaderID.second.isEmpty()) { return; }
Expand All @@ -342,32 +345,13 @@ void EffectsLoader::iniShaderEffectProgramExec(const QString &grePath,
const QString fragPath = QString::fromUtf8("%1/%2.frag").arg(fileInfo.path(),
fileInfo.completeBaseName());
if (!QFile::exists(fragPath)) { return; }
qDebug() << "Loading ShaderEffect" << shaderID.first << shaderID.second << grePath;
qDebug() << "Loading Shader" << shaderID.first << shaderID.second << grePath;
try {
const auto loaded = ShaderEffectCreator::sLoadFromFile(this, grePath).get();
// TODO: we should keep each creator in an list, replace shaderID
/*const auto loaded =*/ ShaderEffectCreator::sLoadFromFile(this, grePath).get();
mLoadedGREPaths << grePath;
mLoadedShaders << shaderID;

if (watch) {
const auto newFileWatcher = QSharedPointer<QFileSystemWatcher>(
new QFileSystemWatcher);
newFileWatcher->addPath(fragPath);
connect(newFileWatcher.get(), &QFileSystemWatcher::fileChanged,
this, [this, loaded, fragPath, newFileWatcher]() {
reloadProgram(loaded, fragPath);
});
}
} catch(...) {
if (watch) {
const auto newFileWatcher = QSharedPointer<QFileSystemWatcher>(
new QFileSystemWatcher);
newFileWatcher->addPath(grePath);
newFileWatcher->addPath(fragPath);
connect(newFileWatcher.get(), &QFileSystemWatcher::fileChanged,
this, [this, grePath]() {
iniSingleRasterEffectProgram(grePath);
});
}
RuntimeThrow("Error while loading ShaderEffect from '" + grePath + "'");
}
}
3 changes: 1 addition & 2 deletions src/app/effectsloader.h
Original file line number Diff line number Diff line change
Expand Up @@ -55,8 +55,7 @@ class EffectsLoader : public QObject, protected OffscreenQGL33c
void reloadProgram(ShaderEffectCreator * const loaded,
const QString &fragPath);
void iniSingleRasterEffectProgram(const QString &grePath);
void iniShaderEffectProgramExec(const QString &grePath,
bool watch = true);
void iniShaderEffectProgramExec(const QString &grePath);

void iniCustomRasterEffect(const QString &soPath);
void iniIfCustomRasterEffect(const QString &path);
Expand Down

0 comments on commit 9c6e936

Please sign in to comment.