]> Dogcows Code - chaz/yoink/blobdiff - src/Moof/Engine.cc
removed Random.{cc,hh}; obsoleted by cml
[chaz/yoink] / src / Moof / Engine.cc
index f4bc712b27887d0b5397c579fc861d196ffc3bc6..785cb4b41ed67ee342cf8df535f9e6726e5d3a35 100644 (file)
 *******************************************************************************/
 
 #include <algorithm>
-#include <cstdlib>                     // exit
+#include <cstdlib>                     // exit, srand
+#include <ctime>                       // time
 #include <list>
 #include <string>
 
+#include <AL/alc.h>
 #include <SDL/SDL.h>
 #include "fastevents.h"
-#include <AL/alut.h>
+
 
 #include "Engine.hh"
 #include "Event.hh"
 #include "Exception.hh"
 #include "Log.hh"
 #include "Math.hh"
-#include "Random.hh"
 #include "Settings.hh"
 #include "Timer.hh"
 
@@ -68,22 +69,40 @@ public:
                        const char* error = SDL_GetError();
                        throw Exception(ErrorCode::SDL_INIT, error);
                }
+               else
+               {
+                       char vdName[128];
+                       SDL_VideoDriverName(vdName, sizeof(vdName));
+                       logDebug("initialized SDL; using video driver `%s'", vdName);
+               }
+
                if (FE_Init() != 0)
                {
                        const char* error = FE_GetError();
                        throw Exception(ErrorCode::FASTEVENTS_INIT, error);
                }
-               int argc = 1;
-               char name[] = "hello";
-               alutInit(&argc, (char**)&name);
-               
+
+               mAlDevice = alcOpenDevice(0);
+               mAlContext = alcCreateContext(mAlDevice, 0);
+               if (!mAlDevice || !mAlContext)
+               {
+                       const char* error = alcGetString(mAlDevice,alcGetError(mAlDevice));
+                       logError("error while creating audio context: %s", error);
+               }
+               else
+               {
+                       alcMakeContextCurrent(mAlContext);
+                       logDebug("opened sound device `%s'",
+                                       alcGetString(mAlDevice, ALC_DEFAULT_DEVICE_SPECIFIER));
+               }
+
                // now load the settings the engine needs
 
                Settings& settings = Settings::getInstance();
 
                unsigned randomSeed;
-               if (settings.get("rngseed", randomSeed)) setSeed(randomSeed);
-               else setSeed();
+               if (settings.get("rngseed", randomSeed)) srand(randomSeed);
+               else srand(time(0));
 
                Scalar timestep = 80.0;
                settings.get("timestep", timestep);
@@ -102,7 +121,10 @@ public:
                // the video object must be destroyed before we can shutdown SDL
                mVideo.reset();
 
-               alutExit();
+               alcMakeContextCurrent(0);
+               alcDestroyContext(mAlContext);
+               alcCloseDevice(mAlDevice);
+
                FE_Quit();
                SDL_Quit();
        }
@@ -329,6 +351,9 @@ public:
        VideoP                                          mVideo;
        Dispatch                                        mDispatch;
 
+       ALCdevice*                                      mAlDevice;
+       ALCcontext*                                     mAlContext;
+
        std::list<LayerP>                       mStack;
        std::list<LayerP>::iterator     mStackIt;
 
This page took 0.01901 seconds and 4 git commands to generate.