X-Git-Url: https://git.dogcows.com/gitweb?p=chaz%2Fyoink;a=blobdiff_plain;f=src%2FGameLayer.cc;h=8ff3a75a1cd5fecdb85144d2c7625ad5a7664731;hp=0498182a9888b22eaac118a55f26b16df2025f86;hb=6f1b787a10d8ab1a3117a4b8c004dd2d90599608;hpb=831f04d4bc19a390415ac0bbac4331c7a65509bc diff --git a/src/GameLayer.cc b/src/GameLayer.cc index 0498182..8ff3a75 100644 --- a/src/GameLayer.cc +++ b/src/GameLayer.cc @@ -9,28 +9,29 @@ * **************************************************************************/ +#include "config.h" + #include #include #include +#include #include #include #include #include "GameLayer.hh" -#if HAVE_CONFIG_H -#include "config.h" -#endif - void GameLayer::loadSceneLoader() { - state_.script.import_standard_libraries(); + state_.script.import_safe_standard_libraries(); moof::log::import(state_.script); + moof::mesh::import(state_.script, "yoink"); + moof::sound::import(state_.script, "yoink"); - std::string path("loader"); - if (!Scene::find_path(path)) + std::string path = moof::resource::find_file("scenes/loader.lua"); + if (path.empty()) { throw std::runtime_error("cannot find scene loader script"); } @@ -47,7 +48,7 @@ void GameLayer::loadSceneLoader() state_.script.top().get(state_.sceneList); if (state_.sceneList.size() == 0) { - throw std::runtime_error("no variable `scenes' in script loader."); + throw std::runtime_error("no variable `scenes' in script loader"); } } @@ -75,21 +76,26 @@ void GameLayer::advanceScene(moof::settings& settings) state_.script.registry().set_field(); } state_.script.pop(); + + table = state_.script.globals().push_field("Event"); + if (table.is_table()) + { + table.push_field("Draw"); + state_.script.registry().set_field("Draw"); + } + state_.script.pop(); } } -GameLayer::GameLayer() : - mMusic("NightFusionIntro"), - mPunchSound("Thump") +GameLayer::GameLayer() { - mMusic.loop(true); - mMusic.enqueue("NightFusionLoop"); + music_.sample("NightFusionIntro.ogg"); + music_.loop(true); + music_.enqueue("NightFusionLoop.ogg"); + music_.position(moof::vector3(10.0, 5.0, 0.0)); - //mMusic.setPosition(moof::vector3(10.0, 5.0, 0.0)); - - mThinkTimer.init(boost::bind(&GameLayer::thinkTimer, this), - 0.1, moof::timer::repeat); + punch_sound_.sample("RobotPunch"); state_.heroine = Heroine::alloc(); state_.heroine->animation.startSequence("FlyDiagonallyUp"); @@ -102,7 +108,7 @@ void GameLayer::did_add_to_view() { bool isMute = false; settings().get("nomusic", isMute); - if (!isMute) mMusic.play(); + music_.play(); loadSceneLoader(); advanceScene(settings()); // load the first scene @@ -138,16 +144,12 @@ void GameLayer::update(moof::scalar t, moof::scalar dt) mRay.point = state_.heroine->state().position; - moof::view::update(t, dt); -} - -void GameLayer::thinkTimer() -{ state_.script.registry().push_field("Think"); if (state_.script[-1].is_function()) state_.script.call(); - else state_.script.pop(); -} + else state_.script.pop(); + moof::view::update(t, dt); +} void GameLayer::rayTimer() { @@ -189,13 +191,35 @@ void GameLayer::draw(moof::scalar alpha) const if (!state_.scene) return; state_.camera.upload_to_gl(alpha); + float pos[] = {state_.heroine->state().position[0], + state_.heroine->state().position[1], 0.0f, 1.0f}; + glLightfv(GL_LIGHT0, GL_POSITION, pos); + // DRAW THE SCENE - moof::texture::reset_binding(); + moof::image::reset_binding(); glEnableClientState(GL_VERTEX_ARRAY); glEnableClientState(GL_TEXTURE_COORD_ARRAY); - state_.scene->draw_if_visible(alpha, state_.camera.frustum()); + //state_.scene->draw_if_visible(alpha, state_.camera.frustum()); + + size_t meh = 23; + state_.script.push(meh); + state_.script.pop(); + + state_.script.registry().push_field("Draw"); + if (state_.script[-1].is_function()) + { + moof::script::status result = state_.script.call(); + if (result != moof::script::success) + { + std::string str; + state_.script[-1].get(str); + throw std::runtime_error("script error: " + str); + } + } + else state_.script.pop(); + state_.heroine->draw(alpha); mRay.draw(); @@ -216,12 +240,12 @@ bool GameLayer::handle_event(const moof::event& event) { state_.heroine->animation.startSequence("Flattened"); moof::log_info("thump!"); - mPunchSound.play(); + punch_sound_.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) @@ -278,7 +302,7 @@ void GameLayer::projection() void GameLayer::projection(moof::scalar width, moof::scalar height) { - state_.camera.projection(moof::rad(45.0), + state_.camera.projection(moof::rad(60.0), width / height, SCALAR(1.0), SCALAR(200.0)); }