From f8029aaa9ed47f3a8092e6561dd1e8cf68e7a351 Mon Sep 17 00:00:00 2001 From: Marc Zinnschlag Date: Sat, 27 Aug 2011 10:30:38 +0200 Subject: [PATCH] more cleanup; fixes for player handling during physics (unrelated to the actual refactoring bugs); fixed minor bug in character initialisation --- apps/openmw/mwrender/mwscene.cpp | 2 +- apps/openmw/mwworld/physicssystem.cpp | 2 -- apps/openmw/mwworld/player.cpp | 3 +++ apps/openmw/mwworld/scene.cpp | 2 +- apps/openmw/mwworld/world.cpp | 34 +++++++++++++++++++++------ 5 files changed, 32 insertions(+), 11 deletions(-) diff --git a/apps/openmw/mwrender/mwscene.cpp b/apps/openmw/mwrender/mwscene.cpp index a1d4aed03d..ebcfefe6a5 100644 --- a/apps/openmw/mwrender/mwscene.cpp +++ b/apps/openmw/mwrender/mwscene.cpp @@ -43,7 +43,7 @@ MWScene::MWScene(OEngine::Render::OgreRenderer &_rend , OEngine::Physic::PhysicE //used to obtain ingame information of ogre objects (which are faced or selected) mRaySceneQuery = rend.getScene()->createRayQuery(Ray()); - Ogre::SceneNode *playerNode = mwRoot->createChildSceneNode(); + Ogre::SceneNode *playerNode = mwRoot->createChildSceneNode ("player"); playerNode->pitch(Degree(90)); Ogre::SceneNode *cameraYawNode = playerNode->createChildSceneNode(); Ogre::SceneNode *cameraPitchNode = cameraYawNode->createChildSceneNode(); diff --git a/apps/openmw/mwworld/physicssystem.cpp b/apps/openmw/mwworld/physicssystem.cpp index f4433af8ee..36b962f087 100644 --- a/apps/openmw/mwworld/physicssystem.cpp +++ b/apps/openmw/mwworld/physicssystem.cpp @@ -112,8 +112,6 @@ namespace MWWorld void PhysicsSystem::moveObject (const std::string& handle, const Ogre::Vector3& position, bool updatePhysics) { - mRender.getScene()->getSceneNode(handle)->setPosition(position); - if(updatePhysics)//TODO: is it an actor? Done? { if (OEngine::Physic::RigidBody* body = mEngine->getRigidBody(handle)) diff --git a/apps/openmw/mwworld/player.cpp b/apps/openmw/mwworld/player.cpp index 8b9bc747b9..0888b42317 100644 --- a/apps/openmw/mwworld/player.cpp +++ b/apps/openmw/mwworld/player.cpp @@ -13,12 +13,14 @@ namespace MWWorld mAutoMove (false), mForwardBackward (0) { mPlayer.base = player; + mPlayer.ref.refID = "player"; mName = player->name; mMale = !(player->flags & ESM::NPC::Female); mRace = player->race; mPlayer.ref.pos.pos[0] = mPlayer.ref.pos.pos[1] = mPlayer.ref.pos.pos[2] = 0; std::cout << renderer->getHandle(); mPlayer.mData.setHandle (renderer->getHandle()); + /// \todo Do not make a copy of classes defined in esm/p records. mClass = new ESM::Class (*world.getStore().classes.find (player->cls)); } @@ -29,6 +31,7 @@ namespace MWWorld void Player::setPos(float x, float y, float z, bool updateCamera) { + /// \todo This fcuntion should be removed during the mwrender-refactoring. mWorld.moveObject (getPlayer(), x, y, z); if (updateCamera) diff --git a/apps/openmw/mwworld/scene.cpp b/apps/openmw/mwworld/scene.cpp index 49cf7ae082..9566ac7a03 100644 --- a/apps/openmw/mwworld/scene.cpp +++ b/apps/openmw/mwworld/scene.cpp @@ -245,7 +245,7 @@ namespace MWWorld { mCellChanged = false; } - + /*#include #include #include diff --git a/apps/openmw/mwworld/world.cpp b/apps/openmw/mwworld/world.cpp index c5f027daf2..bf2ac92126 100644 --- a/apps/openmw/mwworld/world.cpp +++ b/apps/openmw/mwworld/world.cpp @@ -673,6 +673,12 @@ namespace MWWorld } } } + + // \todo cell change for non-player ref + + // \todo this should go into the new scene class and eventually into the objects/actors classes. + mScene.getMgr()->getSceneNode (ptr.getRefData().getHandle())-> + setPosition (Ogre::Vector3 (x, y, z)); } void World::moveObject (Ptr ptr, float x, float y, float z) @@ -680,9 +686,7 @@ namespace MWWorld moveObjectImp(ptr, x, y, z); mPhysics->moveObject (ptr.getRefData().getHandle(), Ogre::Vector3 (x, y, z), - !DoingPhysics::isDoingPhysics()); - - // TODO cell change for non-player ref + true); } void World::indexToPosition (int cellX, int cellY, float &x, float &y, bool centre) const @@ -718,11 +722,27 @@ namespace MWWorld float duration) { std::vector< std::pair > vectors = mPhysics->doPhysics (duration, actors); - std::vector< std::pair >::iterator it; - for(it = vectors.begin(); it != vectors.end(); it++) { - MWWorld::Ptr ptr = getPtrViaHandle (it->first); - moveObject (ptr, it->second.x, it->second.y, it->second.z); + std::vector< std::pair >::iterator player = vectors.end(); + + for (std::vector< std::pair >::iterator it = vectors.begin(); + it!= vectors.end(); ++it) + { + if (it->first=="player") + { + player = it; + } + else + { + MWWorld::Ptr ptr = getPtrViaHandle (it->first); + moveObjectImp (ptr, it->second.x, it->second.y, it->second.z); + } } + + // Make sure player is moved last (otherwise the cell might change in the middle of an update + // loop) + if (player!=vectors.end()) + moveObjectImp (getPtrViaHandle (player->first), + player->second.x, player->second.y, player->second.z); } bool World::toggleCollisionMode()