]> Dogcows Code - chaz/yoink/blobdiff - src/Moof/Engine.cc
cleaned up dispatcher
[chaz/yoink] / src / Moof / Engine.cc
index be8ca5fac61e184f0b54a0da244355e5b33e89a2..78233688d60f69dba90c880a0c9e94b9518f0814 100644 (file)
@@ -32,6 +32,8 @@
 
 #include <SDL/SDL.h>
 #include "fastevents.h"
+#include <SDL/SDL_sound.h>
+#include <AL/alut.h>
 
 #include "Dispatcher.hh"
 #include "Engine.hh"
 namespace Mf {
 
 
-class Engine::EngineImpl
+class Engine::Impl
 {
 public:
-       EngineImpl(int argc, char* argv[], const std::string& configFile,
+       Impl(int argc, char* argv[], const std::string& configFile,
                        const std::string& name, const std::string& iconFile,
                        Engine* outer) :
                interface(outer),
@@ -61,18 +63,18 @@ public:
                {
                        throw Exception(FE_GetError());
                }
+               if (Sound_Init() != 0)
+               {
+                       //throw Exception(Sound_GetError());
+                       std::cerr << Sound_GetError() << std::endl;
+               }
+               alutInit(&argc, argv);
 
                settings.loadFromFile(configFile);
 
                long randomSeed;
-               if (settings.get("engine.rngseed", randomSeed))
-               {
-                       setSeed(randomSeed);
-               }
-               else
-               {
-                       setSeed();
-               }
+               if (settings.get("engine.rngseed", randomSeed)) setSeed(randomSeed);
+               else setSeed();
 
                double ts = 0.01;
                settings.get("engine.timestep", ts);
@@ -89,11 +91,13 @@ public:
                video->makeActive();
        }
 
-       ~EngineImpl()
+       ~Impl()
        {
                // the video object must be destroyed before we can shutdown SDL
                video.reset();
 
+               alutExit();
+               Sound_Quit();
                FE_Quit();
                SDL_Quit();
        }
@@ -103,7 +107,7 @@ public:
         * The main loop.  This just calls dispatchEvents(), update(), and draw()
         * over and over again.  The timing of the update and draw are decoupled.
         * The actual frame rate is also calculated here.  This function will return
-        * with a value of 0 if the member variable running becomes true.
+        * the exit code used to stop the loop.
         */
 
        int run()
@@ -141,6 +145,10 @@ public:
 
                                nextStep += timestep;
                        }
+                       if (ticksNow >= nextStep)
+                       {
+                               nextStep = ticksNow + timestep;
+                       }
 
                        if (ticksNow >= nextDraw)
                        {
@@ -179,7 +187,7 @@ public:
                }
                while (running);
 
-               return 0;
+               return exitCode;
        }
 
 
@@ -216,6 +224,7 @@ public:
        VideoPtr        video;
 
        bool            running;
+       int                     exitCode;
 
        Scalar          timestep;
        Scalar          drawRate;
@@ -227,8 +236,7 @@ public:
 
 Engine::Engine(int argc, char* argv[], const std::string& configFile,
                const std::string& name, const std::string& iconFile) :
-       impl_(new Engine::EngineImpl(argc, argv, configFile, name, iconFile, this))
-{}
+       impl_(new Engine::Impl(argc, argv, configFile, name, iconFile, this)) {}
 
 Engine::~Engine() {}
 
@@ -238,9 +246,10 @@ int Engine::run()
        return impl_->run();
 }
 
-void Engine::stop()
+void Engine::stop(int exitCode)
 {
        impl_->running = false;
+       impl_->exitCode = exitCode;
 }
 
 
This page took 0.025289 seconds and 4 git commands to generate.