DEKI/ENGINE docs
manual api reference
Deki 0.40.1
Modular C++ engine with a visual editor, for 2D and 3D
Loading...
Searching...
No Matches
DekiEditor::AssetFileWatcher Class Reference

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

#include <C:/Users/kirby/Documents/Github/deki/deki-editor/deki-editor/include/deki-editor/AssetFileWatcher.h>

Classes

struct  Event
 One file change under a watched folder. More...

Public Types

enum class  EventKind { Added , Modified , Deleted }

Public Member Functions

 AssetFileWatcher ()
 AssetFileWatcher (const AssetFileWatcher &)=delete
 ~AssetFileWatcher ()
std::vector< Event > DrainReadyEvents ()
 Returns the events that have been quiet for kDebounceMs.
AssetFileWatcher & operator= (const AssetFileWatcher &)=delete
void Start (const std::string &watchPath, const std::string &projectPath)
 Starts watching watchPath (absolute) and everything under it.
void Stop ()
 Stops the watcher thread and clears pending events.
bool TakeMissedEvents ()
 True once after the OS dropped change events (a burst overflowed its buffer, as a large checkout can): files may have changed that no event will report, so the caller should compare with the disk.

Static Public Attributes

static constexpr int kDebounceMs = 100

Detailed Description

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

Wraps an efsw::FileWatcher (ReadDirectoryChangesW / inotify / FSEvents) on its own worker thread. Raw events go into a thread-safe map keyed by project-relative path. AssetPipeline::Tick() calls DrainReadyEvents() once per frame to take the merged, debounced events on the main thread, which is required because onAssetChanged subscribers touch GPU resources.

When a new event arrives for a path that already has one 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

A rename (efsw's Moved action) becomes Deleted(oldPath) + Added(newPath).

An entry is returned only once it has been quiet for kDebounceMs. This turns the usual atomic save (write temp, delete original, rename temp) into one event per 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

◆ DrainReadyEvents()

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

Returns the events that have been quiet for kDebounceMs.

Main thread only. Newer entries stay pending for a later call.

◆ operator=()

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

◆ Start()

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

Starts watching watchPath (absolute) and everything under it.

Usually project/assets; HotReloadService also uses it for project/src and project/packages. Event paths are made relative to projectPath.

◆ Stop()

void DekiEditor::AssetFileWatcher::Stop ( )

Stops the watcher thread and clears pending events.

◆ TakeMissedEvents()

bool DekiEditor::AssetFileWatcher::TakeMissedEvents ( )

True once after the OS dropped change events (a burst overflowed its buffer, as a large checkout can): files may have changed that no event will report, so the caller should compare with the disk.

Main thread.

Member Data Documentation

◆ kDebounceMs

int DekiEditor::AssetFileWatcher::kDebounceMs = 100
staticconstexpr

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