Permalink
Browse files

Full restructuring of object loader. Added loading lights, cameras, o…

…bjects. Removed default entities from GraphicSystem. A few new params in the settings file, like path to the default entities
  • Loading branch information...
max-frai committed Aug 29, 2010
1 parent 1cab311 commit 046fcd9461d17706888010d85bf92cf6abff0225
View
@@ -12,8 +12,8 @@ ogre
window
{
- width "1024"
- height "768"
+ width "1152"
+ height "864"
fullscreen "0"
paramFSAA "0"
@@ -27,15 +27,15 @@ class Camera : public Entity
DONT_USE // If we don't want predefined stuff
} mCameraType;
- Camera(const string entityName);
- void configure(const float nearClip = 1, const float farClip = 1000, bool autoAR = true, const float FOV = 90,
- vec3 pos = vec3(0, 1000, 1000), vec3 lookAt = vec3(0, 0, 0));
- Ogre::Camera *cameraHandle();
+ Camera(const string &entityName);
+
+ Ogre::Camera *handle();
Ogre::SceneNode *getPitchNode();
- void loadFromFile(const string & filename, const string &res = Ogre::ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME);
+ void loadFromFile(const string &filePath);
void setCameraType(CameraType type);
+ void setActive(bool state);
void setMoveStep(float step);
void setRotateStep(float step);
@@ -47,7 +47,6 @@ class Camera : public Entity
void onKeyPressed(const OIS::KeyEvent &e);
void onMouseMoved(const OIS::MouseEvent &e);
- void _loadData();
string type();
void update(float elapsed);
};
@@ -19,36 +19,23 @@ class Entity : private boost::noncopyable
protected:
string mEntityName;
string mEntityMesh;
+ string mResGroup;
bool mDrawable;
- bool mHasMediaFolder;
// TODO: Move entity object to entity class only
Ogre::Entity *mEntity;
Ogre::SceneNode *mNode;
bool parseArguments(const string &argName, const string &argData, float *outData, vector<string> &storage);
- void _defaultLoader(const string &EntityName); // Predefined loading of common settings
- void _declareEntityResources(); // Parsing resources of new entity
- virtual void _loadData() = 0; // Loading entity type-derived settings
+ ptree defaultLoader(const string &infoPath); // Predefined loading of common settings
+ virtual void loadFromFile(const string &filePath) = 0; // Loading entity type-derived settings
public:
virtual ~Entity();
virtual void update(float elapsed) = 0;
virtual string type() = 0;
- template<typename EventType>
- void AddBehavior(const string &eventName, const typename EventType::SignatureSlotType &eventSlot)
- {
- CONNECT(EventType, eventName, eventSlot);
- }
-
- template<typename EventType>
- void RemoveBehavior()
- {
- // TODO: Implement me!
- }
-
const string getName() const;
const string getMeshName() const;
bool isDrawable() const;
@@ -16,12 +16,10 @@ class Light : public Entity
Ogre::Light *mLight;
public:
- Light(const string entityName);
+ Light(const string &entityName);
- void configure(Ogre::Light::LightTypes lt = Ogre::Light::LT_POINT,
- colour diffuse = colour(1, 1, 1), colour specular = colour(1, 1, 1),
- float attenuation = 10, float power = 1);
- Ogre::Light *lightHandle();
+ Ogre::Light *handle();
+ void loadFromFile(const string &filePath);
void setDiffuse(const colour &diffuse);
void setSpecular(const colour &specular);
@@ -34,7 +32,6 @@ class Light : public Entity
float getPower();
string type();
- void _loadData();
void update(float elapsed);
};
@@ -14,9 +14,11 @@ using namespace std;
class Object : public Entity
{
public:
- Object(const string entityName, const string &entityMesh = "", const string &res = Ogre::ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME);
+ Object(const string &entityName, const string &resGroup = Ogre::ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME);
void setImage(const string& imgPath);
- void _loadData();
+
+ // Inherited from Entity class
+ void loadFromFile(const string &filePath);
string type();
void update(float elapsed);
};
@@ -21,6 +21,16 @@ using namespace std;
#define entityManager (EntityManager::get_mutable_instance())
#define entityManagerConst (EntityManager::get_const_instance())
+// Fast creating of entities
+#define MakeObject(entName) entityManager.MakeEntity<Object>(entName)
+#define MakeLight(entName) entityManager.MakeEntity<Light>(entName)
+#define MakeCamera(entName) entityManager.MakeEntity<Camera>(entName)
+
+// Fast accessing to the entities
+#define GetObject(entName) entityManager.GetEntity<Object>(entName)
+#define GetLight(entName) entityManager.GetEntity<Light>(entName)
+#define GetCamera(entName) entityManager.GetEntity<Camera>(entName)
+
class EntityManager : public singleton<EntityManager>
{
protected:
@@ -29,19 +29,13 @@ class GraphicSystem : public ISystem, public ISingleton<GraphicSystem>
Ogre::Viewport *mViewport;
Ogre::Camera *mCamera;
- // For default entities
- Ogre::Entity *mError;
-
public:
Ogre::Root *getRoot() const { return mRoot; }
Ogre::RenderWindow *getWindow() const { return mWindow; }
Ogre::RenderSystem *getRenderSys() const { return mRenderSys; }
Ogre::SceneManager *getSceneMgr() const { return mSceneMgr; }
Ogre:: Viewport *getViewport() const { return mViewport; }
- Ogre::Camera *getCamera() const { return mCamera; }
-
- // For default entities
- void configureEntities();
+ Ogre::Camera *getBaseCamera() const { return mCamera; }
GraphicSystem();
~GraphicSystem();
View
@@ -33,23 +33,9 @@ class GameState : public State
{
public:
void init() {
- /*
- //World::MakeCamera("MenuCamera", true, Camera::FREE);
- Camera *cam = World::MakeCamera("MainCamera", "MainCamera");
- //GraphicSystem::get_mutable_instance().getViewport()->setCamera(cam->cameraHandle());
- //cam->setCameraType(Camera::FREE);
- //World::MakeLight("MainLight", Ogre::Light::LT_DIRECTIONAL)->lightHandle()->setDirection(vec3(0, 100, 0));
-
- World::MakeLight("PointLight", Ogre::Light::LT_POINT,
- colour(1.0, 0.0, 0.0), colour(1.0, 0.0, 0.0))->lightHandle()->setPosition(vec3(0, 150, 250));
- World::MakeLight("DirectionalLight", Ogre::Light::LT_DIRECTIONAL,
- colour(.25, .25, 0), colour(.25, .25, 0))->lightHandle()->setDirection(vec3(0, -1, 1));
- World::MakeLight("SpotLight", Ogre::Light::LT_SPOTLIGHT,
- colour(0, 0, 1.0), colour(0, 0, 1.0))->lightHandle()->setDirection(vec3(-1, -1, 0));
- World::GetLight("SpotLight")->lightHandle()->setPosition(vec3(300, 300, 0));
-
- World::MakeObject("ErrorObject");
- */
+ MakeCamera("MainCamera")->loadFromFile("Entities/MainCamera.info");
+ MakeLight("DirectionalLight");
+ MakeObject("ErrorObject");
}
string type() { return "GameState"; }
@@ -48,7 +48,6 @@ void GameApplication::Start()
mRunning = true;
utils.setMediaPath(CONFIG("resources.MediaFolder", string, "Media"));
- graphicSystem.configureEntities();
SIGNAL(Engine::Events::GlobalInitEvent, "Inited", );
View
@@ -44,7 +44,7 @@ string Utils::checkLocation(const string &path)
{
if (!boost::filesystem::exists(path))
{
- LOG(FORMAT("The path `%1%` isn't valid!", path));
+ LOG(FORMAT("The path `%1%` could be invalid!", path));
}
return path;
@@ -1,77 +1,73 @@
#include "Managers/Entities/Camera.hpp"
-Camera::Camera(const string entityName)
+Camera::Camera(const string &entityName)
{
- Ogre::SceneManager *sceneMgr = graphicSystemConst.getSceneMgr();
+ LOG(FORMAT("Loading new entity `%1%`", entityName));
- mEntityName = entityName;
+ mEntityName = entityName;
- mCamera = sceneMgr->createCamera(entityName);
+ mCamera = graphicSystem.getSceneMgr()->createCamera(entityName);
mMove = 250;
mRotate = 0.13;
- mNode = sceneMgr->getRootSceneNode()->createChildSceneNode("Node:Camera_" + entityName);
+ mNode = graphicSystem.getSceneMgr()->getRootSceneNode()->createChildSceneNode("Node:Camera_" + entityName);
mPitchNode = mNode->createChildSceneNode("Node:CameraPitch_" + entityName);
- mPitchNode->attachObject(mCamera);
-
-}
-
-void Camera::loadFromFile(const string &filename, const string &res)
-{
- _declareEntityResources();
-
- if (Ogre::ResourceGroupManager::getSingletonPtr()->resourceExists(res, filename))
- {
- //Ogre::ResourceGroupManager::getSingleton().declareResource(entMesh, "Mesh", res);
-
- ptree tree_handle;
- read_info(utilsConst.getMediaPath() + "Entities/" + filename + "/init.info", tree_handle);
-
- float fov = tree_handle.get<float>("type_settings.fov", 90);
- float nearClip = tree_handle.get<float>("type_settings.nearClip", 1);
- float farClip = tree_handle.get<float>("type_settings.farClip", 1000);
- bool autoAR = tree_handle.get<bool>("type_settings.autoAR", true);
- configure(nearClip, farClip, autoAR, fov);
- bool attachVP = tree_handle.get<bool>("type_settings.attachVP", true);
- if(attachVP)
- graphicSystem.getViewport()->setCamera(mCamera);
- string type = tree_handle.get<string>("type_settings.cam_type", "DONT_USE");
- if(type == "DONT_USE")
- setCameraType(Camera::DONT_USE);
- else if(type == "FREE")
- setCameraType(Camera::FREE);
- else if(type == "FIRST_PERSON")
- setCameraType(Camera::FIRST_PERSON);
- else if(type == "ATTACHED")
- setCameraType(Camera::ATTACHED);
- LOG("Loaded Camera from " + filename);
- }
-
-
- _defaultLoader(filename);
+ mPitchNode->attachObject(mCamera);
}
-void Camera::configure(const float nearClip, const float farClip, bool autoAR, const float FOV,
- vec3 pos, vec3 lookAt)
+void Camera::loadFromFile(const string &filePath)
{
- mCamera->setNearClipDistance(nearClip);
- mCamera->setFarClipDistance(farClip);
- mCamera->setAutoAspectRatio(autoAR);
- mCamera->setFOVy(deg(FOV));
+ if (boost::filesystem::exists(utils.getMediaPath() + filePath)) return;
+ ptree tree_handle = defaultLoader(filePath);
+
+ mCamera->setFOVy(deg(tree_handle.get<float>("type_settings.fov", 90)));
+ mCamera->setNearClipDistance(tree_handle.get<float>("type_settings.nearClip", 1));
+ mCamera->setFarClipDistance(tree_handle.get<float>("type_settings.farClip", 1000));
+ mCamera->setAutoAspectRatio(tree_handle.get<bool>("type_settings.autoAR", true));
+
+ vector<string> parseStorage;
+ float storage[3];
+ memset(storage, 0, sizeof(float)*3);
+
+ string argName = tree_handle.get<string>("type_settigns.lookAt", "0, 0, 0");
+ if (parseArguments("lookAt", argName, storage, parseStorage))
+ mCamera->lookAt(vec3(storage[0], storage[1], storage[2]));
+
+ if (tree_handle.get<bool>("type_settings.attachVP", false))
+ graphicSystem.getViewport()->setCamera(mCamera);
+
+ string type = tree_handle.get<string>("type_settings.camType", "DONT_USE");
+ if(type == "DONT_USE")
+ setCameraType(Camera::DONT_USE);
+ else if(type == "FREE")
+ setCameraType(Camera::FREE);
+ else if(type == "FIRST_PERSON")
+ setCameraType(Camera::FIRST_PERSON);
+ else if(type == "ATTACHED")
+ setCameraType(Camera::ATTACHED);
+ else
+ setCameraType(Camera::DONT_USE);
}
-Ogre::Camera *Camera::cameraHandle() { return mCamera; }
+Ogre::Camera *Camera::handle() { return mCamera; }
Ogre::SceneNode *Camera::getPitchNode() { return mPitchNode; }
+void Camera::setActive(bool state)
+{
+ // If false, set up base camera
+ if (state)
+ graphicSystem.getViewport()->setCamera(mCamera);
+ else
+ graphicSystem.getViewport()->setCamera(graphicSystem.getBaseCamera());
+}
float Camera::getMoveStep() { return mMove; }
float Camera::getRotateStep() { return mRotate; }
void Camera::setMoveStep(float step) { mMove = step; }
void Camera::setRotateStep(float step) { mRotate = step; }
string Camera::type() { return "camera"; }
-void Camera::_loadData() { }
void Camera::update(float elapsed) { }
#define WIDTH graphicSystem.getWindow()->getWidth()
@@ -97,35 +97,17 @@ bool Entity::parseArguments(const string &argName, const string &argData, float
return true;
}
-void Entity::_declareEntityResources()
+ptree Entity::defaultLoader(const string &infoPath)
{
- LOG(FORMAT("Loading new entity `%1%`", mEntityName));
-
- string entityData = utilsConst.getMediaPath() + "Entities/" + mEntityName;
-
- if (!boost::filesystem::exists(entityData))
- {
- LOG_META(FORMAT("There isn't media-folder for the entity with `%1%` name", mEntityName));
- mHasMediaFolder = false;
- }
- else
- {
- Ogre::ResourceGroupManager::getSingleton().addResourceLocation(entityData, "FileSystem", "General", true);
- mHasMediaFolder = true;
- }
-}
-
-void Entity::_defaultLoader(const string &entityName)
-{
- if (!mHasMediaFolder) return;
-
LOG_NOFORMAT("\tDumping information, parsed from file:\n");
ptree tree_handle;
- read_info(utilsConst.getMediaPath() + "Entities/" + mEntityName + "/init.info", tree_handle);
+ read_info(LOCATION(utilsConst.getMediaPath() + infoPath), tree_handle);
setDrawable( tree_handle.get<bool>("common_settigns.visible", true) );
- setName( tree_handle.get<string>("common_settigns.name", mEntityName) );
+
+ // I don't think we need this
+ // setName( tree_handle.get<string>("common_settigns.name", mEntityName) );
string argName;
vector<string> parseStorage;
@@ -148,4 +130,6 @@ void Entity::_defaultLoader(const string &entityName)
argName = tree_handle.get<string>("common_settigns.scale", "1, 1, 1");
if (parseArguments("scale", argName, storage, parseStorage))
setScale(vec3(storage[0], storage[1], storage[2]));
+
+ return tree_handle;
}
Oops, something went wrong.

0 comments on commit 046fcd9

Please sign in to comment.