]> Dogcows Code - chaz/yoink/blobdiff - src/Moof/Engine.cc
minor refactoring and state progress
[chaz/yoink] / src / Moof / Engine.cc
index 16da8d40620edd59199a02e46ef43302113f8984..ccf2347c175e392af6baaa1b7748b44502b6dfa8 100644 (file)
@@ -51,12 +51,13 @@ namespace Mf {
 class Engine::Impl
 {
 public:
+
        Impl(int argc, char* argv[], const std::string& name,
                        const std::string& iconFile, const std::string& configFile,
                        Engine& engine) :
-               interface(engine),
-               timestep(0.01),
-               printFps(false)
+               mInterface(engine),
+               mTimestep(0.01),
+               mPrintFps(false)
        {
 #if defined(_WIN32) || defined (_WIN64) || defined(__WIN32__)
                if (SDL_Init(SDL_INIT_VIDEO | SDL_INIT_TIMER) != 0)
@@ -82,24 +83,24 @@ public:
                if (settings.get("rngseed", randomSeed)) setSeed(randomSeed);
                else setSeed();
 
-               Scalar timeStep = 80.0;
-               settings.get("timestep", timeStep);
-               timestep = 1.0 / timeStep;
+               Scalar timestep = 80.0;
+               settings.get("timestep", timestep);
+               mTimestep = 1.0 / timestep;
 
                Scalar maxFps = 40.0;
                settings.get("maxfps", maxFps);
-               drawRate = 1.0 / maxFps;
+               mDrawRate = 1.0 / maxFps;
 
-               settings.get("printfps", printFps);
+               settings.get("printfps", mPrintFps);
 
-               video = Video::alloc(name, iconFile);
-               video->makeActive();
+               mVideo = Video::alloc(name, iconFile);
+               mVideo->makeActive();
        }
 
        ~Impl()
        {
                // the video object must be destroyed before we can shutdown SDL
-               video.reset();
+               mVideo.reset();
 
                alutExit();
                FE_Quit();
@@ -124,9 +125,9 @@ public:
 
                Scalar totalTime = 0.0;
                Scalar deltaTime = 0.0;
-               Scalar accumulator = timestep;
+               Scalar accumulator = mTimestep;
 
-               fps = 0;
+               mFps = 0;
                int frameAccum = 0;
 
                do
@@ -140,19 +141,19 @@ public:
 
                        Timer::fireIfExpired(ticksNow);
 
-                       while (accumulator >= timestep)
+                       while (accumulator >= mTimestep)
                        {
                                dispatchEvents();
-                               update(totalTime, timestep);
+                               update(totalTime, mTimestep);
 
-                               totalTime += timestep;
-                               accumulator -= timestep;
+                               totalTime += mTimestep;
+                               accumulator -= mTimestep;
 
-                               nextStep += timestep;
+                               nextStep += mTimestep;
                        }
                        if (ticksNow >= nextStep)
                        {
-                               nextStep = ticksNow + timestep;
+                               nextStep = ticksNow + mTimestep;
                        }
 
                        if (ticksNow >= nextDraw)
@@ -161,7 +162,7 @@ public:
 
                                if (ticksNow >= nextFpsUpdate) // determine the actual fps
                                {
-                                       fps = frameAccum;
+                                       mFps = frameAccum;
                                        frameAccum = 0;
 
                                        nextFpsUpdate += 1.0;
@@ -170,20 +171,20 @@ public:
                                                nextFpsUpdate = ticksNow + 1.0;
                                        }
 
-                                       if (printFps)
+                                       if (mPrintFps)
                                        {
-                                               logInfo("%d fps", fps);
+                                               logInfo("%d fps", mFps);
                                        }
                                }
 
-                               draw(accumulator / timestep);
-                               video->swap();
+                               draw(accumulator / mTimestep);
+                               mVideo->swap();
 
-                               nextDraw += drawRate;
+                               nextDraw += mDrawRate;
                                if (ticksNow >= nextDraw)
                                {
                                        // we missed some scheduled draws, so reset the schedule
-                                       nextDraw = ticksNow + drawRate;
+                                       nextDraw = ticksNow + mDrawRate;
                                }
                        }
 
@@ -191,7 +192,7 @@ public:
                        Timer::sleep(std::min(std::min(nextStep, nextDraw),
                                                Timer::getNextFire()), true);
                }
-               while (!stack.empty());
+               while (!mStack.empty());
        }
 
        void dispatchEvents()
@@ -212,7 +213,7 @@ public:
                                        break;
 
                                case SDL_VIDEORESIZE:
-                                       video->resize(event.resize.w, event.resize.h);
+                                       mVideo->resize(event.resize.w, event.resize.h);
                                        break;
                        }
 
@@ -223,9 +224,9 @@ public:
 
        void update(Scalar t, Scalar dt)
        {
-               for (stackIt = stack.begin(); stackIt != stack.end(); ++stackIt)
+               for (mStackIt = mStack.begin(); mStackIt != mStack.end(); ++mStackIt)
                {
-                       (*stackIt)->update(t, dt);
+                       (*mStackIt)->update(t, dt);
                }
        }
 
@@ -233,7 +234,7 @@ public:
        {
                // FIXME - this will crash if the layer being drawn pops itself
                std::list<LayerP>::reverse_iterator it;
-               for (it = stack.rbegin(); it != stack.rend(); ++it)
+               for (it = mStack.rbegin(); it != mStack.rend(); ++it)
                {
                        (*it)->draw(alpha);
                }
@@ -241,9 +242,9 @@ public:
 
        void handleEvent(const Event& event)
        {
-               for (stackIt = stack.begin(); stackIt != stack.end(); ++stackIt)
+               for (mStackIt = mStack.begin(); mStackIt != mStack.end(); ++mStackIt)
                {
-                       if ((*stackIt)->handleEvent(event)) break;
+                       if ((*mStackIt)->handleEvent(event)) break;
                }
        }
 
@@ -251,22 +252,22 @@ public:
        void push(LayerP layer)
        {
                ASSERT(layer && "cannot push null layer");
-               stack.push_front(layer);
-               logInfo(" push: %d", stack.size());
-               layer->pushed(interface);
+               mStack.push_front(layer);
+               logInfo(" push: %d", mStack.size());
+               layer->pushed(mInterface);
        }
 
        LayerP pop()
        {
                bool fixIt = false;
-               if (stack.begin() == stackIt) fixIt = true;
+               if (mStack.begin() == mStackIt) fixIt = true;
 
-               LayerP popped = stack.front();
-               stack.pop_front();
-               logInfo("  pop: %d", stack.size());
-               popped->popped(interface);
+               LayerP popped = mStack.front();
+               mStack.pop_front();
+               logInfo("  pop: %d", mStack.size());
+               popped->popped(mInterface);
 
-               if (fixIt) stackIt = --stack.begin();
+               if (fixIt) mStackIt = --mStack.begin();
 
                return popped;
        }
@@ -278,23 +279,23 @@ public:
                std::list<LayerP> popped;
 
                std::list<LayerP>::iterator it;
-               for (it = stack.begin(); it != stack.end(); ++it)
+               for (it = mStack.begin(); it != mStack.end(); ++it)
                {
                        popped.push_back(*it);
 
-                       if (it == stackIt) fixIt = true;
+                       if (it == mStackIt) fixIt = true;
 
                        if ((*it).get() == layer)
                        {
                                ++it;
-                               stack.erase(stack.begin(), it);
+                               mStack.erase(mStack.begin(), it);
 
                                for (it = popped.begin(); it != popped.end(); ++it)
                                {
-                                       (*it)->popped(interface);
+                                       (*it)->popped(mInterface);
                                }
 
-                               if (fixIt) stackIt = --stack.begin();
+                               if (fixIt) mStackIt = --mStack.begin();
 
                                return popped.back();
                        }
@@ -305,24 +306,24 @@ public:
 
        void clear()
        {
-               stack.clear();
-               stackIt = stack.begin();
-               logInfo("clear: %d", stack.size());
+               mStack.clear();
+               mStackIt = mStack.begin();
+               logInfo("clear: %d", mStack.size());
        }
 
 
-       Engine&                         interface;
+       Engine&                         mInterface;
 
-       VideoP                          video;
+       VideoP                          mVideo;
 
-       std::list<LayerP>                       stack;
-       std::list<LayerP>::iterator     stackIt;
+       std::list<LayerP>                       mStack;
+       std::list<LayerP>::iterator     mStackIt;
 
-       Scalar                          timestep;
-       Scalar                          drawRate;
+       Scalar                          mTimestep;
+       Scalar                          mDrawRate;
 
-       long                            fps;
-       bool                            printFps;
+       long                            mFps;
+       bool                            mPrintFps;
 };
 
 
@@ -330,7 +331,7 @@ static Engine* instance = 0;
 
 Engine::Engine(int argc, char* argv[], const std::string& name,
                const std::string& iconFile, const std::string& configFile) :
-       impl_(new Engine::Impl(argc, argv, name, iconFile, configFile, *this))
+       mImpl(new Engine::Impl(argc, argv, name, iconFile, configFile, *this))
 {
        instance = this;
 }
@@ -340,6 +341,7 @@ Engine& Engine::getInstance()
 {
        ASSERT(instance && "dereferencing null pointer");
        return *instance;
+       // TODO this has not been completely thought out
        //static Engine engine;
        //return engine;
 }
@@ -347,63 +349,63 @@ Engine& Engine::getInstance()
 
 void Engine::run()
 {
-       return impl_->run();
+       return mImpl->run();
 }
 
 void Engine::setTimestep(Scalar ts)
 {
-       impl_->timestep = ts;
+       mImpl->mTimestep = ts;
 }
 
 Scalar Engine::getTimestep() const
 {
-       return impl_->timestep;
+       return mImpl->mTimestep;
 }
 
 void Engine::setMaxFrameRate(long maxFps)
 {
-       impl_->drawRate = 1.0 / Scalar(maxFps);
+       mImpl->mDrawRate = 1.0 / Scalar(maxFps);
 }
 
 long Engine::getMaxFrameRate() const
 {
-       return long(1.0 / impl_->drawRate);
+       return long(1.0 / mImpl->mDrawRate);
 }
 
 
 Video& Engine::getVideo() const
 {
-       return *impl_->video;
+       return *mImpl->mVideo;
 }
 
 long Engine::getFrameRate() const
 {
-       return impl_->fps;
+       return mImpl->mFps;
 }
 
 
 void Engine::push(LayerP layer)
 {
        // pass through
-       impl_->push(layer);
+       mImpl->push(layer);
 }
 
 LayerP Engine::pop()
 {
        // pass through
-       return impl_->pop();
+       return mImpl->pop();
 }
 
 LayerP Engine::pop(Layer* layer)
 {
        // pass through
-       return impl_->pop(layer);
+       return mImpl->pop(layer);
 }
 
 void Engine::clear()
 {
        // pass through
-       impl_->clear();
+       mImpl->clear();
 }
 
 
This page took 0.030407 seconds and 4 git commands to generate.