]> Dogcows Code - chaz/yoink/blobdiff - src/GameLayer.cc
mesh and other random adjustments
[chaz/yoink] / src / GameLayer.cc
index 5e95b7615393c57709b1cf3bb4d6b578f4d0ef80..8ff3a75a1cd5fecdb85144d2c7625ad5a7664731 100644 (file)
@@ -15,6 +15,7 @@
 
 #include <moof/log.hh>
 #include <moof/math.hh>
+#include <moof/mesh.hh>
 #include <moof/opengl.hh>
 #include <moof/settings.hh>
 #include <moof/video.hh>
 
 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 = moof::resource::find_file("scenes/loader.lua");
        if (path.empty())
@@ -45,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");
        }
 }
 
@@ -73,27 +76,31 @@ 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()
 {
-       moof::log_info("about to load sound resource...");
-       music_.sample("sounds/NightFusionIntro.ogg");
+       music_.sample("NightFusionIntro.ogg");
        music_.loop(true);
-       music_.enqueue("sounds/NightFusionLoop.ogg");
+       music_.enqueue("NightFusionLoop.ogg");
        music_.position(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");
 
        state_.interp.init(0.0, 1.0, 4.0, moof::lerp_scalar::oscillate);
-
-       sceneMesh = moof::resource::load("classic.ac");
 }
 
 
@@ -101,7 +108,7 @@ void GameLayer::did_add_to_view()
 {
        bool isMute = false;
        settings().get("nomusic", isMute);
-       music_.stream();
+       music_.play();
 
        loadSceneLoader();
        advanceScene(settings());               // load the first scene
@@ -137,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,7 +192,7 @@ void GameLayer::draw(moof::scalar alpha) const
        state_.camera.upload_to_gl(alpha);
 
        float pos[] = {state_.heroine->state().position[0],
-                                  state_.heroine->state().position[1], 0.0f};
+                                  state_.heroine->state().position[1], 0.0f, 1.0f};
        glLightfv(GL_LIGHT0, GL_POSITION, pos);
 
        // DRAW THE SCENE
@@ -199,7 +202,24 @@ void GameLayer::draw(moof::scalar alpha) const
        glEnableClientState(GL_TEXTURE_COORD_ARRAY);
 
        //state_.scene->draw_if_visible(alpha, state_.camera.frustum());
-       sceneMesh->draw(alpha);
+
+       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();
This page took 0.024706 seconds and 4 git commands to generate.