2011-10-25 18:06:44 +00:00
|
|
|
#include "debugging.hpp"
|
2010-06-05 18:37:01 +00:00
|
|
|
|
|
|
|
#include <assert.h>
|
|
|
|
|
2012-03-11 22:12:56 +00:00
|
|
|
#include <OgreNode.h>
|
|
|
|
#include <OgreSceneManager.h>
|
2010-06-06 11:36:45 +00:00
|
|
|
|
2010-08-25 07:19:15 +00:00
|
|
|
#include "../mwworld/world.hpp" // these includes can be removed once the static-hack is gone
|
2012-03-10 16:45:55 +00:00
|
|
|
#include "../mwworld/environment.hpp"
|
2010-08-25 07:19:15 +00:00
|
|
|
#include "../mwworld/ptr.hpp"
|
|
|
|
#include <components/esm/loadstat.hpp>
|
2012-03-08 06:46:34 +00:00
|
|
|
#include <components/esm/loadpgrd.hpp>
|
2010-08-25 07:19:15 +00:00
|
|
|
|
2011-01-08 14:11:37 +00:00
|
|
|
#include "player.hpp"
|
|
|
|
|
2010-06-08 11:53:34 +00:00
|
|
|
using namespace MWRender;
|
2010-06-05 18:37:01 +00:00
|
|
|
using namespace Ogre;
|
|
|
|
|
2012-03-11 22:12:56 +00:00
|
|
|
Debugging::Debugging(SceneNode *mwRoot, MWWorld::Environment &env, OEngine::Physic::PhysicEngine *engine) :
|
|
|
|
mMwRoot(mwRoot), mEnvironment(env), mEngine(engine),
|
|
|
|
mSceneMgr(mwRoot->getCreator()),
|
|
|
|
pathgridEnabled(false),
|
|
|
|
mInteriorPathgridNode(NULL), mPathGridRoot(NULL)
|
2012-03-08 06:46:34 +00:00
|
|
|
{
|
2011-10-22 04:15:15 +00:00
|
|
|
}
|
|
|
|
|
2011-10-24 17:42:36 +00:00
|
|
|
|
2011-10-22 04:15:15 +00:00
|
|
|
bool Debugging::toggleRenderMode (int mode){
|
2012-03-08 06:46:34 +00:00
|
|
|
switch (mode)
|
2011-10-22 04:15:15 +00:00
|
|
|
{
|
|
|
|
case MWWorld::World::Render_CollisionDebug:
|
|
|
|
|
|
|
|
// TODO use a proper function instead of accessing the member variable
|
|
|
|
// directly.
|
2012-03-08 06:46:34 +00:00
|
|
|
mEngine->setDebugRenderingMode (!mEngine->isDebugCreated);
|
|
|
|
return mEngine->isDebugCreated;
|
|
|
|
case MWWorld::World::Render_Pathgrid:
|
|
|
|
togglePathgrid();
|
|
|
|
return pathgridEnabled;
|
2011-10-22 04:15:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
2012-03-08 06:46:34 +00:00
|
|
|
|
|
|
|
void Debugging::cellAdded(MWWorld::Ptr::CellStore *store)
|
|
|
|
{
|
|
|
|
std::cout << "Cell added to debugging" << std::endl;
|
|
|
|
mActiveCells.push_back(store);
|
|
|
|
if (pathgridEnabled)
|
|
|
|
togglePathgridForCell(store, true);
|
|
|
|
}
|
|
|
|
|
|
|
|
void Debugging::cellRemoved(MWWorld::Ptr::CellStore *store)
|
|
|
|
{
|
|
|
|
mActiveCells.erase(std::remove(mActiveCells.begin(), mActiveCells.end(), store), mActiveCells.end());
|
|
|
|
std::cout << "Cell removed from debugging, active cells count: " << mActiveCells.size() << std::endl;
|
|
|
|
if (pathgridEnabled)
|
|
|
|
togglePathgridForCell(store, false);
|
|
|
|
}
|
|
|
|
|
|
|
|
void Debugging::togglePathgrid()
|
|
|
|
{
|
|
|
|
pathgridEnabled = !pathgridEnabled;
|
|
|
|
if (pathgridEnabled)
|
|
|
|
{
|
|
|
|
// add path grid meshes to already loaded cells
|
2012-03-11 22:12:56 +00:00
|
|
|
mPathGridRoot = mMwRoot->createChildSceneNode();
|
2012-03-08 06:46:34 +00:00
|
|
|
for(CellList::iterator it = mActiveCells.begin(); it != mActiveCells.end(); it++)
|
|
|
|
{
|
|
|
|
togglePathgridForCell(*it, true);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
// remove path grid meshes from already loaded cells
|
|
|
|
for(CellList::iterator it = mActiveCells.begin(); it != mActiveCells.end(); it++)
|
|
|
|
{
|
|
|
|
togglePathgridForCell(*it, false);
|
|
|
|
}
|
|
|
|
mPathGridRoot->removeAndDestroyAllChildren();
|
|
|
|
mSceneMgr->destroySceneNode(mPathGridRoot);
|
2012-03-11 22:12:56 +00:00
|
|
|
mPathGridRoot = NULL;
|
2012-03-08 06:46:34 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void Debugging::togglePathgridForCell(MWWorld::Ptr::CellStore *store, bool enabled)
|
|
|
|
{
|
2012-03-10 16:45:55 +00:00
|
|
|
ESM::Pathgrid *pathgrid = mEnvironment.mWorld->getStore().pathgrids.search(*store->cell);
|
2012-03-08 06:46:34 +00:00
|
|
|
if (!pathgrid)
|
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (enabled)
|
|
|
|
{
|
|
|
|
Vector3 cellPathGridPos;
|
2012-03-11 22:12:56 +00:00
|
|
|
/// \todo replace tests like this with isExterior method of ESM::Cell after merging with terrain branch
|
2012-03-08 06:46:34 +00:00
|
|
|
if (!(store->cell->data.flags & ESM::Cell::Interior))
|
|
|
|
{
|
|
|
|
/// \todo Replace with ESM::Land::REAL_SIZE after merging with terrain branch
|
|
|
|
cellPathGridPos.x = store->cell->data.gridX * 8192;
|
2012-03-11 22:12:56 +00:00
|
|
|
cellPathGridPos.y = store->cell->data.gridY * 8192;
|
2012-03-08 06:46:34 +00:00
|
|
|
}
|
|
|
|
SceneNode *cellPathGrid = mPathGridRoot->createChildSceneNode(cellPathGridPos);
|
|
|
|
ESM::Pathgrid::PointList points = pathgrid->points;
|
|
|
|
for (ESM::Pathgrid::PointList::iterator it = points.begin(); it != points.end(); it++)
|
|
|
|
{
|
2012-03-11 22:12:56 +00:00
|
|
|
Vector3 position(it->x, it->y, it->z);
|
2012-03-08 06:46:34 +00:00
|
|
|
SceneNode* pointNode = cellPathGrid->createChildSceneNode(position);
|
|
|
|
pointNode->setScale(0.5, 0.5, 0.5);
|
|
|
|
Entity *pointMesh = mSceneMgr->createEntity(SceneManager::PT_CUBE);
|
|
|
|
pointNode->attachObject(pointMesh);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!(store->cell->data.flags & ESM::Cell::Interior))
|
|
|
|
{
|
|
|
|
mExteriorPathgridNodes[std::make_pair(store->cell->data.gridX, store->cell->data.gridY)] = cellPathGrid;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
assert(mInteriorPathgridNode == NULL);
|
|
|
|
mInteriorPathgridNode = cellPathGrid;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
if (!(store->cell->data.flags & ESM::Cell::Interior))
|
|
|
|
{
|
|
|
|
ExteriorPathgridNodes::iterator it =
|
|
|
|
mExteriorPathgridNodes.find(std::make_pair(store->cell->data.gridX, store->cell->data.gridY));
|
|
|
|
if (it != mExteriorPathgridNodes.end())
|
|
|
|
{
|
2012-03-11 22:12:56 +00:00
|
|
|
destroyCellPathgridNode(it->second);
|
2012-03-08 06:46:34 +00:00
|
|
|
mExteriorPathgridNodes.erase(it);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
if (mInteriorPathgridNode)
|
|
|
|
{
|
2012-03-11 22:12:56 +00:00
|
|
|
destroyCellPathgridNode(mInteriorPathgridNode);
|
2012-03-08 06:46:34 +00:00
|
|
|
mInteriorPathgridNode = NULL;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2012-03-11 22:12:56 +00:00
|
|
|
|
|
|
|
void Debugging::destroyCellPathgridNode(SceneNode *node)
|
|
|
|
{
|
|
|
|
mPathGridRoot->removeChild(node);
|
|
|
|
|
|
|
|
SceneNode::ChildNodeIterator childIt = node->getChildIterator();
|
|
|
|
while (childIt.hasMoreElements())
|
|
|
|
{
|
|
|
|
SceneNode *child = static_cast<SceneNode *>(childIt.getNext());
|
|
|
|
SceneNode::ObjectIterator objIt = child->getAttachedObjectIterator();
|
|
|
|
while (objIt.hasMoreElements())
|
|
|
|
{
|
|
|
|
MovableObject *mesh = static_cast<MovableObject *>(objIt.getNext());
|
|
|
|
child->getCreator()->destroyMovableObject(mesh);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
node->removeAndDestroyAllChildren();
|
|
|
|
mSceneMgr->destroySceneNode(node);
|
|
|
|
}
|