FileWatcher library watches files while you play

Spurred by an article a while back in Game Developer Magazine, I decided to write a little cross platform library for detecting changes in files. The library works in both Windows and Linux (tested in ubuntu 8.10, but should work in anything with inotify) with support soon coming to OSX. The library is great for automatically updating game resources during development. Most real game engines have this these days, and now everyone else can too!

The library comes with two samples. OgreDemo.cpp shows a simple example of reloading textures on the fly using the Ogre3D engine. SimpleDemo.cpp just watches a directory and outputs the file names when a file changes.

Some example code:

// Create the object
FW::FileWatcher* fileWatcher = new FW::FileWatcher();
// add a directory watch
FW::WatchID watchid = fileWatcher->addWatch("..\\media", new UpdateListener());
// somewhere in your update loop call update
// where UpdateListener is defined as such
class UpdateListener : public FW::FileWatchListener
    UpdateListener() {}
    void handleFileAction(FW::WatchID watchid, const String& dir,
                                    const String& filename,
                                    FW::FileWatcher::Action action)
        std::cout << "File (" << dir + \\ + filename << ") has event "
                        << action << std::endl;

Download version 2009.02.17

One thought on “FileWatcher library watches files while you play

Leave a Reply

Your email address will not be published. Required fields are marked *

3 + five =