]> Dogcows Code - chaz/yoink/blobdiff - src/MainLayer.cc
moved log level from configure to setting
[chaz/yoink] / src / MainLayer.cc
index 0b2ef3699f0576f1f70d87da7bbe8a59a8e12972..ad2dbbc5f22d9a607f69327783032eee338c4236 100644 (file)
 
 MainLayer::MainLayer()
 {
-       mDispatchHandler = Mf::Engine::getInstance().addHandler("video.newcontext",
+       mDispatchHandler = Mf::engine.addHandler("video.newcontext",
                        boost::bind(&MainLayer::contextRecreated, this));
        setupGL();
 }
 
-void MainLayer::pushed(Mf::Engine& engine)
+void MainLayer::pushedOntoEngine()
 {
        //Mf::Scalar coeff[] = {0.0, 1.0};
        //Mf::Lerp interp(coeff, 0.25);
@@ -67,20 +67,21 @@ void MainLayer::pushed(Mf::Engine& engine)
                //Mf::Transition<Mf::Lerp>::alloc(gameLayer, Mf::LayerP(), interp);
        //engine->push(transition);
        //engine->push(GameLayer::alloc());
-       engine.push(TitleLayer::alloc());
+       Mf::engine.push(TitleLayer::alloc());
 }
 
 
-void MainLayer::update(Mf::Engine& engine, Mf::Scalar t, Mf::Scalar dt)
+void MainLayer::update(Mf::Scalar t, Mf::Scalar dt)
 {
-       if (engine.getSize() == 1)
+       if (Mf::engine.getSize() == 1)
        {
                // this is the only layer left on the stack
-               //engine.push(TitleLayer::alloc());
+               //Mf::engine.push(TitleLayer::alloc());
+               Mf::engine.clear();
        }
 }
 
-void MainLayer::draw(Mf::Engine& engine, Mf::Scalar alpha) const
+void MainLayer::draw(Mf::Scalar alpha) const
 {
        glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
 
@@ -91,22 +92,22 @@ void MainLayer::draw(Mf::Engine& engine, Mf::Scalar alpha) const
        glLoadIdentity();
 }
 
-bool MainLayer::handleEvent(Mf::Engine& engine, const Mf::Event& event)
+bool MainLayer::handleEvent(const Mf::Event& event)
 {
        switch (event.type)
        {
                case SDL_KEYUP:
                        if (event.key.keysym.sym == SDLK_ESCAPE)
                        {
-                               engine.clear();
+                               Mf::engine.clear();
                        }
                        else if (event.key.keysym.sym == SDLK_f)
                        {
-                               engine.getVideo()->toggleFull();
+                               Mf::engine.getVideo()->toggleFull();
                        }
                        else if (event.key.keysym.sym == SDLK_l)
                        {
-                               Mf::VideoP video = engine.getVideo();
+                               Mf::VideoP video = Mf::engine.getVideo();
                                video->toggleCursorGrab();
                                video->toggleCursorVisible();
                        }
@@ -117,7 +118,7 @@ bool MainLayer::handleEvent(Mf::Engine& engine, const Mf::Event& event)
                        break;
 
                case SDL_QUIT:
-                       engine.clear();
+                       Mf::engine.clear();
                        break;
        }
 
@@ -141,11 +142,13 @@ void MainLayer::setupGL()
 
        glClearColor(0.0, 0.0, 0.0, 1.0);
 
-       glMatrixMode(GL_PROJECTION);
-       glLoadIdentity();
-       gluPerspective(60.0, 1.33333, 1.0, 2500.0);
+       //glMatrixMode(GL_PROJECTION);
+       //glLoadIdentity();
+       //Mf::Scalar ratio = Mf::engine.getVideo()->getWidth() /
+               //Mf::engine.getVideo()->getHeight();
+       //gluPerspective(60.0, ratio, 1.0, 250.0);
 
-       glMatrixMode(GL_MODELVIEW);
+       //glMatrixMode(GL_MODELVIEW);
 }
 
 void MainLayer::contextRecreated()
@@ -270,17 +273,20 @@ int main(int argc, char* argv[])
        atexit(goodbye);
 
 
-#if            YOINK_LOGLEVEL >= 4
-       Mf::Log::setLevel(Mf::Log::DEBUGG);
-#elif  YOINK_LOGLEVEL >= 3
-       Mf::Log::setLevel(Mf::Log::INFO);
-#elif  YOINK_LOGLEVEL >= 2
-       Mf::Log::setLevel(Mf::Log::SCRIPT);
-#elif  YOINK_LOGLEVEL >= 1
-       Mf::Log::setLevel(Mf::Log::ERROR);
-#elif  YOINK_LOGLEVEL
-       Mf::Log::setLevel(Mf::Log::NONE);
-#endif
+       // make sure the engine started up okay
+       const Mf::Error& error = Mf::engine.getError();
+       if (error.isError())
+       {
+               Mf::ModalDialog dialog;
+               dialog.title = PACKAGE_STRING;
+               dialog.text1 = "Uh oh!";
+               dialog.text2 = getErrorString(error);
+               dialog.type = Mf::ModalDialog::CRITICAL;
+               dialog.run();
+
+               // openal errors are not fatal
+               if (error.code() != Mf::Error::OPENAL_INIT) return 1;
+       }
 
 
        // Add search paths; they should be searched in this order:
@@ -302,9 +308,7 @@ int main(int argc, char* argv[])
        // 3. $HOME/.yoinkrc
        // 4. YOINKRC (environment)
 
-       std::string configFiles;
-
-       configFiles += Mf::Resource::getPath("yoinkrc");
+       std::string configFiles = Mf::Resource::getPath("yoinkrc");
 #if !defined(_WIN32) && !defined(__WIN32__)
        configFiles += ":/etc/yoinkrc";
 #endif
@@ -321,23 +325,27 @@ int main(int argc, char* argv[])
        settings.loadFromFile(configFiles);
        settings.parseArgs(argc, argv);
 
+       Mf::Log::Level logLevel;
+       if (settings.get("loglevel", logLevel)) Mf::Log::setLevel(logLevel);
+
+       Mf::engine.initWithSettings(settings);
+
        std::string iconFile = Mf::Resource::getPath(PACKAGE".png");
 
 
        try
        {
-               Mf::Engine& app = Mf::Engine::getInstance();
-               app.setVideo(Mf::Video::alloc(PACKAGE_STRING, iconFile));
-               app.push(MainLayer::alloc());
+               Mf::engine.setVideo(Mf::Video::alloc(PACKAGE_STRING, iconFile));
+               Mf::engine.push(MainLayer::alloc());
 
-               app.run();
+               Mf::engine.run();
        }
-       catch (const Mf::Exception& e)
+       catch (const Mf::Error& error)
        {
                Mf::ModalDialog dialog;
                dialog.title = PACKAGE_STRING;
                dialog.text1 = "Unhandled Exception";
-               dialog.text2 = getErrorString(e);
+               dialog.text2 = getErrorString(error);
                dialog.type = Mf::ModalDialog::CRITICAL;
                dialog.run();
 
This page took 0.02582 seconds and 4 git commands to generate.