2010-04-05 23:38:59 +02:00
|
|
|
#ifndef _ENGINE_H
|
|
|
|
#define _ENGINE_H
|
|
|
|
|
|
|
|
#include <globals.h>
|
|
|
|
|
|
|
|
#include <assert.h>
|
|
|
|
|
|
|
|
#include <iostream>
|
|
|
|
#include <fstream>
|
|
|
|
#include <sstream>
|
|
|
|
#include <string>
|
|
|
|
#include <vector>
|
2010-06-10 23:30:29 +02:00
|
|
|
#include <list>
|
2010-04-05 23:38:59 +02:00
|
|
|
#include <map>
|
|
|
|
#include <queue>
|
2011-01-30 21:43:04 +01:00
|
|
|
#include <set>
|
2010-11-22 20:00:44 +01:00
|
|
|
#include <stack>
|
2010-04-05 23:38:59 +02:00
|
|
|
#include <bitset>
|
2010-11-28 00:20:58 +01:00
|
|
|
#include <limits>
|
2010-04-05 23:38:59 +02:00
|
|
|
|
2011-05-04 18:33:44 +02:00
|
|
|
#include <boost/filesystem.hpp>
|
2011-06-13 17:05:07 +02:00
|
|
|
#include <boost/shared_ptr.hpp>
|
2011-05-04 18:33:44 +02:00
|
|
|
|
2010-04-05 23:38:59 +02:00
|
|
|
#include "Module.h"
|
2010-04-14 20:13:19 +02:00
|
|
|
#include "EngineEnums.h"
|
2011-02-12 15:43:06 +01:00
|
|
|
#include "Utils.h"
|
2010-04-05 23:38:59 +02:00
|
|
|
|
2011-06-13 17:05:07 +02:00
|
|
|
// Note: glew.h must be included before any other OpenGL include file!
|
|
|
|
#include <glew.h>
|
|
|
|
|
2010-04-05 23:38:59 +02:00
|
|
|
// Some ugly #defines
|
|
|
|
|
|
|
|
/** \brief Defines the number of keys that can be defined for an EntityController
|
|
|
|
*
|
|
|
|
* The current state of the controls for an entity is stored in an std::bitset
|
|
|
|
* and each bit tells us whether the key is pressed or not. Unfortunately we
|
|
|
|
* have to know the number of bits that are to be reserved in advance so this
|
|
|
|
* is hard coded into the library for now.
|
|
|
|
*/
|
2010-07-15 22:47:17 +02:00
|
|
|
const int EntityControllerMaxKeyStates = 64;
|
2010-04-05 23:38:59 +02:00
|
|
|
|
|
|
|
namespace Engine {
|
|
|
|
|
|
|
|
class ModelBase;
|
|
|
|
class ViewBase;
|
|
|
|
class ControllerBase;
|
|
|
|
class PhysicsBase;
|
|
|
|
class EntityFactoryBase;
|
|
|
|
class EventManager;
|
2010-10-18 00:40:50 +02:00
|
|
|
class SoundBase;
|
2010-04-05 23:38:59 +02:00
|
|
|
|
|
|
|
class Logging;
|
|
|
|
class Commands;
|
|
|
|
class Variables;
|
|
|
|
class Variable;
|
2010-11-27 08:38:32 +01:00
|
|
|
class Timer;
|
2010-04-05 23:38:59 +02:00
|
|
|
|
|
|
|
/** \brief The outermost class which contains just everything!
|
|
|
|
*
|
|
|
|
* Engine::Engine takes care of initializing, running and destroying the whole
|
|
|
|
* Engine.
|
|
|
|
*
|
|
|
|
* When Initialize called, the submodules are created by Engine and
|
|
|
|
* initializes them. There are two initialization phases:
|
|
|
|
* - Basemodules initialization:
|
|
|
|
* The first phase creates the base modules such as Engine::Logging,
|
|
|
|
* Engine::Variables and Engine::Commands and calls Initialize () on them.
|
|
|
|
* - ModelViewController initialization:
|
|
|
|
* In the second phase at first the Submodules for each Engine::ModelBase, Engine::ViewBase and
|
|
|
|
* Engine::ControllerBase are allocated an initialized. Then the Engine::ModelBase,
|
|
|
|
* Engine::View and Engine::ControllerBase Modules are initialized.
|
|
|
|
*/
|
|
|
|
class Engine : public Module {
|
|
|
|
public:
|
|
|
|
Engine () {
|
|
|
|
mModel = NULL;
|
|
|
|
mView = NULL;
|
|
|
|
mController = NULL;
|
|
|
|
mLogging = NULL;
|
|
|
|
mCommands = NULL;
|
|
|
|
mVariables = NULL;
|
|
|
|
mEntityFactory = NULL;
|
|
|
|
mEventManager = NULL;
|
2010-10-18 00:40:50 +02:00
|
|
|
mSoundManager = NULL;
|
2010-04-05 23:38:59 +02:00
|
|
|
}
|
|
|
|
|
2010-11-27 08:38:32 +01:00
|
|
|
void MainLoop () {
|
2010-04-05 23:38:59 +02:00
|
|
|
OnMainLoop ();
|
|
|
|
}
|
|
|
|
|
|
|
|
void SetModel (ModelBase *model) { mModel = model; };
|
|
|
|
ModelBase* GetModel () { return mModel; };
|
|
|
|
void SetView (ViewBase *view) { mView = view; };
|
|
|
|
ViewBase* GetView () { return mView; };
|
|
|
|
void SetPhysics (PhysicsBase *physics) { mPhysics = physics; };
|
|
|
|
PhysicsBase* GetPhysics () { return mPhysics; };
|
|
|
|
void SetEntityFactory (EntityFactoryBase *entityfactory) { mEntityFactory = entityfactory; };
|
|
|
|
|
|
|
|
void SetController (ControllerBase *controller) { mController = controller; };
|
|
|
|
ControllerBase* GetController () { return mController; };
|
|
|
|
void SetLogging (Logging *logging) { mLogging = logging; };
|
|
|
|
void SetCommands (Commands *commands) { mCommands = commands; };
|
|
|
|
void SetVariables (Variables *variables) { mVariables = variables; };
|
|
|
|
|
|
|
|
void SetError (const char* str, ...);
|
|
|
|
const char* GetError ();
|
|
|
|
void SetStatus (const EngineStatus new_status);
|
|
|
|
EngineStatus GetStatus ();
|
|
|
|
|
2010-12-03 00:15:26 +01:00
|
|
|
void SetUserDataPath (const std::string &path) {
|
|
|
|
mUserDataPath = path;
|
|
|
|
};
|
|
|
|
std::string GetUserDataPath () { return mUserDataPath; };
|
|
|
|
|
|
|
|
void SetGameDataPath (const std::string &path) {
|
|
|
|
mGameDataPath = path;
|
|
|
|
};
|
|
|
|
std::string GetGameDataPath () { return mGameDataPath; };
|
|
|
|
|
|
|
|
/** \brief Returns the path to a resource by prepending the game data path to
|
|
|
|
* \brief it
|
|
|
|
*/
|
|
|
|
std::string GetResourceFullPath (const std::string &resource) {
|
2015-06-11 13:54:53 +02:00
|
|
|
return boost::filesystem::path(mGameDataPath + resource).string();
|
2010-12-03 00:15:26 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
/** \brief Returns the path to a file by prepending the user data path to it
|
|
|
|
*/
|
|
|
|
std::string GetUserDirFullPath (const std::string &path) {
|
2015-06-11 13:54:53 +02:00
|
|
|
return boost::filesystem::path(mUserDataPath + path).string();
|
2010-12-03 00:15:26 +01:00
|
|
|
};
|
|
|
|
|
2010-04-05 23:38:59 +02:00
|
|
|
private:
|
|
|
|
// Engine must not be created with the standard constructor!
|
|
|
|
// It must be ensured, that the correct EntityFactory is used!
|
|
|
|
protected:
|
|
|
|
virtual int OnInit (int argc, char* argv[]);
|
|
|
|
virtual void OnDestroy ();
|
|
|
|
virtual void OnRegisterCommands ();
|
|
|
|
|
|
|
|
void OnMainLoop ();
|
|
|
|
|
|
|
|
ModelBase *mModel;
|
|
|
|
ViewBase *mView;
|
|
|
|
ControllerBase *mController;
|
|
|
|
PhysicsBase *mPhysics;
|
|
|
|
EntityFactoryBase *mEntityFactory;
|
|
|
|
EventManager *mEventManager;
|
2010-10-18 00:40:50 +02:00
|
|
|
SoundBase *mSoundManager;
|
2010-04-05 23:38:59 +02:00
|
|
|
|
|
|
|
Logging *mLogging;
|
|
|
|
Commands *mCommands;
|
|
|
|
Variables *mVariables;
|
|
|
|
|
2010-12-03 00:15:26 +01:00
|
|
|
std::string mUserDataPath;
|
|
|
|
std::string mGameDataPath;
|
|
|
|
|
2010-04-05 23:38:59 +02:00
|
|
|
std::string mErrorString;
|
|
|
|
EngineStatus mStatus;
|
|
|
|
};
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Global visible functions and classes
|
|
|
|
*/
|
|
|
|
|
|
|
|
namespace Engine {
|
|
|
|
/* Globaly visible classes */
|
|
|
|
extern Engine* EngineInstance;
|
|
|
|
|
|
|
|
/** \brief Sets the Engine::mErrorString to the given message */
|
|
|
|
void EngineSetError (const char* str, ...);
|
|
|
|
/** \brief Returns Engine::mErrorString */
|
|
|
|
const char* EngineGetError ();
|
|
|
|
|
|
|
|
/** \brief Sets the current state of the Engine */
|
|
|
|
void EngineSetStatus (const EngineStatus status);
|
|
|
|
/** \brief Returns the current state of the Engine */
|
|
|
|
EngineStatus EngineGetStatus ();
|
|
|
|
|
|
|
|
/** \brief Global access functions for the Model */
|
|
|
|
ModelBase* EngineGetModel ();
|
|
|
|
/** \brief Global access functions for the View */
|
|
|
|
ViewBase* EngineGetView ();
|
|
|
|
/** \brief Global access functions for the Controller */
|
|
|
|
ControllerBase* EngineGetController ();
|
|
|
|
|
2010-12-03 00:15:26 +01:00
|
|
|
/** \brief Returns the path to a resource by prepending the game data path to
|
|
|
|
* \brief it
|
|
|
|
*/
|
|
|
|
std::string GetResourceFullPath (const std::string &resource);
|
|
|
|
|
|
|
|
/** \brief Returns the path to a file by prepending the user data path to it
|
|
|
|
*/
|
|
|
|
std::string GetUserDirFullPath (const std::string &path);
|
2011-01-02 21:04:11 +01:00
|
|
|
|
|
|
|
/** \brief Checks whether a given file exists */
|
|
|
|
bool FileExists (const std::string &path);
|
|
|
|
|
2010-04-05 23:38:59 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Include the globally visible declarations of the other modules */
|
|
|
|
#include "LoggingGlobal.h"
|
|
|
|
#include "VariablesGlobal.h"
|
|
|
|
#include "CommandsGlobal.h"
|
|
|
|
#include "ModelBaseGlobal.h"
|
|
|
|
#include "ViewBaseGlobal.h"
|
2010-07-28 18:02:12 +02:00
|
|
|
#include "EventBaseGlobal.h"
|
2010-10-18 00:40:50 +02:00
|
|
|
#include "SoundBaseGlobal.h"
|
2010-04-05 23:38:59 +02:00
|
|
|
|
|
|
|
#endif // _ENGINE_H
|