]> Dogcows Code - chaz/yoink/blobdiff - src/MainLayer.cc
dispatch class not a singleton, engine is static
[chaz/yoink] / src / MainLayer.cc
index 40377365d18149cf02c7ec8fec0ae4cbd1e4e899..568f0cd0ebe84b2185945895692d5045c89c7454 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,21 +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());
-               engine.clear();
+               //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);
 
@@ -92,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();
                        }
@@ -118,7 +118,7 @@ bool MainLayer::handleEvent(Mf::Engine& engine, const Mf::Event& event)
                        break;
 
                case SDL_QUIT:
-                       engine.clear();
+                       Mf::engine.clear();
                        break;
        }
 
@@ -271,6 +271,20 @@ int main(int argc, char* argv[])
        atexit(goodbye);
 
 
+       // make sure the engine started up okay
+       if (Mf::engine.getError().isError())
+       {
+               Mf::ModalDialog dialog;
+               dialog.title = PACKAGE_STRING;
+               dialog.text1 = "Fatal Error";
+               dialog.text2 = getErrorString(Mf::engine.getError());
+               dialog.type = Mf::ModalDialog::CRITICAL;
+               dialog.run();
+
+               return 1;
+       }
+
+
 #if        YOINK_LOGLEVEL >= 3
        Mf::Log::setLevel(Mf::Log::INFO);
 #elif  YOINK_LOGLEVEL >= 2
@@ -325,18 +339,17 @@ int main(int argc, char* argv[])
 
        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.019277 seconds and 4 git commands to generate.