]> Dogcows Code - chaz/yoink/blobdiff - src/Moof/Engine.cc
initial working frustum culling implementation
[chaz/yoink] / src / Moof / Engine.cc
index bcc336c1244f1f8b0a8ed041507c4b5f3e0f7834..53fca73e9e883cfab1d18aced70cd125391f26d1 100644 (file)
@@ -28,7 +28,6 @@
 
 #include <cstdlib>                     // exit
 #include <iostream>
-#include <stdexcept>
 #include <string>
 
 #include <SDL/SDL.h>
@@ -48,26 +47,32 @@ namespace Mf {
 class Engine::EngineImpl
 {
 public:
-       EngineImpl(const std::string& name, int argc, char* argv[],
-                       const std::string& configFile, Engine* outer) :
-               settings(argc, argv),
-               interface(outer)
+       EngineImpl(int argc, char* argv[], const std::string& configFile,
+                       const std::string& name, const std::string& iconFile,
+                       Engine* outer) :
+               interface(outer),
+               settings(argc, argv)
        {
                if (SDL_Init(SDL_INIT_EVERYTHING | SDL_INIT_EVENTTHREAD) != 0)
                {
-                       throw std::runtime_error(SDL_GetError());
+                       throw Exception(SDL_GetError());
                }
                if (FE_Init() != 0)
                {
-                       throw std::runtime_error(FE_GetError());
+                       throw Exception(FE_GetError());
                }
 
-               setSeed();
-
                settings.loadFromFile(configFile);
 
-               video = VideoPtr(new Video(name));
-               video->makeActive();
+               long randomSeed;
+               if (settings.get("engine.rngseed", randomSeed))
+               {
+                       setSeed(randomSeed);
+               }
+               else
+               {
+                       setSeed();
+               }
 
                double ts = 0.01;
                settings.get("engine.timestep", ts);
@@ -79,11 +84,14 @@ public:
 
                printFps = false;
                settings.get("video.printfps", printFps);
+
+               video = VideoPtr(new Video(name, iconFile));
+               video->makeActive();
        }
 
        ~EngineImpl()
        {
-               // The video object must be destroyed before we can shutdown SDL.
+               // the video object must be destroyed before we can shutdown SDL
                video.reset();
 
                FE_Quit();
@@ -95,7 +103,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()
@@ -133,6 +141,10 @@ public:
 
                                nextStep += timestep;
                        }
+                       if (ticksNow >= nextStep)
+                       {
+                               nextStep = ticksNow + timestep;
+                       }
 
                        if (ticksNow >= nextDraw)
                        {
@@ -171,7 +183,7 @@ public:
                }
                while (running);
 
-               return 0;
+               return exitCode;
        }
 
 
@@ -201,25 +213,27 @@ public:
        }
 
 
+       Engine*         interface;
+
        Settings        settings;
        Dispatcher      dispatcher;
        VideoPtr        video;
 
        bool            running;
+       int                     exitCode;
 
        Scalar          timestep;
        Scalar          drawRate;
 
        long            fps;
        bool            printFps;
-
-       Engine*         interface;
 };
 
 
-Engine::Engine(const std::string& name, int argc, char* argv[],
-               const std::string& configFile) :
-       impl_(new Engine::EngineImpl(name, argc, argv, configFile, this)) {}
+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))
+{}
 
 Engine::~Engine() {}
 
@@ -229,9 +243,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.024266 seconds and 4 git commands to generate.