mirror of https://github.com/OpenMW/openmw.git
post-merge fixes
commit
7c8853f6fe
@ -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
|
@ -0,0 +1,157 @@
|
||||
#include "configurationmanager.hpp"
|
||||
|
||||
#include <string>
|
||||
#include <fstream>
|
||||
#include <iostream>
|
||||
|
||||
namespace Cfg
|
||||
{
|
||||
|
||||
static const char* const openmwCfgFile = "openmw.cfg";
|
||||
static const char* const ogreCfgFile = "ogre.cfg";
|
||||
static const char* const pluginsCfgFile = "plugins.cfg";
|
||||
|
||||
|
||||
ConfigurationManager::ConfigurationManager()
|
||||
: mPath("openmw")
|
||||
{
|
||||
/**
|
||||
* According to task #168 plugins.cfg file shall be located in global
|
||||
* configuration path or in runtime configuration path.
|
||||
*/
|
||||
mPluginsCfgPath = mPath.getGlobalConfigPath() / pluginsCfgFile;
|
||||
if (!boost::filesystem::is_regular_file(mPluginsCfgPath))
|
||||
{
|
||||
mPluginsCfgPath = mPath.getRuntimeConfigPath() / pluginsCfgFile;
|
||||
if (!boost::filesystem::is_regular_file(mPluginsCfgPath))
|
||||
{
|
||||
std::cerr << "Failed to find " << pluginsCfgFile << " file!" << std::endl;
|
||||
mPluginsCfgPath.clear();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* According to task #168 ogre.cfg file shall be located only
|
||||
* in user configuration path.
|
||||
*/
|
||||
mOgreCfgPath = mPath.getLocalConfigPath() / ogreCfgFile;
|
||||
|
||||
mLogPath = mPath.getLocalConfigPath();
|
||||
}
|
||||
|
||||
ConfigurationManager::~ConfigurationManager()
|
||||
{
|
||||
}
|
||||
|
||||
void ConfigurationManager::readConfiguration(boost::program_options::variables_map& variables,
|
||||
boost::program_options::options_description& description)
|
||||
{
|
||||
loadConfig(mPath.getLocalConfigPath(), variables, description);
|
||||
boost::program_options::notify(variables);
|
||||
loadConfig(mPath.getRuntimeConfigPath(), variables, description);
|
||||
boost::program_options::notify(variables);
|
||||
loadConfig(mPath.getGlobalConfigPath(), variables, description);
|
||||
boost::program_options::notify(variables);
|
||||
}
|
||||
|
||||
void ConfigurationManager::loadConfig(const boost::filesystem::path& path,
|
||||
boost::program_options::variables_map& variables,
|
||||
boost::program_options::options_description& description)
|
||||
{
|
||||
boost::filesystem::path cfgFile(path);
|
||||
cfgFile /= std::string(openmwCfgFile);
|
||||
if (boost::filesystem::is_regular_file(cfgFile))
|
||||
{
|
||||
std::cout << "Loading config file: " << cfgFile.string() << "... ";
|
||||
|
||||
std::ifstream configFileStream(cfgFile.string().c_str());
|
||||
if (configFileStream.is_open())
|
||||
{
|
||||
boost::program_options::store(boost::program_options::parse_config_file(
|
||||
configFileStream, description), variables);
|
||||
|
||||
std::cout << "done." << std::endl;
|
||||
}
|
||||
else
|
||||
{
|
||||
std::cout << "failed." << std::endl;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
const boost::filesystem::path& ConfigurationManager::getGlobalConfigPath() const
|
||||
{
|
||||
return mPath.getGlobalConfigPath();
|
||||
}
|
||||
|
||||
void ConfigurationManager::setGlobalConfigPath(const boost::filesystem::path& newPath)
|
||||
{
|
||||
mPath.setGlobalConfigPath(newPath);
|
||||
}
|
||||
|
||||
const boost::filesystem::path& ConfigurationManager::getLocalConfigPath() const
|
||||
{
|
||||
return mPath.getLocalConfigPath();
|
||||
}
|
||||
|
||||
void ConfigurationManager::setLocalConfigPath(const boost::filesystem::path& newPath)
|
||||
{
|
||||
mPath.setLocalConfigPath(newPath);
|
||||
}
|
||||
|
||||
const boost::filesystem::path& ConfigurationManager::getRuntimeConfigPath() const
|
||||
{
|
||||
return mPath.getRuntimeConfigPath();
|
||||
}
|
||||
|
||||
void ConfigurationManager::setRuntimeConfigPath(const boost::filesystem::path& newPath)
|
||||
{
|
||||
mPath.setRuntimeConfigPath(newPath);
|
||||
}
|
||||
|
||||
const boost::filesystem::path& ConfigurationManager::getGlobalDataPath() const
|
||||
{
|
||||
return mPath.getGlobalDataPath();
|
||||
}
|
||||
|
||||
void ConfigurationManager::setGlobalDataPath(const boost::filesystem::path& newPath)
|
||||
{
|
||||
mPath.setGlobalDataPath(newPath);
|
||||
}
|
||||
|
||||
const boost::filesystem::path& ConfigurationManager::getLocalDataPath() const
|
||||
{
|
||||
return mPath.getLocalDataPath();
|
||||
}
|
||||
|
||||
void ConfigurationManager::setLocalDataPath(const boost::filesystem::path& newPath)
|
||||
{
|
||||
mPath.setLocalDataPath(newPath);
|
||||
}
|
||||
|
||||
const boost::filesystem::path& ConfigurationManager::getRuntimeDataPath() const
|
||||
{
|
||||
return mPath.getRuntimeDataPath();
|
||||
}
|
||||
|
||||
void ConfigurationManager::setRuntimeDataPath(const boost::filesystem::path& newPath)
|
||||
{
|
||||
mPath.setRuntimeDataPath(newPath);
|
||||
}
|
||||
|
||||
const boost::filesystem::path& ConfigurationManager::getOgreConfigPath() const
|
||||
{
|
||||
return mOgreCfgPath;
|
||||
}
|
||||
|
||||
const boost::filesystem::path& ConfigurationManager::getPluginsConfigPath() const
|
||||
{
|
||||
return mPluginsCfgPath;
|
||||
}
|
||||
|
||||
const boost::filesystem::path& ConfigurationManager::getLogPath() const
|
||||
{
|
||||
return mLogPath;
|
||||
}
|
||||
|
||||
} /* namespace Cfg */
|
@ -0,0 +1,62 @@
|
||||
#ifndef COMPONENTS_CFG_CONFIGURATIONMANAGER_HPP
|
||||
#define COMPONENTS_CFG_CONFIGURATIONMANAGER_HPP
|
||||
|
||||
#include <boost/program_options.hpp>
|
||||
#include <boost/filesystem.hpp>
|
||||
|
||||
#include <components/files/path.hpp>
|
||||
|
||||
/**
|
||||
* \namespace Cfg
|
||||
*/
|
||||
namespace Cfg
|
||||
{
|
||||
|
||||
/**
|
||||
* \struct ConfigurationManager
|
||||
*/
|
||||
struct ConfigurationManager
|
||||
{
|
||||
ConfigurationManager();
|
||||
virtual ~ConfigurationManager();
|
||||
|
||||
void readConfiguration(boost::program_options::variables_map& variables,
|
||||
boost::program_options::options_description& description);
|
||||
|
||||
const boost::filesystem::path& getGlobalConfigPath() const;
|
||||
void setGlobalConfigPath(const boost::filesystem::path& newPath);
|
||||
|
||||
const boost::filesystem::path& getLocalConfigPath() const;
|
||||
void setLocalConfigPath(const boost::filesystem::path& newPath);
|
||||
|
||||
const boost::filesystem::path& getRuntimeConfigPath() const;
|
||||
void setRuntimeConfigPath(const boost::filesystem::path& newPath);
|
||||
|
||||
const boost::filesystem::path& getGlobalDataPath() const;
|
||||
void setGlobalDataPath(const boost::filesystem::path& newPath);
|
||||
|
||||
const boost::filesystem::path& getLocalDataPath() const;
|
||||
void setLocalDataPath(const boost::filesystem::path& newPath);
|
||||
|
||||
const boost::filesystem::path& getRuntimeDataPath() const;
|
||||
void setRuntimeDataPath(const boost::filesystem::path& newPath);
|
||||
|
||||
const boost::filesystem::path& getOgreConfigPath() const;
|
||||
const boost::filesystem::path& getPluginsConfigPath() const;
|
||||
const boost::filesystem::path& getLogPath() const;
|
||||
|
||||
private:
|
||||
void loadConfig(const boost::filesystem::path& path,
|
||||
boost::program_options::variables_map& variables,
|
||||
boost::program_options::options_description& description);
|
||||
|
||||
Files::Path<> mPath;
|
||||
|
||||
boost::filesystem::path mOgreCfgPath;
|
||||
boost::filesystem::path mPluginsCfgPath;
|
||||
boost::filesystem::path mLogPath;
|
||||
};
|
||||
|
||||
} /* namespace Cfg */
|
||||
|
||||
#endif /* COMPONENTS_CFG_CONFIGURATIONMANAGER_HPP */
|
@ -0,0 +1,12 @@
|
||||
#include "fileops.hpp"
|
||||
#include <boost/filesystem.hpp>
|
||||
|
||||
namespace Files
|
||||
{
|
||||
|
||||
bool isFile(const char *name)
|
||||
{
|
||||
return boost::filesystem::exists(boost::filesystem::path(name));
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,13 @@
|
||||
#ifndef COMPONENTS_FILES_FILEOPS_HPP
|
||||
#define COMPONENTS_FILES_FILEOPS_HPP
|
||||
|
||||
namespace Files
|
||||
{
|
||||
|
||||
///\brief Check if a given path is an existing file (not a directory)
|
||||
///\param [in] name - filename
|
||||
bool isFile(const char *name);
|
||||
|
||||
}
|
||||
|
||||
#endif /* COMPONENTS_FILES_FILEOPS_HPP */
|
@ -0,0 +1,160 @@
|
||||
/**
|
||||
* Open Morrowind - an opensource Elder Scrolls III: Morrowind
|
||||
* engine implementation.
|
||||
*
|
||||
* Copyright (C) 2011 Open Morrowind Team
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
/** \file components/files/linuxpath.cpp */
|
||||
|
||||
#include "linuxpath.hpp"
|
||||
|
||||
#if defined(__linux__)
|
||||
|
||||
#include <cstdlib>
|
||||
#include <cstring>
|
||||
#include <pwd.h>
|
||||
#include <unistd.h>
|
||||
|
||||
/**
|
||||
* \namespace Files
|
||||
*/
|
||||
namespace Files
|
||||
{
|
||||
|
||||
boost::filesystem::path LinuxPath::getLocalConfigPath() const
|
||||
{
|
||||
boost::filesystem::path localConfigPath(".");
|
||||
boost::filesystem::path suffix("/");
|
||||
|
||||
const char* theDir = getenv("OPENMW_CONFIG");
|
||||
if (theDir == NULL)
|
||||
{
|
||||
theDir = getenv("XDG_CONFIG_HOME");
|
||||
if (theDir == NULL)
|
||||
{
|
||||
theDir = getenv("HOME");
|
||||
if (theDir == NULL)
|
||||
{
|
||||
struct passwd* pwd = getpwuid(getuid());
|
||||
if (pwd != NULL)
|
||||
{
|
||||
theDir = pwd->pw_dir;
|
||||
}
|
||||
}
|
||||
if (theDir != NULL)
|
||||
{
|
||||
suffix = boost::filesystem::path("/.config/");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (theDir != NULL) {
|
||||
localConfigPath = boost::filesystem::path(theDir);
|
||||
}
|
||||
|
||||
localConfigPath /= suffix;
|
||||
|
||||
return localConfigPath;
|
||||
}
|
||||
|
||||
boost::filesystem::path LinuxPath::getGlobalConfigPath() const
|
||||
{
|
||||
boost::filesystem::path globalConfigPath("/etc/xdg/");
|
||||
|
||||
char* theDir = getenv("XDG_CONFIG_DIRS");
|
||||
if (theDir != NULL)
|
||||
{
|
||||
// We take only first path from list
|
||||
char* ptr = strtok(theDir, ":");
|
||||
if (ptr != NULL)
|
||||
{
|
||||
globalConfigPath = boost::filesystem::path(ptr);
|
||||
globalConfigPath /= boost::filesystem::path("/");
|
||||
}
|
||||
}
|
||||
|
||||
return globalConfigPath;
|
||||
}
|
||||
|
||||
boost::filesystem::path LinuxPath::getRuntimeConfigPath() const
|
||||
{
|
||||
return boost::filesystem::path("./");
|
||||
}
|
||||
|
||||
boost::filesystem::path LinuxPath::getLocalDataPath() const
|
||||
{
|
||||
boost::filesystem::path localDataPath(".");
|
||||
boost::filesystem::path suffix("/");
|
||||
|
||||
const char* theDir = getenv("OPENMW_DATA");
|
||||
if (theDir == NULL)
|
||||
{
|
||||
theDir = getenv("XDG_DATA_HOME");
|
||||
if (theDir == NULL)
|
||||
{
|
||||
theDir = getenv("HOME");
|
||||
if (theDir == NULL)
|
||||
{
|
||||
struct passwd* pwd = getpwuid(getuid());
|
||||
if (pwd != NULL)
|
||||
{
|
||||
theDir = pwd->pw_dir;
|
||||
}
|
||||
}
|
||||
if (theDir != NULL)
|
||||
{
|
||||
suffix = boost::filesystem::path("/.local/share/");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (theDir != NULL) {
|
||||
localDataPath = boost::filesystem::path(theDir);
|
||||
}
|
||||
|
||||
localDataPath /= suffix;
|
||||
return localDataPath;
|
||||
}
|
||||
|
||||
boost::filesystem::path LinuxPath::getGlobalDataPath() const
|
||||
{
|
||||
boost::filesystem::path globalDataPath("/usr/local/share/");
|
||||
|
||||
char* theDir = getenv("XDG_DATA_DIRS");
|
||||
if (theDir != NULL)
|
||||
{
|
||||
// We take only first path from list
|
||||
char* ptr = strtok(theDir, ":");
|
||||
if (ptr != NULL)
|
||||
{
|
||||
globalDataPath = boost::filesystem::path(ptr);
|
||||
globalDataPath /= boost::filesystem::path("/");
|
||||
}
|
||||
}
|
||||
|
||||
return globalDataPath;
|
||||
}
|
||||
|
||||
boost::filesystem::path LinuxPath::getRuntimeDataPath() const
|
||||
{
|
||||
return boost::filesystem::path("./data/");
|
||||
}
|
||||
|
||||
|
||||
} /* namespace Files */
|
||||
|
||||
#endif /* defined(__linux__) */
|
@ -0,0 +1,90 @@
|
||||
/**
|
||||
* Open Morrowind - an opensource Elder Scrolls III: Morrowind
|
||||
* engine implementation.
|
||||
*
|
||||
* Copyright (C) 2011 Open Morrowind Team
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
/** \file components/files/linuxpath.hpp */
|
||||
|
||||
#ifndef COMPONENTS_FILES_LINUXPATH_H
|
||||
#define COMPONENTS_FILES_LINUXPATH_H
|
||||
|
||||
#if defined(__linux__)
|
||||
|
||||
#include <boost/filesystem.hpp>
|
||||
|
||||
/**
|
||||
* \namespace Files
|
||||
*/
|
||||
namespace Files
|
||||
{
|
||||
|
||||
/**
|
||||
* \struct LinuxPath
|
||||
*/
|
||||
struct LinuxPath
|
||||
{
|
||||
/**
|
||||
* \brief Return path to the local configuration directory.
|
||||
*
|
||||
* \return boost::filesystem::path
|
||||
*/
|
||||
boost::filesystem::path getLocalConfigPath() const;
|
||||
|
||||
/**
|
||||
* \brief Return path to the global (system) configuration directory.
|
||||
*
|
||||
* \return boost::filesystem::path
|
||||
*/
|
||||
boost::filesystem::path getGlobalConfigPath() const;
|
||||
|
||||
/**
|
||||
* \brief Return path to the runtime configuration directory which is the
|
||||
* place where an application was started.
|
||||
*
|
||||
* \return boost::filesystem::path
|
||||
*/
|
||||
boost::filesystem::path getRuntimeConfigPath() const;
|
||||
|
||||
/**
|
||||
* \brief Return path to the local data directory.
|
||||
*
|
||||
* \return boost::filesystem::path
|
||||
*/
|
||||
boost::filesystem::path getLocalDataPath() const;
|
||||
|
||||
/**
|
||||
* \brief Return path to the global (system) data directory.
|
||||
*
|
||||
* \return boost::filesystem::path
|
||||
*/
|
||||
boost::filesystem::path getGlobalDataPath() const;
|
||||
|
||||
/**
|
||||
* \brief Return runtime data path which is a location where
|
||||
* an application was started with 'data' suffix.
|
||||
*
|
||||
* \return boost::filesystem::path
|
||||
*/
|
||||
boost::filesystem::path getRuntimeDataPath() const;
|
||||
};
|
||||
|
||||
} /* namespace Files */
|
||||
|
||||
#endif /* defined(__linux__) */
|
||||
|
||||
#endif /* COMPONENTS_FILES_LINUXPATH_H */
|
@ -0,0 +1,118 @@
|
||||
/**
|
||||
* Open Morrowind - an opensource Elder Scrolls III: Morrowind
|
||||
* engine implementation.
|
||||
*
|
||||
* Copyright (C) 2011 Open Morrowind Team
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
/** \file components/files/macospath.cpp */
|
||||
|
||||
#include "macospath.hpp"
|
||||
|
||||
#if defined(macintosh) || defined(Macintosh) || defined(__APPLE__) || defined(__MACH__)
|
||||
|
||||
#include <cstdlib>
|
||||
#include <pwd.h>
|
||||
#include <unistd.h>
|
||||
|
||||
/**
|
||||
* \namespace Files
|
||||
*/
|
||||
namespace Files
|
||||
{
|
||||
|
||||
boost::filesystem::path MacOsPath::getLocalConfigPath() const
|
||||
{
|
||||
boost::filesystem::path localConfigPath(".");
|
||||
boost::filesystem::path suffix("/");
|
||||
|
||||
const char* theDir = getenv("HOME");
|
||||
if (theDir == NULL)
|
||||
{
|
||||
struct passwd* pwd = getpwuid(getuid());
|
||||
if (pwd != NULL)
|
||||
{
|
||||
theDir = pwd->pw_dir;
|
||||
}
|
||||
}
|
||||
if (theDir != NULL)
|
||||
{
|
||||
localConfigPath = boost::filesystem::path(theDir) / "Library/Preferences/";
|
||||
}
|
||||
|
||||
localConfigPath /= suffix;
|
||||
|
||||
return localConfigPath;
|
||||
}
|
||||
|
||||
boost::filesystem::path MacOsPath::getGlobalConfigPath() const
|
||||
{
|
||||
boost::filesystem::path globalConfigPath("/Library/Preferences/");
|
||||
return globalConfigPath;
|
||||
}
|
||||
|
||||
boost::filesystem::path MacOsPath::getRuntimeConfigPath() const
|
||||
{
|
||||
return boost::filesystem::path("./");
|
||||
}
|
||||
|
||||
boost::filesystem::path MacOsPath::getLocalDataPath() const
|
||||
{
|
||||
boost::filesystem::path localDataPath(".");
|
||||
boost::filesystem::path suffix("/");
|
||||
|
||||
const char* theDir = getenv("OPENMW_DATA");
|
||||
if (theDir == NULL)
|
||||
{
|
||||
theDir = getenv("HOME");
|
||||
if (theDir == NULL)
|
||||
{
|
||||
struct passwd* pwd = getpwuid(getuid());
|
||||
if (pwd != NULL)
|
||||
{
|
||||
theDir = pwd->pw_dir;
|
||||
}
|
||||
}
|
||||
if (theDir != NULL)
|
||||
{
|
||||
suffix = boost::filesystem::path("/Library/Application Support/");
|
||||
}
|
||||
}
|
||||
|
||||
if (theDir != NULL)
|
||||
{
|
||||
localDataPath = boost::filesystem::path(theDir);
|
||||
}
|
||||
|
||||
localDataPath /= suffix;
|
||||
return localDataPath;
|
||||
}
|
||||
|
||||
boost::filesystem::path MacOsPath::getGlobalDataPath() const
|
||||
{
|
||||
boost::filesystem::path globalDataPath("/Library/Application Support/");
|
||||
return globalDataPath;
|
||||
}
|
||||
|
||||
boost::filesystem::path MacOsPath::getRuntimeDataPath() const
|
||||
{
|
||||
return boost::filesystem::path("./data/");
|
||||
}
|
||||
|
||||
|
||||
} /* namespace Files */
|
||||
|
||||
#endif /* defined(macintosh) || defined(Macintosh) || defined(__APPLE__) || defined(__MACH__) */
|
@ -0,0 +1,90 @@
|
||||
/**
|
||||
* Open Morrowind - an opensource Elder Scrolls III: Morrowind
|
||||
* engine implementation.
|
||||
*
|
||||
* Copyright (C) 2011 Open Morrowind Team
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
/** \file components/files/macospath.hpp */
|
||||
|
||||
#ifndef COMPONENTS_FILES_MACOSPATH_H
|
||||
#define COMPONENTS_FILES_MACOSPATH_H
|
||||
|
||||
#if defined(macintosh) || defined(Macintosh) || defined(__APPLE__) || defined(__MACH__)
|
||||
|
||||
#include <boost/filesystem.hpp>
|
||||
|
||||
/**
|
||||
* \namespace Files
|
||||
*/
|
||||
namespace Files
|
||||
{
|
||||
|
||||
/**
|
||||
* \struct MacOsPath
|
||||
*/
|
||||
struct MacOsPath
|
||||
{
|
||||
/**
|
||||
* \brief Return path to the local configuration directory.
|
||||
*
|
||||
* \return boost::filesystem::path
|
||||
*/
|
||||
boost::filesystem::path getLocalConfigPath() const;
|
||||
|
||||
/**
|
||||
* \brief Return path to the global (system) configuration directory.
|
||||
*
|
||||
* \return boost::filesystem::path
|
||||
*/
|
||||
boost::filesystem::path getGlobalConfigPath() const;
|
||||
|
||||
/**
|
||||
* \brief Return path to the runtime configuration directory which is the
|
||||
* place where an application was started.
|
||||
*
|
||||
* \return boost::filesystem::path
|
||||
*/
|
||||
boost::filesystem::path getRuntimeConfigPath() const;
|
||||
|
||||
/**
|
||||
* \brief Return path to the local data directory.
|
||||
*
|
||||
* \return boost::filesystem::path
|
||||
*/
|
||||
boost::filesystem::path getLocalDataPath() const;
|
||||
|
||||
/**
|
||||
* \brief Return path to the global (system) data directory.
|
||||
*
|
||||
* \return boost::filesystem::path
|
||||
*/
|
||||
boost::filesystem::path getGlobalDataPath() const;
|
||||
|
||||
/**
|
||||
* \brief Return runtime data path which is a location where
|
||||
* an application was started with 'data' suffix.
|
||||
*
|
||||
* \return boost::filesystem::path
|
||||
*/
|
||||
boost::filesystem::path getRuntimeDataPath() const;
|
||||
};
|
||||
|
||||
} /* namespace Files */
|
||||
|
||||
#endif /* defined(macintosh) || defined(Macintosh) || defined(__APPLE__) || defined(__MACH__) */
|
||||
|
||||
#endif /* COMPONENTS_FILES_MACOSPATH_H */
|
@ -1,61 +0,0 @@
|
||||
#include "path.hpp"
|
||||
|
||||
#include <boost/filesystem.hpp>
|
||||
|
||||
#include <OgrePlatform.h>
|
||||
#include <string>
|
||||
|
||||
#if OGRE_PLATFORM == OGRE_PLATFORM_APPLE
|
||||
#include <OSX/macUtils.h>
|
||||
#endif
|
||||
|
||||
#if OGRE_PLATFORM == OGRE_PLATFORM_LINUX || OGRE_PLATFORM == OGRE_PLATFORM_APPLE
|
||||
#include <stdlib.h> //getenv
|
||||
#endif
|
||||
|
||||
std::string Files::getPath (PathTypeEnum parType, const std::string parApp, const std::string parFile)
|
||||
{
|
||||
std::string theBasePath;
|
||||
if (parType==Path_ConfigGlobal)
|
||||
{
|
||||
#if OGRE_PLATFORM == OGRE_PLATFORM_APPLE
|
||||
boost::filesystem::path path(Ogre::macBundlePath());
|
||||
path = path.parent_path();
|
||||
theBasePath = path.string() + "/";
|
||||
#elif OGRE_PLATFORM == OGRE_PLATFORM_LINUX
|
||||
theBasePath = "/etc/"+parApp+"/";
|
||||
#else
|
||||
theBasePath = "";
|
||||
#endif
|
||||
|
||||
}
|
||||
else if (parType==Path_ConfigUser)
|
||||
{
|
||||
#if OGRE_PLATFORM == OGRE_PLATFORM_LINUX || OGRE_PLATFORM == OGRE_PLATFORM_APPLE
|
||||
const char* theDir;
|
||||
if ((theDir = getenv("OPENMW_HOME")) != NULL)
|
||||
{
|
||||
theBasePath = std::string(theDir)+"/";
|
||||
}
|
||||
else
|
||||
{
|
||||
if ((theDir = getenv("XDG_CONFIG_HOME")))
|
||||
{
|
||||
theBasePath = std::string(theDir)+"/"+parApp+"/";
|
||||
}
|
||||
else
|
||||
{
|
||||
if ((theDir = getenv("HOME")) == NULL)
|
||||
return parFile;
|
||||
theBasePath = std::string(theDir)+"/.config/"+parApp+"/";
|
||||
}
|
||||
}
|
||||
boost::filesystem::create_directories(boost::filesystem::path(theBasePath));
|
||||
#else
|
||||
theBasePath = "";
|
||||
#endif
|
||||
}
|
||||
|
||||
theBasePath.append(parFile);
|
||||
return theBasePath;
|
||||
}
|
@ -1,17 +1,232 @@
|
||||
/**
|
||||
* Open Morrowind - an opensource Elder Scrolls III: Morrowind
|
||||
* engine implementation.
|
||||
*
|
||||
* Copyright (C) 2011 Open Morrowind Team
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
/** \file components/files/path.hpp */
|
||||
|
||||
#ifndef COMPONENTS_FILES_PATH_HPP
|
||||
#define COMPONENTS_FILES_PATH_HPP
|
||||
|
||||
#include <string>
|
||||
#include <boost/filesystem.hpp>
|
||||
|
||||
#if defined(__linux__)
|
||||
#include <components/files/linuxpath.hpp>
|
||||
namespace Files { typedef LinuxPath TargetPathType; }
|
||||
|
||||
#elif defined(__WIN32) || defined(__WINDOWS__)
|
||||
#include <components/files/windowspath.hpp>
|
||||
namespace Files { typedef WindowsPath TargetPathType; }
|
||||
|
||||
#elif defined(macintosh) || defined(Macintosh) || defined(__APPLE__) || defined(__MACH__)
|
||||
#include <components/files/macospath.hpp>
|
||||
namespace Files { typedef MacOsPath TargetPathType; }
|
||||
|
||||
#else
|
||||
#error "Unknown platform!"
|
||||
#endif
|
||||
|
||||
|
||||
/**
|
||||
* \namespace Files
|
||||
*/
|
||||
namespace Files
|
||||
{
|
||||
enum PathTypeEnum
|
||||
|
||||
/**
|
||||
* \struct Path
|
||||
*
|
||||
* \tparam P - Path strategy class type (depends on target system)
|
||||
*
|
||||
*/
|
||||
template
|
||||
<
|
||||
class P = TargetPathType
|
||||
>
|
||||
struct Path
|
||||
{
|
||||
typedef P PathType;
|
||||
|
||||
/**
|
||||
* \brief Path constructor.
|
||||
*
|
||||
* \param [in] application_name - Name of the application
|
||||
*/
|
||||
Path(const std::string& application_name)
|
||||
: mPath()
|
||||
, mLocalConfigPath(mPath.getLocalConfigPath())
|
||||
, mGlobalConfigPath(mPath.getGlobalConfigPath())
|
||||
, mRuntimeConfigPath(mPath.getRuntimeConfigPath())
|
||||
, mLocalDataPath(mPath.getLocalDataPath())
|
||||
, mGlobalDataPath(mPath.getGlobalDataPath())
|
||||
, mRuntimeDataPath(mPath.getRuntimeDataPath())
|
||||
{
|
||||
Path_ConfigUser,
|
||||
Path_ConfigGlobal
|
||||
};
|
||||
if (!application_name.empty())
|
||||
{
|
||||
boost::filesystem::path suffix(application_name + std::string("/"));
|
||||
|
||||
std::string getPath (PathTypeEnum parType, const std::string parApp, const std::string parFile);
|
||||
}
|
||||
mLocalConfigPath /= suffix;
|
||||
mGlobalConfigPath /= suffix;
|
||||
|
||||
#endif
|
||||
mLocalDataPath /= suffix;
|
||||
mGlobalDataPath /= suffix;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* \brief Return path pointing to the user local configuration directory.
|
||||
*
|
||||
* \return boost::filesystem::path
|
||||
*/
|
||||
const boost::filesystem::path& getLocalConfigPath() const
|
||||
{
|
||||
return mLocalConfigPath;
|
||||
}
|
||||
|
||||
/**
|
||||
* \brief Sets new local configuration path.
|
||||
*
|
||||
* \param [in] path - New path
|
||||
*/
|
||||
void setLocalConfigPath(const boost::filesystem::path& path)
|
||||
{
|
||||
mLocalConfigPath = path;
|
||||
}
|
||||
|
||||
/**
|
||||
* \brief Return path pointing to the global (system) configuration directory.
|
||||
*
|
||||
* \return boost::filesystem::path
|
||||
*/
|
||||
const boost::filesystem::path& getGlobalConfigPath() const
|
||||
{
|
||||
return mGlobalConfigPath;
|
||||
}
|
||||
|
||||
/**
|
||||
* \brief Sets new global configuration path.
|
||||
*
|
||||
* \param [in] path - New path
|
||||
*/
|
||||
void setGlobalConfigPath(const boost::filesystem::path& path)
|
||||
{
|
||||
mGlobalConfigPath = path;
|
||||
}
|
||||
|
||||
/**
|
||||
* \brief Return path pointing to the directory where application was started.
|
||||
*
|
||||
* \return boost::filesystem::path
|
||||
*/
|
||||
const boost::filesystem::path& getRuntimeConfigPath() const
|
||||
{
|
||||
return mRuntimeConfigPath;
|
||||
}
|
||||
|
||||
/**
|
||||
* \brief Sets new runtime configuration path.
|
||||
*
|
||||
* \param [in] path - New path
|
||||
*/
|
||||
void setRuntimeConfigPath(const boost::filesystem::path& path)
|
||||
{
|
||||
mRuntimeConfigPath = path;
|
||||
}
|
||||
|
||||
/**
|
||||
* \brief Return path pointing to the user local data directory.
|
||||
*
|
||||
* \return boost::filesystem::path
|
||||
*/
|
||||
const boost::filesystem::path& getLocalDataPath() const
|
||||
{
|
||||
return mLocalDataPath;
|
||||
}
|
||||
|
||||
/**
|
||||
* \brief Sets new local data path.
|
||||
*
|
||||
* \param [in] path - New path
|
||||
*/
|
||||
void setLocalDataPath(const boost::filesystem::path& path)
|
||||
{
|
||||
mLocalDataPath = path;
|
||||
}
|
||||
|
||||
/**
|
||||
* \brief Return path pointing to the global (system) data directory.
|
||||
*
|
||||
* \return boost::filesystem::path
|
||||
*/
|
||||
const boost::filesystem::path& getGlobalDataPath() const
|
||||
{
|
||||
return mGlobalDataPath;
|
||||
}
|
||||
|
||||
/**
|
||||
* \brief Sets new global (system) data directory.
|
||||
*
|
||||
* \param [in] path - New path
|
||||
*/
|
||||
void setGlobalDataPath(const boost::filesystem::path& path)
|
||||
{
|
||||
mGlobalDataPath = path;
|
||||
}
|
||||
|
||||
/**
|
||||
* \brief Return path pointing to the directory where application was started.
|
||||
*
|
||||
* \return boost::filesystem::path
|
||||
*/
|
||||
const boost::filesystem::path& getRuntimeDataPath() const
|
||||
{
|
||||
return mRuntimeDataPath;
|
||||
}
|
||||
|
||||
/**
|
||||
* \brief Sets new runtime data directory.
|
||||
*
|
||||
* \param [in] path - New path
|
||||
*/
|
||||
void setRuntimeDataPath(const boost::filesystem::path& path)
|
||||
{
|
||||
mRuntimeDataPath = path;
|
||||
}
|
||||
|
||||
private:
|
||||
PathType mPath;
|
||||
|
||||
boost::filesystem::path mLocalConfigPath; /**< User local path to the configuration files */
|
||||
boost::filesystem::path mGlobalConfigPath; /**< Global path to the configuration files */
|
||||
boost::filesystem::path mRuntimeConfigPath; /**< Runtime path to the configuration files.
|
||||
By default it is the same directory where
|
||||
application was run */
|
||||
|
||||
boost::filesystem::path mLocalDataPath; /**< User local application data path (user plugins / mods / etc.) */
|
||||
boost::filesystem::path mGlobalDataPath; /**< Global application data path */
|
||||
boost::filesystem::path mRuntimeDataPath; /**< Runtime path to the configuration files.
|
||||
By default it is a 'data' directory in same
|
||||
directory where application was run */
|
||||
|
||||
};
|
||||
|
||||
|
||||
} /* namespace Files */
|
||||
|
||||
#endif /* COMPONENTS_FILES_PATH_HPP */
|
||||
|
@ -0,0 +1,72 @@
|
||||
#include "windowspath.hpp"
|
||||
|
||||
#if defined(_WIN32) || defined(__WINDOWS__)
|
||||
|
||||
#include <cstring>
|
||||
|
||||
#include <windows.h>
|
||||
#include <shobj.h>
|
||||
|
||||
namespace Files
|
||||
{
|
||||
|
||||
boost::filesystem::path WindowsPath::getLocalConfigPath() const
|
||||
{
|
||||
boost::filesystem::path localConfigPath(".");
|
||||
boost::filesystem::path suffix("/");
|
||||
|
||||
TCHAR path[MAX_PATH];
|
||||
memset(path, 0, sizeof(path));
|
||||
|
||||
if(SUCCEEDED(SHGetFolderPath(NULL, CSIDL_PERSONAL | CSIDL_FLAG_CREATE, NULL, 0, path)))
|
||||
{
|
||||
PathAppend(path, TEXT("My Games"));
|
||||
localConfigPath = boost::filesystem::path(path);
|
||||
}
|
||||
|
||||
localConfigPath /= suffix;
|
||||
|
||||
return localConfigPath;
|
||||
}
|
||||
|
||||
boost::filesystem::path WindowsPath::getGlobalConfigPath() const
|
||||
{
|
||||
boost::filesystem::path globalConfigPath(".");
|
||||
boost::filesystem::path suffix("/");
|
||||
|
||||
TCHAR path[MAX_PATH];
|
||||
memset(path, 0, sizeof(path));
|
||||
|
||||
if(SUCCEEDED(SHGetFolderPath(NULL, CSIDL_PROGRAM_FILES | CSIDL_FLAG_CREATE, NULL, 0, path)))
|
||||
{
|
||||
globalConfigPath = boost::filesystem::path(path);
|
||||
}
|
||||
|
||||
globalConfigPath /= suffix;
|
||||
|
||||
return globalConfigPath;
|
||||
}
|
||||
|
||||
boost::filesystem::path WindowsPath::getRuntimeConfigPath() const
|
||||
{
|
||||
return boost::filesystem::path("./");
|
||||
}
|
||||
|
||||
boost::filesystem::path WindowsPath::getLocalDataPath() const
|
||||
{
|
||||
return getLocalConfigPath();
|
||||
}
|
||||
|
||||
boost::filesystem::path WindowsPath::getGlobalDataPath() const
|
||||
{
|
||||
return getGlobalConfigPath();
|
||||
}
|
||||
|
||||
boost::filesystem::path WindowsPath::getRuntimeDataPath() const
|
||||
{
|
||||
return boost::filesystem::path("./data/");
|
||||
}
|
||||
|
||||
} /* namespace Files */
|
||||
|
||||
#endif /* defined(_WIN32) || defined(__WINDOWS__) */
|
@ -0,0 +1,90 @@
|
||||
/**
|
||||
* Open Morrowind - an opensource Elder Scrolls III: Morrowind
|
||||
* engine implementation.
|
||||
*
|
||||
* Copyright (C) 2011 Open Morrowind Team
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
/** \file components/files/windowspath.hpp */
|
||||
|
||||
#ifndef COMPONENTS_FILES_WINDOWSPATH_HPP
|
||||
#define COMPONENTS_FILES_WINDOWSPATH_HPP
|
||||
|
||||
#if defined(_WIN32) || defined(__WINDOWS__)
|
||||
|
||||
#include <boost/filesystem.hpp>
|
||||
|
||||
/**
|
||||
* \namespace Files
|
||||
*/
|
||||
namespace Files
|
||||
{
|
||||
|
||||
/**
|
||||
* \struct WindowsPath
|
||||
*/
|
||||
struct WindowsPath
|
||||
{
|
||||
/**
|
||||
* \brief Returns "X:\Documents And Settings\<User name>\My Documents\My Games\"
|
||||
*
|
||||
* \return boost::filesystem::path
|
||||
*/
|
||||
boost::filesystem::path getLocalConfigPath() const;
|
||||
|
||||
/**
|
||||
* \brief Returns "X:\Program Files\"
|
||||
*
|
||||
* \return boost::filesystem::path
|
||||
*/
|
||||
boost::filesystem::path getGlobalConfigPath() const;
|
||||
|
||||
/**
|
||||
* \brief Return runtime configuration path which is a location where
|
||||
* an application was started
|
||||
*
|
||||
* \return boost::filesystem::path
|
||||
*/
|
||||
boost::filesystem::path getRuntimeConfigPath() const;
|
||||
|
||||
/**
|
||||
* \brief Return same path like getLocalConfigPath
|
||||
*
|
||||
* \return boost::filesystem::path
|
||||
*/
|
||||
boost::filesystem::path getLocalDataPath() const;
|
||||
|
||||
/**
|
||||
* \brief Return same path like getGlobalConfigPath
|
||||
*
|
||||
* \return boost::filesystem::path
|
||||
*/
|
||||
boost::filesystem::path getGlobalDataPath() const;
|
||||
|
||||
/**
|
||||
* \brief Return runtime data path which is a location where
|
||||
* an application was started with 'data' suffix.
|
||||
*
|
||||
* \return boost::filesystem::path
|
||||
*/
|
||||
boost::filesystem::path getRuntimeDataPath() const;
|
||||
};
|
||||
|
||||
} /* namespace Files */
|
||||
|
||||
#endif /* defined(_WIN32) || defined(__WINDOWS__) */
|
||||
|
||||
#endif /* COMPONENTS_FILES_WINDOWSPATH_HPP */
|
@ -1,16 +0,0 @@
|
||||
#include "fileops.hpp"
|
||||
#include <boost/filesystem.hpp>
|
||||
#include <string>
|
||||
|
||||
#include <OgrePrerequisites.h>
|
||||
|
||||
namespace Misc
|
||||
{
|
||||
|
||||
bool isFile(const char *name)
|
||||
{
|
||||
boost::filesystem::path cfg_file_path(name);
|
||||
return boost::filesystem::exists(cfg_file_path);
|
||||
}
|
||||
|
||||
}
|
@ -1,18 +0,0 @@
|
||||
#ifndef MISC_FILEOPS_H
|
||||
#define MISC_FILEOPS_H
|
||||
|
||||
#include <string>
|
||||
|
||||
namespace Misc
|
||||
{
|
||||
|
||||
/// Check if a given path is an existing file (not a directory)
|
||||
bool isFile(const char *name);
|
||||
|
||||
#if OGRE_PLATFORM == OGRE_PLATFORM_APPLE
|
||||
std::string macBundlePath();
|
||||
#endif
|
||||
|
||||
}
|
||||
|
||||
#endif
|
@ -1 +1 @@
|
||||
Subproject commit 0f7d59b4fb742c6479d988f6fc4ec9cdb4330b53
|
||||
Subproject commit 26b9d0fdc374fac648f6293e1d4a4abdc2c20c19
|
Loading…
Reference in New Issue