X-Git-Url: https://git.dogcows.com/gitweb?p=chaz%2Fyoink;a=blobdiff_plain;f=src%2FMoof%2FEngine.cc;h=50711c744c9758cd1a15e965b6166582a5ec35b9;hp=785cb4b41ed67ee342cf8df535f9e6726e5d3a35;hb=a295f8def17036c8071b56e181364f99a377cae7;hpb=f0aed8dbdbdd61ac9d0728058ba5eb9693b4b94c diff --git a/src/Moof/Engine.cc b/src/Moof/Engine.cc index 785cb4b..50711c7 100644 --- a/src/Moof/Engine.cc +++ b/src/Moof/Engine.cc @@ -39,7 +39,6 @@ #include "Engine.hh" #include "Event.hh" -#include "Exception.hh" #include "Log.hh" #include "Math.hh" #include "Settings.hh" @@ -53,8 +52,8 @@ class Engine::Impl { public: - Impl(Engine& engine) : - mInterface(engine), + Impl() : + mError(Error::NONE), mTimestep(0.01), mPrintFps(false) { @@ -67,19 +66,22 @@ public: #endif { const char* error = SDL_GetError(); - throw Exception(ErrorCode::SDL_INIT, error); + mError.init(Error::SDL_INIT, error); + //throw Exception(Error::SDL_INIT, error); } else { char vdName[128]; SDL_VideoDriverName(vdName, sizeof(vdName)); - logDebug("initialized SDL; using video driver `%s'", vdName); + logInfo << "initialized SDL; using video driver `" + << vdName << "'" << std::endl; } if (FE_Init() != 0) { const char* error = FE_GetError(); - throw Exception(ErrorCode::FASTEVENTS_INIT, error); + mError.init(Error::FASTEVENTS_INIT, error); + //throw Exception(Error::FASTEVENTS_INIT, error); } mAlDevice = alcOpenDevice(0); @@ -87,13 +89,15 @@ public: if (!mAlDevice || !mAlContext) { const char* error = alcGetString(mAlDevice,alcGetError(mAlDevice)); - logError("error while creating audio context: %s", error); + logError << "error while creating audio context: " + << error << std::endl; } else { alcMakeContextCurrent(mAlContext); - logDebug("opened sound device `%s'", - alcGetString(mAlDevice, ALC_DEFAULT_DEVICE_SPECIFIER)); + logInfo << "opened sound device `" + << alcGetString(mAlDevice, ALC_DEFAULT_DEVICE_SPECIFIER) + << "'" << std::endl; } // now load the settings the engine needs @@ -196,7 +200,7 @@ public: if (mPrintFps) { - logInfo("%d fps", mFps); + logInfo << mFps << " fps" << std::endl; } } @@ -216,6 +220,8 @@ public: Timer::getNextFire()), Timer::ACTUAL); } while (!mStack.empty()); + + mDispatch.dispatch("engine.stopping"); } void dispatchEvents() @@ -250,7 +256,7 @@ public: { for (mStackIt = mStack.begin(); mStackIt != mStack.end(); ++mStackIt) { - (*mStackIt)->update(mInterface, t, dt); + (*mStackIt)->update(t, dt); } } @@ -260,7 +266,7 @@ public: std::list::reverse_iterator it; for (it = mStack.rbegin(); it != mStack.rend(); ++it) { - (*it)->draw(mInterface, alpha); + (*it)->draw(alpha); } } @@ -268,7 +274,7 @@ public: { for (mStackIt = mStack.begin(); mStackIt != mStack.end(); ++mStackIt) { - if ((*mStackIt)->handleEvent(mInterface, event)) break; + if ((*mStackIt)->handleEvent(event)) break; } } @@ -277,8 +283,9 @@ public: { ASSERT(layer && "cannot push null layer"); mStack.push_front(layer); - logDebug("stack: %d [pushed %X]", mStack.size(), layer.get()); - layer->pushed(mInterface); + logInfo << "stack: " << mStack.size() + << " [pushed " << layer.get() << "]" << std::endl; + layer->pushedOntoEngine(); } LayerP pop() @@ -288,8 +295,9 @@ public: LayerP layer = mStack.front(); mStack.pop_front(); - logDebug("stack: %d [popped %X]", mStack.size(), layer.get()); - layer->popped(mInterface); + logInfo << "stack: " << mStack.size() + << " [popped " << layer.get() << "]" << std::endl; + layer->poppedFromEngine(); if (fixIt) mStackIt = --mStack.begin(); @@ -316,8 +324,9 @@ public: for (it = layers.begin(); it != layers.end(); ++it) { - (*it)->popped(mInterface); - logDebug("stack: %d [popped %X]", mStack.size(), (*it).get()); + (*it)->poppedFromEngine(); + logInfo << "stack: " << mStack.size() + << " [popped " << (*it).get() << "]" << std::endl; } if (fixIt) mStackIt = --mStack.begin(); @@ -333,7 +342,7 @@ public: { mStack.clear(); mStackIt = mStack.begin(); - logDebug("stack: 0 [cleared]"); + logInfo("stack: 0 [cleared]"); } @@ -341,13 +350,15 @@ public: { if (mMaxFps < mTimestep) { - logWarning("capping maximum fps to timestep (%f)", mTimestep); + logWarning << "capping maximum fps to timestep (" + << mTimestep << ")" << std::endl; mMaxFps = mTimestep; } } - Engine& mInterface; + Error mError; + VideoP mVideo; Dispatch mDispatch; @@ -367,12 +378,13 @@ public: Engine::Engine() : // pass through - mImpl(new Engine::Impl(*this)) {} + mImpl(new Engine::Impl) {} + -Engine& Engine::getInstance() +const Error& Engine::getError() const { - static Engine engine; - return engine; + // pass through + return mImpl->mError; } @@ -474,6 +486,9 @@ void Engine::dispatch(const std::string& event, } +Engine engine; + + } // namespace Mf /** vim: set ts=4 sw=4 tw=80: *************************************************/