#include "ErrorHandler.hh"
-std::string getErrorString(const Mf::Exception& e)
+std::string getErrorString(const Mf::Error& error)
{
std::string str;
- switch(e.code())
+ switch(error.code())
{
- case Mf::ErrorCode::ALC_INIT:
+ case Mf::Error::ALC_INIT:
str += "An error occurred during OpenAL initialization: ";
- str += e.what();
+ str += error.what();
return str;
- case Mf::ErrorCode::FASTEVENTS_INIT:
- case Mf::ErrorCode::SDL_INIT:
+ case Mf::Error::FASTEVENTS_INIT:
+ case Mf::Error::SDL_INIT:
str += "An error occurred during SDL initialization: ";
- str += e.what();
+ str += error.what();
return str;
- case Mf::ErrorCode::FILE_NOT_FOUND:
+ case Mf::Error::FILE_NOT_FOUND:
str += "A required file (";
- str += e.what();
+ str += error.what();
str += ") could not be found.";
return str;
- case Mf::ErrorCode::RESOURCE_NOT_FOUND:
+ case Mf::Error::RESOURCE_NOT_FOUND:
str += "A required resource (";
- str += e.what();
+ str += error.what();
str += ") could not be found.";
return str;
- case Mf::ErrorCode::SCRIPT_ERROR:
+ case Mf::Error::SCRIPT_ERROR:
str += "An error occurred in a script: ";
- str == e.what();
+ str == error.what();
return str;
- case Mf::ErrorCode::SDL_VIDEOMODE:
+ case Mf::Error::SDL_VIDEOMODE:
str += "An error occurred while trying to set up the video mode.";
return str;
- case Mf::ErrorCode::UNKNOWN_AUDIO_FORMAT:
+ case Mf::Error::UNKNOWN_AUDIO_FORMAT:
str += "An error occurred while trying to load an audio file, ";
- str += e.what();
+ str += error.what();
str += ".";
return str;
- case Mf::ErrorCode::UNKNOWN_IMAGE_FORMAT:
+ case Mf::Error::UNKNOWN_IMAGE_FORMAT:
str += "An error occurred while trying to load an image file, ";
- str += e.what();
+ str += error.what();
str += ".";
return str;
}
std::ostringstream stream;
- stream << "An unknown error (code " << e.code() << ") occurred.";
+ stream << "An unknown error (code " << error.code() << ") occurred.";
return stream.str();
}
#ifndef _ERRORHANDLER_HH_
#define _ERRORHANDLER_HH_
-#include <Moof/Exception.hh>
+#include <Moof/Error.hh>
-std::string getErrorString(const Mf::Exception& e);
+std::string getErrorString(const Mf::Error& error);
#endif // _ERRORHANDLER_HH_
*******************************************************************************/
#include <Moof/Engine.hh>
-#include <Moof/Exception.hh>
+#include <Moof/Error.hh>
#include <Moof/Log.hh>
#include <Moof/Math.hh>
#include <Moof/OpenGL.hh>
#include <Moof/Video.hh>
#include "GameLayer.hh"
-#include "Hud.hh"
#if HAVE_CONFIG_H
#include "config.h"
std::string loaderPath = Scene::getPath("loader");
if (loaderPath == "")
{
- throw Mf::Exception(Mf::ErrorCode::RESOURCE_NOT_FOUND, "loader");
+ throw Mf::Error(Mf::Error::RESOURCE_NOT_FOUND, "loader");
}
Mf::Script::Result status = mState.script.doFile(loaderPath);
std::string str;
mState.script[-1].get(str);
- throw Mf::Exception(Mf::ErrorCode::SCRIPT_ERROR, str);
+ throw Mf::Error(Mf::Error::SCRIPT_ERROR, str);
}
mState.script.getGlobalTable().pushField("scenes");
mState.script.getTop().get(mState.sceneList);
if (mState.sceneList.size() == 0)
{
- throw Mf::Exception(Mf::ErrorCode::SCRIPT_ERROR,
+ throw Mf::Error(Mf::Error::SCRIPT_ERROR,
"no variable `scenes' within loader");
}
}
std::string str;
mState.script[-1].get(str);
- throw Mf::Exception(Mf::ErrorCode::SCRIPT_ERROR, str);
+ throw Mf::Error(Mf::Error::SCRIPT_ERROR, str);
}
mState.script.getGlobalTable().pushField("Event");
GameLayer::GameLayer() :
+ mHud(Hud::alloc(mState)),
mMusic("NightFusionIntro"),
mPunchSound("Thump")
{
}
-void GameLayer::pushed(Mf::Engine& engine)
+void GameLayer::pushedOntoEngine()
{
- engine.push(Hud::alloc(mState));
+ Mf::engine.push(mHud);
mRay.direction.set(1.0, 0.0);
}
-void GameLayer::update(Mf::Engine& engine, Mf::Scalar t, Mf::Scalar dt)
+void GameLayer::update(Mf::Scalar t, Mf::Scalar dt)
{
mState.camera.update(t, dt);
mState.heroine->update(t, dt);
}
-void GameLayer::draw(Mf::Engine& engine, Mf::Scalar alpha) const
+void GameLayer::draw(Mf::Scalar alpha) const
{
mState.camera.uploadToGL(alpha);
mSphere.draw();
}
-bool GameLayer::handleEvent(Mf::Engine& engine, const Mf::Event& event)
+bool GameLayer::handleEvent(const Mf::Event& event)
{
switch (event.type)
{
case SDL_KEYUP:
if (event.key.keysym.sym == SDLK_ESCAPE)
{
- engine.pop(this);
+ Mf::engine.pop(this);
return true;
}
else if (event.key.keysym.sym == SDLK_h)
{
- engine.push(Hud::alloc(mState));
+ Mf::engine.push(mHud);
return true;
}
return mState.heroine->handleEvent(event);
void GameLayer::setProjection()
{
- Mf::VideoP video = Mf::Engine::getInstance().getVideo();
+ Mf::VideoP video = Mf::engine.getVideo();
setProjection(video->getWidth(), video->getHeight());
}
#include <boost/shared_ptr.hpp>
-#include <Moof/Camera.hh>
-#include <Moof/Interpolator.hh>
#include <Moof/Layer.hh>
#include <Moof/Math.hh>
-#include <Moof/Script.hh>
#include <Moof/Sound.hh>
#include <Moof/Line.hh>
#include <Moof/Sphere.hh>
#include <Moof/Timer.hh>
-#include "Character.hh"
-#include "Heroine.hh"
-#include "Scene.hh"
+#include "Hud.hh"
+#include "GameState.hh"
class GameLayer;
return GameLayerP(new GameLayer);
}
- void pushed(Mf::Engine& engine);
+ void pushedOntoEngine();
- void update(Mf::Engine& engine, Mf::Scalar t, Mf::Scalar dt);
- void draw(Mf::Engine& engine, Mf::Scalar alpha) const;
- bool handleEvent(Mf::Engine& engine, const Mf::Event& event);
-
- struct State
- {
- Mf::Script script;
- std::vector<std::string> sceneList;
-
- HeroineP heroine;
- SceneP scene;
-
- Mf::PolynomialInterpolator<5> interp;
-
- Mf::Camera camera;
- };
+ void update(Mf::Scalar t, Mf::Scalar dt);
+ void draw(Mf::Scalar alpha) const;
+ bool handleEvent(const Mf::Event& event);
private:
void setProjection();
void setProjection(Mf::Scalar width, Mf::Scalar height);
- State mState;
+ GameState mState;
Mf::Timer mThinkTimer;
+ HudP mHud;
+
Mf::SoundStream mMusic;
Mf::Sound mPunchSound;
--- /dev/null
+
+/*******************************************************************************
+
+ Copyright (c) 2009, Charles McGarvey
+ All rights reserved.
+
+ Redistribution and use in source and binary forms, with or without
+ modification, are permitted provided that the following conditions are met:
+
+ * Redistributions of source code must retain the above copyright notice,
+ this list of conditions and the following disclaimer.
+ * Redistributions in binary form must reproduce the above copyright notice,
+ this list of conditions and the following disclaimer in the documentation
+ and/or other materials provided with the distribution.
+
+ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+ AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
+ FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
+ SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
+ CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
+ OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+
+*******************************************************************************/
+
+#ifndef _GAMESTATE_HH_
+#define _GAMESTATE_HH_
+
+/**
+ * @file GameState.hh
+ * The data.
+ */
+
+#include <boost/shared_ptr.hpp>
+
+#include <Moof/Camera.hh>
+#include <Moof/Interpolator.hh>
+#include <Moof/Script.hh>
+
+#include "Character.hh"
+#include "Heroine.hh"
+#include "Scene.hh"
+
+
+struct GameState
+{
+ Mf::Script script;
+ std::vector<std::string> sceneList;
+
+ HeroineP heroine;
+ SceneP scene;
+
+ Mf::PolynomialInterpolator<5> interp;
+
+ Mf::Camera camera;
+};
+
+
+#endif // _GAMESTATE_HH_
+
+/** vim: set ts=4 sw=4 tw=80: *************************************************/
+
}
-Hud::Hud(GameLayer::State& state) :
+Hud::Hud(GameState& state) :
mState(state),
mBar1(Tilemap("StatusBars"), 0),
mBar2(Tilemap("StatusBars"), 2),
mFont("Font")
{
- Mf::VideoP video = Mf::Engine::getInstance().getVideo();
+ Mf::VideoP video = Mf::engine.getVideo();
resize(video->getWidth(), video->getHeight());
}
#include <Moof/Math.hh>
#include <Moof/Rectangle.hh>
-#include "GameLayer.hh"
+#include "GameState.hh"
#include "Tilemap.hh"
{
public:
- Hud(GameLayer::State& state);
+ Hud(GameState& state);
- static HudP alloc(GameLayer::State& state)
+ static HudP alloc(GameState& state)
{
return HudP(new Hud(state));
}
private:
- GameLayer::State& mState;
+ GameState& mState;
ProgressBar mBar1;
ProgressBar mBar2;
MainLayer::MainLayer()
{
- mDispatchHandler = Mf::Engine::getInstance().addHandler("video.newcontext",
+ mDispatchHandler = Mf::engine.addHandler("video.newcontext",
boost::bind(&MainLayer::contextRecreated, this));
setupGL();
}
-void MainLayer::pushed(Mf::Engine& engine)
+void MainLayer::pushedOntoEngine()
{
//Mf::Scalar coeff[] = {0.0, 1.0};
//Mf::Lerp interp(coeff, 0.25);
//Mf::Transition<Mf::Lerp>::alloc(gameLayer, Mf::LayerP(), interp);
//engine->push(transition);
//engine->push(GameLayer::alloc());
- engine.push(TitleLayer::alloc());
+ Mf::engine.push(TitleLayer::alloc());
}
-void MainLayer::update(Mf::Engine& engine, Mf::Scalar t, Mf::Scalar dt)
+void MainLayer::update(Mf::Scalar t, Mf::Scalar dt)
{
- if (engine.getSize() == 1)
+ if (Mf::engine.getSize() == 1)
{
// this is the only layer left on the stack
- //engine.push(TitleLayer::alloc());
- engine.clear();
+ //Mf::engine.push(TitleLayer::alloc());
+ Mf::engine.clear();
}
}
-void MainLayer::draw(Mf::Engine& engine, Mf::Scalar alpha) const
+void MainLayer::draw(Mf::Scalar alpha) const
{
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glLoadIdentity();
}
-bool MainLayer::handleEvent(Mf::Engine& engine, const Mf::Event& event)
+bool MainLayer::handleEvent(const Mf::Event& event)
{
switch (event.type)
{
case SDL_KEYUP:
if (event.key.keysym.sym == SDLK_ESCAPE)
{
- engine.clear();
+ Mf::engine.clear();
}
else if (event.key.keysym.sym == SDLK_f)
{
- engine.getVideo()->toggleFull();
+ Mf::engine.getVideo()->toggleFull();
}
else if (event.key.keysym.sym == SDLK_l)
{
- Mf::VideoP video = engine.getVideo();
+ Mf::VideoP video = Mf::engine.getVideo();
video->toggleCursorGrab();
video->toggleCursorVisible();
}
break;
case SDL_QUIT:
- engine.clear();
+ Mf::engine.clear();
break;
}
atexit(goodbye);
+ // make sure the engine started up okay
+ if (Mf::engine.getError().isError())
+ {
+ Mf::ModalDialog dialog;
+ dialog.title = PACKAGE_STRING;
+ dialog.text1 = "Fatal Error";
+ dialog.text2 = getErrorString(Mf::engine.getError());
+ dialog.type = Mf::ModalDialog::CRITICAL;
+ dialog.run();
+
+ return 1;
+ }
+
+
#if YOINK_LOGLEVEL >= 3
Mf::Log::setLevel(Mf::Log::INFO);
#elif YOINK_LOGLEVEL >= 2
try
{
- Mf::Engine& app = Mf::Engine::getInstance();
- app.setVideo(Mf::Video::alloc(PACKAGE_STRING, iconFile));
- app.push(MainLayer::alloc());
+ Mf::engine.setVideo(Mf::Video::alloc(PACKAGE_STRING, iconFile));
+ Mf::engine.push(MainLayer::alloc());
- app.run();
+ Mf::engine.run();
}
- catch (const Mf::Exception& e)
+ catch (const Mf::Error& error)
{
Mf::ModalDialog dialog;
dialog.title = PACKAGE_STRING;
dialog.text1 = "Unhandled Exception";
- dialog.text2 = getErrorString(e);
+ dialog.text2 = getErrorString(error);
dialog.type = Mf::ModalDialog::CRITICAL;
dialog.run();
return MainLayerP(new MainLayer);
}
- void pushed(Mf::Engine& engine);
+ void pushedOntoEngine();
- void update(Mf::Engine& engine, Mf::Scalar t, Mf::Scalar dt);
- void draw(Mf::Engine& engine, Mf::Scalar alpha) const;
- bool handleEvent(Mf::Engine& engine, const Mf::Event& event);
+ void update(Mf::Scalar t, Mf::Scalar dt);
+ void draw(Mf::Scalar alpha) const;
+ bool handleEvent(const Mf::Event& event);
private:
mImpl(new Dispatch::Impl) {}
-Dispatch& Dispatch::getInstance()
-{
- static Dispatch dispatch;
- return dispatch;
-}
-
-
Dispatch::Handler Dispatch::addHandler(const std::string& event,
const Function& callback)
{
Dispatch();
- // create and/or get a global instance
- static Dispatch& getInstance();
-
Handler addHandler(const std::string& event, const Function& callback);
Handler addHandler(const std::string& event, const Function& callback,
Handler handler);
#include "Engine.hh"
#include "Event.hh"
-#include "Exception.hh"
#include "Log.hh"
#include "Math.hh"
#include "Settings.hh"
{
public:
- Impl(Engine& engine) :
- mInterface(engine),
+ Impl() :
+ mError(Error::NONE),
mTimestep(0.01),
mPrintFps(false)
{
#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
{
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);
{
for (mStackIt = mStack.begin(); mStackIt != mStack.end(); ++mStackIt)
{
- (*mStackIt)->update(mInterface, t, dt);
+ (*mStackIt)->update(t, dt);
}
}
std::list<LayerP>::reverse_iterator it;
for (it = mStack.rbegin(); it != mStack.rend(); ++it)
{
- (*it)->draw(mInterface, alpha);
+ (*it)->draw(alpha);
}
}
{
for (mStackIt = mStack.begin(); mStackIt != mStack.end(); ++mStackIt)
{
- if ((*mStackIt)->handleEvent(mInterface, event)) break;
+ if ((*mStackIt)->handleEvent(event)) break;
}
}
mStack.push_front(layer);
logInfo << "stack: " << mStack.size()
<< " [pushed " << layer.get() << "]" << std::endl;
- layer->pushed(mInterface);
+ layer->pushedOntoEngine();
}
LayerP pop()
mStack.pop_front();
logInfo << "stack: " << mStack.size()
<< " [popped " << layer.get() << "]" << std::endl;
- layer->popped(mInterface);
+ layer->poppedFromEngine();
if (fixIt) mStackIt = --mStack.begin();
for (it = layers.begin(); it != layers.end(); ++it)
{
- (*it)->popped(mInterface);
+ (*it)->poppedFromEngine();
logInfo << "stack: " << mStack.size()
<< " [popped " << (*it).get() << "]" << std::endl;
}
}
- Engine& mInterface;
+ Error mError;
+
VideoP mVideo;
Dispatch mDispatch;
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;
}
}
+Engine engine;
+
+
} // namespace Mf
/** vim: set ts=4 sw=4 tw=80: *************************************************/
#include <boost/shared_ptr.hpp>
#include <Moof/Dispatch.hh>
+#include <Moof/Error.hh>
#include <Moof/Video.hh>
#include <Moof/Layer.hh>
/**
* The engine is essentially a stack of layers. While running, it updates each
* layer from the bottom up every timestep. It also draws each layer from the
- * bottom up, adhering to the maximum frame-rate. Events are send to each layer
+ * bottom up, adhering to the maximum frame-rate. Events are sent to each layer
* from the top down until a layer signals the event was handled. The engine is
* also responsible for firing timers on time. The engine will continue running
* as long as there are layers on the stack.
{
public:
+ Engine();
~Engine() {}
- // get global instance
- static Engine& getInstance();
+ const Error& getError() const;
// setting the video is required before you can run the engine and should
// probably be done before adding any layers
private:
- Engine(); // use getInstance() to access the engine
-
class Impl;
boost::shared_ptr<Impl> mImpl;
};
+extern Engine engine;
+
+
} // namespace Mf
#endif // _MOOF_ENGINE_HH_
*******************************************************************************/
-#ifndef _MOOF_EXCEPTION_HH_
-#define _MOOF_EXCEPTION_HH_
+#ifndef _MOOF_ERROR_HH_
+#define _MOOF_ERROR_HH_
-#include <cstring>
+#include <cstring> // strncpy
#include <exception>
#include <string>
-#include <Moof/Math.hh>
-
namespace Mf {
-class Exception : public std::exception
+class Error : public std::exception
{
public:
- explicit Exception(unsigned code, const std::string& what = "")
+ enum Code
+ {
+ NONE = 0,
+ ALC_INIT, // description
+ FASTEVENTS_INIT, // description
+ FILE_NOT_FOUND, // path of missing file
+ RESOURCE_NOT_FOUND, // name of missing resource
+ SCRIPT_ERROR, // description
+ SDL_INIT, // description
+ SDL_VIDEOMODE, // -
+ UNKNOWN_AUDIO_FORMAT, // name of resource
+ UNKNOWN_IMAGE_FORMAT, // name of resource
+ };
+
+ explicit Error(unsigned code, const std::string& what = "")
+ {
+ init(code, what);
+ }
+ virtual ~Error() throw() {}
+
+ void init(unsigned code, const std::string& what = "")
{
mWhat[sizeof(mWhat)-1] = '\0';
strncpy(mWhat, what.c_str(), sizeof(mWhat)-1);
mCode = code;
}
- virtual ~Exception() throw() {}
virtual void raise()
{
return mWhat;
}
+ bool isError() const throw()
+ {
+ return mCode != NONE;
+ }
+
private:
unsigned mCode;
char mWhat[1024];
};
-namespace ErrorCode {
-enum Code
-{
- NONE = 0,
- ALC_INIT, // description
- FASTEVENTS_INIT, // description
- FILE_NOT_FOUND, // path of missing file
- RESOURCE_NOT_FOUND, // name of missing resource
- SCRIPT_ERROR, // description
- SDL_INIT, // description
- SDL_VIDEOMODE, // -
- UNKNOWN_AUDIO_FORMAT, // name of resource
- UNKNOWN_IMAGE_FORMAT, // name of resource
-};
-} // namespace ErrorCode
-
} // namespace Mf
-#endif // _MOOF_EXCEPTION_HH_
+#endif // _MOOF_ERROR_HH_
/** vim: set ts=4 sw=4 tw=80: *************************************************/
namespace Mf {
-// forward declaration
-class Engine;
-
-
class Layer
{
public:
virtual ~Layer() {}
- virtual void pushed(Engine& engine) {}
- virtual void popped(Engine& engine) {}
+ virtual void pushedOntoEngine() {}
+ virtual void poppedFromEngine() {}
- virtual void update(Engine& engine, Scalar t, Scalar dt) {}
- virtual void draw(Engine& engine, Scalar alpha) const {}
- virtual bool handleEvent(Engine& engine, const Event& event)
+ virtual void update(Scalar t, Scalar dt) {}
+ virtual void draw(Scalar alpha) const {}
+ virtual bool handleEvent(const Event& event)
{
return false;
}
#include <Moof/Math.hh>
#include <Moof/OpenGL.hh>
#include <Moof/Ray.hh>
+#include <Moof/Shape.hh>
#include <Moof/Texture.hh>
#include <Moof/Log.hh>
#include <vorbis/vorbisfile.h>
#include "Engine.hh"
-#include "Exception.hh"
#include "Library.hh"
#include "Log.hh"
#include "Sound.hh"
{
logWarning << "error while loading sound "
<< getName() << std::endl;
- throw Exception(ErrorCode::UNKNOWN_AUDIO_FORMAT, getName());
+ throw Error(Error::UNKNOWN_AUDIO_FORMAT, getName());
}
vorbis_info* vorbisInfo = ov_info(&mOggStream, -1);
void init()
{
- // make sure the engine is initialized
- Engine::getInstance();
-
mIsLoaded = false;
mIsPlaying = false;
mIsLooping = false;
#include <boost/shared_ptr.hpp>
-#include <Moof/Exception.hh>
#include <Moof/Math.hh>
#include <Moof/Resource.hh>
#include "Dispatch.hh"
#include "Engine.hh"
-#include "Exception.hh"
+#include "Error.hh"
#include "Image.hh"
#include "Library.hh"
#include "Log.hh"
mWrapT(GL_CLAMP),
mObject(0)
{
- // make sure the engine is initialized
- Engine& engine = Engine::getInstance();
+ // make sure we have a video
VideoP video = engine.getVideo();
ASSERT(video && "cannot load textures without a current video context");
if (!mImage.isValid())
{
logWarning << "texture not found: " << getName() << std::endl;
- throw Exception(ErrorCode::RESOURCE_NOT_FOUND, getName());
+ throw Error(Error::RESOURCE_NOT_FOUND, getName());
}
mImage.flip();
}
- void popped(Engine& engine)
+ void poppedFromEngine()
{
if (mTo) engine.push(mTo);
}
- void update(Engine& engine, Scalar t, Scalar dt)
+ void update(Scalar t, Scalar dt)
{
mInterp.update(t, dt);
- if (mFrom) mFrom->update(engine, t, dt);
- if (mTo) mTo->update(engine, t, dt);
+ if (mFrom) mFrom->update(t, dt);
+ if (mTo) mTo->update(t, dt);
if (mInterp.isDone())
{
glPopMatrix();
}
- void draw(Engine& engine, Scalar alpha) const
+ void draw(Scalar alpha) const
{
Scalar a = mInterp.getState(alpha);
logInfo << "transition state: " << a << std::endl;
glPushMatrix();
glLoadIdentity();
glRotate(180.0 * a, 0.0, 1.0, 0.0);
- mFrom->draw(engine, alpha);
+ mFrom->draw(alpha);
glPopMatrix();
}
//drawFade(a);
glPushMatrix();
glLoadIdentity();
glRotate(180.0 * (1.0 - a), 0.0, 1.0, 0.0);
- mTo->draw(engine, alpha);
+ mTo->draw(alpha);
glPopMatrix();
}
//drawFade(1.0 - a);
}
- bool handleEvent(Engine& engine, const Event& event)
+ bool handleEvent(const Event& event)
{
if (mTo)
{
- return mTo->handleEvent(engine, event);
+ return mTo->handleEvent(event);
}
else if (mFrom)
{
- return mFrom->handleEvent(engine, event);
+ return mFrom->handleEvent(event);
}
return false;
}
#include "Dispatch.hh"
#include "Engine.hh"
-#include "Exception.hh"
+#include "Error.hh"
#include "Image.hh"
#include "Log.hh"
#include "Settings.hh"
void Video::init(const Attributes& attribs)
{
- // make sure the engine is initialized before setting up the video
- Engine::getInstance();
-
mContext = 0;
mFlags = 0;
mAttribs = attribs;
logInfo("video context recreated");
#endif
}
- else throw Exception(ErrorCode::SDL_VIDEOMODE);
+ else throw Error(Error::SDL_VIDEOMODE);
}
}
#include <Moof/Aabb.hh>
#include <Moof/Camera.hh>
#include <Moof/Entity.hh>
-#include <Moof/Exception.hh>
#include <Moof/Library.hh>
#include <Moof/Line.hh>
#include <Moof/Log.hh>
#include "TitleLayer.hh"
-void TitleLayer::pushed(Mf::Engine& engine)
+void TitleLayer::pushedOntoEngine()
{
Mf::Scalar coeff[] = {0.0, 1.0};
mFadeIn.init(coeff, 0.1);
mGameLayer = GameLayer::alloc();
}
-void TitleLayer::update(Mf::Engine& engine, Mf::Scalar t, Mf::Scalar dt)
+void TitleLayer::update(Mf::Scalar t, Mf::Scalar dt)
{
if (!mFadeIn.isDone()) mFadeIn.update(t, dt);
}
-void TitleLayer::draw(Mf::Engine& engine, Mf::Scalar alpha) const
+void TitleLayer::draw(Mf::Scalar alpha) const
{
glClearColor(0.0, 0.0, mFadeIn.getState(alpha), 1.0);
glClear(GL_COLOR_BUFFER_BIT);
}
-bool TitleLayer::handleEvent(Mf::Engine& engine, const Mf::Event& event)
+bool TitleLayer::handleEvent(const Mf::Event& event)
{
switch (event.type)
{
//break;
//}
- Mf::LayerP titleLayer = engine.pop(this);
+ Mf::LayerP titleLayer = Mf::engine.pop(this);
//engine.pushLayer(GameLayer::alloc());
Mf::Scalar coeff[] = {0.0, 0.75, 0.99, 1.0};
//Mf::LayerP mGameLayer = GameLayer::alloc();
Mf::Transition<Mf::PolynomialInterpolator<3> >::Ptr transition =
Mf::Transition<Mf::PolynomialInterpolator<3> >::alloc(mGameLayer, titleLayer, interp);
- engine.push(transition);
+ Mf::engine.push(transition);
return true;
}
return TitleLayerP(new TitleLayer);
}
- void pushed(Mf::Engine& engine);
+ void pushedOntoEngine();
- void update(Mf::Engine& engine, Mf::Scalar t, Mf::Scalar dt);
- void draw(Mf::Engine& engine, Mf::Scalar alpha) const;
- bool handleEvent(Mf::Engine& engine, const Mf::Event& event);
+ void update(Mf::Scalar t, Mf::Scalar dt);
+ void draw(Mf::Scalar alpha) const;
+ bool handleEvent(const Mf::Event& event);
private: