mirror of
https://github.com/OpenMW/openmw.git
synced 2025-02-05 03:45:35 +00:00
Merge branch 'cells' into next
Conflicts: apps/openmw/engine.cpp
This commit is contained in:
commit
cd7aaab48e
25 changed files with 1210 additions and 659 deletions
|
@ -16,6 +16,7 @@ set(GAME_HEADER
|
|||
source_group(game FILES ${GAME} ${GAME_HEADER})
|
||||
|
||||
set(GAMEREND
|
||||
mwrender/rendering_manager.cpp
|
||||
mwrender/mwscene.cpp
|
||||
mwrender/cellimp.cpp
|
||||
mwrender/interior.cpp
|
||||
|
@ -24,6 +25,7 @@ set(GAMEREND
|
|||
mwrender/player.cpp
|
||||
)
|
||||
set(GAMEREND_HEADER
|
||||
mwrender/rendering_manager.hpp
|
||||
mwrender/cell.hpp
|
||||
mwrender/cellimp.hpp
|
||||
mwrender/mwscene.hpp
|
||||
|
@ -137,6 +139,8 @@ source_group(apps\\openmw\\mwsound FILES ${GAMESOUND} ${GAMESOUND_HEADER})
|
|||
|
||||
set(GAMEWORLD
|
||||
mwworld/world.cpp
|
||||
mwworld/scene.cpp
|
||||
mwworld/physicssystem.cpp
|
||||
mwworld/globals.cpp
|
||||
mwworld/class.cpp
|
||||
mwworld/actionteleport.cpp
|
||||
|
@ -144,12 +148,13 @@ set(GAMEWORLD
|
|||
mwworld/actiontake.cpp
|
||||
mwworld/containerutil.cpp
|
||||
mwworld/player.cpp
|
||||
mwworld/doingphysics.cpp
|
||||
mwworld/cells.cpp
|
||||
)
|
||||
set(GAMEWORLD_HEADER
|
||||
mwworld/refdata.hpp
|
||||
mwworld/world.hpp
|
||||
mwworld/ptr.hpp
|
||||
mwworld/physicssystem.hpp
|
||||
mwworld/scene.hpp
|
||||
mwworld/environment.hpp
|
||||
mwworld/globals.hpp
|
||||
mwworld/class.hpp
|
||||
|
@ -163,8 +168,8 @@ set(GAMEWORLD_HEADER
|
|||
mwworld/manualref.hpp
|
||||
mwworld/containerutil.hpp
|
||||
mwworld/player.hpp
|
||||
mwworld/doingphysics.hpp
|
||||
mwworld/cellfunctors.hpp
|
||||
mwworld/cells.hpp
|
||||
)
|
||||
source_group(apps\\openmw\\mwworld FILES ${GAMEWORLD} ${GAMEWORLD_HEADER})
|
||||
|
||||
|
|
|
@ -34,8 +34,8 @@ bool ExteriorCellRender::lightOutQuadInLin = false;
|
|||
int ExteriorCellRender::uniqueID = 0;
|
||||
|
||||
ExteriorCellRender::ExteriorCellRender(ESMS::CellStore<MWWorld::RefData> &_cell, MWWorld::Environment& environment,
|
||||
MWScene &_scene)
|
||||
: mCell(_cell), mEnvironment (environment), mScene(_scene), mBase(NULL), mInsert(NULL), mAmbientMode (0)
|
||||
MWScene &_scene, MWWorld::PhysicsSystem *physics)
|
||||
: mCell(_cell), mEnvironment (environment), mScene(_scene), mPhysics(physics), mBase(NULL), mInsert(NULL), mAmbientMode (0)
|
||||
{
|
||||
uniqueID = uniqueID +1;
|
||||
sg = mScene.getMgr()->createStaticGeometry( "sg" + Ogre::StringConverter::toString(uniqueID));
|
||||
|
@ -233,13 +233,15 @@ void ExteriorCellRender::insertMesh(const std::string &mesh)
|
|||
void ExteriorCellRender::insertObjectPhysics()
|
||||
{
|
||||
if (!mInsertMesh.empty())
|
||||
mScene.addObject (mInsert->getName(), mInsertMesh, mInsert->getOrientation(),
|
||||
{
|
||||
mPhysics->addObject (mInsert->getName(), mInsertMesh, mInsert->getOrientation(),
|
||||
mInsert->getScale().x, mInsert->getPosition());
|
||||
}
|
||||
}
|
||||
|
||||
void ExteriorCellRender::insertActorPhysics()
|
||||
{
|
||||
mScene.addActor (mInsert->getName(), mInsertMesh, mInsert->getPosition());
|
||||
mPhysics->addActor (mInsert->getName(), mInsertMesh, mInsert->getPosition());
|
||||
}
|
||||
|
||||
// insert a light related to the most recent insertBegin call.
|
||||
|
@ -348,13 +350,14 @@ void ExteriorCellRender::setAmbientMode()
|
|||
|
||||
void ExteriorCellRender::show()
|
||||
{
|
||||
// FIXME: this one may be the bug
|
||||
mBase = mScene.getRoot()->createChildSceneNode();
|
||||
|
||||
|
||||
configureAmbient();
|
||||
configureFog();
|
||||
|
||||
|
||||
insertCell(mCell, mEnvironment);
|
||||
|
||||
|
||||
sg->build();
|
||||
}
|
||||
|
||||
|
|
|
@ -3,6 +3,7 @@
|
|||
|
||||
#include "cell.hpp"
|
||||
#include "cellimp.hpp"
|
||||
#include "../mwworld/physicssystem.hpp"
|
||||
|
||||
#include "OgreColourValue.h"
|
||||
#include <OgreMath.h>
|
||||
|
@ -49,6 +50,7 @@ namespace MWRender
|
|||
ESMS::CellStore<MWWorld::RefData> &mCell;
|
||||
MWWorld::Environment &mEnvironment;
|
||||
MWScene &mScene;
|
||||
MWWorld::PhysicsSystem *mPhysics;
|
||||
|
||||
/// The scene node that contains all objects belonging to this
|
||||
/// cell.
|
||||
|
@ -101,7 +103,7 @@ namespace MWRender
|
|||
public:
|
||||
|
||||
ExteriorCellRender(ESMS::CellStore<MWWorld::RefData> &_cell, MWWorld::Environment& environment,
|
||||
MWScene &_scene);
|
||||
MWScene &_scene, MWWorld::PhysicsSystem *physics);
|
||||
|
||||
virtual ~ExteriorCellRender() { destroy(); }
|
||||
|
||||
|
|
|
@ -195,13 +195,15 @@ void InteriorCellRender::insertMesh(const std::string &mesh)
|
|||
void InteriorCellRender::insertObjectPhysics()
|
||||
{
|
||||
if (!mInsertMesh.empty())
|
||||
scene.addObject (insert->getName(), mInsertMesh, insert->getOrientation(),
|
||||
{
|
||||
mPhysics->addObject (insert->getName(), mInsertMesh, insert->getOrientation(),
|
||||
insert->getScale().x, insert->getPosition());
|
||||
}
|
||||
}
|
||||
|
||||
void InteriorCellRender::insertActorPhysics()
|
||||
{
|
||||
scene.addActor (insert->getName(), mInsertMesh, insert->getPosition());
|
||||
mPhysics->addActor (insert->getName(), mInsertMesh, insert->getPosition());
|
||||
}
|
||||
|
||||
// insert a light related to the most recent insertBegin call.
|
||||
|
|
|
@ -3,6 +3,7 @@
|
|||
|
||||
#include "cell.hpp"
|
||||
#include "cellimp.hpp"
|
||||
#include "../mwworld/physicssystem.hpp"
|
||||
|
||||
#include "OgreColourValue.h"
|
||||
#include <OgreSceneNode.h>
|
||||
|
@ -48,6 +49,7 @@ namespace MWRender
|
|||
ESMS::CellStore<MWWorld::RefData> &cell;
|
||||
MWWorld::Environment &mEnvironment;
|
||||
MWScene &scene;
|
||||
MWWorld::PhysicsSystem *mPhysics;
|
||||
|
||||
/// The scene node that contains all objects belonging to this
|
||||
/// cell.
|
||||
|
@ -93,8 +95,11 @@ namespace MWRender
|
|||
public:
|
||||
|
||||
InteriorCellRender(ESMS::CellStore<MWWorld::RefData> &_cell, MWWorld::Environment& environment,
|
||||
MWScene &_scene)
|
||||
: cell(_cell), mEnvironment (environment), scene(_scene), base(NULL), insert(NULL), ambientMode (0) {}
|
||||
MWScene &_scene, MWWorld::PhysicsSystem *physics)
|
||||
: cell(_cell), mEnvironment (environment), scene(_scene), base(NULL), insert(NULL), ambientMode (0)
|
||||
{
|
||||
mPhysics = physics;
|
||||
}
|
||||
|
||||
virtual ~InteriorCellRender() { destroy(); }
|
||||
|
||||
|
|
|
@ -11,7 +11,6 @@
|
|||
|
||||
#include "../mwworld/world.hpp" // these includes can be removed once the static-hack is gone
|
||||
#include "../mwworld/ptr.hpp"
|
||||
#include "../mwworld/doingphysics.hpp"
|
||||
#include <components/esm/loadstat.hpp>
|
||||
|
||||
#include "player.hpp"
|
||||
|
@ -43,7 +42,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();
|
||||
|
@ -51,8 +50,6 @@ MWScene::MWScene(OEngine::Render::OgreRenderer &_rend , OEngine::Physic::PhysicE
|
|||
|
||||
|
||||
mPlayer = new MWRender::Player (getCamera(), playerNode->getName());
|
||||
|
||||
mFreeFly = true;
|
||||
}
|
||||
|
||||
MWScene::~MWScene()
|
||||
|
@ -76,149 +73,6 @@ std::pair<std::string, float> MWScene::getFacedHandle (MWWorld::World& world)
|
|||
return eng->rayTest(from,to);
|
||||
}
|
||||
|
||||
void MWScene::doPhysics (float duration, MWWorld::World& world,
|
||||
const std::vector<std::pair<std::string, Ogre::Vector3> >& actors)
|
||||
{
|
||||
// stop changes to world from being reported back to the physics system
|
||||
MWWorld::DoingPhysics scopeGuard;
|
||||
|
||||
//set the DebugRenderingMode. To disable it,set it to 0
|
||||
//eng->setDebugRenderingMode(1);
|
||||
|
||||
//set the walkdirection to 0 (no movement) for every actor)
|
||||
for(std::map<std::string,OEngine::Physic::PhysicActor*>::iterator it = eng->PhysicActorMap.begin(); it != eng->PhysicActorMap.end();it++)
|
||||
{
|
||||
OEngine::Physic::PhysicActor* act = it->second;
|
||||
act->setWalkDirection(btVector3(0,0,0));
|
||||
}
|
||||
|
||||
for (std::vector<std::pair<std::string, Ogre::Vector3> >::const_iterator iter (actors.begin());
|
||||
iter!=actors.end(); ++iter)
|
||||
{
|
||||
OEngine::Physic::PhysicActor* act = eng->getCharacter(iter->first);
|
||||
|
||||
//dirty stuff to get the camera orientation. Must be changed!
|
||||
|
||||
Ogre::SceneNode *sceneNode = rend.getScene()->getSceneNode (iter->first);
|
||||
Ogre::Vector3 dir;
|
||||
Ogre::Node* yawNode = sceneNode->getChildIterator().getNext();
|
||||
Ogre::Node* pitchNode = yawNode->getChildIterator().getNext();
|
||||
if(mFreeFly)
|
||||
{
|
||||
Ogre::Quaternion yawQuat = yawNode->getOrientation();
|
||||
Ogre::Quaternion pitchQuat = pitchNode->getOrientation();
|
||||
Ogre::Vector3 dir1(iter->second.x,iter->second.z,-iter->second.y);
|
||||
dir = 0.07*(yawQuat*pitchQuat*dir1);
|
||||
}
|
||||
else
|
||||
{
|
||||
Ogre::Quaternion quat = yawNode->getOrientation();
|
||||
Ogre::Vector3 dir1(iter->second.x,iter->second.z,-iter->second.y);
|
||||
dir = 0.025*(quat*dir1);
|
||||
}
|
||||
|
||||
//set the walk direction
|
||||
act->setWalkDirection(btVector3(dir.x,-dir.z,dir.y));
|
||||
}
|
||||
eng->stepSimulation(duration);
|
||||
|
||||
for(std::map<std::string,OEngine::Physic::PhysicActor*>::iterator it = eng->PhysicActorMap.begin(); it != eng->PhysicActorMap.end();it++)
|
||||
{
|
||||
OEngine::Physic::PhysicActor* act = it->second;
|
||||
btVector3 newPos = act->getPosition();
|
||||
MWWorld::Ptr ptr = world.getPtrViaHandle (it->first);
|
||||
world.moveObject (ptr, newPos.x(), newPos.y(), newPos.z());
|
||||
}
|
||||
}
|
||||
|
||||
void MWScene::addObject (const std::string& handle, const std::string& mesh,
|
||||
const Ogre::Quaternion& rotation, float scale, const Ogre::Vector3& position)
|
||||
{
|
||||
OEngine::Physic::RigidBody* body = eng->createRigidBody(mesh,handle);
|
||||
eng->addRigidBody(body);
|
||||
btTransform tr;
|
||||
tr.setOrigin(btVector3(position.x,position.y,position.z));
|
||||
tr.setRotation(btQuaternion(rotation.x,rotation.y,rotation.z,rotation.w));
|
||||
body->setWorldTransform(tr);
|
||||
}
|
||||
|
||||
void MWScene::addActor (const std::string& handle, const std::string& mesh,
|
||||
const Ogre::Vector3& position)
|
||||
{
|
||||
//TODO:optimize this. Searching the std::map isn't very efficient i think.
|
||||
eng->addCharacter(handle);
|
||||
OEngine::Physic::PhysicActor* act = eng->getCharacter(handle);
|
||||
act->setPosition(btVector3(position.x,position.y,position.z));
|
||||
}
|
||||
|
||||
void MWScene::removeObject (const std::string& handle)
|
||||
{
|
||||
//TODO:check if actor???
|
||||
eng->removeCharacter(handle);
|
||||
eng->removeRigidBody(handle);
|
||||
eng->deleteRigidBody(handle);
|
||||
}
|
||||
|
||||
void MWScene::moveObject (const std::string& handle, const Ogre::Vector3& position, bool updatePhysics)
|
||||
{
|
||||
rend.getScene()->getSceneNode(handle)->setPosition(position);
|
||||
|
||||
if(updatePhysics)//TODO: is it an actor? Done?
|
||||
{
|
||||
if (OEngine::Physic::RigidBody* body = eng->getRigidBody(handle))
|
||||
{
|
||||
// TODO very dirty hack to avoid crash during setup -> needs cleaning up to allow
|
||||
// start positions others than 0, 0, 0
|
||||
btTransform tr = body->getWorldTransform();
|
||||
tr.setOrigin(btVector3(position.x,position.y,position.z));
|
||||
body->setWorldTransform(tr);
|
||||
}
|
||||
if (OEngine::Physic::PhysicActor* act = eng->getCharacter(handle))
|
||||
{
|
||||
// TODO very dirty hack to avoid crash during setup -> needs cleaning up to allow
|
||||
// start positions others than 0, 0, 0
|
||||
act->setPosition(btVector3(position.x,position.y,position.z));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void MWScene::rotateObject (const std::string& handle, const Ogre::Quaternion& rotation)
|
||||
{
|
||||
}
|
||||
|
||||
void MWScene::scaleObject (const std::string& handle, float scale)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
bool MWScene::toggleCollisionMode()
|
||||
{
|
||||
for(std::map<std::string,OEngine::Physic::PhysicActor*>::iterator it = eng->PhysicActorMap.begin(); it != eng->PhysicActorMap.end();it++)
|
||||
{
|
||||
OEngine::Physic::PhysicActor* act = it->second;
|
||||
bool cmode = act->getCollisionMode();
|
||||
if(cmode)
|
||||
{
|
||||
act->enableCollisions(false);
|
||||
act->setGravity(0.);
|
||||
act->setVerticalVelocity(0);
|
||||
mFreeFly = true;
|
||||
return false;
|
||||
}
|
||||
else
|
||||
{
|
||||
mFreeFly = false;
|
||||
act->enableCollisions(true);
|
||||
act->setGravity(4.);
|
||||
act->setVerticalVelocity(0);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return false; // This should never happen, but it shall not bother us now, since
|
||||
// this part of the code needs a rewrite anyway.
|
||||
}
|
||||
|
||||
bool MWScene::toggleRenderMode (int mode)
|
||||
{
|
||||
switch (mode)
|
||||
|
|
|
@ -44,8 +44,6 @@ namespace MWRender
|
|||
|
||||
MWRender::Player *mPlayer;
|
||||
|
||||
bool mFreeFly;
|
||||
|
||||
public:
|
||||
|
||||
MWScene (OEngine::Render::OgreRenderer &_rend , OEngine::Physic::PhysicEngine* physEng);
|
||||
|
@ -65,35 +63,6 @@ namespace MWRender
|
|||
/// can be faced
|
||||
std::pair<std::string, float> getFacedHandle (MWWorld::World& world);
|
||||
|
||||
/// Run physics simulation and modify \a world accordingly.
|
||||
void doPhysics (float duration, MWWorld::World& world,
|
||||
const std::vector<std::pair<std::string, Ogre::Vector3> >& actors);
|
||||
|
||||
/// Add object to physics system.
|
||||
void addObject (const std::string& handle, const std::string& mesh,
|
||||
const Ogre::Quaternion& rotation, float scale, const Ogre::Vector3& position);
|
||||
|
||||
/// Add actor to physics system.
|
||||
void addActor (const std::string& handle, const std::string& mesh,
|
||||
const Ogre::Vector3& position);
|
||||
|
||||
/// Remove object from physic systems.
|
||||
void removeObject (const std::string& handle);
|
||||
|
||||
/// Move object.
|
||||
void moveObject (const std::string& handle, const Ogre::Vector3& position, bool updatePhysics);
|
||||
|
||||
/// Change object's orientation.
|
||||
void rotateObject (const std::string& handle, const Ogre::Quaternion& rotation);
|
||||
|
||||
/// Change object's scale.
|
||||
void scaleObject (const std::string& handle, float scale);
|
||||
|
||||
/// Toggle collision mode for player. If disabled player object should ignore
|
||||
/// collisions and gravity.
|
||||
/// \return Resulting mode
|
||||
bool toggleCollisionMode();
|
||||
|
||||
/// Toggle render mode
|
||||
/// \todo Using an int instead of a enum here to avoid cyclic includes. Will be fixed
|
||||
/// when the mw*-refactoring is done.
|
||||
|
|
52
apps/openmw/mwrender/rendering_manager.cpp
Normal file
52
apps/openmw/mwrender/rendering_manager.cpp
Normal file
|
@ -0,0 +1,52 @@
|
|||
#include "rendering_manager.hpp"
|
||||
|
||||
namespace MWRender {
|
||||
|
||||
RenderingManager::RenderingManager (SkyManager *skyManager) :
|
||||
mSkyManager(skyManager)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
RenderingManager::~RenderingManager ()
|
||||
{
|
||||
delete mSkyManager;
|
||||
}
|
||||
|
||||
void RenderingManager::skyEnable ()
|
||||
{
|
||||
mSkyManager->enable();
|
||||
}
|
||||
|
||||
void RenderingManager::skyDisable ()
|
||||
{
|
||||
mSkyManager->disable();
|
||||
}
|
||||
|
||||
void RenderingManager::skySetHour (double hour)
|
||||
{
|
||||
mSkyManager->setHour(hour);
|
||||
}
|
||||
|
||||
|
||||
void RenderingManager::skySetDate (int day, int month)
|
||||
{
|
||||
mSkyManager->setDate(day, month);
|
||||
}
|
||||
|
||||
int RenderingManager::skyGetMasserPhase() const
|
||||
{
|
||||
return mSkyManager->getMasserPhase();
|
||||
}
|
||||
|
||||
int RenderingManager::skyGetSecundaPhase() const
|
||||
{
|
||||
return mSkyManager->getSecundaPhase();
|
||||
}
|
||||
|
||||
void RenderingManager::skySetMoonColour (bool red)
|
||||
{
|
||||
mSkyManager->setMoonColour(red);
|
||||
}
|
||||
|
||||
}
|
51
apps/openmw/mwrender/rendering_manager.hpp
Normal file
51
apps/openmw/mwrender/rendering_manager.hpp
Normal file
|
@ -0,0 +1,51 @@
|
|||
#ifndef _GAME_RENDERING_MANAGER_H
|
||||
#define _GAME_RENDERING_MANAGER_H
|
||||
|
||||
|
||||
#include "sky.hpp"
|
||||
|
||||
#include "../mwworld/ptr.hpp"
|
||||
#include <openengine/ogre/renderer.hpp>
|
||||
#include <openengine/bullet/physic.hpp>
|
||||
|
||||
namespace MWRender
|
||||
{
|
||||
|
||||
class RenderingManager {
|
||||
public:
|
||||
RenderingManager(SkyManager *skyManager);
|
||||
~RenderingManager();
|
||||
|
||||
void removeCell (MWWorld::Ptr::CellStore *store); // TODO do we want this?
|
||||
|
||||
void addObject (const MWWorld::Ptr& ptr, MWWorld::Ptr::CellStore *store);
|
||||
void removeObject (const MWWorld::Ptr& ptr, MWWorld::Ptr::CellStore *store);
|
||||
|
||||
void moveObject (const MWWorld::Ptr& ptr, const Ogre::Vector3& position);
|
||||
void scaleObject (const MWWorld::Ptr& ptr, const Ogre::Vector3& scale);
|
||||
void rotateObject (const MWWorld::Ptr& ptr, const::Ogre::Quaternion& orientation);
|
||||
void moveObjectToCell (const MWWorld::Ptr& ptr, const Ogre::Vector3& position, MWWorld::Ptr::CellStore *store);
|
||||
|
||||
void setPhysicsDebugRendering (bool);
|
||||
bool getPhysicsDebugRendering() const;
|
||||
|
||||
void update (float duration);
|
||||
|
||||
void skyEnable ();
|
||||
void skyDisable ();
|
||||
void skySetHour (double hour);
|
||||
void skySetDate (int day, int month);
|
||||
int skyGetMasserPhase() const;
|
||||
int skyGetSecundaPhase() const;
|
||||
void skySetMoonColour (bool red);
|
||||
|
||||
private:
|
||||
|
||||
SkyManager* mSkyManager;
|
||||
|
||||
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
#endif
|
198
apps/openmw/mwworld/cells.cpp
Normal file
198
apps/openmw/mwworld/cells.cpp
Normal file
|
@ -0,0 +1,198 @@
|
|||
#include "cells.hpp"
|
||||
|
||||
#include <cctype>
|
||||
|
||||
#include <algorithm>
|
||||
|
||||
MWWorld::Ptr::CellStore *MWWorld::Cells::getCellStore (const ESM::Cell *cell)
|
||||
{
|
||||
if (cell->data.flags & ESM::Cell::Interior)
|
||||
{
|
||||
std::map<std::string, Ptr::CellStore>::iterator result = mInteriors.find (cell->name);
|
||||
|
||||
if (result==mInteriors.end())
|
||||
{
|
||||
result = mInteriors.insert (std::make_pair (cell->name, Ptr::CellStore (cell))).first;
|
||||
}
|
||||
|
||||
return &result->second;
|
||||
}
|
||||
else
|
||||
{
|
||||
std::map<std::pair<int, int>, Ptr::CellStore>::iterator result =
|
||||
mExteriors.find (std::make_pair (cell->data.gridX, cell->data.gridY));
|
||||
|
||||
if (result==mExteriors.end())
|
||||
{
|
||||
result = mExteriors.insert (std::make_pair (
|
||||
std::make_pair (cell->data.gridX, cell->data.gridY), Ptr::CellStore (cell))).first;
|
||||
|
||||
}
|
||||
|
||||
return &result->second;
|
||||
}
|
||||
}
|
||||
|
||||
MWWorld::Cells::Cells (const ESMS::ESMStore& store, ESM::ESMReader& reader)
|
||||
: mStore (store), mReader (reader) {}
|
||||
|
||||
MWWorld::Ptr::CellStore *MWWorld::Cells::getExterior (int x, int y)
|
||||
{
|
||||
std::map<std::pair<int, int>, Ptr::CellStore>::iterator result =
|
||||
mExteriors.find (std::make_pair (x, y));
|
||||
|
||||
if (result==mExteriors.end())
|
||||
{
|
||||
const ESM::Cell *cell = mStore.cells.findExt (x, y);
|
||||
|
||||
result = mExteriors.insert (std::make_pair (
|
||||
std::make_pair (x, y), Ptr::CellStore (cell))).first;
|
||||
|
||||
result->second.load (mStore, mReader);
|
||||
}
|
||||
|
||||
return &result->second;
|
||||
}
|
||||
|
||||
MWWorld::Ptr::CellStore *MWWorld::Cells::getInterior (const std::string& name)
|
||||
{
|
||||
std::map<std::string, Ptr::CellStore>::iterator result = mInteriors.find (name);
|
||||
|
||||
if (result==mInteriors.end())
|
||||
{
|
||||
const ESM::Cell *cell = mStore.cells.findInt (name);
|
||||
|
||||
result = mInteriors.insert (std::make_pair (name, Ptr::CellStore (cell))).first;
|
||||
|
||||
result->second.load (mStore, mReader);
|
||||
}
|
||||
|
||||
return &result->second;
|
||||
}
|
||||
|
||||
MWWorld::Ptr MWWorld::Cells::getPtr (const std::string& name, Ptr::CellStore& cell)
|
||||
{
|
||||
if (cell.mState==Ptr::CellStore::State_Unloaded)
|
||||
cell.preload (mStore, mReader);
|
||||
|
||||
if (cell.mState==Ptr::CellStore::State_Preloaded)
|
||||
{
|
||||
std::string lowerCase;
|
||||
|
||||
std::transform (name.begin(), name.end(), std::back_inserter (lowerCase),
|
||||
(int(*)(int)) std::tolower);
|
||||
|
||||
if (std::binary_search (cell.mIds.begin(), cell.mIds.end(), lowerCase))
|
||||
cell.load (mStore, mReader);
|
||||
else
|
||||
return Ptr();
|
||||
}
|
||||
|
||||
if (ESMS::LiveCellRef<ESM::Activator, RefData> *ref = cell.activators.find (name))
|
||||
return Ptr (ref, &cell);
|
||||
|
||||
if (ESMS::LiveCellRef<ESM::Potion, RefData> *ref = cell.potions.find (name))
|
||||
return Ptr (ref, &cell);
|
||||
|
||||
if (ESMS::LiveCellRef<ESM::Apparatus, RefData> *ref = cell.appas.find (name))
|
||||
return Ptr (ref, &cell);
|
||||
|
||||
if (ESMS::LiveCellRef<ESM::Armor, RefData> *ref = cell.armors.find (name))
|
||||
return Ptr (ref, &cell);
|
||||
|
||||
if (ESMS::LiveCellRef<ESM::Book, RefData> *ref = cell.books.find (name))
|
||||
return Ptr (ref, &cell);
|
||||
|
||||
if (ESMS::LiveCellRef<ESM::Clothing, RefData> *ref = cell.clothes.find (name))
|
||||
return Ptr (ref, &cell);
|
||||
|
||||
if (ESMS::LiveCellRef<ESM::Container, RefData> *ref = cell.containers.find (name))
|
||||
return Ptr (ref, &cell);
|
||||
|
||||
if (ESMS::LiveCellRef<ESM::Creature, RefData> *ref = cell.creatures.find (name))
|
||||
return Ptr (ref, &cell);
|
||||
|
||||
if (ESMS::LiveCellRef<ESM::Door, RefData> *ref = cell.doors.find (name))
|
||||
return Ptr (ref, &cell);
|
||||
|
||||
if (ESMS::LiveCellRef<ESM::Ingredient, RefData> *ref = cell.ingreds.find (name))
|
||||
return Ptr (ref, &cell);
|
||||
|
||||
if (ESMS::LiveCellRef<ESM::CreatureLevList, RefData> *ref = cell.creatureLists.find (name))
|
||||
return Ptr (ref, &cell);
|
||||
|
||||
if (ESMS::LiveCellRef<ESM::ItemLevList, RefData> *ref = cell.itemLists.find (name))
|
||||
return Ptr (ref, &cell);
|
||||
|
||||
if (ESMS::LiveCellRef<ESM::Light, RefData> *ref = cell.lights.find (name))
|
||||
return Ptr (ref, &cell);
|
||||
|
||||
if (ESMS::LiveCellRef<ESM::Tool, RefData> *ref = cell.lockpicks.find (name))
|
||||
return Ptr (ref, &cell);
|
||||
|
||||
if (ESMS::LiveCellRef<ESM::Miscellaneous, RefData> *ref = cell.miscItems.find (name))
|
||||
return Ptr (ref, &cell);
|
||||
|
||||
if (ESMS::LiveCellRef<ESM::NPC, RefData> *ref = cell.npcs.find (name))
|
||||
return Ptr (ref, &cell);
|
||||
|
||||
if (ESMS::LiveCellRef<ESM::Probe, RefData> *ref = cell.probes.find (name))
|
||||
return Ptr (ref, &cell);
|
||||
|
||||
if (ESMS::LiveCellRef<ESM::Repair, RefData> *ref = cell.repairs.find (name))
|
||||
return Ptr (ref, &cell);
|
||||
|
||||
if (ESMS::LiveCellRef<ESM::Static, RefData> *ref = cell.statics.find (name))
|
||||
return Ptr (ref, &cell);
|
||||
|
||||
if (ESMS::LiveCellRef<ESM::Weapon, RefData> *ref = cell.weapons.find (name))
|
||||
return Ptr (ref, &cell);
|
||||
|
||||
return Ptr();
|
||||
}
|
||||
|
||||
MWWorld::Ptr MWWorld::Cells::getPtr (const std::string& name)
|
||||
{
|
||||
// First check cells that are already listed
|
||||
for (std::map<std::string, Ptr::CellStore>::iterator iter = mInteriors.begin();
|
||||
iter!=mInteriors.end(); ++iter)
|
||||
{
|
||||
Ptr ptr = getPtr (name, iter->second);
|
||||
if (!ptr.isEmpty())
|
||||
return ptr;
|
||||
}
|
||||
|
||||
for (std::map<std::pair<int, int>, Ptr::CellStore>::iterator iter = mExteriors.begin();
|
||||
iter!=mExteriors.end(); ++iter)
|
||||
{
|
||||
Ptr ptr = getPtr (name, iter->second);
|
||||
if (!ptr.isEmpty())
|
||||
return ptr;
|
||||
}
|
||||
|
||||
// Now try the other cells
|
||||
for (ESMS::CellList::IntCells::const_iterator iter = mStore.cells.intCells.begin();
|
||||
iter!=mStore.cells.intCells.end(); ++iter)
|
||||
{
|
||||
Ptr::CellStore *cellStore = getCellStore (iter->second);
|
||||
|
||||
Ptr ptr = getPtr (name, *cellStore);
|
||||
|
||||
if (!ptr.isEmpty())
|
||||
return ptr;
|
||||
}
|
||||
|
||||
for (ESMS::CellList::ExtCells::const_iterator iter = mStore.cells.extCells.begin();
|
||||
iter!=mStore.cells.extCells.end(); ++iter)
|
||||
{
|
||||
Ptr::CellStore *cellStore = getCellStore (iter->second);
|
||||
|
||||
Ptr ptr = getPtr (name, *cellStore);
|
||||
|
||||
if (!ptr.isEmpty())
|
||||
return ptr;
|
||||
}
|
||||
|
||||
// giving up
|
||||
return Ptr();
|
||||
}
|
48
apps/openmw/mwworld/cells.hpp
Normal file
48
apps/openmw/mwworld/cells.hpp
Normal file
|
@ -0,0 +1,48 @@
|
|||
#ifndef GAME_MWWORLD_CELLS_H
|
||||
#define GAME_MWWORLD_CELLS_H
|
||||
|
||||
#include <map>
|
||||
#include <string>
|
||||
|
||||
#include "ptr.hpp"
|
||||
|
||||
namespace ESM
|
||||
{
|
||||
class ESMReader;
|
||||
}
|
||||
|
||||
namespace ESM
|
||||
{
|
||||
class ESMStore;
|
||||
}
|
||||
|
||||
namespace MWWorld
|
||||
{
|
||||
/// \brief Cell container
|
||||
class Cells
|
||||
{
|
||||
const ESMS::ESMStore& mStore;
|
||||
ESM::ESMReader& mReader;
|
||||
std::map<std::string, Ptr::CellStore> mInteriors;
|
||||
std::map<std::pair<int, int>, Ptr::CellStore> mExteriors;
|
||||
|
||||
Cells (const Cells&);
|
||||
Cells& operator= (const Cells&);
|
||||
|
||||
Ptr::CellStore *getCellStore (const ESM::Cell *cell);
|
||||
|
||||
public:
|
||||
|
||||
Cells (const ESMS::ESMStore& store, ESM::ESMReader& reader);
|
||||
|
||||
Ptr::CellStore *getExterior (int x, int y);
|
||||
|
||||
Ptr::CellStore *getInterior (const std::string& name);
|
||||
|
||||
Ptr getPtr (const std::string& name, Ptr::CellStore& cellStore);
|
||||
|
||||
Ptr getPtr (const std::string& name);
|
||||
};
|
||||
}
|
||||
|
||||
#endif
|
|
@ -1,33 +0,0 @@
|
|||
|
||||
#include "doingphysics.hpp"
|
||||
|
||||
namespace MWWorld
|
||||
{
|
||||
int DoingPhysics::sCounter = 0;
|
||||
int DoingPhysics::sSuppress = 0;
|
||||
|
||||
DoingPhysics::DoingPhysics()
|
||||
{
|
||||
++sCounter;
|
||||
}
|
||||
|
||||
DoingPhysics::~DoingPhysics()
|
||||
{
|
||||
--sCounter;
|
||||
}
|
||||
|
||||
bool DoingPhysics::isDoingPhysics()
|
||||
{
|
||||
return sCounter>0 && sSuppress==0;
|
||||
}
|
||||
|
||||
SuppressDoingPhysics::SuppressDoingPhysics()
|
||||
{
|
||||
++DoingPhysics::sSuppress;
|
||||
}
|
||||
|
||||
SuppressDoingPhysics::~SuppressDoingPhysics()
|
||||
{
|
||||
--DoingPhysics::sSuppress;
|
||||
}
|
||||
}
|
|
@ -1,46 +0,0 @@
|
|||
#ifndef GAME_MWWORLD_DOINGPHYSICS_H
|
||||
#define GAME_MWWORLD_DOINGPHYSICS_H
|
||||
|
||||
namespace MWWorld
|
||||
{
|
||||
class SuppressDoingPhysics;
|
||||
|
||||
/// Scope guard for blocking physics updates during physics simulation.
|
||||
class DoingPhysics
|
||||
{
|
||||
static int sCounter;
|
||||
static int sSuppress;
|
||||
|
||||
private:
|
||||
|
||||
DoingPhysics (const DoingPhysics&);
|
||||
DoingPhysics& operator= (const DoingPhysics&);
|
||||
|
||||
public:
|
||||
|
||||
DoingPhysics();
|
||||
|
||||
~DoingPhysics();
|
||||
|
||||
static bool isDoingPhysics();
|
||||
|
||||
friend class SuppressDoingPhysics;
|
||||
};
|
||||
|
||||
/// Scope guard for temporarily lifting the block issues by DoingPhysics
|
||||
class SuppressDoingPhysics
|
||||
{
|
||||
private:
|
||||
|
||||
SuppressDoingPhysics (const SuppressDoingPhysics&);
|
||||
SuppressDoingPhysics& operator= (const SuppressDoingPhysics&);
|
||||
|
||||
public:
|
||||
|
||||
SuppressDoingPhysics();
|
||||
|
||||
~SuppressDoingPhysics();
|
||||
};
|
||||
}
|
||||
|
||||
#endif
|
164
apps/openmw/mwworld/physicssystem.cpp
Normal file
164
apps/openmw/mwworld/physicssystem.cpp
Normal file
|
@ -0,0 +1,164 @@
|
|||
#include "physicssystem.hpp"
|
||||
#include "../mwworld/ptr.hpp"
|
||||
#include "../mwworld/world.hpp" // FIXME
|
||||
|
||||
#include "OgreRoot.h"
|
||||
#include "OgreRenderWindow.h"
|
||||
#include "OgreSceneManager.h"
|
||||
#include "OgreViewport.h"
|
||||
#include "OgreCamera.h"
|
||||
#include "OgreTextureManager.h"
|
||||
|
||||
|
||||
namespace MWWorld
|
||||
{
|
||||
|
||||
PhysicsSystem::PhysicsSystem(OEngine::Render::OgreRenderer &_rend , OEngine::Physic::PhysicEngine* physEng) :
|
||||
mRender(_rend), mEngine(physEng), mFreeFly (true)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
PhysicsSystem::~PhysicsSystem()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
std::vector< std::pair<std::string, Ogre::Vector3> > PhysicsSystem::doPhysics (float duration,
|
||||
const std::vector<std::pair<std::string, Ogre::Vector3> >& actors)
|
||||
{
|
||||
//set the DebugRenderingMode. To disable it,set it to 0
|
||||
//eng->setDebugRenderingMode(1);
|
||||
|
||||
//set the walkdirection to 0 (no movement) for every actor)
|
||||
for(std::map<std::string,OEngine::Physic::PhysicActor*>::iterator it = mEngine->PhysicActorMap.begin(); it != mEngine->PhysicActorMap.end();it++)
|
||||
{
|
||||
OEngine::Physic::PhysicActor* act = it->second;
|
||||
act->setWalkDirection(btVector3(0,0,0));
|
||||
}
|
||||
|
||||
for (std::vector<std::pair<std::string, Ogre::Vector3> >::const_iterator iter (actors.begin());
|
||||
iter!=actors.end(); ++iter)
|
||||
{
|
||||
OEngine::Physic::PhysicActor* act = mEngine->getCharacter(iter->first);
|
||||
|
||||
//dirty stuff to get the camera orientation. Must be changed!
|
||||
|
||||
Ogre::SceneNode *sceneNode = mRender.getScene()->getSceneNode (iter->first);
|
||||
Ogre::Vector3 dir;
|
||||
Ogre::Node* yawNode = sceneNode->getChildIterator().getNext();
|
||||
Ogre::Node* pitchNode = yawNode->getChildIterator().getNext();
|
||||
if(mFreeFly)
|
||||
{
|
||||
Ogre::Quaternion yawQuat = yawNode->getOrientation();
|
||||
Ogre::Quaternion pitchQuat = pitchNode->getOrientation();
|
||||
Ogre::Vector3 dir1(iter->second.x,iter->second.z,-iter->second.y);
|
||||
dir = 0.07*(yawQuat*pitchQuat*dir1);
|
||||
}
|
||||
else
|
||||
{
|
||||
Ogre::Quaternion quat = yawNode->getOrientation();
|
||||
Ogre::Vector3 dir1(iter->second.x,iter->second.z,-iter->second.y);
|
||||
dir = 0.025*(quat*dir1);
|
||||
}
|
||||
|
||||
//set the walk direction
|
||||
act->setWalkDirection(btVector3(dir.x,-dir.z,dir.y));
|
||||
}
|
||||
mEngine->stepSimulation(duration);
|
||||
|
||||
std::vector< std::pair<std::string, Ogre::Vector3> > response;
|
||||
for(std::map<std::string,OEngine::Physic::PhysicActor*>::iterator it = mEngine->PhysicActorMap.begin(); it != mEngine->PhysicActorMap.end();it++)
|
||||
{
|
||||
btVector3 newPos = it->second->getPosition();
|
||||
Ogre::Vector3 coord(newPos.x(), newPos.y(), newPos.z());
|
||||
|
||||
response.push_back(std::pair<std::string, Ogre::Vector3>(it->first, coord));
|
||||
}
|
||||
return response;
|
||||
}
|
||||
|
||||
void PhysicsSystem::addObject (const std::string& handle, const std::string& mesh,
|
||||
const Ogre::Quaternion& rotation, float scale, const Ogre::Vector3& position)
|
||||
{
|
||||
OEngine::Physic::RigidBody* body = mEngine->createRigidBody(mesh,handle);
|
||||
mEngine->addRigidBody(body);
|
||||
btTransform tr;
|
||||
tr.setOrigin(btVector3(position.x,position.y,position.z));
|
||||
tr.setRotation(btQuaternion(rotation.x,rotation.y,rotation.z,rotation.w));
|
||||
body->setWorldTransform(tr);
|
||||
}
|
||||
|
||||
void PhysicsSystem::addActor (const std::string& handle, const std::string& mesh,
|
||||
const Ogre::Vector3& position)
|
||||
{
|
||||
//TODO:optimize this. Searching the std::map isn't very efficient i think.
|
||||
mEngine->addCharacter(handle);
|
||||
OEngine::Physic::PhysicActor* act = mEngine->getCharacter(handle);
|
||||
act->setPosition(btVector3(position.x,position.y,position.z));
|
||||
}
|
||||
|
||||
void PhysicsSystem::removeObject (const std::string& handle)
|
||||
{
|
||||
//TODO:check if actor???
|
||||
mEngine->removeCharacter(handle);
|
||||
mEngine->removeRigidBody(handle);
|
||||
mEngine->deleteRigidBody(handle);
|
||||
}
|
||||
|
||||
void PhysicsSystem::moveObject (const std::string& handle, const Ogre::Vector3& position)
|
||||
{
|
||||
if (OEngine::Physic::RigidBody* body = mEngine->getRigidBody(handle))
|
||||
{
|
||||
// TODO very dirty hack to avoid crash during setup -> needs cleaning up to allow
|
||||
// start positions others than 0, 0, 0
|
||||
btTransform tr = body->getWorldTransform();
|
||||
tr.setOrigin(btVector3(position.x,position.y,position.z));
|
||||
body->setWorldTransform(tr);
|
||||
}
|
||||
if (OEngine::Physic::PhysicActor* act = mEngine->getCharacter(handle))
|
||||
{
|
||||
// TODO very dirty hack to avoid crash during setup -> needs cleaning up to allow
|
||||
// start positions others than 0, 0, 0
|
||||
act->setPosition(btVector3(position.x,position.y,position.z));
|
||||
}
|
||||
}
|
||||
|
||||
void PhysicsSystem::rotateObject (const std::string& handle, const Ogre::Quaternion& rotation)
|
||||
{
|
||||
}
|
||||
|
||||
void PhysicsSystem::scaleObject (const std::string& handle, float scale)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
bool PhysicsSystem::toggleCollisionMode()
|
||||
{
|
||||
for(std::map<std::string,OEngine::Physic::PhysicActor*>::iterator it = mEngine->PhysicActorMap.begin(); it != mEngine->PhysicActorMap.end();it++)
|
||||
{
|
||||
OEngine::Physic::PhysicActor* act = it->second;
|
||||
bool cmode = act->getCollisionMode();
|
||||
if(cmode)
|
||||
{
|
||||
act->enableCollisions(false);
|
||||
act->setGravity(0.);
|
||||
act->setVerticalVelocity(0);
|
||||
mFreeFly = true;
|
||||
return false;
|
||||
}
|
||||
else
|
||||
{
|
||||
mFreeFly = false;
|
||||
act->enableCollisions(true);
|
||||
act->setGravity(4.);
|
||||
act->setVerticalVelocity(0);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return false; // This should never happen, but it shall not bother us now, since
|
||||
// this part of the code needs a rewrite anyway.
|
||||
}
|
||||
|
||||
}
|
47
apps/openmw/mwworld/physicssystem.hpp
Normal file
47
apps/openmw/mwworld/physicssystem.hpp
Normal file
|
@ -0,0 +1,47 @@
|
|||
#ifndef GAME_MWWORLD_PHYSICSSYSTEM_H
|
||||
#define GAME_MWWORLD_PHYSICSSYSTEM_H
|
||||
|
||||
#include <vector>
|
||||
#include <openengine/ogre/renderer.hpp>
|
||||
#include <openengine/bullet/physic.hpp>
|
||||
|
||||
namespace MWWorld
|
||||
{
|
||||
|
||||
class PhysicsSystem
|
||||
{
|
||||
public:
|
||||
PhysicsSystem (OEngine::Render::OgreRenderer &_rend , OEngine::Physic::PhysicEngine* physEng);
|
||||
~PhysicsSystem ();
|
||||
|
||||
std::vector< std::pair<std::string, Ogre::Vector3> > doPhysics (float duration,
|
||||
const std::vector<std::pair<std::string, Ogre::Vector3> >& actors);
|
||||
|
||||
void addObject (const std::string& handle, const std::string& mesh,
|
||||
const Ogre::Quaternion& rotation, float scale, const Ogre::Vector3& position);
|
||||
|
||||
void addActor (const std::string& handle, const std::string& mesh,
|
||||
const Ogre::Vector3& position);
|
||||
|
||||
void removeObject (const std::string& handle);
|
||||
|
||||
void moveObject (const std::string& handle, const Ogre::Vector3& position);
|
||||
|
||||
void rotateObject (const std::string& handle, const Ogre::Quaternion& rotation);
|
||||
|
||||
void scaleObject (const std::string& handle, float scale);
|
||||
|
||||
bool toggleCollisionMode();
|
||||
|
||||
private:
|
||||
OEngine::Render::OgreRenderer &mRender;
|
||||
OEngine::Physic::PhysicEngine* mEngine;
|
||||
bool mFreeFly;
|
||||
|
||||
PhysicsSystem (const PhysicsSystem&);
|
||||
PhysicsSystem& operator= (const PhysicsSystem&);
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
#endif
|
|
@ -13,11 +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));
|
||||
}
|
||||
|
||||
|
@ -26,15 +29,10 @@ namespace MWWorld
|
|||
delete mClass;
|
||||
}
|
||||
|
||||
void Player::setPos(float x, float y, float z, bool updateCamera)
|
||||
void Player::setPos(float x, float y, float z)
|
||||
{
|
||||
/// \todo This fcuntion should be removed during the mwrender-refactoring.
|
||||
mWorld.moveObject (getPlayer(), x, y, z);
|
||||
|
||||
if (updateCamera)
|
||||
mRenderer->getCamera()->setPosition (Ogre::Vector3 (
|
||||
mPlayer.ref.pos.pos[0],
|
||||
mPlayer.ref.pos.pos[2],
|
||||
-mPlayer.ref.pos.pos[1]));
|
||||
}
|
||||
|
||||
void Player::setClass (const ESM::Class& class_)
|
||||
|
|
|
@ -39,7 +39,7 @@ namespace MWWorld
|
|||
~Player();
|
||||
|
||||
/// Set the player position. Uses Morrowind coordinates.
|
||||
void setPos(float _x, float _y, float _z, bool updateCamera = false);
|
||||
void setPos(float x, float y, float z);
|
||||
|
||||
void setCell (MWWorld::Ptr::CellStore *cellStore)
|
||||
{
|
||||
|
|
273
apps/openmw/mwworld/scene.cpp
Normal file
273
apps/openmw/mwworld/scene.cpp
Normal file
|
@ -0,0 +1,273 @@
|
|||
#include "scene.hpp"
|
||||
#include "world.hpp"
|
||||
|
||||
#include "../mwrender/interior.hpp"
|
||||
#include "../mwrender/exterior.hpp"
|
||||
|
||||
#include "../mwmechanics/mechanicsmanager.hpp"
|
||||
|
||||
#include "../mwsound/soundmanager.hpp"
|
||||
|
||||
#include "ptr.hpp"
|
||||
#include "environment.hpp"
|
||||
#include "player.hpp"
|
||||
#include "class.hpp"
|
||||
|
||||
#include "cellfunctors.hpp"
|
||||
|
||||
namespace {
|
||||
|
||||
template<typename T>
|
||||
void insertCellRefList (T& cellRefList, ESMS::CellStore<MWWorld::RefData> &cell)
|
||||
{
|
||||
if (!cellRefList.list.empty())
|
||||
{
|
||||
//const MWWorld::Class& class_ = MWWorld::Class::get (MWWorld::Ptr (&*cellRefList.list.begin(), &cell));
|
||||
|
||||
for (typename T::List::iterator it = cellRefList.list.begin();
|
||||
it != cellRefList.list.end(); it++)
|
||||
{
|
||||
if (it->mData.getCount() || it->mData.isEnabled())
|
||||
{
|
||||
MWWorld::Ptr ptr (&*it, &cell);
|
||||
/* TODO: call
|
||||
* RenderingManager.insertObject
|
||||
* class_.insertObjectPhysic
|
||||
* class_.insertObjectMechanics
|
||||
*/
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
namespace MWWorld
|
||||
{
|
||||
|
||||
void Scene::unloadCell (CellRenderCollection::iterator iter)
|
||||
{
|
||||
ListHandles functor;
|
||||
iter->first->forEach<ListHandles>(functor);
|
||||
|
||||
{ // silence annoying g++ warning
|
||||
for (std::vector<std::string>::const_iterator iter (functor.mHandles.begin());
|
||||
iter!=functor.mHandles.end(); ++iter)
|
||||
mPhysics->removeObject (*iter);
|
||||
}
|
||||
|
||||
mWorld->removeScripts (iter->first);
|
||||
|
||||
mEnvironment.mMechanicsManager->dropActors (iter->first);
|
||||
mEnvironment.mSoundManager->stopSound (iter->first);
|
||||
delete iter->second;
|
||||
mActiveCells.erase (iter);
|
||||
}
|
||||
|
||||
void Scene::loadCell (Ptr::CellStore *cell, MWRender::CellRender *render)
|
||||
{
|
||||
// register local scripts
|
||||
mWorld->insertInteriorScripts (*cell);
|
||||
|
||||
// This connects the cell data with the rendering scene.
|
||||
std::pair<CellRenderCollection::iterator, bool> result =
|
||||
mActiveCells.insert (std::make_pair (cell, render));
|
||||
|
||||
if (result.second)
|
||||
{
|
||||
// Load the cell and insert it into the renderer
|
||||
result.first->second->show();
|
||||
}
|
||||
}
|
||||
|
||||
void Scene::playerCellChange (Ptr::CellStore *cell, const ESM::Position& position,
|
||||
bool adjustPlayerPos)
|
||||
{
|
||||
if (adjustPlayerPos)
|
||||
mWorld->getPlayer().setPos (position.pos[0], position.pos[1], position.pos[2]);
|
||||
|
||||
mWorld->getPlayer().setCell (cell);
|
||||
// TODO orientation
|
||||
mEnvironment.mMechanicsManager->addActor (mWorld->getPlayer().getPlayer());
|
||||
mEnvironment.mMechanicsManager->watchActor (mWorld->getPlayer().getPlayer());
|
||||
}
|
||||
|
||||
void Scene::changeCell (int X, int Y, const ESM::Position& position, bool adjustPlayerPos)
|
||||
{
|
||||
// remove active
|
||||
mEnvironment.mMechanicsManager->removeActor (mWorld->getPlayer().getPlayer());
|
||||
|
||||
CellRenderCollection::iterator active = mActiveCells.begin();
|
||||
|
||||
while (active!=mActiveCells.end())
|
||||
{
|
||||
if (!(active->first->cell->data.flags & ESM::Cell::Interior))
|
||||
{
|
||||
if (std::abs (X-active->first->cell->data.gridX)<=1 &&
|
||||
std::abs (Y-active->first->cell->data.gridY)<=1)
|
||||
{
|
||||
// keep cells within the new 3x3 grid
|
||||
++active;
|
||||
continue;
|
||||
}
|
||||
}
|
||||
|
||||
unloadCell (active++);
|
||||
}
|
||||
|
||||
// Load cells
|
||||
for (int x=X-1; x<=X+1; ++x)
|
||||
for (int y=Y-1; y<=Y+1; ++y)
|
||||
{
|
||||
CellRenderCollection::iterator iter = mActiveCells.begin();
|
||||
|
||||
while (iter!=mActiveCells.end())
|
||||
{
|
||||
assert (!(iter->first->cell->data.flags & ESM::Cell::Interior));
|
||||
|
||||
if (x==iter->first->cell->data.gridX &&
|
||||
y==iter->first->cell->data.gridY)
|
||||
break;
|
||||
|
||||
++iter;
|
||||
}
|
||||
|
||||
if (iter==mActiveCells.end())
|
||||
{
|
||||
Ptr::CellStore *cell = mWorld->getExterior(x, y);
|
||||
|
||||
loadCell (cell, new MWRender::ExteriorCellRender (*cell, mEnvironment, mScene, mPhysics));
|
||||
}
|
||||
}
|
||||
|
||||
// find current cell
|
||||
CellRenderCollection::iterator iter = mActiveCells.begin();
|
||||
|
||||
while (iter!=mActiveCells.end())
|
||||
{
|
||||
assert (!(iter->first->cell->data.flags & ESM::Cell::Interior));
|
||||
|
||||
if (X==iter->first->cell->data.gridX &&
|
||||
Y==iter->first->cell->data.gridY)
|
||||
break;
|
||||
|
||||
++iter;
|
||||
}
|
||||
|
||||
assert (iter!=mActiveCells.end());
|
||||
|
||||
mCurrentCell = iter->first;
|
||||
|
||||
// adjust player
|
||||
playerCellChange (mWorld->getExterior(X, Y), position, adjustPlayerPos);
|
||||
|
||||
// Sky system
|
||||
mWorld->adjustSky();
|
||||
|
||||
mCellChanged = true;
|
||||
}
|
||||
|
||||
Scene::Scene (Environment& environment, World *world, MWRender::MWScene& scene, PhysicsSystem *physics)
|
||||
: mScene (scene), mCurrentCell (0),
|
||||
mCellChanged (false), mEnvironment (environment), mWorld(world), mPhysics(physics)
|
||||
{
|
||||
}
|
||||
|
||||
Scene::~Scene()
|
||||
{
|
||||
for (CellRenderCollection::iterator iter (mActiveCells.begin());
|
||||
iter!=mActiveCells.end(); ++iter)
|
||||
delete iter->second;
|
||||
}
|
||||
|
||||
bool Scene::hasCellChanged() const
|
||||
{
|
||||
return mCellChanged;
|
||||
}
|
||||
|
||||
const Scene::CellRenderCollection& Scene::getActiveCells() const
|
||||
{
|
||||
return mActiveCells;
|
||||
}
|
||||
|
||||
void Scene::changeToInteriorCell (const std::string& cellName, const ESM::Position& position)
|
||||
{
|
||||
// remove active
|
||||
CellRenderCollection::iterator active = mActiveCells.begin();
|
||||
|
||||
while (active!=mActiveCells.end())
|
||||
{
|
||||
unloadCell (active++);
|
||||
}
|
||||
|
||||
// Load cell.
|
||||
std::cout << "cellName:" << cellName << std::endl;
|
||||
Ptr::CellStore *cell = mWorld->getInterior(cellName);
|
||||
|
||||
loadCell (cell, new MWRender::InteriorCellRender (*cell, mEnvironment, mScene, mPhysics));
|
||||
|
||||
// adjust player
|
||||
mCurrentCell = cell;
|
||||
playerCellChange (cell, position);
|
||||
|
||||
// Sky system
|
||||
mWorld->adjustSky();
|
||||
|
||||
mCellChanged = true;
|
||||
//currentRegion->name = "";
|
||||
}
|
||||
|
||||
void Scene::changeToExteriorCell (const ESM::Position& position)
|
||||
{
|
||||
int x = 0;
|
||||
int y = 0;
|
||||
|
||||
mWorld->positionToIndex (position.pos[0], position.pos[1], x, y);
|
||||
|
||||
changeCell (x, y, position, true);
|
||||
}
|
||||
|
||||
Ptr::CellStore* Scene::getCurrentCell ()
|
||||
{
|
||||
return mCurrentCell;
|
||||
}
|
||||
|
||||
void Scene::markCellAsUnchanged()
|
||||
{
|
||||
mCellChanged = false;
|
||||
}
|
||||
|
||||
/*#include <cassert>
|
||||
#include <iostream>
|
||||
#include <exception>
|
||||
|
||||
#include "../mwworld/class.hpp"
|
||||
#include "../mwworld/ptr.hpp"*/
|
||||
|
||||
void Scene::insertCell(ESMS::CellStore<MWWorld::RefData> &cell)
|
||||
{
|
||||
// Loop through all references in the cell
|
||||
insertCellRefList (cell.activators, cell);
|
||||
insertCellRefList (cell.potions, cell);
|
||||
insertCellRefList (cell.appas, cell);
|
||||
insertCellRefList (cell.armors, cell);
|
||||
insertCellRefList (cell.books, cell);
|
||||
insertCellRefList (cell.clothes, cell);
|
||||
insertCellRefList (cell.containers, cell);
|
||||
insertCellRefList (cell.creatures, cell);
|
||||
insertCellRefList (cell.doors, cell);
|
||||
insertCellRefList (cell.ingreds, cell);
|
||||
insertCellRefList (cell.creatureLists, cell);
|
||||
insertCellRefList (cell.itemLists, cell);
|
||||
insertCellRefList (cell.lights, cell);
|
||||
insertCellRefList (cell.lockpicks, cell);
|
||||
insertCellRefList (cell.miscItems, cell);
|
||||
insertCellRefList (cell.npcs, cell);
|
||||
insertCellRefList (cell.probes, cell);
|
||||
insertCellRefList (cell.repairs, cell);
|
||||
insertCellRefList (cell.statics, cell);
|
||||
insertCellRefList (cell.weapons, cell);
|
||||
}
|
||||
|
||||
}
|
105
apps/openmw/mwworld/scene.hpp
Normal file
105
apps/openmw/mwworld/scene.hpp
Normal file
|
@ -0,0 +1,105 @@
|
|||
#ifndef GAME_MWWORLD_SCENE_H
|
||||
#define GAME_MWWORLD_SCENE_H
|
||||
|
||||
#include <vector>
|
||||
#include <map>
|
||||
|
||||
#include <boost/filesystem.hpp>
|
||||
|
||||
#include <components/esm_store/cell_store.hpp>
|
||||
|
||||
#include "../mwrender/mwscene.hpp"
|
||||
#include "physicssystem.hpp"
|
||||
|
||||
#include "refdata.hpp"
|
||||
#include "ptr.hpp"
|
||||
#include "globals.hpp"
|
||||
|
||||
#include <openengine/bullet/physic.hpp>
|
||||
|
||||
namespace Ogre
|
||||
{
|
||||
class Vector3;
|
||||
}
|
||||
|
||||
namespace ESM
|
||||
{
|
||||
struct Position;
|
||||
}
|
||||
|
||||
namespace Files
|
||||
{
|
||||
class Collections;
|
||||
}
|
||||
|
||||
namespace Render
|
||||
{
|
||||
class OgreRenderer;
|
||||
}
|
||||
|
||||
namespace MWRender
|
||||
{
|
||||
class SkyManager;
|
||||
class CellRender;
|
||||
}
|
||||
|
||||
namespace MWWorld
|
||||
{
|
||||
class Environment;
|
||||
class Player;
|
||||
|
||||
class Scene
|
||||
{
|
||||
|
||||
public:
|
||||
|
||||
typedef std::map<Ptr::CellStore *, MWRender::CellRender *> CellRenderCollection;
|
||||
|
||||
private:
|
||||
|
||||
MWRender::MWScene& mScene;
|
||||
Ptr::CellStore *mCurrentCell; // the cell, the player is in
|
||||
CellRenderCollection mActiveCells;
|
||||
bool mCellChanged;
|
||||
Environment& mEnvironment;
|
||||
World *mWorld;
|
||||
PhysicsSystem *mPhysics;
|
||||
|
||||
void playerCellChange (Ptr::CellStore *cell, const ESM::Position& position,
|
||||
bool adjustPlayerPos = true);
|
||||
public:
|
||||
|
||||
Scene (Environment& environment, World *world, MWRender::MWScene& scene, PhysicsSystem *physics);
|
||||
|
||||
~Scene();
|
||||
|
||||
void unloadCell (CellRenderCollection::iterator iter);
|
||||
|
||||
void loadCell (Ptr::CellStore *cell, MWRender::CellRender *render);
|
||||
|
||||
void changeCell (int X, int Y, const ESM::Position& position, bool adjustPlayerPos);
|
||||
///< Move from exterior to interior or from interior cell to a different
|
||||
/// interior cell.
|
||||
|
||||
Ptr::CellStore* getCurrentCell ();
|
||||
|
||||
const CellRenderCollection& getActiveCells () const;
|
||||
|
||||
bool hasCellChanged() const;
|
||||
///< Has the player moved to a different cell, since the last frame?
|
||||
|
||||
void changeToInteriorCell (const std::string& cellName, const ESM::Position& position);
|
||||
///< Move to interior cell.
|
||||
|
||||
void changeToExteriorCell (const ESM::Position& position);
|
||||
///< Move to exterior cell.
|
||||
|
||||
void markCellAsUnchanged();
|
||||
|
||||
// std::string getFacedHandle();
|
||||
|
||||
void insertCell(ESMS::CellStore<MWWorld::RefData> &cell);
|
||||
};
|
||||
}
|
||||
|
||||
#endif
|
|
@ -1,4 +1,3 @@
|
|||
|
||||
#include "world.hpp"
|
||||
|
||||
#include <cmath>
|
||||
|
@ -22,7 +21,6 @@
|
|||
|
||||
#include "refdata.hpp"
|
||||
#include "globals.hpp"
|
||||
#include "doingphysics.hpp"
|
||||
#include "cellfunctors.hpp"
|
||||
|
||||
namespace
|
||||
|
@ -91,71 +89,6 @@ namespace MWWorld
|
|||
listCellScripts (mStore, cell.weapons, mLocalScripts, &cell);
|
||||
}
|
||||
|
||||
Ptr World::getPtr (const std::string& name, Ptr::CellStore& cell)
|
||||
{
|
||||
if (ESMS::LiveCellRef<ESM::Activator, RefData> *ref = cell.activators.find (name))
|
||||
return Ptr (ref, &cell);
|
||||
|
||||
if (ESMS::LiveCellRef<ESM::Potion, RefData> *ref = cell.potions.find (name))
|
||||
return Ptr (ref, &cell);
|
||||
|
||||
if (ESMS::LiveCellRef<ESM::Apparatus, RefData> *ref = cell.appas.find (name))
|
||||
return Ptr (ref, &cell);
|
||||
|
||||
if (ESMS::LiveCellRef<ESM::Armor, RefData> *ref = cell.armors.find (name))
|
||||
return Ptr (ref, &cell);
|
||||
|
||||
if (ESMS::LiveCellRef<ESM::Book, RefData> *ref = cell.books.find (name))
|
||||
return Ptr (ref, &cell);
|
||||
|
||||
if (ESMS::LiveCellRef<ESM::Clothing, RefData> *ref = cell.clothes.find (name))
|
||||
return Ptr (ref, &cell);
|
||||
|
||||
if (ESMS::LiveCellRef<ESM::Container, RefData> *ref = cell.containers.find (name))
|
||||
return Ptr (ref, &cell);
|
||||
|
||||
if (ESMS::LiveCellRef<ESM::Creature, RefData> *ref = cell.creatures.find (name))
|
||||
return Ptr (ref, &cell);
|
||||
|
||||
if (ESMS::LiveCellRef<ESM::Door, RefData> *ref = cell.doors.find (name))
|
||||
return Ptr (ref, &cell);
|
||||
|
||||
if (ESMS::LiveCellRef<ESM::Ingredient, RefData> *ref = cell.ingreds.find (name))
|
||||
return Ptr (ref, &cell);
|
||||
|
||||
if (ESMS::LiveCellRef<ESM::CreatureLevList, RefData> *ref = cell.creatureLists.find (name))
|
||||
return Ptr (ref, &cell);
|
||||
|
||||
if (ESMS::LiveCellRef<ESM::ItemLevList, RefData> *ref = cell.itemLists.find (name))
|
||||
return Ptr (ref, &cell);
|
||||
|
||||
if (ESMS::LiveCellRef<ESM::Light, RefData> *ref = cell.lights.find (name))
|
||||
return Ptr (ref, &cell);
|
||||
|
||||
if (ESMS::LiveCellRef<ESM::Tool, RefData> *ref = cell.lockpicks.find (name))
|
||||
return Ptr (ref, &cell);
|
||||
|
||||
if (ESMS::LiveCellRef<ESM::Miscellaneous, RefData> *ref = cell.miscItems.find (name))
|
||||
return Ptr (ref, &cell);
|
||||
|
||||
if (ESMS::LiveCellRef<ESM::NPC, RefData> *ref = cell.npcs.find (name))
|
||||
return Ptr (ref, &cell);
|
||||
|
||||
if (ESMS::LiveCellRef<ESM::Probe, RefData> *ref = cell.probes.find (name))
|
||||
return Ptr (ref, &cell);
|
||||
|
||||
if (ESMS::LiveCellRef<ESM::Repair, RefData> *ref = cell.repairs.find (name))
|
||||
return Ptr (ref, &cell);
|
||||
|
||||
if (ESMS::LiveCellRef<ESM::Static, RefData> *ref = cell.statics.find (name))
|
||||
return Ptr (ref, &cell);
|
||||
|
||||
if (ESMS::LiveCellRef<ESM::Weapon, RefData> *ref = cell.weapons.find (name))
|
||||
return Ptr (ref, &cell);
|
||||
|
||||
return Ptr();
|
||||
}
|
||||
|
||||
Ptr World::getPtrViaHandle (const std::string& handle, Ptr::CellStore& cell)
|
||||
{
|
||||
if (ESMS::LiveCellRef<ESM::Activator, RefData> *ref =
|
||||
|
@ -221,18 +154,12 @@ namespace MWWorld
|
|||
|
||||
MWRender::CellRender *World::searchRender (Ptr::CellStore *store)
|
||||
{
|
||||
CellRenderCollection::iterator iter = mActiveCells.find (store);
|
||||
Scene::CellRenderCollection::const_iterator iter = mWorldScene->getActiveCells().find (store);
|
||||
|
||||
if (iter!=mActiveCells.end())
|
||||
if (iter!=mWorldScene->getActiveCells().end())
|
||||
{
|
||||
return iter->second;
|
||||
}
|
||||
else
|
||||
{
|
||||
iter = mBufferedCells.find (store);
|
||||
if (iter!=mBufferedCells.end())
|
||||
return iter->second;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
@ -271,52 +198,6 @@ namespace MWWorld
|
|||
}
|
||||
}
|
||||
|
||||
void World::unloadCell (CellRenderCollection::iterator iter)
|
||||
{
|
||||
ListHandles functor;
|
||||
iter->first->forEach<ListHandles>(functor);
|
||||
|
||||
{ // silence annoying g++ warning
|
||||
for (std::vector<std::string>::const_iterator iter (functor.mHandles.begin());
|
||||
iter!=functor.mHandles.end(); ++iter)
|
||||
mScene.removeObject (*iter);
|
||||
}
|
||||
|
||||
removeScripts (iter->first);
|
||||
mEnvironment.mMechanicsManager->dropActors (iter->first);
|
||||
mEnvironment.mSoundManager->stopSound (iter->first);
|
||||
delete iter->second;
|
||||
mActiveCells.erase (iter);
|
||||
}
|
||||
|
||||
void World::loadCell (Ptr::CellStore *cell, MWRender::CellRender *render)
|
||||
{
|
||||
// register local scripts
|
||||
insertInteriorScripts (*cell);
|
||||
|
||||
// This connects the cell data with the rendering scene.
|
||||
std::pair<CellRenderCollection::iterator, bool> result =
|
||||
mActiveCells.insert (std::make_pair (cell, render));
|
||||
|
||||
if (result.second)
|
||||
{
|
||||
// Load the cell and insert it into the renderer
|
||||
result.first->second->show();
|
||||
}
|
||||
}
|
||||
|
||||
void World::playerCellChange (Ptr::CellStore *cell, const ESM::Position& position,
|
||||
bool adjustPlayerPos)
|
||||
{
|
||||
if (adjustPlayerPos)
|
||||
mPlayer->setPos (position.pos[0], position.pos[1], position.pos[2], false);
|
||||
|
||||
mPlayer->setCell (cell);
|
||||
// TODO orientation
|
||||
mEnvironment.mMechanicsManager->addActor (mPlayer->getPlayer());
|
||||
mEnvironment.mMechanicsManager->watchActor (mPlayer->getPlayer());
|
||||
}
|
||||
|
||||
|
||||
void World::adjustSky()
|
||||
{
|
||||
|
@ -328,93 +209,17 @@ namespace MWWorld
|
|||
}
|
||||
}
|
||||
|
||||
void World::changeCell (int X, int Y, const ESM::Position& position, bool adjustPlayerPos)
|
||||
{
|
||||
SuppressDoingPhysics scopeGuard;
|
||||
|
||||
// remove active
|
||||
mEnvironment.mMechanicsManager->removeActor (mPlayer->getPlayer());
|
||||
|
||||
CellRenderCollection::iterator active = mActiveCells.begin();
|
||||
|
||||
while (active!=mActiveCells.end())
|
||||
{
|
||||
if (!(active->first->cell->data.flags & ESM::Cell::Interior))
|
||||
{
|
||||
if (std::abs (X-active->first->cell->data.gridX)<=1 &&
|
||||
std::abs (Y-active->first->cell->data.gridY)<=1)
|
||||
{
|
||||
// keep cells within the new 3x3 grid
|
||||
++active;
|
||||
continue;
|
||||
}
|
||||
}
|
||||
|
||||
unloadCell (active++);
|
||||
}
|
||||
|
||||
// Load cells
|
||||
for (int x=X-1; x<=X+1; ++x)
|
||||
for (int y=Y-1; y<=Y+1; ++y)
|
||||
{
|
||||
CellRenderCollection::iterator iter = mActiveCells.begin();
|
||||
|
||||
while (iter!=mActiveCells.end())
|
||||
{
|
||||
assert (!(iter->first->cell->data.flags & ESM::Cell::Interior));
|
||||
|
||||
if (x==iter->first->cell->data.gridX &&
|
||||
y==iter->first->cell->data.gridY)
|
||||
break;
|
||||
|
||||
++iter;
|
||||
}
|
||||
|
||||
if (iter==mActiveCells.end())
|
||||
{
|
||||
mExteriors[std::make_pair (x, y)].loadExt (x, y, mStore, mEsm);
|
||||
Ptr::CellStore *cell = &mExteriors[std::make_pair (x, y)];
|
||||
|
||||
loadCell (cell, new MWRender::ExteriorCellRender (*cell, mEnvironment, mScene));
|
||||
}
|
||||
}
|
||||
|
||||
// find current cell
|
||||
CellRenderCollection::iterator iter = mActiveCells.begin();
|
||||
|
||||
while (iter!=mActiveCells.end())
|
||||
{
|
||||
assert (!(iter->first->cell->data.flags & ESM::Cell::Interior));
|
||||
|
||||
if (X==iter->first->cell->data.gridX &&
|
||||
Y==iter->first->cell->data.gridY)
|
||||
break;
|
||||
|
||||
++iter;
|
||||
}
|
||||
|
||||
assert (iter!=mActiveCells.end());
|
||||
|
||||
mCurrentCell = iter->first;
|
||||
|
||||
// adjust player
|
||||
playerCellChange (&mExteriors[std::make_pair (X, Y)], position, adjustPlayerPos);
|
||||
|
||||
// Sky system
|
||||
adjustSky();
|
||||
|
||||
mCellChanged = true;
|
||||
}
|
||||
|
||||
World::World (OEngine::Render::OgreRenderer& renderer, OEngine::Physic::PhysicEngine* physEng,
|
||||
const Files::Collections& fileCollections,
|
||||
const std::string& master, const boost::filesystem::path& resDir,
|
||||
bool newGame, Environment& environment, const std::string& encoding)
|
||||
: mSkyManager (0), mScene (renderer,physEng), mPlayer (0), mCurrentCell (0), mGlobalVariables (0),
|
||||
mSky (false), mCellChanged (false), mEnvironment (environment), mNextDynamicRecord (0)
|
||||
: mScene (renderer,physEng), mPlayer (0), mGlobalVariables (0),
|
||||
mSky (false), mEnvironment (environment), mNextDynamicRecord (0), mCells (mStore, mEsm)
|
||||
{
|
||||
mPhysEngine = physEng;
|
||||
|
||||
mPhysics = new PhysicsSystem(renderer, physEng);
|
||||
|
||||
boost::filesystem::path masterPath (fileCollections.getCollection (".esm").getPath (master));
|
||||
|
||||
std::cout << "Loading ESM " << masterPath.string() << "\n";
|
||||
|
@ -425,7 +230,7 @@ namespace MWWorld
|
|||
mStore.load (mEsm);
|
||||
|
||||
mPlayer = new MWWorld::Player (mScene.getPlayer(), mStore.npcs.find ("player"), *this);
|
||||
mScene.addActor (mPlayer->getPlayer().getRefData().getHandle(), "", Ogre::Vector3 (0, 0, 0));
|
||||
mPhysics->addActor (mPlayer->getPlayer().getRefData().getHandle(), "", Ogre::Vector3 (0, 0, 0));
|
||||
|
||||
// global variables
|
||||
mGlobalVariables = new Globals (mStore);
|
||||
|
@ -436,25 +241,54 @@ namespace MWWorld
|
|||
mGlobalVariables->setInt ("chargenstate", 1);
|
||||
}
|
||||
|
||||
mSkyManager =
|
||||
MWRender::SkyManager::create(renderer.getWindow(), mScene.getCamera(), resDir);
|
||||
|
||||
mPhysEngine = physEng;
|
||||
|
||||
mWorldScene = new Scene(environment, this, mScene, mPhysics);
|
||||
mRenderingManager = new MWRender::RenderingManager(
|
||||
MWRender::SkyManager::create(renderer.getWindow(), mScene.getCamera(), resDir)
|
||||
);
|
||||
}
|
||||
|
||||
World::~World()
|
||||
{
|
||||
for (CellRenderCollection::iterator iter (mActiveCells.begin());
|
||||
iter!=mActiveCells.end(); ++iter)
|
||||
delete iter->second;
|
||||
|
||||
for (CellRenderCollection::iterator iter (mBufferedCells.begin());
|
||||
iter!=mBufferedCells.end(); ++iter)
|
||||
delete iter->second;
|
||||
|
||||
delete mPlayer;
|
||||
delete mSkyManager;
|
||||
delete mWorldScene;
|
||||
delete mGlobalVariables;
|
||||
delete mPlayer;
|
||||
delete mPhysics;
|
||||
}
|
||||
|
||||
const ESM::Cell *World::getExterior (const std::string& cellName) const
|
||||
{
|
||||
// first try named cells
|
||||
if (const ESM::Cell *cell = mStore.cells.searchExtByName (cellName))
|
||||
return cell;
|
||||
|
||||
// didn't work -> now check for regions
|
||||
std::string cellName2 = ESMS::RecListT<ESM::Region>::toLower (cellName);
|
||||
|
||||
for (ESMS::RecListT<ESM::Region>::MapType::const_iterator iter (mStore.regions.list.begin());
|
||||
iter!=mStore.regions.list.end(); ++iter)
|
||||
{
|
||||
if (ESMS::RecListT<ESM::Region>::toLower (iter->second.name)==cellName2)
|
||||
{
|
||||
if (const ESM::Cell *cell = mStore.cells.searchExtByRegion (iter->first))
|
||||
return cell;
|
||||
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
Ptr::CellStore *World::getExterior (int x, int y)
|
||||
{
|
||||
return mCells.getExterior (x, y);
|
||||
}
|
||||
|
||||
Ptr::CellStore *World::getInterior (const std::string& name)
|
||||
{
|
||||
return mCells.getInterior (name);
|
||||
}
|
||||
|
||||
MWWorld::Player& World::getPlayer()
|
||||
|
@ -467,6 +301,11 @@ namespace MWWorld
|
|||
return mStore;
|
||||
}
|
||||
|
||||
ESM::ESMReader& World::getEsmReader()
|
||||
{
|
||||
return mEsm;
|
||||
}
|
||||
|
||||
const World::ScriptList& World::getLocalScripts() const
|
||||
{
|
||||
return mLocalScripts;
|
||||
|
@ -474,7 +313,7 @@ namespace MWWorld
|
|||
|
||||
bool World::hasCellChanged() const
|
||||
{
|
||||
return mCellChanged;
|
||||
return mWorldScene->hasCellChanged();
|
||||
}
|
||||
|
||||
Globals::Data& World::getGlobalVariable (const std::string& name)
|
||||
|
@ -501,10 +340,10 @@ namespace MWWorld
|
|||
}
|
||||
|
||||
// active cells
|
||||
for (CellRenderCollection::iterator iter (mActiveCells.begin());
|
||||
iter!=mActiveCells.end(); ++iter)
|
||||
for (Scene::CellRenderCollection::const_iterator iter (mWorldScene->getActiveCells().begin());
|
||||
iter!=mWorldScene->getActiveCells().end(); ++iter)
|
||||
{
|
||||
Ptr ptr = getPtr (name, *iter->first);
|
||||
Ptr ptr = mCells.getPtr (name, *iter->first);
|
||||
|
||||
if (!ptr.isEmpty())
|
||||
return ptr;
|
||||
|
@ -512,7 +351,10 @@ namespace MWWorld
|
|||
|
||||
if (!activeOnly)
|
||||
{
|
||||
// TODO: inactive cells
|
||||
Ptr ptr = mCells.getPtr (name);
|
||||
|
||||
if (!ptr.isEmpty())
|
||||
return ptr;
|
||||
}
|
||||
|
||||
throw std::runtime_error ("unknown ID: " + name);
|
||||
|
@ -523,8 +365,8 @@ namespace MWWorld
|
|||
if (mPlayer->getPlayer().getRefData().getHandle()==handle)
|
||||
return mPlayer->getPlayer();
|
||||
|
||||
for (CellRenderCollection::iterator iter (mActiveCells.begin());
|
||||
iter!=mActiveCells.end(); ++iter)
|
||||
for (Scene::CellRenderCollection::const_iterator iter (mWorldScene->getActiveCells().begin());
|
||||
iter!=mWorldScene->getActiveCells().end(); ++iter)
|
||||
{
|
||||
Ptr ptr = getPtrViaHandle (handle, *iter->first);
|
||||
|
||||
|
@ -545,7 +387,7 @@ namespace MWWorld
|
|||
{
|
||||
render->enable (reference.getRefData().getHandle());
|
||||
|
||||
if (mActiveCells.find (reference.getCell())!=mActiveCells.end())
|
||||
if (mWorldScene->getActiveCells().find (reference.getCell())!=mWorldScene->getActiveCells().end())
|
||||
Class::get (reference).enable (reference, mEnvironment);
|
||||
}
|
||||
}
|
||||
|
@ -561,7 +403,7 @@ namespace MWWorld
|
|||
{
|
||||
render->disable (reference.getRefData().getHandle());
|
||||
|
||||
if (mActiveCells.find (reference.getCell())!=mActiveCells.end())
|
||||
if (mWorldScene->getActiveCells().find (reference.getCell())!=mWorldScene->getActiveCells().end())
|
||||
{
|
||||
Class::get (reference).disable (reference, mEnvironment);
|
||||
mEnvironment.mSoundManager->stopSound3D (reference);
|
||||
|
@ -593,7 +435,7 @@ namespace MWWorld
|
|||
|
||||
mGlobalVariables->setFloat ("gamehour", hour);
|
||||
|
||||
mSkyManager->setHour (hour);
|
||||
mRenderingManager->skySetHour (hour);
|
||||
|
||||
if (days>0)
|
||||
setDay (days + mGlobalVariables->getInt ("day"));
|
||||
|
@ -628,7 +470,7 @@ namespace MWWorld
|
|||
mGlobalVariables->setInt ("day", day);
|
||||
mGlobalVariables->setInt ("month", month);
|
||||
|
||||
mSkyManager->setDate (day, month);
|
||||
mRenderingManager->skySetDate (day, month);
|
||||
}
|
||||
|
||||
void World::setMonth (int month)
|
||||
|
@ -649,7 +491,7 @@ namespace MWWorld
|
|||
if (years>0)
|
||||
mGlobalVariables->setInt ("year", years+mGlobalVariables->getInt ("year"));
|
||||
|
||||
mSkyManager->setDate (mGlobalVariables->getInt ("day"), month);
|
||||
mRenderingManager->skySetDate (mGlobalVariables->getInt ("day"), month);
|
||||
}
|
||||
|
||||
bool World::toggleSky()
|
||||
|
@ -657,34 +499,34 @@ namespace MWWorld
|
|||
if (mSky)
|
||||
{
|
||||
mSky = false;
|
||||
mSkyManager->disable();
|
||||
mRenderingManager->skyDisable();
|
||||
return false;
|
||||
}
|
||||
else
|
||||
{
|
||||
mSky = true;
|
||||
// TODO check for extorior or interior with sky.
|
||||
mSkyManager->setHour (mGlobalVariables->getFloat ("gamehour"));
|
||||
mSkyManager->setDate (mGlobalVariables->getInt ("day"),
|
||||
mRenderingManager->skySetHour (mGlobalVariables->getFloat ("gamehour"));
|
||||
mRenderingManager->skySetDate (mGlobalVariables->getInt ("day"),
|
||||
mGlobalVariables->getInt ("month"));
|
||||
mSkyManager->enable();
|
||||
mRenderingManager->skyEnable();
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
int World::getMasserPhase() const
|
||||
{
|
||||
return mSkyManager->getMasserPhase();
|
||||
return mRenderingManager->skyGetMasserPhase();
|
||||
}
|
||||
|
||||
int World::getSecundaPhase() const
|
||||
{
|
||||
return mSkyManager->getSecundaPhase();
|
||||
return mRenderingManager->skyGetSecundaPhase();
|
||||
}
|
||||
|
||||
void World::setMoonColour (bool red)
|
||||
{
|
||||
mSkyManager->setMoonColour (red);
|
||||
mRenderingManager->skySetMoonColour (red);
|
||||
}
|
||||
|
||||
float World::getTimeScaleFactor() const
|
||||
|
@ -694,70 +536,17 @@ namespace MWWorld
|
|||
|
||||
void World::changeToInteriorCell (const std::string& cellName, const ESM::Position& position)
|
||||
{
|
||||
SuppressDoingPhysics scopeGuard;
|
||||
|
||||
// remove active
|
||||
CellRenderCollection::iterator active = mActiveCells.begin();
|
||||
|
||||
while (active!=mActiveCells.end())
|
||||
{
|
||||
unloadCell (active++);
|
||||
}
|
||||
|
||||
// Load cell.
|
||||
mInteriors[cellName].loadInt (cellName, mStore, mEsm);
|
||||
Ptr::CellStore *cell = &mInteriors[cellName];
|
||||
|
||||
loadCell (cell, new MWRender::InteriorCellRender (*cell, mEnvironment, mScene));
|
||||
|
||||
// adjust player
|
||||
mCurrentCell = cell;
|
||||
playerCellChange (cell, position);
|
||||
|
||||
// Sky system
|
||||
adjustSky();
|
||||
|
||||
mCellChanged = true;
|
||||
//currentRegion->name = "";
|
||||
return mWorldScene->changeToInteriorCell(cellName, position);
|
||||
}
|
||||
|
||||
void World::changeToExteriorCell (const ESM::Position& position)
|
||||
{
|
||||
int x = 0;
|
||||
int y = 0;
|
||||
|
||||
positionToIndex (position.pos[0], position.pos[1], x, y);
|
||||
|
||||
changeCell (x, y, position, true);
|
||||
}
|
||||
|
||||
const ESM::Cell *World::getExterior (const std::string& cellName) const
|
||||
{
|
||||
// first try named cells
|
||||
if (const ESM::Cell *cell = mStore.cells.searchExtByName (cellName))
|
||||
return cell;
|
||||
|
||||
// didn't work -> now check for regions
|
||||
std::string cellName2 = ESMS::RecListT<ESM::Region>::toLower (cellName);
|
||||
|
||||
for (ESMS::RecListT<ESM::Region>::MapType::const_iterator iter (mStore.regions.list.begin());
|
||||
iter!=mStore.regions.list.end(); ++iter)
|
||||
{
|
||||
if (ESMS::RecListT<ESM::Region>::toLower (iter->second.name)==cellName2)
|
||||
{
|
||||
if (const ESM::Cell *cell = mStore.cells.searchExtByRegion (iter->first))
|
||||
return cell;
|
||||
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
return 0;
|
||||
return mWorldScene->changeToExteriorCell(position);
|
||||
}
|
||||
|
||||
void World::markCellAsUnchanged()
|
||||
{
|
||||
mCellChanged = false;
|
||||
return mWorldScene->markCellAsUnchanged();
|
||||
}
|
||||
|
||||
std::string World::getFacedHandle()
|
||||
|
@ -779,13 +568,12 @@ namespace MWWorld
|
|||
|
||||
if (MWRender::CellRender *render = searchRender (ptr.getCell()))
|
||||
{
|
||||
if (mActiveCells.find (ptr.getCell())!=mActiveCells.end())
|
||||
if (mWorldScene->getActiveCells().find (ptr.getCell())!=mWorldScene->getActiveCells().end())
|
||||
{
|
||||
Class::get (ptr).disable (ptr, mEnvironment);
|
||||
mEnvironment.mSoundManager->stopSound3D (ptr);
|
||||
|
||||
if (!DoingPhysics::isDoingPhysics())
|
||||
mScene.removeObject (ptr.getRefData().getHandle());
|
||||
mPhysics->removeObject (ptr.getRefData().getHandle());
|
||||
}
|
||||
|
||||
render->deleteObject (ptr.getRefData().getHandle());
|
||||
|
@ -794,7 +582,7 @@ namespace MWWorld
|
|||
}
|
||||
}
|
||||
|
||||
void World::moveObject (Ptr ptr, float x, float y, float z)
|
||||
void World::moveObjectImp (Ptr ptr, float x, float y, float z)
|
||||
{
|
||||
ptr.getCellRef().pos.pos[0] = x;
|
||||
ptr.getCellRef().pos.pos[1] = y;
|
||||
|
@ -802,9 +590,10 @@ namespace MWWorld
|
|||
|
||||
if (ptr==mPlayer->getPlayer())
|
||||
{
|
||||
if (mCurrentCell)
|
||||
Ptr::CellStore *currentCell = mWorldScene->getCurrentCell();
|
||||
if (currentCell)
|
||||
{
|
||||
if (!(mCurrentCell->cell->data.flags & ESM::Cell::Interior))
|
||||
if (!(currentCell->cell->data.flags & ESM::Cell::Interior))
|
||||
{
|
||||
// exterior -> adjust loaded cells
|
||||
int cellX = 0;
|
||||
|
@ -812,19 +601,27 @@ namespace MWWorld
|
|||
|
||||
positionToIndex (x, y, cellX, cellY);
|
||||
|
||||
if (mCurrentCell->cell->data.gridX!=cellX || mCurrentCell->cell->data.gridY!=cellY)
|
||||
if (currentCell->cell->data.gridX!=cellX || currentCell->cell->data.gridY!=cellY)
|
||||
{
|
||||
changeCell (cellX, cellY, mPlayer->getPlayer().getCellRef().pos, false);
|
||||
mWorldScene->changeCell (cellX, cellY, mPlayer->getPlayer().getCellRef().pos, false);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
mScene.moveObject (ptr.getRefData().getHandle(), Ogre::Vector3 (x, y, z),
|
||||
!DoingPhysics::isDoingPhysics());
|
||||
// \todo cell change for non-player ref
|
||||
|
||||
// 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)
|
||||
{
|
||||
moveObjectImp(ptr, x, y, z);
|
||||
|
||||
mPhysics->moveObject (ptr.getRefData().getHandle(), Ogre::Vector3 (x, y, z));
|
||||
}
|
||||
|
||||
void World::indexToPosition (int cellX, int cellY, float &x, float &y, bool centre) const
|
||||
|
@ -859,12 +656,34 @@ namespace MWWorld
|
|||
void World::doPhysics (const std::vector<std::pair<std::string, Ogre::Vector3> >& actors,
|
||||
float duration)
|
||||
{
|
||||
mScene.doPhysics (duration, *this, actors);
|
||||
std::vector< std::pair<std::string, Ogre::Vector3> > vectors = mPhysics->doPhysics (duration, actors);
|
||||
|
||||
std::vector< std::pair<std::string, Ogre::Vector3> >::iterator player = vectors.end();
|
||||
|
||||
for (std::vector< std::pair<std::string, Ogre::Vector3> >::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()
|
||||
{
|
||||
return mScene.toggleCollisionMode();
|
||||
return mPhysics->toggleCollisionMode();
|
||||
}
|
||||
|
||||
bool World::toggleRenderMode (RenderMode mode)
|
||||
|
|
|
@ -9,10 +9,14 @@
|
|||
#include <components/esm_store/cell_store.hpp>
|
||||
|
||||
#include "../mwrender/mwscene.hpp"
|
||||
#include "../mwrender/rendering_manager.hpp"
|
||||
|
||||
#include "refdata.hpp"
|
||||
#include "ptr.hpp"
|
||||
#include "globals.hpp"
|
||||
#include "scene.hpp"
|
||||
#include "physicssystem.hpp"
|
||||
#include "cells.hpp"
|
||||
|
||||
#include <openengine/bullet/physic.hpp>
|
||||
|
||||
|
@ -62,55 +66,35 @@ namespace MWWorld
|
|||
|
||||
private:
|
||||
|
||||
typedef std::map<Ptr::CellStore *, MWRender::CellRender *> CellRenderCollection;
|
||||
|
||||
MWRender::SkyManager* mSkyManager;
|
||||
MWRender::MWScene mScene;
|
||||
MWWorld::Scene *mWorldScene;
|
||||
MWWorld::Player *mPlayer;
|
||||
Ptr::CellStore *mCurrentCell; // the cell, the player is in
|
||||
CellRenderCollection mActiveCells;
|
||||
CellRenderCollection mBufferedCells; // loaded, but not active (buffering not implementd yet)
|
||||
ESM::ESMReader mEsm;
|
||||
ESMS::ESMStore mStore;
|
||||
std::map<std::string, Ptr::CellStore> mInteriors;
|
||||
std::map<std::pair<int, int>, Ptr::CellStore> mExteriors;
|
||||
ScriptList mLocalScripts;
|
||||
MWWorld::Globals *mGlobalVariables;
|
||||
MWWorld::PhysicsSystem *mPhysics;
|
||||
bool mSky;
|
||||
bool mCellChanged;
|
||||
Environment& mEnvironment;
|
||||
MWRender::RenderingManager *mRenderingManager;
|
||||
int mNextDynamicRecord;
|
||||
|
||||
Cells mCells;
|
||||
|
||||
OEngine::Physic::PhysicEngine* mPhysEngine;
|
||||
|
||||
// not implemented
|
||||
World (const World&);
|
||||
World& operator= (const World&);
|
||||
|
||||
void insertInteriorScripts (ESMS::CellStore<RefData>& cell);
|
||||
|
||||
Ptr getPtr (const std::string& name, Ptr::CellStore& cellStore);
|
||||
|
||||
Ptr getPtrViaHandle (const std::string& handle, Ptr::CellStore& cellStore);
|
||||
|
||||
MWRender::CellRender *searchRender (Ptr::CellStore *store);
|
||||
|
||||
int getDaysPerMonth (int month) const;
|
||||
|
||||
void removeScripts (Ptr::CellStore *cell);
|
||||
void moveObjectImp (Ptr ptr, float x, float y, float z);
|
||||
|
||||
void unloadCell (CellRenderCollection::iterator iter);
|
||||
|
||||
void loadCell (Ptr::CellStore *cell, MWRender::CellRender *render);
|
||||
|
||||
void playerCellChange (Ptr::CellStore *cell, const ESM::Position& position,
|
||||
bool adjustPlayerPos = true);
|
||||
|
||||
void adjustSky();
|
||||
|
||||
void changeCell (int X, int Y, const ESM::Position& position, bool adjustPlayerPos);
|
||||
///< Move from exterior to interior or from interior cell to a different
|
||||
/// interior cell.
|
||||
public:
|
||||
|
||||
World (OEngine::Render::OgreRenderer& renderer, OEngine::Physic::PhysicEngine* physEng,
|
||||
|
@ -120,10 +104,22 @@ namespace MWWorld
|
|||
|
||||
~World();
|
||||
|
||||
Ptr::CellStore *getExterior (int x, int y);
|
||||
|
||||
Ptr::CellStore *getInterior (const std::string& name);
|
||||
|
||||
void removeScripts (Ptr::CellStore *cell);
|
||||
|
||||
void insertInteriorScripts (ESMS::CellStore<RefData>& cell);
|
||||
|
||||
void adjustSky();
|
||||
|
||||
MWWorld::Player& getPlayer();
|
||||
|
||||
const ESMS::ESMStore& getStore() const;
|
||||
|
||||
ESM::ESMReader& getEsmReader();
|
||||
|
||||
const ScriptList& getLocalScripts() const;
|
||||
///< Names and local variable state of all local scripts in active cells.
|
||||
|
||||
|
|
|
@ -1,5 +1,8 @@
|
|||
#include "loadcell.hpp"
|
||||
|
||||
#include <string>
|
||||
#include <sstream>
|
||||
|
||||
namespace ESM
|
||||
{
|
||||
|
||||
|
@ -47,6 +50,20 @@ void Cell::restore(ESMReader &esm) const
|
|||
esm.restoreContext(context);
|
||||
}
|
||||
|
||||
std::string Cell::getDescription() const
|
||||
{
|
||||
if (data.flags & Interior)
|
||||
{
|
||||
return name;
|
||||
}
|
||||
else
|
||||
{
|
||||
std::ostringstream stream;
|
||||
stream << data.gridX << ", " << data.gridY;
|
||||
return stream.str();
|
||||
}
|
||||
}
|
||||
|
||||
bool Cell::getNextRef(ESMReader &esm, CellRef &ref)
|
||||
{
|
||||
if (!esm.hasMoreSubs())
|
||||
|
|
|
@ -126,6 +126,9 @@ struct Cell
|
|||
// exactly.
|
||||
void restore(ESMReader &esm) const;
|
||||
|
||||
std::string getDescription() const;
|
||||
///< Return a short string describing the cell (mostly used for debugging/logging purpose)
|
||||
|
||||
/* Get the next reference in this cell, if any. Returns false when
|
||||
there are no more references in the cell.
|
||||
|
||||
|
|
|
@ -13,8 +13,10 @@
|
|||
#include "store.hpp"
|
||||
#include "components/esm/records.hpp"
|
||||
#include "components/esm/loadcell.hpp"
|
||||
#include <list>
|
||||
|
||||
#include <list>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
#include <iostream>
|
||||
#include <stdexcept>
|
||||
#include <algorithm>
|
||||
|
@ -81,9 +83,17 @@ namespace ESMS
|
|||
class CellStore
|
||||
{
|
||||
public:
|
||||
CellStore() : cell (0) {}
|
||||
|
||||
enum State
|
||||
{
|
||||
State_Unloaded, State_Preloaded, State_Loaded
|
||||
};
|
||||
|
||||
CellStore (const ESM::Cell *cell_) : cell (cell_), mState (State_Unloaded) {}
|
||||
|
||||
const ESM::Cell *cell;
|
||||
State mState;
|
||||
std::vector<std::string> mIds;
|
||||
|
||||
// Lists for each individual object type
|
||||
CellRefList<Activator, D> activators;
|
||||
|
@ -107,31 +117,29 @@ namespace ESMS
|
|||
CellRefList<Static, D> statics;
|
||||
CellRefList<Weapon, D> weapons;
|
||||
|
||||
/** Look up and load an interior cell from the given ESM data
|
||||
storage. */
|
||||
void loadInt(const std::string &name, const ESMStore &store, ESMReader &esm)
|
||||
void load (const ESMStore &store, ESMReader &esm)
|
||||
{
|
||||
std::cout << "loading cell '" << name << "'\n";
|
||||
if (mState!=State_Loaded)
|
||||
{
|
||||
if (mState==State_Preloaded)
|
||||
mIds.clear();
|
||||
|
||||
cell = store.cells.findInt(name);
|
||||
std::cout << "loading cell " << cell->getDescription() << std::endl;
|
||||
|
||||
if(cell == NULL)
|
||||
throw std::runtime_error("Cell not found - " + name);
|
||||
loadRefs (store, esm);
|
||||
|
||||
loadRefs(store, esm);
|
||||
mState = State_Loaded;
|
||||
}
|
||||
}
|
||||
|
||||
/** Ditto for exterior cell. */
|
||||
void loadExt(int X, int Y, const ESMStore &store, ESMReader &esm)
|
||||
void preload (const ESMStore &store, ESMReader &esm)
|
||||
{
|
||||
std::cout << "loading exterior cell '" << X << ", " << Y << "'\n";
|
||||
if (mState==State_Unloaded)
|
||||
{
|
||||
listRefs (store, esm);
|
||||
|
||||
cell = store.cells.searchExt (X, Y);
|
||||
|
||||
if(cell == NULL)
|
||||
throw std::runtime_error("Exterior cell not found");
|
||||
|
||||
loadRefs(store, esm);
|
||||
mState = State_Preloaded;
|
||||
}
|
||||
}
|
||||
|
||||
/// Call functor (ref) for each reference. functor must return a bool. Returning
|
||||
|
@ -176,6 +184,30 @@ namespace ESMS
|
|||
return true;
|
||||
}
|
||||
|
||||
/// Run through references and store IDs
|
||||
void listRefs(const ESMStore &store, ESMReader &esm)
|
||||
{
|
||||
assert (cell);
|
||||
|
||||
// Reopen the ESM reader and seek to the right position.
|
||||
cell->restore (esm);
|
||||
|
||||
CellRef ref;
|
||||
|
||||
// Get each reference in turn
|
||||
while (cell->getNextRef (esm, ref))
|
||||
{
|
||||
std::string lowerCase;
|
||||
|
||||
std::transform (ref.refID.begin(), ref.refID.end(), std::back_inserter (lowerCase),
|
||||
(int(*)(int)) std::tolower);
|
||||
|
||||
mIds.push_back (lowerCase);
|
||||
}
|
||||
|
||||
std::sort (mIds.begin(), mIds.end());
|
||||
}
|
||||
|
||||
void loadRefs(const ESMStore &store, ESMReader &esm)
|
||||
{
|
||||
assert (cell);
|
||||
|
|
|
@ -287,8 +287,7 @@ namespace ESMS
|
|||
IntCells intCells;
|
||||
|
||||
// List of exterior cells. Indexed as extCells[gridX][gridY].
|
||||
typedef std::map<int, ESM::Cell*> ExtCellsCol;
|
||||
typedef std::map<int, ExtCellsCol> ExtCells;
|
||||
typedef std::map<std::pair<int, int>, ESM::Cell*> ExtCells;
|
||||
ExtCells extCells;
|
||||
|
||||
virtual void listIdentifier (std::vector<std::string>& identifier) const
|
||||
|
@ -303,13 +302,7 @@ namespace ESMS
|
|||
delete it->second;
|
||||
|
||||
for (ExtCells::iterator it = extCells.begin(); it!=extCells.end(); ++it)
|
||||
{
|
||||
ExtCellsCol& col = it->second;
|
||||
for (ExtCellsCol::iterator it = col.begin(); it!=col.end(); ++it)
|
||||
{
|
||||
delete it->second;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
@ -318,36 +311,36 @@ namespace ESMS
|
|||
IntCells::const_iterator it = intCells.find(id);
|
||||
|
||||
if(it == intCells.end())
|
||||
return NULL;
|
||||
throw std::runtime_error ("Interior cell not found - " + id);
|
||||
|
||||
return it->second;
|
||||
}
|
||||
|
||||
const ESM::Cell *searchExt (int x, int y) const
|
||||
{
|
||||
ExtCells::const_iterator it = extCells.find (x);
|
||||
ExtCells::const_iterator it = extCells.find (std::make_pair (x, y));
|
||||
|
||||
if (it==extCells.end())
|
||||
return 0;
|
||||
|
||||
ExtCellsCol::const_iterator it2 = it->second.find (y);
|
||||
|
||||
if (it2 == it->second.end())
|
||||
return 0;
|
||||
|
||||
return it2->second;
|
||||
return it->second;
|
||||
}
|
||||
|
||||
const ESM::Cell *findExt (int x, int y) const
|
||||
{
|
||||
const ESM::Cell *cell = searchExt (x, y);
|
||||
|
||||
if (!cell)
|
||||
throw std::runtime_error ("Exterior cell not found");
|
||||
|
||||
return cell;
|
||||
}
|
||||
const ESM::Cell *searchExtByName (const std::string& id) const
|
||||
{
|
||||
for (ExtCells::const_iterator iter = extCells.begin(); iter!=extCells.end(); ++iter)
|
||||
{
|
||||
const ExtCellsCol& column = iter->second;
|
||||
for (ExtCellsCol::const_iterator iter = column.begin(); iter!=column.end(); ++iter)
|
||||
{
|
||||
if ( toLower(iter->second->name) == toLower(id))
|
||||
return iter->second;
|
||||
}
|
||||
if (toLower (iter->second->name) == toLower (id))
|
||||
return iter->second;
|
||||
}
|
||||
|
||||
return 0;
|
||||
|
@ -358,14 +351,8 @@ namespace ESMS
|
|||
std::string id2 = toLower (id);
|
||||
|
||||
for (ExtCells::const_iterator iter = extCells.begin(); iter!=extCells.end(); ++iter)
|
||||
{
|
||||
const ExtCellsCol& column = iter->second;
|
||||
for (ExtCellsCol::const_iterator iter = column.begin(); iter!=column.end(); ++iter)
|
||||
{
|
||||
if (toLower (iter->second->region)==id)
|
||||
return iter->second;
|
||||
}
|
||||
}
|
||||
if (toLower (iter->second->region)==id)
|
||||
return iter->second;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
@ -389,7 +376,7 @@ namespace ESMS
|
|||
else
|
||||
{
|
||||
// Store exterior cells by grid position
|
||||
extCells[cell->data.gridX][cell->data.gridY] = cell;
|
||||
extCells[std::make_pair (cell->data.gridX, cell->data.gridY)] = cell;
|
||||
}
|
||||
}
|
||||
};
|
||||
|
|
Loading…
Reference in a new issue