Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Merge branch 'master' of http://github.com/Phosfor/Pseudoform-2

  • Loading branch information...
commit 8d40c62bd3b5ac1f54590f98c573ad4356b6d94b 2 parents a02a813 + ff0a6fa
@svenstaro authored
View
4 include/Managers/Entities/Camera.hpp
@@ -19,6 +19,9 @@ class Camera : public Entity
float mMove;
float mRotate;
+ boost::signals2::connection mEMouseMoved;
+ boost::signals2::connection mEUpdated;
+
public:
enum CameraType
{
@@ -29,6 +32,7 @@ class Camera : public Entity
} mCameraType;
Camera(const string &entityName);
+ ~Camera();
Ogre::Camera *handle();
Ogre::SceneNode *getPitchNode();
View
3  include/Managers/Entities/Entity.hpp
@@ -35,7 +35,10 @@ class Entity : private boost::noncopyable
void defaultDump(); // Dumping default entity settings
virtual Entity *dump() = 0; // Dumping type-related entity settings
+ void deleteOgre();
+
public:
+ Entity(){mEntity = NULL; mNode = NULL; mDebugEntity = NULL;}
virtual ~Entity();
virtual void update(float elapsed) = 0;
virtual string type() = 0;
View
1  include/Managers/Entities/Light.hpp
@@ -17,6 +17,7 @@ class Light : public Entity
public:
Light(const string &entityName);
+ ~Light();
Ogre::Light *handle();
Light *loadFromFile(const string &filePath);
View
4 include/Managers/EntityManager.hpp
@@ -34,11 +34,13 @@ using namespace std;
class EntityManager : public singleton<EntityManager>
{
protected:
- boost::ptr_map<const string, Entity> mEntityList;
+ typedef boost::ptr_map<const string, Entity> TEntityList;
+ TEntityList mEntityList;
public:
// Templated interface
bool DeleteEntity(const string &entityName);
+ int DeleteAllEntities();
// Predefined interface for all objects types
template<typename EntityType>
View
5 samples/pong-cpp/main.cpp
@@ -34,11 +34,12 @@ class GameState : public State
public:
void init() {
MakeCamera("MainCamera")->loadFromFile("Entities/MainCamera.info")->dump();
- MakeLight("DirectionalLight")->loadFromFile("Entities/MainLight.info")->dump();
+ MakeLight("Light")->loadFromFile("Entities/MainLight.info")->dump();
//MakeObject("ErrorObject")->loadFromFile("Entities/ErrorObject.info");//->dump();
MakeObject("Head")->loadFromFile("Entities/OgreHead.info")->dump();
- MakeObject("TestLight")->loadFromFile("Entities/LightObject.info")->setPosition(vec3(0, 50, 0));//->dump();
+ //MakeObject("TestLight")->loadFromFile("Entities/LightObject.info")->setPosition(vec3(0, 50, 0));//->dump();
+ entityManager.DeleteAllEntities();
//GetCamera("MainCamera")->dump();
//GetObject("ErrorObject")->dump();
}
View
21 src/Managers/Entities/Camera.cpp
@@ -1,6 +1,6 @@
#include "Managers/Entities/Camera.hpp"
-Camera::Camera(const string &entityName)
+Camera::Camera(const string &entityName):Entity()
{
LOG(FORMAT("Loading new entity `%1%` of type `%2%`", entityName % type()));
@@ -17,6 +17,19 @@ Camera::Camera(const string &entityName)
mPitchNode->attachObject(mCamera);
}
+Camera::~Camera()
+{
+ if(mPitchNode)
+ mNode->removeAndDestroyChild(mPitchNode->getName());
+ mPitchNode = NULL;
+ if(mCamera)
+ graphicSystem.getSceneMgr()->destroyCamera(mCamera);
+ mCamera = NULL;
+
+ if (mEMouseMoved.connected()) mEMouseMoved.disconnect();
+ if (mEUpdated.connected()) mEUpdated.disconnect();
+}
+
Camera *Camera::loadFromFile(const string &filePath)
{
ptree tree_handle = defaultLoader(filePath);
@@ -98,9 +111,9 @@ Camera *Camera::setCameraType(CameraType type)
if (type != Camera::DONT_USE)
{
//CONNECT(Engine::Events::KeyEvent, "KeyPressed", &Camera::onKeyPressed) //we don't need this anymore
- CONNECT(Engine::Events::MouseMoveEvent, "MouseMoved", &Camera::onMouseMoved);
- CONNECT0(Engine::Events::GlobalUpdateEvent, "Updated", &Camera::onUpdated);
- CONNECT0(Engine::Events::GlobalInitEvent, "Inited", &Camera::onInited);
+ mEMouseMoved = CONNECT(Engine::Events::MouseMoveEvent, "MouseMoved", &Camera::onMouseMoved);
+ mEUpdated = CONNECT0(Engine::Events::GlobalUpdateEvent, "Updated", &Camera::onUpdated);
+ //CONNECT0(Engine::Events::GlobalInitEvent, "Inited", &Camera::onInited);
}
return this;
}
View
18 src/Managers/Entities/Entity.cpp
@@ -1,6 +1,22 @@
#include "Managers/Entities/Entity.hpp"
-Entity::~Entity() { }
+Entity::~Entity()
+{
+ deleteOgre();
+}
+
+void Entity::deleteOgre()
+{
+ if(mNode)
+ graphicSystem.getSceneMgr()->getRootSceneNode()->removeAndDestroyChild(mNode->getName());
+ mNode = NULL;
+ if(mEntity)
+ graphicSystem.getSceneMgr()->destroyEntity(mEntity);
+ mEntity = NULL;
+ if(mDebugEntity)
+ graphicSystem.getSceneMgr()->destroyEntity(mDebugEntity);
+ mDebugEntity = NULL;
+}
// =============================================================================
// Getters
View
9 src/Managers/Entities/Light.cpp
@@ -1,6 +1,6 @@
#include "Managers/Entities/Light.hpp"
-Light::Light(const string &entityName)
+Light::Light(const string &entityName):Entity()
{
LOG(FORMAT("Loading new entity `%1%` of type `%2%`", entityName % type()));
@@ -8,7 +8,6 @@ Light::Light(const string &entityName)
// TODO: Load not Error mesh in Light class (get some other mesh type)
mLight = graphicSystem.getSceneMgr()->createLight("Light:" + entityName);
- //mLight->setType(Ogre::Light::LT_SPOTLIGHT);
mDebugEntity = graphicSystem.getSceneMgr()->createEntity("LightMesh:" + entityName, CONFIG("resorces.LightMesh", string, "Engine/Light.mesh"));
mNode = graphicSystem.getSceneMgr()->getRootSceneNode()->createChildSceneNode("Node:" + entityName);
@@ -16,6 +15,12 @@ Light::Light(const string &entityName)
mNode->attachObject(mLight);
}
+Light::~Light()
+{
+ if(mLight)
+ graphicSystem.getSceneMgr()->destroyLight(mLight);
+}
+
Light *Light::loadFromFile(const string &filePath)
{
ptree tree_handle = defaultLoader(filePath);
View
2  src/Managers/Entities/Object.cpp
@@ -3,7 +3,7 @@
#include <OgreMeshManager.h>
#include <OgreMaterial.h>
-Object::Object(const string &entityName, const string &resGroup)
+Object::Object(const string &entityName, const string &resGroup):Entity()
{
LOG(FORMAT("Loading new entity `%1%` of type `%2%`", entityName % type()));
mEntityName = entityName;
View
15 src/Managers/EntityManager.cpp
@@ -10,3 +10,18 @@ bool EntityManager::DeleteEntity(const string& entityName)
mEntityList.erase(entityName);
return true;
}
+
+int EntityManager::DeleteAllEntities()
+{
+ int i = 0;
+ LOG("=====Deleting all entitys!======");
+ BOOST_FOREACH(TEntityList::value_type entity, mEntityList)
+ {
+ LOG("\tDeleting " + entity.first);
+ mEntityList.erase(entity.first);
+ i++;
+ }
+ LOG(FORMAT("Deleted %1% entitys", i));
+
+ return i;
+}
Please sign in to comment.
Something went wrong with that request. Please try again.