X-Git-Url: https://git.dogcows.com/gitweb?p=chaz%2Fyoink;a=blobdiff_plain;f=src%2FMoof%2FEngine.hh;h=07e982abd9ee4207478d077b8365cedc01897643;hp=a0c23002080ff5ef65fa1a336cedd1294e101a35;hb=a295f8def17036c8071b56e181364f99a377cae7;hpb=892da43bf5796e7c5f593a6d0f53bd797a36bd3e diff --git a/src/Moof/Engine.hh b/src/Moof/Engine.hh index a0c2300..07e982a 100644 --- a/src/Moof/Engine.hh +++ b/src/Moof/Engine.hh @@ -31,58 +31,74 @@ #include -#include +#include +#include +#include #include -#include namespace Mf { -// forward declarations -class Video; +/** + * 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. + */ -struct Engine +class Engine { - Engine(int argc, char* argv[], const std::string& name, - const std::string& iconFile, const std::string& configFile); +public: + + Engine(); ~Engine() {} - // get global instance - static Engine& getInstance(); + const Error& getError() const; - void run(); + // 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; + + void setTimestep(int ts); + int getTimestep() const; - void setTimestep(Scalar ts); - Scalar getTimestep() const; - void setMaxFrameRate(long maxFps); - long getMaxFrameRate() const; + void setMaxFps(int maxFps); // draw rate is always capped at the timestep + int getMaxFps() const; - Video& getVideo() const; - long getFrameRate() const; + int getFps() const; - void pushLayer(LayerP layer); - void popLayer(); - void popLayer(Layer* layer); - void clearLayers(); + 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) - struct Exception : public Mf::Exception - { - explicit Exception(unsigned error) : - Mf::Exception(error) {} + int getSize() const; // get the size of the stack + + // set this machine in motion + void run(); - 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 impl_; + boost::shared_ptr mImpl; }; +extern Engine engine; + + } // namespace Mf #endif // _MOOF_ENGINE_HH_