Upgrade project asset watcher to native Win32 notifications

This commit is contained in:
2026-04-10 21:36:53 +08:00
parent 2338e306bf
commit 1119af2e38
2 changed files with 314 additions and 10 deletions

View File

@@ -2,9 +2,12 @@
#include "Core/IEditorContext.h"
#include <atomic>
#include <cstdint>
#include <filesystem>
#include <mutex>
#include <string>
#include <thread>
#include <unordered_map>
namespace XCEngine {
@@ -12,6 +15,8 @@ namespace Editor {
class ProjectAssetWatcher {
public:
~ProjectAssetWatcher();
void Attach(const std::string& projectPath);
void Detach();
void Update(IEditorContext& context, float dt);
@@ -54,6 +59,11 @@ private:
using Snapshot = std::unordered_map<std::string, AssetEntryState>;
void RefreshProjectBinding(const std::string& projectPath);
void StartNativeWatcher();
void StopNativeWatcher();
void RunNativeWatcher(void* directoryHandle, std::filesystem::path watchedRoot);
void ConsumeNativeChanges();
void ScheduleRefresh(const ChangeStats& changes);
void ScanForChanges();
void FlushPendingRefresh(IEditorContext& context);
static void BuildSnapshot(const std::filesystem::path& assetsRoot, Snapshot& outSnapshot);
@@ -64,8 +74,15 @@ private:
Snapshot m_snapshot;
ChangeStats m_pendingChanges;
float m_scanCooldownSeconds = 0.0f;
float m_nativeRestartCooldownSeconds = 0.0f;
float m_debounceSeconds = 0.0f;
bool m_hasPendingRefresh = false;
std::thread m_nativeWatcherThread;
std::mutex m_nativeChangeMutex;
ChangeStats m_threadPendingChanges;
std::atomic<bool> m_nativeWatcherHealthy{false};
std::atomic<bool> m_pollingResyncRequested{false};
void* m_nativeStopEvent = nullptr;
};
} // namespace Editor