]> Dogcows Code - chaz/yoink/blobdiff - src/Moof/Engine.hh
fixed permissions for stlplus files
[chaz/yoink] / src / Moof / Engine.hh
index e49f44db853cbf30ca59539a5ab6f04bac64a1be..c5e99864f103e49dedffee2721609f48e136fe84 100644 (file)
 
 #include <boost/shared_ptr.hpp>
 
-#include <Moof/Exception.hh>
+#include <Moof/Dispatch.hh>
+#include <Moof/Video.hh>
 #include <Moof/Layer.hh>
-#include <Moof/Math.hh>
 
 
 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 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.
+ */
 
-struct Engine
+class Engine
 {
-       Engine(int argc, char* argv[], const std::string& name, 
-                       const std::string& iconFile, const std::string& configFile);
+public:
+
        ~Engine() {}
 
        // get global instance
        static Engine& getInstance();
 
-       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 setMaxFps(int maxFps);     // draw rate is always capped at the timestep
+       int getMaxFps() const;
 
-       void setTimestep(Scalar ts);
-       Scalar getTimestep() const;
-       void setMaxFrameRate(long maxFps);
-       long getMaxFrameRate() const;
+       int getFps() const;
 
-       Video& getVideo() const;
-       long getFrameRate() 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)
 
-       void push(LayerP layer);
-       LayerP pop();
-       // pops a specific layer and all layers above it
-       LayerP pop(Layer* layer);
-       void clear();
+       int getSize() const;            // get the size of the stack
 
-       struct Exception : public Mf::Exception
-       {
-               explicit Exception(unsigned error) :
-                       Mf::Exception(error) {}
+       // 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 raise()
-               {
-                       throw *this;
-               }
-       };
+       void dispatch(const std::string& event,
+                       const Dispatch::Message* message = 0);
 
 private:
+
+       Engine();               // use getInstance() to access the engine
+
        class Impl;
-       boost::shared_ptr<Impl> impl_;
+       boost::shared_ptr<Impl> mImpl;
 };
 
 
This page took 0.01943 seconds and 4 git commands to generate.