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);
//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);
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();
}
break;
case SDL_QUIT:
- engine.clear();
+ Mf::engine.clear();
break;
}
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()
atexit(goodbye);
-#if YOINK_LOGLEVEL >= 3
- Mf::Log::setLevel(Mf::Log::INFO);
-#elif YOINK_LOGLEVEL >= 2
- Mf::Log::setLevel(Mf::Log::WARNING);
-#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:
// 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
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();