]> Dogcows Code - chaz/yoink/blobdiff - src/GameLayer.cc
stream-based logging classes
[chaz/yoink] / src / GameLayer.cc
index 41000f395d645b8f13b4031e4f7db9e7a88bfcb6..3f5a7a869fb2dd8d13e6da4671d82f78d474f47d 100644 (file)
@@ -31,6 +31,7 @@
 #include <Moof/Log.hh>
 #include <Moof/Math.hh>
 #include <Moof/OpenGL.hh>
+#include <Moof/Settings.hh>
 #include <Moof/Video.hh>
 
 #include "GameLayer.hh"
@@ -67,13 +68,12 @@ void GameLayer::loadSceneLoader()
                throw Mf::Exception(Mf::ErrorCode::RESOURCE_NOT_FOUND, "loader");
        }
 
-       Mf::Script::Status status = mState.script.doFile(loaderPath);
+       Mf::Script::Result status = mState.script.doFile(loaderPath);
        if (status != Mf::Script::SUCCESS)
        {
                std::string str;
                mState.script[-1].get(str);
 
-               Mf::logScript("%s", str.c_str());
                throw Mf::Exception(Mf::ErrorCode::SCRIPT_ERROR, str);
        }
 
@@ -81,8 +81,8 @@ void GameLayer::loadSceneLoader()
        mState.script.getTop().get(mState.sceneList);
        if (mState.sceneList.size() == 0)
        {
-               Mf::logScript("no variable `scenes' within loader");
-               throw Mf::Exception(Mf::ErrorCode::SCRIPT_ERROR, "no scenes to load");
+               throw Mf::Exception(Mf::ErrorCode::SCRIPT_ERROR,
+                               "no variable `scenes' within loader");
        }
 }
 
@@ -92,7 +92,15 @@ void GameLayer::advanceScene()
        {
                mState.scene = Scene::alloc(mState.sceneList[0]);
                mState.sceneList.erase(mState.sceneList.begin());
-               mState.scene->load(mState.script);
+
+               Mf::Script::Result status = mState.scene->load(mState.script);
+               if (status != Mf::Script::SUCCESS)
+               {
+                       std::string str;
+                       mState.script[-1].get(str);
+
+                       throw Mf::Exception(Mf::ErrorCode::SCRIPT_ERROR, str);
+               }
        }
 }
 
@@ -103,7 +111,12 @@ GameLayer::GameLayer() :
 {
        mMusic.setLooping(true);
        mMusic.enqueue("NightFusionLoop");
-       mMusic.stream();
+
+       bool isMute = false;
+       Mf::Settings::getInstance().get("nomusic", isMute);
+       if (!isMute) mMusic.play();
+
+       //mMusic.setPosition(Mf::Vector3(10.0, 5.0, 0.0));
 
        loadSceneLoader();
        advanceScene();                         // load the first scene
@@ -127,11 +140,10 @@ void GameLayer::pushed(Mf::Engine& engine)
        mLine.a.set(20, 10);
        mLine.b.set(19, 14);
 
-       mPlane.normal.set(-1.0, 0.0, 0.0);
-       mPlane.d = 0.0;
-
        mSphere.point.set(22, 5);
        mSphere.radius = 2;
+
+       mRayTimer.init(boost::bind(&GameLayer::rayTimer, this), 1.0, Mf::Timer::REPEAT);
 }
 
 
@@ -146,33 +158,37 @@ void GameLayer::update(Mf::Engine& engine, Mf::Scalar t, Mf::Scalar dt)
                                -mState.heroine->getState().position[1], -9));
        //mState.camera.lookAt(Mf::promote(mState.heroine->getState().position));
 
-       //Mf::Vector3 heroinePosition = Mf::promote(mState.heroine->getState().position);
-       //Mf::Sound::setListenerPosition(heroinePosition);
-       
        mRay.point = mState.heroine->getState().position;
+}
 
+
+void GameLayer::rayTimer()
+{
        Mf::Ray<2>::Intersection meh;
+       std::list<Mf::Ray<2>::Intersection> hits;
+       Mf::Vector2 point;
+
+       bool bam = mLine.intersectRay(mRay, meh);
+       if (bam)
+       {
+               meh.normal.normalize();
+               hits.push_back(meh);
+       }
 
-       Mf::Scalar d = mLine.intersectRay(mRay, meh);
-       if (d > 0.0)
+       bam = mSphere.intersectRay(mRay, meh);
+       if (bam)
        {
-               Mf::logDebug("line: d = %f", d);
-               Mf::logDebug("      P = <%f,%f>", meh.point[0], meh.point[1]);
-               Mf::logDebug("      n = <%f,%f>", meh.normal[0], meh.normal[1]);
+               meh.normal.normalize();
+               hits.push_back(meh);
        }
-       //d = mPlane.intersectRay(mRay, meh);
-       //if (d > 0.0)
-       //{
-               //Mf::logDebug("plane: d = %f", d);
-               //Mf::logDebug("       P = <%f,%f>", meh.point[0], meh.point[1]);
-               //Mf::logDebug("       n = <%f,%f>", meh.normal[0], meh.normal[1]);
-       //}
-       d = mSphere.intersectRay(mRay, meh);
-       if (d > 0.0)
+
+       if (mState.scene->castRay(mRay, hits))
        {
-               Mf::logDebug("sphere: d = %f", d);
-               Mf::logDebug("        P = <%f,%f>", meh.point[0], meh.point[1]);
-               Mf::logDebug("        n = <%f,%f>", meh.normal[0], meh.normal[1]);
+               hits.front().normal.normalize();
+               mRay.solve(point, hits.front().distance);
+               Mf::logDebug << "scene: d = " << hits.front().distance << std::endl;
+               Mf::logDebug << "       P = " << point << std::endl;
+               Mf::logDebug << "       n = " << hits.front().normal << std::endl;
        }
 }
 
@@ -216,12 +232,14 @@ bool GameLayer::handleEvent(Mf::Engine& engine, const Mf::Event& event)
                        }
                        else if (event.key.keysym.sym == SDLK_PAGEUP)
                        {
-                               mRay.direction = cml::rotate_vector_2D(mRay.direction, cml::rad(10.0));
+                               mRay.direction = cml::rotate_vector_2D(mRay.direction,
+                                               cml::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 = cml::rotate_vector_2D(mRay.direction,
+                                               cml::rad(-10.0));
                                return true;
                        }
                        return mState.heroine->handleEvent(event);
This page took 0.023862 seconds and 4 git commands to generate.