X-Git-Url: https://git.dogcows.com/gitweb?p=chaz%2Fyoink;a=blobdiff_plain;f=src%2FMoof%2FEngine.hh;h=c5e99864f103e49dedffee2721609f48e136fe84;hp=112b87ea8dba3ea07f8d1cbefe5407003e045b4e;hb=71bd9dbaf1c1e3c55a9f63392a73865d8aeee7d4;hpb=c2321281bf12a7efaedde930422c7ddbc92080d4 diff --git a/src/Moof/Engine.hh b/src/Moof/Engine.hh index 112b87e..c5e9986 100644 --- a/src/Moof/Engine.hh +++ b/src/Moof/Engine.hh @@ -31,44 +31,69 @@ #include -#include -#include -#include -#include +#include +#include +#include namespace Mf { -// forward declaration -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 send 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 : public Singleton +class Engine { public: - Engine(const std::string& name, int argc, char* argv[], - const std::string& configFile); - virtual ~Engine(); - int run(); - void stop(); + ~Engine() {} - void setTimestep(Scalar ts); - Scalar getTimestep(); - void setMaxFrameRate(long maxFps); - long getMaxFrameRate(); + // get global instance + static Engine& getInstance(); - Video& getVideo(); - long getFrameRate(); + // 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; - // Override these if you want. - virtual void update(Scalar t, Scalar dt); - virtual void draw(Scalar alpha); - virtual void handleEvent(const Event& event); + void setTimestep(int ts); + int getTimestep() const; + + void setMaxFps(int maxFps); // draw rate is always capped at the timestep + int getMaxFps() const; + + int getFps() const; + + 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(); + + 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 EngineImpl; - boost::shared_ptr impl_; + + Engine(); // use getInstance() to access the engine + + class Impl; + boost::shared_ptr mImpl; };