Merge branch 'optimisation'

actorid
Marc Zinnschlag 14 years ago
commit 5fb3dc854b

@ -19,7 +19,7 @@ namespace MWClass
const std::string &model = ref->base->model; const std::string &model = ref->base->model;
if (!model.empty()) if (!model.empty())
{ {
MWRender::Rendering rendering (cellRender, ref->ref); MWRender::Rendering rendering (cellRender, ref->ref, true);
cellRender.insertMesh ("meshes\\" + model); cellRender.insertMesh ("meshes\\" + model);
cellRender.insertObjectPhysics(); cellRender.insertObjectPhysics();
ref->mData.setHandle (rendering.end (ref->mData.isEnabled())); ref->mData.setHandle (rendering.end (ref->mData.isEnabled()));

@ -35,7 +35,7 @@ namespace MWRender
virtual ~CellRenderImp() {} virtual ~CellRenderImp() {}
/// start inserting a new reference. /// start inserting a new reference.
virtual void insertBegin (ESM::CellRef &ref) = 0; virtual void insertBegin (ESM::CellRef &ref, bool static_ = false) = 0;
virtual void rotateMesh(Ogre::Vector3 axis, Ogre::Radian angle, std::string sceneNodeName[], int elements) = 0; virtual void rotateMesh(Ogre::Vector3 axis, Ogre::Radian angle, std::string sceneNodeName[], int elements) = 0;
/// insert a mesh related to the most recent insertBegin call. /// insert a mesh related to the most recent insertBegin call.
@ -71,10 +71,10 @@ namespace MWRender
public: public:
Rendering (CellRenderImp& cellRender, ESM::CellRef &ref) Rendering (CellRenderImp& cellRender, ESM::CellRef &ref, bool static_ = false)
: mCellRender (cellRender), mEnd (false) : mCellRender (cellRender), mEnd (false)
{ {
mCellRender.insertBegin (ref); mCellRender.insertBegin (ref, static_);
} }
~Rendering() ~Rendering()

@ -31,12 +31,24 @@ float ExteriorCellRender::lightQuadraticRadiusMult = 1;
bool ExteriorCellRender::lightOutQuadInLin = false; bool ExteriorCellRender::lightOutQuadInLin = false;
// start inserting a new reference. int ExteriorCellRender::uniqueID = 0;
void ExteriorCellRender::insertBegin (ESM::CellRef &ref) ExteriorCellRender::ExteriorCellRender(ESMS::CellStore<MWWorld::RefData> &_cell, MWWorld::Environment& environment,
MWScene &_scene)
: mCell(_cell), mEnvironment (environment), mScene(_scene), mBase(NULL), mInsert(NULL), mAmbientMode (0)
{
uniqueID = uniqueID +1;
sg = mScene.getMgr()->createStaticGeometry( "sg" + Ogre::StringConverter::toString(uniqueID));
}
void ExteriorCellRender::insertBegin (ESM::CellRef &ref, bool static_)
{ {
assert (!mInsert); assert (!mInsert);
isStatic = static_;
// Create and place scene node for this object // Create and place scene node for this object
mInsert = mBase->createChildSceneNode(); mInsert = mBase->createChildSceneNode();
@ -59,7 +71,7 @@ void ExteriorCellRender::insertBegin (ESM::CellRef &ref)
// Rotates first around z, then y, then x // Rotates first around z, then y, then x
mInsert->setOrientation(xr*yr*zr); mInsert->setOrientation(xr*yr*zr);
mInsertMesh.clear(); mInsertMesh.clear();
} }
@ -202,11 +214,20 @@ void ExteriorCellRender::insertMesh(const std::string &mesh)
assert (mInsert); assert (mInsert);
NIFLoader::load(mesh); NIFLoader::load(mesh);
MovableObject *ent = mScene.getMgr()->createEntity(mesh); Entity *ent = mScene.getMgr()->createEntity(mesh);
mInsert->attachObject(ent);
if (mInsertMesh.empty()) if(!isStatic)
mInsertMesh = mesh; {
mInsert->attachObject(ent);
}
else
{
sg->addEntity(ent,mInsert->_getDerivedPosition(),mInsert->_getDerivedOrientation(),mInsert->_getDerivedScale());
sg->setRegionDimensions(Ogre::Vector3(100000,10000,100000));
mScene.getMgr()->destroyEntity(ent);
}
if (mInsertMesh.empty())
mInsertMesh = mesh;
} }
void ExteriorCellRender::insertObjectPhysics() void ExteriorCellRender::insertObjectPhysics()
@ -333,6 +354,8 @@ void ExteriorCellRender::show()
configureFog(); configureFog();
insertCell(mCell, mEnvironment); insertCell(mCell, mEnvironment);
sg->build();
} }
void ExteriorCellRender::hide() void ExteriorCellRender::hide()
@ -341,15 +364,49 @@ void ExteriorCellRender::hide()
mBase->setVisible(false); mBase->setVisible(false);
} }
void ExteriorCellRender::destroyAllAttachedMovableObjects(Ogre::SceneNode* i_pSceneNode)
{
if ( !i_pSceneNode )
{
assert( false );
return;
}
// Destroy all the attached objects
SceneNode::ObjectIterator itObject = i_pSceneNode->getAttachedObjectIterator();
while ( itObject.hasMoreElements() )
{
MovableObject* pObject = static_cast<MovableObject*>(itObject.getNext());
i_pSceneNode->getCreator()->destroyMovableObject( pObject );
}
// Recurse to child SceneNodes
SceneNode::ChildNodeIterator itChild = i_pSceneNode->getChildIterator();
while ( itChild.hasMoreElements() )
{
SceneNode* pChildNode = static_cast<SceneNode*>(itChild.getNext());
destroyAllAttachedMovableObjects( pChildNode );
}
}
void ExteriorCellRender::destroy() void ExteriorCellRender::destroy()
{ {
if(mBase) if(mBase)
{ {
destroyAllAttachedMovableObjects(mBase);
mBase->removeAndDestroyAllChildren(); mBase->removeAndDestroyAllChildren();
mScene.getMgr()->destroySceneNode(mBase); mScene.getMgr()->destroySceneNode(mBase);
} }
mBase = NULL; mBase = 0;
if (sg)
{
mScene.getMgr()->destroyStaticGeometry (sg);
sg = 0;
}
} }
// Switch through lighting modes. // Switch through lighting modes.

@ -57,13 +57,17 @@ namespace MWRender
std::string mInsertMesh; std::string mInsertMesh;
Ogre::SceneNode *mNpcPart; Ogre::SceneNode *mNpcPart;
//the static geometry
Ogre::StaticGeometry *sg;
bool isStatic;
// 0 normal, 1 more bright, 2 max // 0 normal, 1 more bright, 2 max
int mAmbientMode; int mAmbientMode;
Ogre::ColourValue mAmbientColor; Ogre::ColourValue mAmbientColor;
/// start inserting a new reference. /// start inserting a new reference.
virtual void insertBegin (ESM::CellRef &ref); virtual void insertBegin (ESM::CellRef &ref, bool static_ = false);
/// insert a mesh related to the most recent insertBegin call. /// insert a mesh related to the most recent insertBegin call.
virtual void insertMesh(const std::string &mesh, Ogre::Vector3 vec, Ogre::Vector3 axis, Ogre::Radian angle, std::string sceneNodeName, std::string sceneParent[], int elements); virtual void insertMesh(const std::string &mesh, Ogre::Vector3 vec, Ogre::Vector3 axis, Ogre::Radian angle, std::string sceneNodeName, std::string sceneParent[], int elements);
@ -95,8 +99,7 @@ namespace MWRender
public: public:
ExteriorCellRender(ESMS::CellStore<MWWorld::RefData> &_cell, MWWorld::Environment& environment, ExteriorCellRender(ESMS::CellStore<MWWorld::RefData> &_cell, MWWorld::Environment& environment,
MWScene &_scene) MWScene &_scene);
: mCell(_cell), mEnvironment (environment), mScene(_scene), mBase(NULL), mInsert(NULL), mAmbientMode (0) {}
virtual ~ExteriorCellRender() { destroy(); } virtual ~ExteriorCellRender() { destroy(); }
@ -121,6 +124,10 @@ namespace MWRender
/// Remove the reference with the given handle permanently from the scene. /// Remove the reference with the given handle permanently from the scene.
virtual void deleteObject (const std::string& handle); virtual void deleteObject (const std::string& handle);
void destroyAllAttachedMovableObjects(Ogre::SceneNode* i_pSceneNode);
static int uniqueID;
}; };
} }

@ -35,7 +35,7 @@ bool InteriorCellRender::lightOutQuadInLin = false;
// start inserting a new reference. // start inserting a new reference.
void InteriorCellRender::insertBegin (ESM::CellRef &ref) void InteriorCellRender::insertBegin (ESM::CellRef &ref, bool static_)
{ {
assert (!insert); assert (!insert);

@ -63,7 +63,7 @@ namespace MWRender
Ogre::ColourValue ambientColor; Ogre::ColourValue ambientColor;
/// start inserting a new reference. /// start inserting a new reference.
virtual void insertBegin (ESM::CellRef &ref); virtual void insertBegin (ESM::CellRef &ref, bool static_ = false);
virtual void rotateMesh(Ogre::Vector3 axis, Ogre::Radian angle, std::string sceneNodeName[], int elements); virtual void rotateMesh(Ogre::Vector3 axis, Ogre::Radian angle, std::string sceneNodeName[], int elements);
virtual void scaleMesh(Ogre::Vector3 axis, std::string sceneNodeName[], int elements); virtual void scaleMesh(Ogre::Vector3 axis, std::string sceneNodeName[], int elements);
/// insert a mesh related to the most recent insertBegin call. /// insert a mesh related to the most recent insertBegin call.

@ -284,7 +284,6 @@ namespace MWWorld
removeScripts (iter->first); removeScripts (iter->first);
mEnvironment.mMechanicsManager->dropActors (iter->first); mEnvironment.mMechanicsManager->dropActors (iter->first);
iter->second->destroy();
mEnvironment.mSoundManager->stopSound (iter->first); mEnvironment.mSoundManager->stopSound (iter->first);
delete iter->second; delete iter->second;
mActiveCells.erase (iter); mActiveCells.erase (iter);

@ -26,8 +26,8 @@ namespace Files
for (std::size_t i=0; i<min; ++i) for (std::size_t i=0; i<min; ++i)
{ {
char l = std::tolower (left[i]); char l = std::tolower (left[i],std::locale());
char r = std::tolower (right[i]); char r = std::tolower (right[i],std::locale());
if (l<r) if (l<r)
return true; return true;

@ -581,8 +581,27 @@ void NIFLoader::handleNiTriShape(NiTriShape *shape, int flags, BoundsFinder &bou
{ {
// Use NiMaterialProperty data to create the data // Use NiMaterialProperty data to create the data
const S_MaterialProperty *d = m->data; const S_MaterialProperty *d = m->data;
createMaterial(material, d->ambient, d->diffuse, d->specular, d->emissive,
d->glossiness, d->alpha, alphaFlags, alphaTest, texName); std::multimap<std::string,std::string>::iterator itr = MaterialMap.find(texName);
std::multimap<std::string,std::string>::iterator lastElement;
lastElement = MaterialMap.upper_bound(texName);
if (itr != MaterialMap.end())
{
for ( ; itr != lastElement; ++itr)
{
//std::cout << "OK!";
//MaterialPtr mat = MaterialManager::getSingleton().getByName(itr->second,recourceGroup);
material = itr->second;
//if( mat->getA
}
}
else
{
//std::cout << "new";
createMaterial(material, d->ambient, d->diffuse, d->specular, d->emissive,
d->glossiness, d->alpha, alphaFlags, alphaTest, texName);
MaterialMap.insert(std::make_pair(texName,material));
}
} }
else else
{ {

@ -132,6 +132,7 @@ class NIFLoader : Ogre::ManualResourceLoader
int numbers; int numbers;
int stack; int stack;
std::multimap<std::string,std::string> MaterialMap;
// pointer to the ogre mesh which is currently build // pointer to the ogre mesh which is currently build
Ogre::Mesh *mesh; Ogre::Mesh *mesh;

Loading…
Cancel
Save