Deki 1.3.0
Modular C++ 2D engine for embedded displays and desktop
Loading...
Searching...
No Matches
DekiEditor::AssetFileWatcher Class Reference

OS-level file watcher that feeds AssetPipeline::Tick(). More...

#include <AssetFileWatcher.h>

Classes

struct  Event

Public Types

enum class  EventKind { Added , Modified , Deleted }

Public Member Functions

 AssetFileWatcher ()
 ~AssetFileWatcher ()
 AssetFileWatcher (const AssetFileWatcher &)=delete
AssetFileWatcheroperator= (const AssetFileWatcher &)=delete
void Start (const std::string &watchPath, const std::string &projectPath)
 Start watching a directory recursively.
void Stop ()
 Stop the watcher thread and clear pending events.
std::vector< EventDrainReadyEvents ()
 Drain coalesced events that have been quiet for >= kDebounceMs.

Static Public Attributes

static constexpr int kDebounceMs = 100

Detailed Description

OS-level file watcher that feeds AssetPipeline::Tick().

Wraps an efsw::FileWatcher (ReadDirectoryChangesW / inotify / FSEvents) running on its own worker thread. The listener pushes raw events into a thread-safe map keyed by project-relative path. AssetPipeline::Tick() calls DrainReadyEvents() once per frame to receive coalesced, debounced events on the main thread — required because downstream OnAssetChanged subscribers touch GPU resources.

Coalescing rules per path (when a new event arrives for a path already pending): pending=Added, new=Modified -> keep Added pending=Added, new=Deleted -> drop entry (created+deleted before drain) pending=Modified, new=Modified -> keep Modified, refresh timestamp pending=Modified, new=Deleted -> switch to Deleted pending=Deleted, new=Added -> switch to Modified (replaced) pending=Deleted, new=Modified -> switch to Modified pending=Deleted, new=Deleted -> keep Deleted

Renames arrive from efsw as a Moved action with both old and new filenames. The watcher emits two pending entries: Deleted(oldPath) + Added(newPath).

Debounce: an entry is only returned by DrainReadyEvents() once it has been quiet for >= kDebounceMs (default 100ms). This collapses the typical write-temp / delete-original / rename-temp atomic-save sequence into one dispatched event per logical change.

Member Enumeration Documentation

◆ EventKind

Enumerator
Added 
Modified 
Deleted 

Constructor & Destructor Documentation

◆ AssetFileWatcher() [1/2]

DekiEditor::AssetFileWatcher::AssetFileWatcher ( )

◆ ~AssetFileWatcher()

DekiEditor::AssetFileWatcher::~AssetFileWatcher ( )

◆ AssetFileWatcher() [2/2]

DekiEditor::AssetFileWatcher::AssetFileWatcher ( const AssetFileWatcher & )
delete

Member Function Documentation

◆ operator=()

AssetFileWatcher & DekiEditor::AssetFileWatcher::operator= ( const AssetFileWatcher & )
delete

◆ Start()

void DekiEditor::AssetFileWatcher::Start ( const std::string & watchPath,
const std::string & projectPath )

Start watching a directory recursively.

Parameters
watchPathAbsolute path to the directory to watch (recursive). Typically project/assets, but the class is generic — also used by HotReloadService for project/src and project/packages.
projectPathAbsolute path to the project root, used to compute project-relative paths for emitted events.

◆ Stop()

void DekiEditor::AssetFileWatcher::Stop ( )

Stop the watcher thread and clear pending events.

◆ DrainReadyEvents()

std::vector< Event > DekiEditor::AssetFileWatcher::DrainReadyEvents ( )

Drain coalesced events that have been quiet for >= kDebounceMs.

Must be called on the main thread. Entries still inside the debounce window remain pending and may be returned by a subsequent call.

Member Data Documentation

◆ kDebounceMs

int DekiEditor::AssetFileWatcher::kDebounceMs = 100
staticconstexpr

The documentation for this class was generated from the following file: