X-Git-Url: https://git.dogcows.com/gitweb?p=chaz%2Fyoink;a=blobdiff_plain;f=src%2FMoof%2FEngine.hh;h=28d7fa03eab8119d16a58ca5f2c81ad40da69ad5;hp=e42510d3d86af61744bab076f2186249e1e91e26;hb=4f62ce947db282f0bbf4d49b3aafb83d7cf51adc;hpb=a31d65a998121df0651c57bfb68782e2a07d2e2f diff --git a/src/Moof/Engine.hh b/src/Moof/Engine.hh index e42510d..28d7fa0 100644 --- a/src/Moof/Engine.hh +++ b/src/Moof/Engine.hh @@ -31,60 +31,75 @@ #include -#include +#include +#include +#include #include -#include namespace Mf { -// forward declarations -class Video; +class Settings; + + +/** + * The engine is essentially a stack of layers. While running, it updates each + * layer from the bottom up every timestep. It also draws each layer from the + * bottom up, adhering to the maximum frame-rate. Events are sent to each layer + * from the top down until a layer signals the event was handled. The engine is + * also responsible for firing timers on time. The engine will continue running + * as long as there are layers on the stack. + */ class Engine { - class Impl; - boost::shared_ptr mImpl; - public: - Engine(int argc, char* argv[], const std::string& name, - const std::string& iconFile, const std::string& configFile); + Engine(); ~Engine() {} + + // loads settings: rngseed, timestep, framerate, showfps + bool initWithSettings(const Settings& settings); + + const Error& getError() const; + void clearError(); + + // setting the video is required before you can run the engine and should + // probably be done before adding any layers + void setVideo(VideoP video); + VideoP getVideo() const; + + int getFps() const; - // get global instance - static Engine& getInstance(); + void push(LayerP layer); // push a layer onto the top + LayerP pop(); // pop the top layer + LayerP pop(Layer* layer); // pops a specific layer and all layers above it + void clear(); // remove all layers (the engine will stop) + int getSize() const; // get the size of the stack + + // set this machine in motion void run(); - void setTimestep(Scalar ts); - Scalar getTimestep() const; - void setMaxFrameRate(long maxFps); - long getMaxFrameRate() const; - - Video& getVideo() const; - long getFrameRate() const; - - void push(LayerP layer); - LayerP pop(); - // pops a specific layer and all layers above it - LayerP pop(Layer* layer); - void clear(); - - struct Exception : public Mf::Exception - { - explicit Exception(unsigned error) : - Mf::Exception(error) {} - - void raise() - { - throw *this; - } - }; + Dispatch::Handler addHandler(const std::string& event, + const Dispatch::Function& callback); + Dispatch::Handler addHandler(const std::string& event, + const Dispatch::Function& callback, Dispatch::Handler handler); + + void dispatch(const std::string& event, + const Dispatch::Message* message = 0); + +private: + + class Impl; + boost::shared_ptr mImpl; }; +extern Engine engine; + + } // namespace Mf #endif // _MOOF_ENGINE_HH_