commit
cd7aaab48e
@ -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);
|
||||
}
|
||||
|
||||
}
|
@ -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
|
@ -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();
|
||||
}
|
@ -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
|
@ -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.
|
||||
}
|
||||
|
||||
}
|
@ -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
|
@ -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);
|
||||
}
|
||||
|
||||
}
|
@ -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
|
Loading…
Reference in New Issue