X-Git-Url: https://git.dogcows.com/gitweb?p=chaz%2Fyoink;a=blobdiff_plain;f=src%2FGameLayer.cc;h=d696f5ebdf851a0276f625f5c886eddb3dfd7594;hp=8f2f4ec006d953ae70bfe5083b38385d0eb4abc5;hb=449366f5f32d24f2a2a6589da6e16b2bf0d61773;hpb=90b2c7fb10b244b781b84965a0d36f1f323ee94d diff --git a/src/GameLayer.cc b/src/GameLayer.cc index 8f2f4ec..d696f5e 100644 --- a/src/GameLayer.cc +++ b/src/GameLayer.cc @@ -9,112 +9,108 @@ * **************************************************************************/ -#include -#include -#include -#include -#include -#include +#include "../config.h" -#include "GameLayer.hh" +#include + +#include +#include +#include +#include +#include -#if HAVE_CONFIG_H -#include "config.h" -#endif +#include "GameLayer.hh" void GameLayer::loadSceneLoader() { - mState.script.importStandardLibraries(); - importLogFunctions(mState.script); + state_.script.import_standard_libraries(); + moof::log::import(state_.script); std::string path("loader"); - if (!Scene::getPath(path)) + if (!moof::resource::find(path)) { - throw Mf::Error(Mf::Error::RESOURCE_NOT_FOUND, "loader"); + throw std::runtime_error("cannot find scene loader script"); } - Mf::Script::Result status = mState.script.doFile(path); - if (status != Mf::Script::SUCCESS) + moof::script::status status = state_.script.do_file(path); + if (status != moof::script::success) { std::string str; - mState.script[-1].get(str); - - throw Mf::Error(Mf::Error::SCRIPT_ERROR, str); + state_.script[-1].get(str); + throw std::runtime_error("script error: " + str); } - mState.script.getGlobalTable().pushField("scenes"); - mState.script.getTop().get(mState.sceneList); - if (mState.sceneList.size() == 0) + state_.script.globals().push_field("scenes"); + state_.script.top().get(state_.sceneList); + if (state_.sceneList.size() == 0) { - throw Mf::Error(Mf::Error::SCRIPT_ERROR, - "no variable `scenes' within loader"); + throw std::runtime_error("no variable `scenes' in script loader."); } } -void GameLayer::advanceScene(Mf::Settings& settings) +void GameLayer::advanceScene(moof::settings& settings) { - if (mState.sceneList.size() != 0) + if (state_.sceneList.size() != 0) { - mState.scene = Scene::alloc(mState.sceneList[0]); - mState.sceneList.erase(mState.sceneList.begin()); + state_.scene = Scene::alloc(state_.sceneList[0]); + state_.sceneList.erase(state_.sceneList.begin()); - Mf::Script::Result status = mState.scene->load(settings, - mState.script); - if (status != Mf::Script::SUCCESS) + moof::script::status status = state_.scene->load(settings, + state_.script); + if (status != moof::script::success) { std::string str; - mState.script[-1].get(str); - - throw Mf::Error(Mf::Error::SCRIPT_ERROR, str); + state_.script[-1].get(str); + throw std::runtime_error("script error: " + str); } - mState.script.getGlobalTable().pushField("Event"); - if (mState.script[-1].isTable()) + moof::script::slot table = state_.script.globals().push_field("Event"); + if (table.is_table()) { - mState.script[-1].pushField("Think"); - mState.script.set("Think", Mf::Script::REGISTRY); - mState.script.pop(2); - } - else - { - mState.script.pop(); + state_.script.push("Think"); + table.push_field("Think"); + state_.script.registry().set_field(); } + state_.script.pop(); } } -GameLayer::GameLayer() : - mMusic("NightFusionIntro"), - mPunchSound("Thump") +GameLayer::GameLayer() { - mMusic.setLooping(true); - mMusic.enqueue("NightFusionLoop"); + moof::log_info("about to load sound resource..."); + music_ = moof::resource::load("sounds/NightFusionIntro.ogg"); + if (music_) + { + music_->loop(true); + music_->enqueue("NightFusionLoop"); + } + else moof::log_error("music not loaded"); - //mMusic.setPosition(Mf::Vector3(10.0, 5.0, 0.0)); + //music_->position(moof::vector3(10.0, 5.0, 0.0)); mThinkTimer.init(boost::bind(&GameLayer::thinkTimer, this), - 0.1, Mf::Timer::REPEAT); + 0.1, moof::timer::repeat); - mState.heroine = Heroine::alloc(); - mState.heroine->animation.startSequence("FlyDiagonallyUp"); + state_.heroine = Heroine::alloc(); + state_.heroine->animation.startSequence("FlyDiagonallyUp"); - mState.interp.init(0.0, 1.0); - mState.interp.reset(4.0, Mf::Interp::OSCILLATE); + state_.interp.init(0.0, 1.0, 4.0, moof::lerp_scalar::oscillate); } -void GameLayer::didAddToView() +void GameLayer::did_add_to_view() { bool isMute = false; settings().get("nomusic", isMute); - if (!isMute) mMusic.play(); + if (!isMute) music_->play(); loadSceneLoader(); advanceScene(settings()); // load the first scene - mHud = Hud::alloc(mState); - addChild(mHud); + mHud = Hud::alloc(state_); + add_child(mHud); mRay.direction.set(1.0, 0.0); @@ -125,121 +121,121 @@ void GameLayer::didAddToView() mCircle.radius = 2; mRayTimer.init(boost::bind(&GameLayer::rayTimer, this), - 1.0, Mf::Timer::REPEAT); + 1.0, moof::timer::repeat); - setProjection(); + projection(); } -void GameLayer::update(Mf::Scalar t, Mf::Scalar dt) +void GameLayer::update(moof::scalar t, moof::scalar dt) { - if (!mState.scene) return; - mState.camera.update(t, dt); - mState.heroine->update(t, dt); + if (!state_.scene) return; + state_.camera.update(t, dt); + state_.heroine->update(t, dt); - mState.scene->checkForCollision(*mState.heroine); + state_.scene->checkForCollision(*state_.heroine); - Mf::Vector3 cam= -Mf::promote(mState.heroine->getState().position, 8); - mState.camera.setPosition(cam); + moof::vector3 cam= -moof::promote(state_.heroine->state().position, 8); + state_.camera.position(cam); - mRay.point = mState.heroine->getState().position; + mRay.point = state_.heroine->state().position; - Mf::View::update(t, dt); + moof::view::update(t, dt); } void GameLayer::thinkTimer() { - mState.script.getRegistryTable().pushField("Think"); - if (mState.script[-1].isFunction()) mState.script.call(); - else mState.script.pop(); + state_.script.registry().push_field("Think"); + if (state_.script[-1].is_function()) state_.script.call(); + else state_.script.pop(); } void GameLayer::rayTimer() { - Mf::Ray2::Contact meh; - std::list hits; - Mf::Vector2 point; + moof::ray2::contact meh; + std::list hits; + moof::vector2 point; - bool bam = mLine.intersectRay(mRay, meh); + bool bam = mLine.intersect_ray(mRay, meh); if (bam) { //meh.normal.normalize(); //hits.push_back(meh); mRay.solve(point, meh.distance); - Mf::logInfo << "line: d = " << meh.distance << std::endl; - Mf::logInfo << " P = " << point << std::endl; - Mf::logInfo << " n = " << meh.normal << std::endl; + moof::log_info << "line: d = " << meh.distance << std::endl; + moof::log_info << " P = " << point << std::endl; + moof::log_info << " n = " << meh.normal << std::endl; } - bam = mCircle.intersectRay(mRay, meh); + bam = mCircle.intersect_ray(mRay, meh); if (bam) { meh.normal.normalize(); hits.push_back(meh); } - if (mState.scene->castRay(mRay, hits)) + if (state_.scene->castRay(mRay, hits)) { hits.front().normal.normalize(); mRay.solve(point, hits.front().distance); - Mf::logInfo << "scene: d = " << hits.front().distance << std::endl; - Mf::logInfo << " P = " << point << std::endl; - Mf::logInfo << " n = " << hits.front().normal << std::endl; + moof::log_info << "scene: d = " << hits.front().distance << std::endl; + moof::log_info << " P = " << point << std::endl; + moof::log_info << " n = " << hits.front().normal << std::endl; } } -void GameLayer::draw(Mf::Scalar alpha) const +void GameLayer::draw(moof::scalar alpha) const { - if (!mState.scene) return; - mState.camera.uploadToGL(alpha); + if (!state_.scene) return; + state_.camera.upload_to_gl(alpha); // DRAW THE SCENE - Mf::Texture::resetBind(); + moof::texture::reset_binding(); glEnableClientState(GL_VERTEX_ARRAY); glEnableClientState(GL_TEXTURE_COORD_ARRAY); - mState.scene->drawIfVisible(alpha, mState.camera.getFrustum()); - mState.heroine->draw(alpha); + state_.scene->draw_if_visible(alpha, state_.camera.frustum()); + state_.heroine->draw(alpha); mRay.draw(); mLine.draw(); mCircle.draw(); - Mf::View::draw(alpha); + moof::view::draw(alpha); } -bool GameLayer::handleEvent(const Mf::Event& event) +bool GameLayer::handle_event(const moof::event& event) { - if (Mf::View::handleEvent(event)) return true; + if (moof::view::handle_event(event)) return true; switch (event.type) { case SDL_KEYDOWN: if (event.key.keysym.sym == SDLK_SPACE) { - mState.heroine->animation.startSequence("Flattened"); - Mf::logInfo("thump!"); - mPunchSound.play(); + state_.heroine->animation.startSequence("Flattened"); + moof::log_info("thump!"); + //mPunchSound.play(); return true; } else if (event.key.keysym.sym == SDLK_m) { - mMusic.toggle(); + music_->toggle(); return true; } else if (event.key.keysym.sym == SDLK_PAGEUP) { - mRay.direction = cml::rotate_vector_2D(mRay.direction, - cml::rad(10.0)); + mRay.direction = moof::rotate_vector_2D(mRay.direction, + moof::rad(10.0)); return true; } else if (event.key.keysym.sym == SDLK_PAGEDOWN) { - mRay.direction = cml::rotate_vector_2D(mRay.direction, - cml::rad(-10.0)); + mRay.direction = moof::rotate_vector_2D(mRay.direction, + moof::rad(-10.0)); return true; } else if (event.key.keysym.sym == SDLK_r) @@ -248,28 +244,28 @@ bool GameLayer::handleEvent(const Mf::Event& event) advanceScene(settings()); return true; } - return mState.heroine->handleEvent(event); + return state_.heroine->handle_event(event); case SDL_KEYUP: if (event.key.keysym.sym == SDLK_ESCAPE) { - parent().removeChild(this); + parent().remove_child(this); return true; } else if (event.key.keysym.sym == SDLK_h) { - addChild(mHud); + add_child(mHud); return true; } - return mState.heroine->handleEvent(event); + return state_.heroine->handle_event(event); case SDL_MOUSEMOTION: case SDL_MOUSEBUTTONDOWN: - mState.camera.handleEvent(event); + state_.camera.handle_event(event); return true; case SDL_VIDEORESIZE: - setProjection(event.resize.w, event.resize.h); + projection(event.resize.w, event.resize.h); break; } @@ -277,15 +273,15 @@ bool GameLayer::handleEvent(const Mf::Event& event) } -void GameLayer::setProjection() +void GameLayer::projection() { - setProjection(video().getWidth(), video().getHeight()); + projection(video().width(), video().height()); } -void GameLayer::setProjection(Mf::Scalar width, Mf::Scalar height) +void GameLayer::projection(moof::scalar width, moof::scalar height) { - mState.camera.setProjection(cml::rad(45.0), - width / height, - SCALAR(1.0), SCALAR(200.0)); + state_.camera.projection(moof::rad(60.0), + width / height, + SCALAR(1.0), SCALAR(200.0)); }