]> Dogcows Code - chaz/yoink/blobdiff - src/Moof/Engine.hh
finally fixed broken main loop
[chaz/yoink] / src / Moof / Engine.hh
index 971d68fe1e28eb59e3536056dd19c4355ec0668c..28d7fa03eab8119d16a58ca5f2c81ad40da69ad5 100644 (file)
 #ifndef _MOOF_ENGINE_HH_
 #define _MOOF_ENGINE_HH_
 
-#include <stdexcept>
-
 #include <boost/shared_ptr.hpp>
 
-#include <Moof/Dispatcher.hh>
-#include <Moof/Event.hh>
-#include <Moof/Math.hh>
-#include <Moof/Singleton.hh>
+#include <Moof/Dispatch.hh>
+#include <Moof/Error.hh>
+#include <Moof/Video.hh>
+#include <Moof/Layer.hh>
 
 
 namespace Mf {
 
 
-// forward declaration
-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 : public Singleton<Engine>
+class Engine
 {
 public:
-       Engine(int argc, char* argv[], const std::string& configFile,
-                       const std::string& name, const std::string& iconFile);
-       virtual ~Engine();
 
-       int run();
-       void stop(int exitCode = 0);
+       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;
 
-       void setTimestep(Scalar ts);
-       Scalar getTimestep();
-       void setMaxFrameRate(long maxFps);
-       long getMaxFrameRate();
+       int getFps() const;
 
-       Video& getVideo();
-       long getFrameRate();
+       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)
 
-       // Override these if you want.
-       virtual void update(Scalar t, Scalar dt);
-       virtual void draw(Scalar alpha);
-       virtual void handleEvent(const Event& event);
+       int getSize() const;            // get the size of the stack
 
-       struct Exception : std::runtime_error
-       {
-               explicit Exception(const std::string& what_arg) :
-                       std::runtime_error(what_arg) {}
-       };
+       // 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 Impl;
-       boost::shared_ptr<Impl> impl_;
+       boost::shared_ptr<Impl> mImpl;
 };
 
 
+extern Engine engine;
+
+
 } // namespace Mf
 
 #endif // _MOOF_ENGINE_HH_
This page took 0.018753 seconds and 4 git commands to generate.