]> Dogcows Code - chaz/yoink/blobdiff - src/yoink.cc
further implementing runloop support
[chaz/yoink] / src / yoink.cc
similarity index 69%
rename from src/GameLayer.cc
rename to src/yoink.cc
index 7d36f3312045ca00781a6294e7cd0f4e45701fc9..72fef6d01b3f59d3a354f0998aae93f29e2a9c18 100644 (file)
 #include <moof/math.hh>
 #include <moof/mesh.hh>
 #include <moof/opengl.hh>
-#include <moof/settings.hh>
+//#include <moof/settings.hh>
 #include <moof/video.hh>
 
-#include "GameLayer.hh"
+#include "yoink.hh"
 
 
-void GameLayer::loadSceneLoader()
+void yoink::load_scene_loader()
 {
        state_.script.import_safe_standard_libraries();
        moof::log::import(state_.script);
@@ -52,15 +52,24 @@ void GameLayer::loadSceneLoader()
        }
 }
 
-void GameLayer::advanceScene(moof::settings& settings)
+void yoink::advance_scene()
 {
        if (state_.sceneList.size() != 0)
        {
-               state_.scene = Scene::alloc(state_.sceneList[0]);
-               state_.sceneList.erase(state_.sceneList.begin());
+               //state_.scene = Scene::alloc(state_.sceneList[0]);
+               //state_.sceneList.erase(state_.sceneList.begin());
 
-               moof::script::status status = state_.scene->load(settings,
-                                                                                                          state_.script);
+               //moof::script::status status = state_.scene->load(settings,
+                                                                                                          //state_.script);
+
+               std::string path = moof::resource::find_file("scenes/"+state_.sceneList[0], "lua");
+               if (path.empty())
+               {
+                       throw "the scene file could not be found";
+               }
+
+               //importSceneBindings(settings, script);
+               moof::script::status status = state_.script.do_file(path);
                if (status != moof::script::success)
                {
                        std::string str;
@@ -88,7 +97,7 @@ void GameLayer::advanceScene(moof::settings& settings)
 }
 
 
-GameLayer::GameLayer()
+yoink::yoink()
 {
        music_.queue("NightFusionIntro");
        music_.loop(true);
@@ -101,20 +110,17 @@ GameLayer::GameLayer()
        state_.heroine->animation.startSequence("FlyDiagonallyUp");
 
        state_.interp.init(0.0, 1.0, 4.0, moof::lerp_scalar::oscillate);
-}
 
 
-void GameLayer::did_add_to_view()
-{
-       bool isMute = false;
-       settings().get("nomusic", isMute);
-       music_.play();
+       //bool isMute = false;
+       //settings().get("nomusic", isMute);
+       //music_.play();
 
-       loadSceneLoader();
-       advanceScene(settings());               // load the first scene
+       load_scene_loader();
+       advance_scene();                // load the first scene
 
        mHud = Hud::alloc(state_);
-       add_child(mHud);
+       //add_child(mHud);
 
        mRay.direction.set(1.0, 0.0);
 
@@ -124,20 +130,20 @@ void GameLayer::did_add_to_view()
        mCircle.point.set(22, 5);
        mCircle.radius = 2;
 
-       mRayTimer.init(boost::bind(&GameLayer::rayTimer, this),
-                                  1.0, moof::timer::repeat);
+       //mRayTimer.init(boost::bind(&yoink::rayTimer, this),
+                                  //1.0, moof::timer::repeat);
 
        projection();
 }
 
 
-void GameLayer::update(moof::scalar t, moof::scalar dt)
+void yoink::update(moof::scalar t, moof::scalar dt)
 {
-       if (!state_.scene) return;
+       //if (!state_.scene) return;
        state_.camera.update(t, dt);
        state_.heroine->update(t, dt);
 
-       state_.scene->checkForCollision(*state_.heroine);
+       //state_.scene->checkForCollision(*state_.heroine);
 
        moof::vector3 cam= -moof::promote(state_.heroine->state().position, 8);
        state_.camera.position(cam);
@@ -148,10 +154,10 @@ void GameLayer::update(moof::scalar t, moof::scalar dt)
        if (state_.script[-1].is_function()) state_.script.call();
        else                                 state_.script.pop();
 
-       moof::view::update(t, dt);
+       //moof::view::update(t, dt);
 }
 
-void GameLayer::rayTimer()
+void yoink::rayTimer()
 {
        moof::ray2::contact meh;
        std::list<moof::ray2::contact> hits;
@@ -175,20 +181,20 @@ void GameLayer::rayTimer()
                hits.push_back(meh);
        }
 
-       if (state_.scene->castRay(mRay, hits))
-       {
-               hits.front().normal.normalize();
-               mRay.solve(point, hits.front().distance);
-               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;
-       }
+       //if (state_.scene->castRay(mRay, hits))
+       //{
+               //hits.front().normal.normalize();
+               //mRay.solve(point, hits.front().distance);
+               //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(moof::scalar alpha) const
+void yoink::draw(moof::scalar alpha) const
 {
-       if (!state_.scene) return;
+       //if (!state_.scene) return;
        state_.camera.upload_to_gl(alpha);
 
        float pos[] = {state_.heroine->state().position[0],
@@ -222,16 +228,18 @@ void GameLayer::draw(moof::scalar alpha) const
 
        state_.heroine->draw(alpha);
 
-       mRay.draw();
+       //mRay.draw();
        mLine.draw();
        mCircle.draw();
 
-       moof::view::draw(alpha);
+       //moof::view::draw(alpha);
 }
 
-bool GameLayer::handle_event(const moof::event& event)
+bool yoink::handle_event(const moof::event& event)
 {
-       if (moof::view::handle_event(event)) return true;
+       //if (moof::view::handle_event(event)) return true;
+       
+       static moof::scalar scale = SCALAR(1.0);
 
        switch (event.type)
        {
@@ -250,20 +258,24 @@ bool GameLayer::handle_event(const moof::event& event)
                        }
                        else if (event.key.keysym.sym == SDLK_PAGEUP)
                        {
-                               mRay.direction = moof::rotate_vector_2D(mRay.direction,
-                                                                                                               moof::rad(10.0));
+                               //mRay.direction = moof::rotate_vector_2D(mRay.direction,
+                                                                                                               //moof::rad(10.0));
+                               scale += SCALAR(0.1);
+                               moof::timer::default_source().scale(scale);
                                return true;
                        }
                        else if (event.key.keysym.sym == SDLK_PAGEDOWN)
                        {
-                               mRay.direction = moof::rotate_vector_2D(mRay.direction,
-                                                                                                               moof::rad(-10.0));
+                               //mRay.direction = moof::rotate_vector_2D(mRay.direction,
+                                                                                                               //moof::rad(-10.0));
+                               scale -= SCALAR(0.1);
+                               moof::timer::default_source().scale(scale);
                                return true;
                        }
                        else if (event.key.keysym.sym == SDLK_r)
                        {
-                               loadSceneLoader();
-                               advanceScene(settings());
+                               load_scene_loader();
+                               advance_scene();
                                return true;
                        }
                        return state_.heroine->handle_event(event);
@@ -271,12 +283,12 @@ bool GameLayer::handle_event(const moof::event& event)
                case SDL_KEYUP:
                        if (event.key.keysym.sym == SDLK_ESCAPE)
                        {
-                               parent().remove_child(this);
-                               return true;
+                               //parent().remove_child(this);
+                               return false;
                        }
                        else if (event.key.keysym.sym == SDLK_h)
                        {
-                               add_child(mHud);
+                               //add_child(mHud);
                                return true;
                        }
                        return state_.heroine->handle_event(event);
@@ -295,12 +307,13 @@ bool GameLayer::handle_event(const moof::event& event)
 }
 
 
-void GameLayer::projection()
+void yoink::projection()
 {
-       projection(video().width(), video().height());
+       moof::video* video = moof::video::current();
+       projection(video->width(), video->height());
 }
 
-void GameLayer::projection(moof::scalar width, moof::scalar height)
+void yoink::projection(moof::scalar width, moof::scalar height)
 {
        state_.camera.projection(moof::rad(60.0),
                                                         width / height,
This page took 0.025156 seconds and 4 git commands to generate.