From f292a5a7ca8295d61b6bf6c9f6fd9850b750ae6c Mon Sep 17 00:00:00 2001 From: Nikolay Kasyanov Date: Mon, 12 Mar 2012 02:12:56 +0400 Subject: [PATCH] Feature #37 (In Progress) Render Path Grid now using mwRoot instead of ogre's root, so no more messing with coordinates. --- apps/openmw/mwrender/debugging.cpp | 55 ++++++++++++++--------- apps/openmw/mwrender/debugging.hpp | 8 ++-- apps/openmw/mwrender/renderingmanager.cpp | 4 +- components/esm_store/reclists.hpp | 4 -- 4 files changed, 40 insertions(+), 31 deletions(-) diff --git a/apps/openmw/mwrender/debugging.cpp b/apps/openmw/mwrender/debugging.cpp index 8df4850db..ebaab5703 100644 --- a/apps/openmw/mwrender/debugging.cpp +++ b/apps/openmw/mwrender/debugging.cpp @@ -2,12 +2,8 @@ #include -#include "OgreRoot.h" -#include "OgreRenderWindow.h" -#include "OgreSceneManager.h" -#include "OgreViewport.h" -#include "OgreCamera.h" -#include "OgreTextureManager.h" +#include +#include #include "../mwworld/world.hpp" // these includes can be removed once the static-hack is gone #include "../mwworld/environment.hpp" @@ -20,8 +16,11 @@ using namespace MWRender; using namespace Ogre; -Debugging::Debugging(MWWorld::Environment &env, SceneManager* sceneMgr, OEngine::Physic::PhysicEngine *engine) : - mEnvironment(env), mSceneMgr(sceneMgr), mEngine(engine), pathgridEnabled(false) +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) { } @@ -65,7 +64,7 @@ void Debugging::togglePathgrid() if (pathgridEnabled) { // add path grid meshes to already loaded cells - mPathGridRoot = mSceneMgr->getRootSceneNode()->createChildSceneNode(); + mPathGridRoot = mMwRoot->createChildSceneNode(); for(CellList::iterator it = mActiveCells.begin(); it != mActiveCells.end(); it++) { togglePathgridForCell(*it, true); @@ -79,6 +78,7 @@ void Debugging::togglePathgrid() } mPathGridRoot->removeAndDestroyAllChildren(); mSceneMgr->destroySceneNode(mPathGridRoot); + mPathGridRoot = NULL; } } @@ -87,25 +87,24 @@ void Debugging::togglePathgridForCell(MWWorld::Ptr::CellStore *store, bool enabl ESM::Pathgrid *pathgrid = mEnvironment.mWorld->getStore().pathgrids.search(*store->cell); if (!pathgrid) { - std::cout << "No path grid :(" << std::endl; return; } - std::cout << "Path grid exists!" << std::endl; if (enabled) { Vector3 cellPathGridPos; + /// \todo replace tests like this with isExterior method of ESM::Cell after merging with terrain branch 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; - cellPathGridPos.z = -store->cell->data.gridY * 8192; + cellPathGridPos.y = store->cell->data.gridY * 8192; } SceneNode *cellPathGrid = mPathGridRoot->createChildSceneNode(cellPathGridPos); ESM::Pathgrid::PointList points = pathgrid->points; for (ESM::Pathgrid::PointList::iterator it = points.begin(); it != points.end(); it++) { - Vector3 position(it->x, it->z, -it->y); + Vector3 position(it->x, it->y, it->z); SceneNode* pointNode = cellPathGrid->createChildSceneNode(position); pointNode->setScale(0.5, 0.5, 0.5); Entity *pointMesh = mSceneMgr->createEntity(SceneManager::PT_CUBE); @@ -124,18 +123,13 @@ void Debugging::togglePathgridForCell(MWWorld::Ptr::CellStore *store, bool enabl } else { - /// \todo Don't forget to destroy cubes too! - SceneNode *cellPathGridNode; 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()) { - cellPathGridNode = it->second; - mPathGridRoot->removeChild(cellPathGridNode); - cellPathGridNode->removeAndDestroyAllChildren(); - mSceneMgr->destroySceneNode(cellPathGridNode); + destroyCellPathgridNode(it->second); mExteriorPathgridNodes.erase(it); } } @@ -143,11 +137,28 @@ void Debugging::togglePathgridForCell(MWWorld::Ptr::CellStore *store, bool enabl { if (mInteriorPathgridNode) { - mPathGridRoot->removeChild(mInteriorPathgridNode); - mInteriorPathgridNode->removeAndDestroyAllChildren(); - mSceneMgr->destroySceneNode(mInteriorPathgridNode); + destroyCellPathgridNode(mInteriorPathgridNode); mInteriorPathgridNode = NULL; } } } } + +void Debugging::destroyCellPathgridNode(SceneNode *node) +{ + mPathGridRoot->removeChild(node); + + SceneNode::ChildNodeIterator childIt = node->getChildIterator(); + while (childIt.hasMoreElements()) + { + SceneNode *child = static_cast(childIt.getNext()); + SceneNode::ObjectIterator objIt = child->getAttachedObjectIterator(); + while (objIt.hasMoreElements()) + { + MovableObject *mesh = static_cast(objIt.getNext()); + child->getCreator()->destroyMovableObject(mesh); + } + } + node->removeAndDestroyAllChildren(); + mSceneMgr->destroySceneNode(node); +} diff --git a/apps/openmw/mwrender/debugging.hpp b/apps/openmw/mwrender/debugging.hpp index 2b47eb773..eb592b98d 100644 --- a/apps/openmw/mwrender/debugging.hpp +++ b/apps/openmw/mwrender/debugging.hpp @@ -33,9 +33,8 @@ namespace MWRender class Debugging { OEngine::Physic::PhysicEngine* mEngine; - Ogre::SceneManager* mSceneMgr; + Ogre::SceneManager *mSceneMgr; MWWorld::Environment& mEnvironment; - //const ESMS::ESMStore& mStore; // Path grid stuff bool pathgridEnabled; @@ -46,6 +45,7 @@ namespace MWRender CellList mActiveCells; + Ogre::SceneNode *mMwRoot; Ogre::SceneNode *mPathGridRoot; Ogre::SceneNode *mInteriorPathgridNode; @@ -54,8 +54,10 @@ namespace MWRender void togglePathgridForCell(MWWorld::Ptr::CellStore *store, bool enabled); + void destroyCellPathgridNode(Ogre::SceneNode *node); + public: - Debugging(MWWorld::Environment &env, Ogre::SceneManager *mSceneMgr, OEngine::Physic::PhysicEngine* engine); + Debugging(Ogre::SceneNode* mwRoot, MWWorld::Environment &env, OEngine::Physic::PhysicEngine *engine); bool toggleRenderMode (int mode); void cellAdded(MWWorld::Ptr::CellStore* store); diff --git a/apps/openmw/mwrender/renderingmanager.cpp b/apps/openmw/mwrender/renderingmanager.cpp index 4cb8b42fa..888012280 100644 --- a/apps/openmw/mwrender/renderingmanager.cpp +++ b/apps/openmw/mwrender/renderingmanager.cpp @@ -24,8 +24,6 @@ RenderingManager::RenderingManager (OEngine::Render::OgreRenderer& _rend, const { mRendering.createScene("PlayerCam", 55, 5); - mDebugging = new Debugging(environment, mRendering.getScene(), engine); - // Set default mipmap level (NB some APIs ignore this) TextureManager::getSingleton().setDefaultNumMipmaps(5); @@ -57,6 +55,8 @@ RenderingManager::RenderingManager (OEngine::Render::OgreRenderer& _rend, const mPlayer = new MWRender::Player (mRendering.getCamera(), playerNode); mSun = 0; + + mDebugging = new Debugging(mMwRoot, environment, engine); } RenderingManager::~RenderingManager () diff --git a/components/esm_store/reclists.hpp b/components/esm_store/reclists.hpp index da6e9b3d5..f2c07dda5 100644 --- a/components/esm_store/reclists.hpp +++ b/components/esm_store/reclists.hpp @@ -428,12 +428,10 @@ namespace ESMS if (grid->data.x == 0 && grid->data.y == 0) { intGrids[grid->cell] = grid; - std::cout << "int grids size " << intGrids.size() << std::endl; } else { extGrids[std::make_pair(grid->data.x, grid->data.y)] = grid; - std::cout << "ext grids size " << extGrids.size() << std::endl; } } @@ -449,8 +447,6 @@ namespace ESMS Pathgrid *search(int cellX, int cellY, const std::string &cellName) const { - std::cout << "int grids size " << intGrids.size() << std::endl; - std::cout << "ext grids size " << extGrids.size() << std::endl; Pathgrid *result = NULL; if (cellX == 0 && cellY == 0) // possibly interior {