]> Dogcows Code - chaz/yoink/blobdiff - src/GameLayer.cc
destroyed global classes; view hierarchy instead
[chaz/yoink] / src / GameLayer.cc
index 331d04fbc9db98f81d02ba12a3c07c9fea618fed..0be8eb744f9fe1720acbb7ac2d9753bbf431987f 100644 (file)
@@ -9,7 +9,6 @@
 *
 **************************************************************************/
 
-#include <Moof/Core.hh>
 #include <Moof/Error.hh>
 #include <Moof/Log.hh>
 #include <Moof/Math.hh>
@@ -53,14 +52,15 @@ void GameLayer::loadSceneLoader()
        }
 }
 
-void GameLayer::advanceScene()
+void GameLayer::advanceScene(Mf::Settings& settings)
 {
        if (mState.sceneList.size() != 0)
        {
                mState.scene = Scene::alloc(mState.sceneList[0]);
                mState.sceneList.erase(mState.sceneList.begin());
 
-               Mf::Script::Result status = mState.scene->load(mState.script);
+               Mf::Script::Result status = mState.scene->load(settings,
+                                                                                                          mState.script);
                if (status != Mf::Script::SUCCESS)
                {
                        std::string str;
@@ -85,22 +85,14 @@ void GameLayer::advanceScene()
 
 
 GameLayer::GameLayer() :
-       mHud(Hud::alloc(mState)),
        mMusic("NightFusionIntro"),
        mPunchSound("Thump")
 {
        mMusic.setLooping(true);
        mMusic.enqueue("NightFusionLoop");
 
-       bool isMute = false;
-       Mf::settings.get("nomusic", isMute);
-       if (!isMute) mMusic.play();
-
        //mMusic.setPosition(Mf::Vector3(10.0, 5.0, 0.0));
 
-       loadSceneLoader();
-       advanceScene();                         // load the first scene
-
        mThinkTimer.init(boost::bind(&GameLayer::thinkTimer, this),
                        0.1, Mf::Timer::REPEAT);
 
@@ -109,14 +101,20 @@ GameLayer::GameLayer() :
 
        mState.interp.init(0.0, 1.0);
        mState.interp.reset(4.0, Mf::Interp::OSCILLATE);
-
-       setProjection();
 }
 
 
-void GameLayer::addedToCore()
+void GameLayer::didAddToView()
 {
-       Mf::core.push(mHud);
+       bool isMute = false;
+       settings().get("nomusic", isMute);
+       if (!isMute) mMusic.play();
+
+       loadSceneLoader();
+       advanceScene(settings());               // load the first scene
+
+       mHud = Hud::alloc(mState);
+       addChild(mHud);
 
        mRay.direction.set(1.0, 0.0);
 
@@ -128,21 +126,25 @@ void GameLayer::addedToCore()
 
        mRayTimer.init(boost::bind(&GameLayer::rayTimer, this),
                                   1.0, Mf::Timer::REPEAT);
+
+       setProjection();
 }
 
 
 void GameLayer::update(Mf::Scalar t, Mf::Scalar dt)
 {
+       if (!mState.scene) return;
        mState.camera.update(t, dt);
        mState.heroine->update(t, dt);
 
        mState.scene->checkForCollision(*mState.heroine);
 
-       Mf::Vector3 camPosition(-mState.heroine->getState().position[0],
-                                                       -mState.heroine->getState().position[1], -8);
-       mState.camera.setPosition(camPosition);
+       Mf::Vector3 cam= -Mf::promote(mState.heroine->getState().position, 8);
+       mState.camera.setPosition(cam);
 
        mRay.point = mState.heroine->getState().position;
+
+       Mf::View::update(t, dt);
 }
 
 void GameLayer::thinkTimer()
@@ -162,8 +164,12 @@ void GameLayer::rayTimer()
        bool bam = mLine.intersectRay(mRay, meh);
        if (bam)
        {
-               meh.normal.normalize();
-               hits.push_back(meh);
+               //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;
        }
 
        bam = mCircle.intersectRay(mRay, meh);
@@ -186,6 +192,7 @@ void GameLayer::rayTimer()
 
 void GameLayer::draw(Mf::Scalar alpha) const
 {
+       if (!mState.scene) return;
        mState.camera.uploadToGL(alpha);
 
        // DRAW THE SCENE
@@ -200,10 +207,14 @@ void GameLayer::draw(Mf::Scalar alpha) const
        mRay.draw();
        mLine.draw();
        mCircle.draw();
+
+       Mf::View::draw(alpha);
 }
 
 bool GameLayer::handleEvent(const Mf::Event& event)
 {
+       if (Mf::View::handleEvent(event)) return true;
+
        switch (event.type)
        {
                case SDL_KEYDOWN:
@@ -234,7 +245,7 @@ bool GameLayer::handleEvent(const Mf::Event& event)
                        else if (event.key.keysym.sym == SDLK_r)
                        {
                                loadSceneLoader();
-                               advanceScene();
+                               advanceScene(settings());
                                return true;
                        }
                        return mState.heroine->handleEvent(event);
@@ -242,12 +253,12 @@ bool GameLayer::handleEvent(const Mf::Event& event)
                case SDL_KEYUP:
                        if (event.key.keysym.sym == SDLK_ESCAPE)
                        {
-                               Mf::core.pop(this);
+                               parent().removeChild(this);
                                return true;
                        }
                        else if (event.key.keysym.sym == SDLK_h)
                        {
-                               Mf::core.push(mHud);
+                               addChild(mHud);
                                return true;
                        }
                        return mState.heroine->handleEvent(event);
@@ -268,9 +279,7 @@ bool GameLayer::handleEvent(const Mf::Event& event)
 
 void GameLayer::setProjection()
 {
-       ASSERT(Mf::video &&
-                  "no current video context from which to get dimensions");
-       setProjection(Mf::video->getWidth(), Mf::video->getHeight());
+       setProjection(video().getWidth(), video().getHeight());
 }
 
 void GameLayer::setProjection(Mf::Scalar width, Mf::Scalar height)
This page took 0.021184 seconds and 4 git commands to generate.