X-Git-Url: https://git.dogcows.com/gitweb?p=chaz%2Fyoink;a=blobdiff_plain;f=src%2FYoinkApp.cc;h=d391927d02b364bc1a07c8ba170de838a03a4ad0;hp=a1c2dbbf8133f273e2aca98efdf2dc3f8db133ef;hb=1dd005530930657fd6216edc1dfcfa4c270a81c9;hpb=bfa6212d09d8735d8fd5e2638188e4a99f21ada4 diff --git a/src/YoinkApp.cc b/src/YoinkApp.cc index a1c2dbb..d391927 100644 --- a/src/YoinkApp.cc +++ b/src/YoinkApp.cc @@ -32,6 +32,8 @@ #include +#include +#include #include #include #include @@ -107,15 +109,17 @@ YoinkApp::YoinkApp(int argc, char* argv[]) : music("NightFusion"), punchSound("RobotPunch") { - Mf::Dispatcher::instance().addHandler("video.context_recreated", + Mf::dispatcher::addHandler("video.context_recreated", boost::bind(&YoinkApp::contextRecreated, this, _1), this); setupGL(); + Mf::Scalar fade[2] = {0.0, 1.0}; + musicFade.init(fade, 0.0); music.play(); state = 0.0; - heroine = CharacterPtr(new Character("RobotTrooper")); + heroine = Character::alloc("RobotTrooper"); heroine->getAnimation().startSequence("Run"); font = new TilemapFont; @@ -130,7 +134,7 @@ YoinkApp::YoinkApp(int argc, char* argv[]) : Mf::Scalar coeff[2] = {1.0, 0.0}; fadeIn.init(coeff, 0.1); - testScene = new Mf::Scene("Test"); + testScene = Mf::Scene::alloc("Test"); heroine->treeNode = testScene->getOctree()->insert(heroine); } @@ -138,9 +142,8 @@ YoinkApp::~YoinkApp() { //delete heroine; delete font; - delete testScene; - Mf::Dispatcher::instance().removeHandler(this); + Mf::dispatcher::removeHandler(this); } @@ -176,7 +179,7 @@ void YoinkApp::setupGL() //glLineWidth(10.0f); } -void YoinkApp::contextRecreated(const Mf::Notification& note) +void YoinkApp::contextRecreated(const Mf::Notification* note) { // Whenever the context and a new one created, it probably won't contain our // state so we need to set that up again. @@ -187,6 +190,10 @@ void YoinkApp::contextRecreated(const Mf::Notification& note) void YoinkApp::update(Mf::Scalar t, Mf::Scalar dt) { //dt *= 0.2; + + musicFade.update(dt); + music.update(t, dt); + music.setGain(musicFade.getValue()); fadeIn.update(dt); @@ -194,6 +201,7 @@ void YoinkApp::update(Mf::Scalar t, Mf::Scalar dt) heroine->update(t, dt); heroine->treeNode = testScene->getOctree()->reinsert(heroine, heroine->treeNode); + testScene->getOctree()->print(heroine->treeNode); //camera.lookAt(heroine->getSphere().point); camera.setPosition(Mf::Vector3(-heroine->current.position[0], -heroine->current.position[1], -256)); @@ -234,6 +242,7 @@ void YoinkApp::draw(Mf::Scalar alpha) //heroine->draw(alpha); + heroine->getAabb().draw(); hud.draw(); @@ -390,24 +399,39 @@ void YoinkApp::handleEvent(const Mf::Event& event) if (event.key.keysym.sym == SDLK_ESCAPE) { stop(); + break; } else if (event.key.keysym.sym == SDLK_f) { getVideo().toggleFull(); + break; } else if (event.key.keysym.sym == SDLK_SPACE) { heroine->getAnimation().startSequence("Punch"); punchSound.play(); + break; } else if (event.key.keysym.sym == SDLK_r) { testScene->refresh(); + break; + } + else if (event.key.keysym.sym == SDLK_t) + { + Mf::dispatcher::dispatch("video.context_recreated"); + break; + } + else if (event.key.keysym.sym == SDLK_p) + { + music.togglePlayPause(); + break; } else if (event.key.keysym.sym == SDLK_l) { getVideo().toggleCursorGrab(); getVideo().toggleCursorVisible(); + break; } case SDL_KEYUP: @@ -415,7 +439,7 @@ void YoinkApp::handleEvent(const Mf::Event& event) case SDL_MOUSEMOTION: case SDL_MOUSEBUTTONDOWN: - camera.adjustFromInput(event); + camera.handleEvent(event); break; case SDL_QUIT: @@ -435,11 +459,15 @@ void YoinkApp::handleEvent(const Mf::Event& event) int main(int argc, char* argv[]) { - std::cout << PACKAGE_STRING << std::endl + std::cout << std::endl << PACKAGE_STRING << std::endl << "Compiled " << __TIME__ " " __DATE__ << std::endl << "Send patches and bug reports to <" PACKAGE_BUGREPORT << ">." << std::endl << std::endl; +#if ! NDEBUG + Mf::setLogLevel(Mf::DEBUGGING); +#endif + int status = 0; try @@ -447,13 +475,14 @@ int main(int argc, char* argv[]) YoinkApp app(argc, argv); status = app.run(); } - catch (Mf::Engine::Exception e) + catch (Mf::Exception e) { - std::cerr << "Unhandled exception: " << e.what() << std::endl; + Mf::logError("unhandled exception: <<%s>>", e.what()); + Mf::logInfo("it's time to crash now :-("); status = 1; } - std::cout << "Goodbye..." << std::endl; + std::cout << std::endl << "Goodbye..." << std::endl << std::endl; return status; }