]> Dogcows Code - chaz/yoink/blobdiff - src/Moof/Engine.hh
better logging (maybe) and exception handling
[chaz/yoink] / src / Moof / Engine.hh
index 112b87ea8dba3ea07f8d1cbefe5407003e045b4e..f088dc56e85fcb663766594a2c9b454788e7c519 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/Exception.hh>
 #include <Moof/Math.hh>
-#include <Moof/Singleton.hh>
 
 
 namespace Mf {
@@ -43,15 +45,19 @@ namespace Mf {
 // forward declaration
 class Video;
 
-class Engine : public Singleton<Engine>
+class Engine
 {
+protected:
+
+       Engine(int argc, char* argv[], const std::string& configFile,
+                       const std::string& name, const std::string& iconFile);
+
 public:
-       Engine(const std::string& name, int argc, char* argv[],
-                       const std::string& configFile);
+
        virtual ~Engine();
 
        int run();
-       void stop();
+       void stop(int exitCode = 0);
 
        void setTimestep(Scalar ts);
        Scalar getTimestep();
@@ -61,14 +67,27 @@ public:
        Video& getVideo();
        long getFrameRate();
 
-       // Override these if you want.
+       // override these if you want
        virtual void update(Scalar t, Scalar dt);
        virtual void draw(Scalar alpha);
        virtual void handleEvent(const Event& event);
 
+       struct Exception : public Mf::Exception
+       {
+               explicit Exception(unsigned error) :
+                       Mf::Exception(error) {}
+
+               void raise()
+               {
+                       throw *this;
+               }
+       };
+
 private:
-       class EngineImpl;
-       boost::shared_ptr<EngineImpl> impl_;
+       Engine() {} // this class must be subclassed to be useful
+
+       class Impl;
+       boost::shared_ptr<Impl> impl_;
 };
 
 
This page took 0.018893 seconds and 4 git commands to generate.