48 lines
1.2 KiB
C++
48 lines
1.2 KiB
C++
#pragma once
|
|
|
|
#include <assets/handle.h>
|
|
#include <assets/io/asset_file_system.h>
|
|
#include <renderer/shader.h>
|
|
#include <renderer/texture.h>
|
|
#include <functional>
|
|
#include <mutex>
|
|
#include <shared_mutex>
|
|
#include <string>
|
|
#include <vector>
|
|
|
|
namespace extra2d {
|
|
|
|
class AssetHotReloader {
|
|
public:
|
|
struct FileWatchInfo {
|
|
std::string path;
|
|
std::filesystem::file_time_type lastWriteTime;
|
|
Handle<Texture> textureHandle;
|
|
Handle<Shader> shaderHandle;
|
|
bool isTexture = false;
|
|
};
|
|
|
|
explicit AssetHotReloader(const AssetFileSystem &fileSystem);
|
|
|
|
void enable(bool enable);
|
|
bool enabled() const;
|
|
void setInterval(float interval);
|
|
void addFileWatch(const std::string &path, Handle<Texture> handle);
|
|
void addFileWatch(const std::string &path, Handle<Shader> handle);
|
|
void clear();
|
|
void checkForChanges(
|
|
const std::function<void(const FileWatchInfo &)> &reloadTexture,
|
|
const std::function<void(const FileWatchInfo &)> &reloadShader);
|
|
|
|
private:
|
|
void addFileWatchInternal(const std::string &path, FileWatchInfo &&info);
|
|
|
|
const AssetFileSystem &fileSystem_;
|
|
bool enabled_ = false;
|
|
float interval_ = 1.0f;
|
|
std::vector<FileWatchInfo> watchList_;
|
|
mutable std::shared_mutex mutex_;
|
|
};
|
|
|
|
} // namespace extra2d
|