From e7057bed29e4c75d2d77596e43f349cff9cda841 Mon Sep 17 00:00:00 2001 From: Sebastian Wick Date: Sun, 31 Jul 2011 17:07:11 +0200 Subject: [PATCH 01/41] moving stuff from MWWorld::World to MWWorld::Scene but receiving segfault signals --- apps/openmw/CMakeLists.txt | 5 +- apps/openmw/mwrender/player.hpp | 2 +- apps/openmw/mwrender/render_manager.cpp | 1 + apps/openmw/mwrender/render_manager.hpp | 9 + apps/openmw/mwworld/physikssystem.cpp | 7 + apps/openmw/mwworld/physikssystem.hpp | 4 + apps/openmw/mwworld/player.cpp | 3 + apps/openmw/mwworld/scene.cpp | 539 ++++++++++++++++++++++++ apps/openmw/mwworld/scene.hpp | 65 +++ apps/openmw/mwworld/world.cpp | 8 +- apps/openmw/mwworld/world.hpp | 12 +- 11 files changed, 648 insertions(+), 7 deletions(-) create mode 100644 apps/openmw/mwrender/render_manager.cpp create mode 100644 apps/openmw/mwrender/render_manager.hpp create mode 100644 apps/openmw/mwworld/physikssystem.cpp create mode 100644 apps/openmw/mwworld/physikssystem.hpp create mode 100644 apps/openmw/mwworld/scene.cpp create mode 100644 apps/openmw/mwworld/scene.hpp diff --git a/apps/openmw/CMakeLists.txt b/apps/openmw/CMakeLists.txt index f8b4d7a59..8fc10079c 100644 --- a/apps/openmw/CMakeLists.txt +++ b/apps/openmw/CMakeLists.txt @@ -16,6 +16,7 @@ set(GAME_HEADER source_group(game FILES ${GAME} ${GAME_HEADER}) set(GAMEREND + mwrender/render_manager.cpp mwrender/mwscene.cpp mwrender/cellimp.cpp mwrender/interior.cpp @@ -24,6 +25,7 @@ set(GAMEREND mwrender/player.cpp ) set(GAMEREND_HEADER + mwrender/render_manager.hpp mwrender/cell.hpp mwrender/cellimp.hpp mwrender/mwscene.hpp @@ -137,6 +139,7 @@ source_group(apps\\openmw\\mwsound FILES ${GAMESOUND} ${GAMESOUND_HEADER}) set(GAMEWORLD mwworld/world.cpp + mwworld/scene.cpp mwworld/globals.cpp mwworld/class.cpp mwworld/actionteleport.cpp @@ -149,7 +152,7 @@ set(GAMEWORLD set(GAMEWORLD_HEADER mwworld/refdata.hpp mwworld/world.hpp - mwworld/ptr.hpp + mwworld/scene.hpp mwworld/environment.hpp mwworld/globals.hpp mwworld/class.hpp diff --git a/apps/openmw/mwrender/player.hpp b/apps/openmw/mwrender/player.hpp index f2d819116..399d3f485 100644 --- a/apps/openmw/mwrender/player.hpp +++ b/apps/openmw/mwrender/player.hpp @@ -22,7 +22,7 @@ namespace MWRender Ogre::Camera *getCamera() { return mCamera; } - std::string getHandle() const { return mHandle; } + std::string getHandle() const { std::cout << "mHandle " << mHandle << std::endl; return mHandle; } }; } diff --git a/apps/openmw/mwrender/render_manager.cpp b/apps/openmw/mwrender/render_manager.cpp new file mode 100644 index 000000000..4212c0cec --- /dev/null +++ b/apps/openmw/mwrender/render_manager.cpp @@ -0,0 +1 @@ +#include "render_manager.hpp" diff --git a/apps/openmw/mwrender/render_manager.hpp b/apps/openmw/mwrender/render_manager.hpp new file mode 100644 index 000000000..67b2fb93f --- /dev/null +++ b/apps/openmw/mwrender/render_manager.hpp @@ -0,0 +1,9 @@ +#ifndef _GAME_RENDER_MANAGER_H +#define _GAME_RENDER_MANAGER_H + +namespace MWRender +{ + +} + +#endif diff --git a/apps/openmw/mwworld/physikssystem.cpp b/apps/openmw/mwworld/physikssystem.cpp new file mode 100644 index 000000000..5e2042937 --- /dev/null +++ b/apps/openmw/mwworld/physikssystem.cpp @@ -0,0 +1,7 @@ +#include "physikssystem.hpp" + + +namespace MWWorld +{ + +} diff --git a/apps/openmw/mwworld/physikssystem.hpp b/apps/openmw/mwworld/physikssystem.hpp new file mode 100644 index 000000000..450f630b5 --- /dev/null +++ b/apps/openmw/mwworld/physikssystem.hpp @@ -0,0 +1,4 @@ +#ifndef GAME_MWWORLD_PHYSIKSSYSTEM_H +#define GAME_MWWORLD_PHYSIKSSYSTEM_H + +#endif diff --git a/apps/openmw/mwworld/player.cpp b/apps/openmw/mwworld/player.cpp index 259348938..d28569a9d 100644 --- a/apps/openmw/mwworld/player.cpp +++ b/apps/openmw/mwworld/player.cpp @@ -17,6 +17,9 @@ namespace MWWorld mMale = !(player->flags & ESM::NPC::Female); mRace = player->race; mPlayer.ref.pos.pos[0] = mPlayer.ref.pos.pos[1] = mPlayer.ref.pos.pos[2] = 0; + std::cout << "mData.setHandle" << std::endl; + std::cout << renderer->getHandle(); + std::cout << "mData end" << std::endl; mPlayer.mData.setHandle (renderer->getHandle()); mClass = new ESM::Class (*world.getStore().classes.find (player->cls)); } diff --git a/apps/openmw/mwworld/scene.cpp b/apps/openmw/mwworld/scene.cpp new file mode 100644 index 000000000..2e9784d46 --- /dev/null +++ b/apps/openmw/mwworld/scene.cpp @@ -0,0 +1,539 @@ +#include "scene.hpp" + +#include "world.hpp" +#include "ptr.hpp" +#include "environment.hpp" +#include "class.hpp" +#include "player.hpp" + +#include "refdata.hpp" +#include "globals.hpp" +#include "doingphysics.hpp" +#include "cellfunctors.hpp" +#include "environment.hpp" + +#include +#include + +#include +#include + +#include "../mwrender/sky.hpp" +#include "../mwrender/interior.hpp" +#include "../mwrender/exterior.hpp" + +#include "../mwmechanics/mechanicsmanager.hpp" + +#include "../mwsound/soundmanager.hpp" + +#include "ptr.hpp" +#include "environment.hpp" +#include "class.hpp" +#include "player.hpp" + +#include "refdata.hpp" +#include "globals.hpp" +#include "doingphysics.hpp" +#include "cellfunctors.hpp" + +namespace { + + template + ESMS::LiveCellRef *searchViaHandle (const std::string& handle, + ESMS::CellRefList& refList) + { + typedef typename ESMS::CellRefList::List::iterator iterator; + + for (iterator iter (refList.list.begin()); iter!=refList.list.end(); ++iter) + { + if (iter->mData.getHandle()==handle) + { + return &*iter; + } + } + + return 0; + } +} + + +namespace MWWorld +{ + + Scene::Scene(Environment& environment, World *world, MWRender::MWScene scene) : + mEnvironment(environment), mWorld(world), mScene(scene) + { + } + + Ptr Scene::getPtr (const std::string& name, Ptr::CellStore& cell) + { + if (ESMS::LiveCellRef *ref = cell.activators.find (name)) + return Ptr (ref, &cell); + + if (ESMS::LiveCellRef *ref = cell.potions.find (name)) + return Ptr (ref, &cell); + + if (ESMS::LiveCellRef *ref = cell.appas.find (name)) + return Ptr (ref, &cell); + + if (ESMS::LiveCellRef *ref = cell.armors.find (name)) + return Ptr (ref, &cell); + + if (ESMS::LiveCellRef *ref = cell.books.find (name)) + return Ptr (ref, &cell); + + if (ESMS::LiveCellRef *ref = cell.clothes.find (name)) + return Ptr (ref, &cell); + + if (ESMS::LiveCellRef *ref = cell.containers.find (name)) + return Ptr (ref, &cell); + + if (ESMS::LiveCellRef *ref = cell.creatures.find (name)) + return Ptr (ref, &cell); + + if (ESMS::LiveCellRef *ref = cell.doors.find (name)) + return Ptr (ref, &cell); + + if (ESMS::LiveCellRef *ref = cell.ingreds.find (name)) + return Ptr (ref, &cell); + + if (ESMS::LiveCellRef *ref = cell.creatureLists.find (name)) + return Ptr (ref, &cell); + + if (ESMS::LiveCellRef *ref = cell.itemLists.find (name)) + return Ptr (ref, &cell); + + if (ESMS::LiveCellRef *ref = cell.lights.find (name)) + return Ptr (ref, &cell); + + if (ESMS::LiveCellRef *ref = cell.lockpicks.find (name)) + return Ptr (ref, &cell); + + if (ESMS::LiveCellRef *ref = cell.miscItems.find (name)) + return Ptr (ref, &cell); + + if (ESMS::LiveCellRef *ref = cell.npcs.find (name)) + return Ptr (ref, &cell); + + if (ESMS::LiveCellRef *ref = cell.probes.find (name)) + return Ptr (ref, &cell); + + if (ESMS::LiveCellRef *ref = cell.repairs.find (name)) + return Ptr (ref, &cell); + + if (ESMS::LiveCellRef *ref = cell.statics.find (name)) + return Ptr (ref, &cell); + + if (ESMS::LiveCellRef *ref = cell.weapons.find (name)) + return Ptr (ref, &cell); + + return Ptr(); + } + + + + Ptr Scene::getPtrViaHandle (const std::string& handle, Ptr::CellStore& cell) + { + if (ESMS::LiveCellRef *ref = + searchViaHandle (handle, cell.activators)) + return Ptr (ref, &cell); + + if (ESMS::LiveCellRef *ref = searchViaHandle (handle, cell.potions)) + return Ptr (ref, &cell); + + if (ESMS::LiveCellRef *ref = searchViaHandle (handle, cell.appas)) + return Ptr (ref, &cell); + + if (ESMS::LiveCellRef *ref = searchViaHandle (handle, cell.armors)) + return Ptr (ref, &cell); + + if (ESMS::LiveCellRef *ref = searchViaHandle (handle, cell.books)) + return Ptr (ref, &cell); + + if (ESMS::LiveCellRef *ref = searchViaHandle (handle, cell.clothes)) + return Ptr (ref, &cell); + + if (ESMS::LiveCellRef *ref = + searchViaHandle (handle, cell.containers)) + return Ptr (ref, &cell); + + if (ESMS::LiveCellRef *ref = + searchViaHandle (handle, cell.creatures)) + return Ptr (ref, &cell); + + if (ESMS::LiveCellRef *ref = searchViaHandle (handle, cell.doors)) + return Ptr (ref, &cell); + + if (ESMS::LiveCellRef *ref = + searchViaHandle (handle, cell.ingreds)) + return Ptr (ref, &cell); + + if (ESMS::LiveCellRef *ref = searchViaHandle (handle, cell.lights)) + return Ptr (ref, &cell); + + if (ESMS::LiveCellRef *ref = searchViaHandle (handle, cell.lockpicks)) + return Ptr (ref, &cell); + + if (ESMS::LiveCellRef *ref = searchViaHandle (handle, cell.miscItems)) + return Ptr (ref, &cell); + + if (ESMS::LiveCellRef *ref = searchViaHandle (handle, cell.npcs)) + return Ptr (ref, &cell); + + if (ESMS::LiveCellRef *ref = searchViaHandle (handle, cell.probes)) + return Ptr (ref, &cell); + + if (ESMS::LiveCellRef *ref = searchViaHandle (handle, cell.repairs)) + return Ptr (ref, &cell); + + if (ESMS::LiveCellRef *ref = searchViaHandle (handle, cell.statics)) + return Ptr (ref, &cell); + + if (ESMS::LiveCellRef *ref = searchViaHandle (handle, cell.weapons)) + return Ptr (ref, &cell); + + return Ptr(); + } + + MWRender::CellRender *Scene::searchRender (Ptr::CellStore *store) + { + CellRenderCollection::iterator iter = mActiveCells.find (store); + + if (iter!=mActiveCells.end()) + { + return iter->second; + } + + return 0; + } + + void Scene::unloadCell (CellRenderCollection::iterator iter) + { + ListHandles functor; + iter->first->forEach(functor); + + { // silence annoying g++ warning + for (std::vector::const_iterator iter (functor.mHandles.begin()); + iter!=functor.mHandles.end(); ++iter) + { + mScene.removeObject (*iter); // FIXME + } + } + + 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); // FIXME + + // This connects the cell data with the rendering scene. + std::pair 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::changeCell (int X, int Y, const ESM::Position& position, bool adjustPlayerPos) + { + SuppressDoingPhysics scopeGuard; + + // 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()) + { + mExteriors[std::make_pair (x, y)].loadExt (x, y, mWorld->getStore(), mWorld->getEsmReader()); + Ptr::CellStore *cell = &mExteriors[std::make_pair (x, y)]; + + loadCell (cell, new MWRender::ExteriorCellRender (*cell, mEnvironment, mScene)); + } + } + + // find current cell + CellRenderCollection::iterator iter = mActiveCells.begin(); + + while (iter!=mActiveCells.end()) + { + assert (!(iter->first->cell->data.flags & ESM::Cell::Interior)); + + if (X==iter->first->cell->data.gridX && + Y==iter->first->cell->data.gridY) + break; + + ++iter; + } + + assert (iter!=mActiveCells.end()); + + mCurrentCell = iter->first; + + // adjust player + playerCellChange (&mExteriors[std::make_pair (X, Y)], position, adjustPlayerPos); + + // Sky system + mWorld->adjustSky(); // FIXME + + mCellChanged = true; + + } + + Ptr Scene::getPtr (const std::string& name, bool activeOnly) + { + // the player is always in an active cell. + if (name=="player") + { + return mWorld->getPlayer().getPlayer(); + } + + // active cells + for (CellRenderCollection::iterator iter (mActiveCells.begin()); + iter!=mActiveCells.end(); ++iter) + { + Ptr ptr = getPtr (name, *iter->first); + + if (!ptr.isEmpty()) + return ptr; + } + + if (!activeOnly) + { + // TODO: inactive cells + } + + throw std::runtime_error ("unknown ID: " + name); + + } + + Ptr Scene::getPtrViaHandle (const std::string& handle) + { + if (mWorld->getPlayer().getPlayer().getRefData().getHandle()==handle) + return mWorld->getPlayer().getPlayer(); + + for (CellRenderCollection::iterator iter (mActiveCells.begin()); + iter!=mActiveCells.end(); ++iter) + { + Ptr ptr = getPtrViaHandle (handle, *iter->first); + + if (!ptr.isEmpty()) + return ptr; + } + + throw std::runtime_error ("unknown Ogre handle: " + handle); + + } + + 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], false); + + mWorld->getPlayer().setCell (cell); + // TODO orientation + mEnvironment.mMechanicsManager->addActor (mWorld->getPlayer().getPlayer()); + mEnvironment.mMechanicsManager->watchActor (mWorld->getPlayer().getPlayer()); + + } + + void Scene::enable (Ptr reference) + { + if (!reference.getRefData().isEnabled()) + { + reference.getRefData().enable(); + + if (MWRender::CellRender *render = searchRender (reference.getCell())) + { + render->enable (reference.getRefData().getHandle()); + + if (mActiveCells.find (reference.getCell())!=mActiveCells.end()) + { + Class::get (reference).enable (reference, mEnvironment); //FIXME + } + } + } + } + + void Scene::disable (Ptr reference) + { + if (reference.getRefData().isEnabled()) + { + reference.getRefData().disable(); + + if (MWRender::CellRender *render = searchRender (reference.getCell())) + { + render->disable (reference.getRefData().getHandle()); + + if (mActiveCells.find (reference.getCell())!=mActiveCells.end()) + { + Class::get (reference).disable (reference, mEnvironment); + mEnvironment.mSoundManager->stopSound3D (reference); + } + } + } + } + + void Scene::changeToInteriorCell (const std::string& cellName, const ESM::Position& position) + { + SuppressDoingPhysics scopeGuard; + + // remove active + CellRenderCollection::iterator active = mActiveCells.begin(); + + while (active!=mActiveCells.end()) + { + unloadCell (active++); + } + + // Load cell. + mInteriors[cellName].loadInt (cellName, mWorld->getStore(), mWorld->getEsmReader()); + Ptr::CellStore *cell = &mInteriors[cellName]; + + loadCell (cell, new MWRender::InteriorCellRender (*cell, mEnvironment, mScene)); + + // adjust player + mCurrentCell = cell; + playerCellChange (cell, position, true); // FIXME + + // Sky system + mWorld->adjustSky(); // FIXME + + 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); + } + + const ESM::Cell *Scene::getExterior (const std::string& cellName) const + { + // first try named cells + if (const ESM::Cell *cell = mWorld->getStore().cells.searchExtByName (cellName)) + return cell; + + // didn't work -> now check for regions + std::string cellName2 = ESMS::RecListT::toLower (cellName); + + for (ESMS::RecListT::MapType::const_iterator iter (mWorld->getStore().regions.list.begin()); + iter!=mWorld->getStore().regions.list.end(); ++iter) + { + if (ESMS::RecListT::toLower (iter->second.name)==cellName2) + { + if (const ESM::Cell *cell = mWorld->getStore().cells.searchExtByRegion (iter->first)) + return cell; + + break; + } + } + + return 0; + } + + void Scene::deleteObject (Ptr ptr) + { + if (ptr.getRefData().getCount()>0) + { + ptr.getRefData().setCount (0); + + if (MWRender::CellRender *render = searchRender (ptr.getCell())) + { + if (mActiveCells.find (ptr.getCell())!=mActiveCells.end()) + { + Class::get (ptr).disable (ptr, mEnvironment); + mEnvironment.mSoundManager->stopSound3D (ptr); + + if (!DoingPhysics::isDoingPhysics()) + mScene.removeObject (ptr.getRefData().getHandle()); + } + + render->deleteObject (ptr.getRefData().getHandle()); + ptr.getRefData().setHandle (""); + } + } + } + + void Scene::moveObject (Ptr ptr, float x, float y, float z) + { + ptr.getCellRef().pos.pos[0] = x; + ptr.getCellRef().pos.pos[1] = y; + ptr.getCellRef().pos.pos[2] = z; + + if (ptr==mWorld->getPlayer().getPlayer()) + { + if (mCurrentCell) + { + if (!(mCurrentCell->cell->data.flags & ESM::Cell::Interior)) + { + // exterior -> adjust loaded cells + int cellX = 0; + int cellY = 0; + + mWorld->positionToIndex (x, y, cellX, cellY); + + if (mCurrentCell->cell->data.gridX!=cellX || mCurrentCell->cell->data.gridY!=cellY) + { + changeCell (cellX, cellY, mWorld->getPlayer().getPlayer().getCellRef().pos, false); + } + + } + } + } + + mScene.moveObject (ptr.getRefData().getHandle(), Ogre::Vector3 (x, y, z), + !DoingPhysics::isDoingPhysics()); + + // TODO cell change for non-player ref + } + +} diff --git a/apps/openmw/mwworld/scene.hpp b/apps/openmw/mwworld/scene.hpp new file mode 100644 index 000000000..97c04ebcf --- /dev/null +++ b/apps/openmw/mwworld/scene.hpp @@ -0,0 +1,65 @@ +#ifndef GAME_MWWORLD_SCENE_H +#define GAME_MWWORLD_SCENE_H + +#include +#include "ptr.hpp" +#include "environment.hpp" +#include "../mwrender/mwscene.hpp" + +namespace Render +{ + class OgreRenderer; +} + +namespace MWRender +{ + class SkyManager; + class CellRender; +} + +namespace MWWorld +{ + + class Scene + { + public: + Scene(Environment& environment, World *world, MWRender::MWScene scene); + + private: + + typedef std::map CellRenderCollection; + + CellRenderCollection mActiveCells; + Ptr::CellStore *mCurrentCell; // the cell, the player is in + std::map mInteriors; + std::map, Ptr::CellStore> mExteriors; + Environment& mEnvironment; + World *mWorld; + MWRender::MWScene mScene; + bool mCellChanged; + + Ptr getPtr (const std::string& name, Ptr::CellStore& cell); + Ptr getPtrViaHandle (const std::string& handle, Ptr::CellStore& cell); + + public: + + MWRender::CellRender *searchRender (Ptr::CellStore *store); + + 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); + Ptr getPtr (const std::string& name, bool activeOnly); + Ptr getPtrViaHandle (const std::string& handle); + void playerCellChange (Ptr::CellStore *cell, const ESM::Position& position, bool adjustPlayerPos); + void enable (Ptr reference); + void disable (Ptr reference); + void changeToInteriorCell (const std::string& cellName, const ESM::Position& position); + void changeToExteriorCell (const ESM::Position& position); + const ESM::Cell *getExterior (const std::string& cellName) const; + void deleteObject (Ptr ptr); + void moveObject (Ptr ptr, float x, float y, float z); + }; + +} + +#endif diff --git a/apps/openmw/mwworld/world.cpp b/apps/openmw/mwworld/world.cpp index 063f54d6f..f8fda8b05 100644 --- a/apps/openmw/mwworld/world.cpp +++ b/apps/openmw/mwworld/world.cpp @@ -1,4 +1,3 @@ - #include "world.hpp" #include @@ -466,6 +465,11 @@ namespace MWWorld { return mStore; } + + ESM::ESMReader& World::getEsmReader() + { + return mEsm; + } const World::ScriptList& World::getLocalScripts() const { @@ -694,6 +698,7 @@ namespace MWWorld void World::changeToInteriorCell (const std::string& cellName, const ESM::Position& position) { + return mWorldScene->changeToInteriorCell(cellName, position); SuppressDoingPhysics scopeGuard; // remove active @@ -904,3 +909,4 @@ namespace MWWorld return std::make_pair (stream.str(), created); } } + diff --git a/apps/openmw/mwworld/world.hpp b/apps/openmw/mwworld/world.hpp index cccd8816d..f9ff4d714 100644 --- a/apps/openmw/mwworld/world.hpp +++ b/apps/openmw/mwworld/world.hpp @@ -13,6 +13,7 @@ #include "refdata.hpp" #include "ptr.hpp" #include "globals.hpp" +#include "scene.hpp" #include @@ -66,6 +67,7 @@ namespace MWWorld MWRender::SkyManager* mSkyManager; MWRender::MWScene mScene; + MWWorld::Scene *mWorldScene; MWWorld::Player *mPlayer; Ptr::CellStore *mCurrentCell; // the cell, the player is in CellRenderCollection mActiveCells; @@ -87,8 +89,6 @@ namespace MWWorld World (const World&); World& operator= (const World&); - void insertInteriorScripts (ESMS::CellStore& cell); - Ptr getPtr (const std::string& name, Ptr::CellStore& cellStore); Ptr getPtrViaHandle (const std::string& handle, Ptr::CellStore& cellStore); @@ -106,8 +106,6 @@ namespace MWWorld void playerCellChange (Ptr::CellStore *cell, const ESM::Position& position, bool adjustPlayerPos = true); - void adjustSky(); - void changeCell (int X, int Y, const ESM::Position& position, bool adjustPlayerPos); ///< Move from exterior to interior or from interior cell to a different /// interior cell. @@ -120,9 +118,15 @@ namespace MWWorld ~World(); + void insertInteriorScripts (ESMS::CellStore& cell); + + void adjustSky(); + MWWorld::Player& getPlayer(); const ESMS::ESMStore& getStore() const; + + ESM::ESMReader& getEsmReader(); const ScriptList& getLocalScripts() const; ///< Names and local variable state of all local scripts in active cells. From 008a3768e2a39338b50fc571561a5314beed339b Mon Sep 17 00:00:00 2001 From: Sebastian Wick Date: Sun, 31 Jul 2011 17:59:08 +0200 Subject: [PATCH 02/41] use MWWorld::Scene --- apps/openmw/mwworld/world.cpp | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/apps/openmw/mwworld/world.cpp b/apps/openmw/mwworld/world.cpp index f8fda8b05..75d9f35bc 100644 --- a/apps/openmw/mwworld/world.cpp +++ b/apps/openmw/mwworld/world.cpp @@ -18,6 +18,7 @@ #include "environment.hpp" #include "class.hpp" #include "player.hpp" +#include "scene.hpp" #include "refdata.hpp" #include "globals.hpp" @@ -220,6 +221,7 @@ namespace MWWorld MWRender::CellRender *World::searchRender (Ptr::CellStore *store) { + return mWorldScene->searchRender(store); CellRenderCollection::iterator iter = mActiveCells.find (store); if (iter!=mActiveCells.end()) @@ -272,6 +274,7 @@ namespace MWWorld void World::unloadCell (CellRenderCollection::iterator iter) { + return mWorldScene->unloadCell(iter); ListHandles functor; iter->first->forEach(functor); @@ -290,6 +293,7 @@ namespace MWWorld void World::loadCell (Ptr::CellStore *cell, MWRender::CellRender *render) { + return mWorldScene->loadCell(cell, render); // register local scripts insertInteriorScripts (*cell); @@ -329,6 +333,7 @@ namespace MWWorld void World::changeCell (int X, int Y, const ESM::Position& position, bool adjustPlayerPos) { + return mWorldScene->changeCell(X, Y, position, adjustPlayerPos); SuppressDoingPhysics scopeGuard; // remove active @@ -412,6 +417,7 @@ namespace MWWorld : mSkyManager (0), mScene (renderer,physEng), mPlayer (0), mCurrentCell (0), mGlobalVariables (0), mSky (false), mCellChanged (false), mEnvironment (environment), mNextDynamicRecord (0) { + mWorldScene = new Scene(environment, this, mScene); mPhysEngine = physEng; boost::filesystem::path masterPath (fileCollections.getCollection (".esm").getPath (master)); @@ -498,6 +504,7 @@ namespace MWWorld Ptr World::getPtr (const std::string& name, bool activeOnly) { + return mWorldScene->getPtr(name, activeOnly); // the player is always in an active cell. if (name=="player") { @@ -524,6 +531,7 @@ namespace MWWorld Ptr World::getPtrViaHandle (const std::string& handle) { + return mWorldScene->getPtrViaHandle(handle); if (mPlayer->getPlayer().getRefData().getHandle()==handle) return mPlayer->getPlayer(); @@ -541,6 +549,7 @@ namespace MWWorld void World::enable (Ptr reference) { + return mWorldScene->enable(reference); if (!reference.getRefData().isEnabled()) { reference.getRefData().enable(); @@ -557,6 +566,7 @@ namespace MWWorld void World::disable (Ptr reference) { + return mWorldScene->disable(reference); if (reference.getRefData().isEnabled()) { reference.getRefData().disable(); @@ -728,6 +738,7 @@ namespace MWWorld void World::changeToExteriorCell (const ESM::Position& position) { + return mWorldScene->changeToExteriorCell(position); int x = 0; int y = 0; @@ -738,6 +749,7 @@ namespace MWWorld const ESM::Cell *World::getExterior (const std::string& cellName) const { + return mWorldScene->getExterior(cellName); // first try named cells if (const ESM::Cell *cell = mStore.cells.searchExtByName (cellName)) return cell; @@ -778,6 +790,7 @@ namespace MWWorld void World::deleteObject (Ptr ptr) { + return mWorldScene->deleteObject(ptr); if (ptr.getRefData().getCount()>0) { ptr.getRefData().setCount (0); @@ -801,6 +814,7 @@ namespace MWWorld void World::moveObject (Ptr ptr, float x, float y, float z) { + return mWorldScene->moveObject(ptr, x, y, z); ptr.getCellRef().pos.pos[0] = x; ptr.getCellRef().pos.pos[1] = y; ptr.getCellRef().pos.pos[2] = z; From ff68ca7e528e9125cc0b81fae8f60636c4c8fb02 Mon Sep 17 00:00:00 2001 From: Sebastian Wick Date: Mon, 1 Aug 2011 03:33:02 +0200 Subject: [PATCH 03/41] next try :/ --- apps/openmw/mwworld/scene.cpp | 289 +++++++++++++++++++++++++++------- apps/openmw/mwworld/scene.hpp | 187 ++++++++++++++++++---- apps/openmw/mwworld/world.cpp | 17 +- 3 files changed, 386 insertions(+), 107 deletions(-) diff --git a/apps/openmw/mwworld/scene.cpp b/apps/openmw/mwworld/scene.cpp index 2e9784d46..8b542af59 100644 --- a/apps/openmw/mwworld/scene.cpp +++ b/apps/openmw/mwworld/scene.cpp @@ -1,16 +1,5 @@ #include "scene.hpp" - #include "world.hpp" -#include "ptr.hpp" -#include "environment.hpp" -#include "class.hpp" -#include "player.hpp" - -#include "refdata.hpp" -#include "globals.hpp" -#include "doingphysics.hpp" -#include "cellfunctors.hpp" -#include "environment.hpp" #include #include @@ -36,7 +25,29 @@ #include "doingphysics.hpp" #include "cellfunctors.hpp" -namespace { +namespace +{ + template + void listCellScripts (const ESMS::ESMStore& store, + ESMS::CellRefList& cellRefList, MWWorld::Scene::ScriptList& scriptList, + MWWorld::Ptr::CellStore *cell) + { + for (typename ESMS::CellRefList::List::iterator iter ( + cellRefList.list.begin()); + iter!=cellRefList.list.end(); ++iter) + { + if (!iter->base->script.empty() && iter->mData.getCount()) + { + if (const ESM::Script *script = store.scripts.find (iter->base->script)) + { + iter->mData.setLocals (*script); + + scriptList.push_back ( + std::make_pair (iter->base->script, MWWorld::Ptr (&*iter, cell))); + } + } + } + } template ESMS::LiveCellRef *searchViaHandle (const std::string& handle, @@ -56,15 +67,30 @@ namespace { } } - namespace MWWorld { - Scene::Scene(Environment& environment, World *world, MWRender::MWScene scene) : - mEnvironment(environment), mWorld(world), mScene(scene) + void Scene::insertInteriorScripts (ESMS::CellStore& cell) { + listCellScripts (mWorld->getStore(), cell.activators, mLocalScripts, &cell); + listCellScripts (mWorld->getStore(), cell.potions, mLocalScripts, &cell); + listCellScripts (mWorld->getStore(), cell.appas, mLocalScripts, &cell); + listCellScripts (mWorld->getStore(), cell.armors, mLocalScripts, &cell); + listCellScripts (mWorld->getStore(), cell.books, mLocalScripts, &cell); + listCellScripts (mWorld->getStore(), cell.clothes, mLocalScripts, &cell); + listCellScripts (mWorld->getStore(), cell.containers, mLocalScripts, &cell); + listCellScripts (mWorld->getStore(), cell.creatures, mLocalScripts, &cell); + listCellScripts (mWorld->getStore(), cell.doors, mLocalScripts, &cell); + listCellScripts (mWorld->getStore(), cell.ingreds, mLocalScripts, &cell); + listCellScripts (mWorld->getStore(), cell.lights, mLocalScripts, &cell); + listCellScripts (mWorld->getStore(), cell.lockpicks, mLocalScripts, &cell); + listCellScripts (mWorld->getStore(), cell.miscItems, mLocalScripts, &cell); + listCellScripts (mWorld->getStore(), cell.npcs, mLocalScripts, &cell); + listCellScripts (mWorld->getStore(), cell.probes, mLocalScripts, &cell); + listCellScripts (mWorld->getStore(), cell.repairs, mLocalScripts, &cell); + listCellScripts (mWorld->getStore(), cell.weapons, mLocalScripts, &cell); } - + Ptr Scene::getPtr (const std::string& name, Ptr::CellStore& cell) { if (ESMS::LiveCellRef *ref = cell.activators.find (name)) @@ -129,8 +155,6 @@ namespace MWWorld return Ptr(); } - - Ptr Scene::getPtrViaHandle (const std::string& handle, Ptr::CellStore& cell) { @@ -203,10 +227,50 @@ namespace MWWorld { return iter->second; } + else + { + iter = mBufferedCells.find (store); + if (iter!=mBufferedCells.end()) + return iter->second; + } return 0; } - + + int Scene::getDaysPerMonth (int month) const + { + switch (month) + { + case 0: return 31; + case 1: return 28; + case 2: return 31; + case 3: return 30; + case 4: return 31; + case 5: return 30; + case 6: return 31; + case 7: return 31; + case 8: return 30; + case 9: return 31; + case 10: return 30; + case 11: return 31; + } + + throw std::runtime_error ("month out of range"); + } + + void Scene::removeScripts (Ptr::CellStore *cell) + { + ScriptList::iterator iter = mLocalScripts.begin(); + + while (iter!=mLocalScripts.end()) + { + if (iter->second.getCell()==cell) + mLocalScripts.erase (iter++); + else + ++iter; + } + } + void Scene::unloadCell (CellRenderCollection::iterator iter) { ListHandles functor; @@ -215,21 +279,20 @@ namespace MWWorld { // silence annoying g++ warning for (std::vector::const_iterator iter (functor.mHandles.begin()); iter!=functor.mHandles.end(); ++iter) - { - mScene.removeObject (*iter); // FIXME - } + mScene.removeObject (*iter); } + 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); // FIXME + insertInteriorScripts (*cell); // This connects the cell data with the rendering scene. std::pair result = @@ -240,9 +303,20 @@ namespace MWWorld // 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], false); + + 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) { SuppressDoingPhysics scopeGuard; @@ -287,7 +361,7 @@ namespace MWWorld if (iter==mActiveCells.end()) { - mExteriors[std::make_pair (x, y)].loadExt (x, y, mWorld->getStore(), mWorld->getEsmReader()); + mExteriors[std::make_pair (x, y)].loadExt (x, y, mWorld->getStore(), mEsm); Ptr::CellStore *cell = &mExteriors[std::make_pair (x, y)]; loadCell (cell, new MWRender::ExteriorCellRender (*cell, mEnvironment, mScene)); @@ -316,12 +390,59 @@ namespace MWWorld playerCellChange (&mExteriors[std::make_pair (X, Y)], position, adjustPlayerPos); // Sky system - mWorld->adjustSky(); // FIXME + mWorld->adjustSky(); mCellChanged = true; - } - + + Scene::Scene (OEngine::Render::OgreRenderer& renderer, OEngine::Physic::PhysicEngine* physEng, + const Files::Collections& fileCollections, + const std::string& master, const boost::filesystem::path& resDir, + bool newGame, Environment& environment, const std::string& encoding, World *world, MWRender::MWScene& scene) + : mSkyManager (0), mScene (scene), mCurrentCell (0), mGlobalVariables (0), + mSky (false), mCellChanged (false), mEnvironment (environment), mNextDynamicRecord (0), mWorld(world) + { + } + + Scene::~Scene() + { + for (CellRenderCollection::iterator iter (mActiveCells.begin()); + iter!=mActiveCells.end(); ++iter) + delete iter->second; + + for (CellRenderCollection::iterator iter (mBufferedCells.begin()); + iter!=mBufferedCells.end(); ++iter) + delete iter->second; + + delete mSkyManager; + delete mGlobalVariables; + } + + const Scene::ScriptList& Scene::getLocalScripts() const + { + return mLocalScripts; + } + + bool Scene::hasCellChanged() const + { + return mCellChanged; + } + + Globals::Data& Scene::getGlobalVariable (const std::string& name) + { + return (*mGlobalVariables)[name]; + } + + Globals::Data Scene::getGlobalVariable (const std::string& name) const + { + return (*mGlobalVariables)[name]; + } + + char Scene::getGlobalVariableType (const std::string& name) const + { + return mGlobalVariables->getType (name); + } + Ptr Scene::getPtr (const std::string& name, bool activeOnly) { // the player is always in an active cell. @@ -346,9 +467,8 @@ namespace MWWorld } throw std::runtime_error ("unknown ID: " + name); - } - + Ptr Scene::getPtrViaHandle (const std::string& handle) { if (mWorld->getPlayer().getPlayer().getRefData().getHandle()==handle) @@ -364,22 +484,8 @@ namespace MWWorld } throw std::runtime_error ("unknown Ogre handle: " + handle); - } - - 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], false); - mWorld->getPlayer().setCell (cell); - // TODO orientation - mEnvironment.mMechanicsManager->addActor (mWorld->getPlayer().getPlayer()); - mEnvironment.mMechanicsManager->watchActor (mWorld->getPlayer().getPlayer()); - - } - void Scene::enable (Ptr reference) { if (!reference.getRefData().isEnabled()) @@ -391,13 +497,11 @@ namespace MWWorld render->enable (reference.getRefData().getHandle()); if (mActiveCells.find (reference.getCell())!=mActiveCells.end()) - { - Class::get (reference).enable (reference, mEnvironment); //FIXME - } + Class::get (reference).enable (reference, mEnvironment); } } } - + void Scene::disable (Ptr reference) { if (reference.getRefData().isEnabled()) @@ -416,7 +520,8 @@ namespace MWWorld } } } - + + void Scene::changeToInteriorCell (const std::string& cellName, const ESM::Position& position) { SuppressDoingPhysics scopeGuard; @@ -430,32 +535,32 @@ namespace MWWorld } // Load cell. - mInteriors[cellName].loadInt (cellName, mWorld->getStore(), mWorld->getEsmReader()); + mInteriors[cellName].loadInt (cellName, mWorld->getStore(), mEsm); Ptr::CellStore *cell = &mInteriors[cellName]; loadCell (cell, new MWRender::InteriorCellRender (*cell, mEnvironment, mScene)); // adjust player mCurrentCell = cell; - playerCellChange (cell, position, true); // FIXME + playerCellChange (cell, position); // Sky system - mWorld->adjustSky(); // FIXME + 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); + positionToIndex (position.pos[0], position.pos[1], x, y); changeCell (x, y, position, true); } - + const ESM::Cell *Scene::getExterior (const std::string& cellName) const { // first try named cells @@ -479,7 +584,25 @@ namespace MWWorld return 0; } - + + void Scene::markCellAsUnchanged() + { + mCellChanged = false; + } + + std::string Scene::getFacedHandle() + { + // FIXME + /*std::pair result = mScene.getFacedHandle (*this); + + if (result.first.empty() || + result.second>getStore().gameSettings.find ("iMaxActivateDist")->i) + return ""; + + return result.first;*/ + return std::string(""); + } + void Scene::deleteObject (Ptr ptr) { if (ptr.getRefData().getCount()>0) @@ -502,7 +625,7 @@ namespace MWWorld } } } - + void Scene::moveObject (Ptr ptr, float x, float y, float z) { ptr.getCellRef().pos.pos[0] = x; @@ -519,7 +642,7 @@ namespace MWWorld int cellX = 0; int cellY = 0; - mWorld->positionToIndex (x, y, cellX, cellY); + positionToIndex (x, y, cellX, cellY); if (mCurrentCell->cell->data.gridX!=cellX || mCurrentCell->cell->data.gridY!=cellY) { @@ -536,4 +659,50 @@ namespace MWWorld // TODO cell change for non-player ref } + void Scene::indexToPosition (int cellX, int cellY, float &x, float &y, bool centre) const + { + const int cellSize = 8192; + + x = cellSize * cellX; + y = cellSize * cellY; + + if (centre) + { + x += cellSize/2; + y += cellSize/2; + } + } + + void Scene::positionToIndex (float x, float y, int &cellX, int &cellY) const + { + const int cellSize = 8192; + + cellX = static_cast (x/cellSize); + + if (x<0) + --cellX; + + cellY = static_cast (y/cellSize); + + if (y<0) + --cellY; + } + + void Scene::doPhysics (const std::vector >& actors, + float duration) + { + // FIXME + // mScene.doPhysics (duration, *this, actors); + } + + bool Scene::toggleCollisionMode() + { + return mScene.toggleCollisionMode(); + } + + bool Scene::toggleRenderMode (RenderMode mode) + { + return mScene.toggleRenderMode (mode); + } } + diff --git a/apps/openmw/mwworld/scene.hpp b/apps/openmw/mwworld/scene.hpp index 97c04ebcf..3533ee532 100644 --- a/apps/openmw/mwworld/scene.hpp +++ b/apps/openmw/mwworld/scene.hpp @@ -1,11 +1,36 @@ #ifndef GAME_MWWORLD_SCENE_H #define GAME_MWWORLD_SCENE_H +#include +#include + +#include + #include -#include "ptr.hpp" -#include "environment.hpp" + #include "../mwrender/mwscene.hpp" +#include "refdata.hpp" +#include "ptr.hpp" +#include "globals.hpp" + +#include + +namespace Ogre +{ + class Vector3; +} + +namespace ESM +{ + struct Position; +} + +namespace Files +{ + class Collections; +} + namespace Render { class OgreRenderer; @@ -19,47 +44,145 @@ namespace MWRender namespace MWWorld { + class Environment; + class Player; + + /// \brief The game world and its visual representation class Scene { + public: - Scene(Environment& environment, World *world, MWRender::MWScene scene); - + typedef std::list > ScriptList; + + enum RenderMode + { + Render_CollisionDebug + }; + private: - + typedef std::map CellRenderCollection; - - CellRenderCollection mActiveCells; + + MWRender::SkyManager* mSkyManager; + MWRender::MWScene mScene; Ptr::CellStore *mCurrentCell; // the cell, the player is in + CellRenderCollection mActiveCells; + CellRenderCollection mBufferedCells; // loaded, but not active (buffering not implementd yet) + ESM::ESMReader mEsm; + ESMS::ESMStore mStore; std::map mInteriors; std::map, Ptr::CellStore> mExteriors; - Environment& mEnvironment; - World *mWorld; - MWRender::MWScene mScene; + ScriptList mLocalScripts; + MWWorld::Globals *mGlobalVariables; + bool mSky; bool mCellChanged; - - Ptr getPtr (const std::string& name, Ptr::CellStore& cell); - Ptr getPtrViaHandle (const std::string& handle, Ptr::CellStore& cell); - - public: - - MWRender::CellRender *searchRender (Ptr::CellStore *store); - - 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); - Ptr getPtr (const std::string& name, bool activeOnly); - Ptr getPtrViaHandle (const std::string& handle); - void playerCellChange (Ptr::CellStore *cell, const ESM::Position& position, bool adjustPlayerPos); - void enable (Ptr reference); - void disable (Ptr reference); - void changeToInteriorCell (const std::string& cellName, const ESM::Position& position); - void changeToExteriorCell (const ESM::Position& position); - const ESM::Cell *getExterior (const std::string& cellName) const; - void deleteObject (Ptr ptr); - void moveObject (Ptr ptr, float x, float y, float z); - }; + Environment& mEnvironment; + int mNextDynamicRecord; + World *mWorld; + OEngine::Physic::PhysicEngine* mPhysEngine; + + // not implemented + Scene (const Scene&); + Scene& operator= (const Scene&); + + Ptr getPtr (const std::string& name, Ptr::CellStore& cellStore); + + Ptr getPtrViaHandle (const std::string& handle, Ptr::CellStore& cellStore); + + MWRender::CellRender *searchRender (Ptr::CellStore *store); + + int getDaysPerMonth (int month) const; + + void removeScripts (Ptr::CellStore *cell); + + void unloadCell (CellRenderCollection::iterator iter); + + void loadCell (Ptr::CellStore *cell, MWRender::CellRender *render); + + void playerCellChange (Ptr::CellStore *cell, const ESM::Position& position, + bool adjustPlayerPos = true); + + void changeCell (int X, int Y, const ESM::Position& position, bool adjustPlayerPos); + ///< Move from exterior to interior or from interior cell to a different + /// interior cell. + public: + + Scene (OEngine::Render::OgreRenderer& renderer, OEngine::Physic::PhysicEngine* physEng, + const Files::Collections& fileCollections, + const std::string& master, const boost::filesystem::path& resDir, bool newGame, + Environment& environment, const std::string& encoding, World* world, MWRender::MWScene& scene); + + ~Scene(); + + void insertInteriorScripts (ESMS::CellStore& cell); + + MWWorld::Player& getPlayer(); + + const ESMS::ESMStore& getStore() const; + + const ScriptList& getLocalScripts() const; + ///< Names and local variable state of all local scripts in active cells. + + bool hasCellChanged() const; + ///< Has the player moved to a different cell, since the last frame? + + Globals::Data& getGlobalVariable (const std::string& name); + + Globals::Data getGlobalVariable (const std::string& name) const; + + char getGlobalVariableType (const std::string& name) const; + ///< Return ' ', if there is no global variable with this name. + + Ptr getPtr (const std::string& name, bool activeOnly); + ///< Return a pointer to a liveCellRef with the given name. + /// \param activeOnly do non search inactive cells. + + Ptr getPtrViaHandle (const std::string& handle); + ///< Return a pointer to a liveCellRef with the given Ogre handle. + + void enable (Ptr reference); + + void disable (Ptr reference); + + void changeToInteriorCell (const std::string& cellName, const ESM::Position& position); // FIXME: YEAH! + ///< Move to interior cell. + + void changeToExteriorCell (const ESM::Position& position); // FIXME: YEAH! + ///< Move to exterior cell. + + const ESM::Cell *getExterior (const std::string& cellName) const; // FIXME: YEAH! + ///< Return a cell matching the given name or a 0-pointer, if there is no such cell. + + void markCellAsUnchanged(); // FIXME: YEAH! + + std::string getFacedHandle(); + ///< Return handle of the object the player is looking at + + void deleteObject (Ptr ptr); // FIXME: DONT KNOW + + void moveObject (Ptr ptr, float x, float y, float z); // FIXME: DONT KNOW + + void indexToPosition (int cellX, int cellY, float &x, float &y, bool centre = false) const; + ///< Convert cell numbers to position. + + void positionToIndex (float x, float y, int &cellX, int &cellY) const; + ///< Convert position to cell numbers + + void doPhysics (const std::vector >& actors, + float duration); + ///< Run physics simulation and modify \a world accordingly. + + bool toggleCollisionMode(); + ///< Toggle collision mode for player. If disabled player object should ignore + /// collisions and gravity. + ///< \return Resulting mode + + bool toggleRenderMode (RenderMode mode); + ///< Toggle a render mode. + ///< \return Resulting mode + }; } #endif diff --git a/apps/openmw/mwworld/world.cpp b/apps/openmw/mwworld/world.cpp index 75d9f35bc..9c2e07175 100644 --- a/apps/openmw/mwworld/world.cpp +++ b/apps/openmw/mwworld/world.cpp @@ -18,7 +18,6 @@ #include "environment.hpp" #include "class.hpp" #include "player.hpp" -#include "scene.hpp" #include "refdata.hpp" #include "globals.hpp" @@ -221,7 +220,6 @@ namespace MWWorld MWRender::CellRender *World::searchRender (Ptr::CellStore *store) { - return mWorldScene->searchRender(store); CellRenderCollection::iterator iter = mActiveCells.find (store); if (iter!=mActiveCells.end()) @@ -274,7 +272,6 @@ namespace MWWorld void World::unloadCell (CellRenderCollection::iterator iter) { - return mWorldScene->unloadCell(iter); ListHandles functor; iter->first->forEach(functor); @@ -293,7 +290,6 @@ namespace MWWorld void World::loadCell (Ptr::CellStore *cell, MWRender::CellRender *render) { - return mWorldScene->loadCell(cell, render); // register local scripts insertInteriorScripts (*cell); @@ -333,7 +329,6 @@ namespace MWWorld void World::changeCell (int X, int Y, const ESM::Position& position, bool adjustPlayerPos) { - return mWorldScene->changeCell(X, Y, position, adjustPlayerPos); SuppressDoingPhysics scopeGuard; // remove active @@ -417,7 +412,6 @@ namespace MWWorld : mSkyManager (0), mScene (renderer,physEng), mPlayer (0), mCurrentCell (0), mGlobalVariables (0), mSky (false), mCellChanged (false), mEnvironment (environment), mNextDynamicRecord (0) { - mWorldScene = new Scene(environment, this, mScene); mPhysEngine = physEng; boost::filesystem::path masterPath (fileCollections.getCollection (".esm").getPath (master)); @@ -445,6 +439,8 @@ namespace MWWorld MWRender::SkyManager::create(renderer.getWindow(), mScene.getCamera(), resDir); mPhysEngine = physEng; + + mWorldScene = new Scene(renderer, physEng, fileCollections, master, resDir, newGame, environment, encoding, this, mScene); } World::~World() @@ -504,7 +500,6 @@ namespace MWWorld Ptr World::getPtr (const std::string& name, bool activeOnly) { - return mWorldScene->getPtr(name, activeOnly); // the player is always in an active cell. if (name=="player") { @@ -531,7 +526,6 @@ namespace MWWorld Ptr World::getPtrViaHandle (const std::string& handle) { - return mWorldScene->getPtrViaHandle(handle); if (mPlayer->getPlayer().getRefData().getHandle()==handle) return mPlayer->getPlayer(); @@ -549,7 +543,6 @@ namespace MWWorld void World::enable (Ptr reference) { - return mWorldScene->enable(reference); if (!reference.getRefData().isEnabled()) { reference.getRefData().enable(); @@ -566,7 +559,6 @@ namespace MWWorld void World::disable (Ptr reference) { - return mWorldScene->disable(reference); if (reference.getRefData().isEnabled()) { reference.getRefData().disable(); @@ -708,7 +700,6 @@ namespace MWWorld void World::changeToInteriorCell (const std::string& cellName, const ESM::Position& position) { - return mWorldScene->changeToInteriorCell(cellName, position); SuppressDoingPhysics scopeGuard; // remove active @@ -738,7 +729,6 @@ namespace MWWorld void World::changeToExteriorCell (const ESM::Position& position) { - return mWorldScene->changeToExteriorCell(position); int x = 0; int y = 0; @@ -749,7 +739,6 @@ namespace MWWorld const ESM::Cell *World::getExterior (const std::string& cellName) const { - return mWorldScene->getExterior(cellName); // first try named cells if (const ESM::Cell *cell = mStore.cells.searchExtByName (cellName)) return cell; @@ -790,7 +779,6 @@ namespace MWWorld void World::deleteObject (Ptr ptr) { - return mWorldScene->deleteObject(ptr); if (ptr.getRefData().getCount()>0) { ptr.getRefData().setCount (0); @@ -814,7 +802,6 @@ namespace MWWorld void World::moveObject (Ptr ptr, float x, float y, float z) { - return mWorldScene->moveObject(ptr, x, y, z); ptr.getCellRef().pos.pos[0] = x; ptr.getCellRef().pos.pos[1] = y; ptr.getCellRef().pos.pos[2] = z; From 64633ddcdbd6622d96005207da275f6c7c31e8db Mon Sep 17 00:00:00 2001 From: Sebastian Wick Date: Mon, 1 Aug 2011 04:06:38 +0200 Subject: [PATCH 04/41] wired string to_utf8 error (maybe it returnes an empty string) --- apps/openmw/mwworld/scene.cpp | 10 ++ apps/openmw/mwworld/scene.hpp | 20 ++-- apps/openmw/mwworld/world.cpp | 204 ++++------------------------------ apps/openmw/mwworld/world.hpp | 4 - 4 files changed, 45 insertions(+), 193 deletions(-) diff --git a/apps/openmw/mwworld/scene.cpp b/apps/openmw/mwworld/scene.cpp index 8b542af59..3d1b66aca 100644 --- a/apps/openmw/mwworld/scene.cpp +++ b/apps/openmw/mwworld/scene.cpp @@ -520,6 +520,11 @@ namespace MWWorld } } } + + std::map Scene::getActiveCells () + { + return mActiveCells; + } void Scene::changeToInteriorCell (const std::string& cellName, const ESM::Position& position) @@ -584,6 +589,11 @@ namespace MWWorld return 0; } + + Ptr::CellStore* Scene::getCurrentCell () + { + return mCurrentCell; + } void Scene::markCellAsUnchanged() { diff --git a/apps/openmw/mwworld/scene.hpp b/apps/openmw/mwworld/scene.hpp index 3533ee532..c9b8390f8 100644 --- a/apps/openmw/mwworld/scene.hpp +++ b/apps/openmw/mwworld/scene.hpp @@ -97,16 +97,8 @@ namespace MWWorld void removeScripts (Ptr::CellStore *cell); - void unloadCell (CellRenderCollection::iterator iter); - - void loadCell (Ptr::CellStore *cell, MWRender::CellRender *render); - void playerCellChange (Ptr::CellStore *cell, const ESM::Position& position, bool adjustPlayerPos = true); - - void changeCell (int X, int Y, const ESM::Position& position, bool adjustPlayerPos); - ///< Move from exterior to interior or from interior cell to a different - /// interior cell. public: Scene (OEngine::Render::OgreRenderer& renderer, OEngine::Physic::PhysicEngine* physEng, @@ -116,6 +108,18 @@ namespace MWWorld ~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 (); + + CellRenderCollection getActiveCells (); + void insertInteriorScripts (ESMS::CellStore& cell); MWWorld::Player& getPlayer(); diff --git a/apps/openmw/mwworld/world.cpp b/apps/openmw/mwworld/world.cpp index 9c2e07175..00d1cc631 100644 --- a/apps/openmw/mwworld/world.cpp +++ b/apps/openmw/mwworld/world.cpp @@ -220,18 +220,12 @@ namespace MWWorld MWRender::CellRender *World::searchRender (Ptr::CellStore *store) { - CellRenderCollection::iterator iter = mActiveCells.find (store); + CellRenderCollection::iterator iter = mWorldScene->getActiveCells().find (store); - if (iter!=mActiveCells.end()) + if (iter!=mWorldScene->getActiveCells().end()) { return iter->second; } - else - { - iter = mBufferedCells.find (store); - if (iter!=mBufferedCells.end()) - return iter->second; - } return 0; } @@ -272,36 +266,12 @@ namespace MWWorld void World::unloadCell (CellRenderCollection::iterator iter) { - ListHandles functor; - iter->first->forEach(functor); - - { // silence annoying g++ warning - for (std::vector::const_iterator iter (functor.mHandles.begin()); - iter!=functor.mHandles.end(); ++iter) - mScene.removeObject (*iter); - } - - removeScripts (iter->first); - mEnvironment.mMechanicsManager->dropActors (iter->first); - mEnvironment.mSoundManager->stopSound (iter->first); - delete iter->second; - mActiveCells.erase (iter); + return mWorldScene->unloadCell(iter); } void World::loadCell (Ptr::CellStore *cell, MWRender::CellRender *render) { - // register local scripts - insertInteriorScripts (*cell); - - // This connects the cell data with the rendering scene. - std::pair result = - mActiveCells.insert (std::make_pair (cell, render)); - - if (result.second) - { - // Load the cell and insert it into the renderer - result.first->second->show(); - } + return mWorldScene->loadCell(cell, render); } void World::playerCellChange (Ptr::CellStore *cell, const ESM::Position& position, @@ -329,88 +299,15 @@ namespace MWWorld void World::changeCell (int X, int Y, const ESM::Position& position, bool adjustPlayerPos) { - SuppressDoingPhysics scopeGuard; - - // remove active - mEnvironment.mMechanicsManager->removeActor (mPlayer->getPlayer()); - - CellRenderCollection::iterator active = mActiveCells.begin(); - - while (active!=mActiveCells.end()) - { - if (!(active->first->cell->data.flags & ESM::Cell::Interior)) - { - if (std::abs (X-active->first->cell->data.gridX)<=1 && - std::abs (Y-active->first->cell->data.gridY)<=1) - { - // keep cells within the new 3x3 grid - ++active; - continue; - } - } - - unloadCell (active++); - } - - // Load cells - for (int x=X-1; x<=X+1; ++x) - for (int y=Y-1; y<=Y+1; ++y) - { - CellRenderCollection::iterator iter = mActiveCells.begin(); - - while (iter!=mActiveCells.end()) - { - assert (!(iter->first->cell->data.flags & ESM::Cell::Interior)); - - if (x==iter->first->cell->data.gridX && - y==iter->first->cell->data.gridY) - break; - - ++iter; - } - - if (iter==mActiveCells.end()) - { - mExteriors[std::make_pair (x, y)].loadExt (x, y, mStore, mEsm); - Ptr::CellStore *cell = &mExteriors[std::make_pair (x, y)]; - - loadCell (cell, new MWRender::ExteriorCellRender (*cell, mEnvironment, mScene)); - } - } - - // find current cell - CellRenderCollection::iterator iter = mActiveCells.begin(); - - while (iter!=mActiveCells.end()) - { - assert (!(iter->first->cell->data.flags & ESM::Cell::Interior)); - - if (X==iter->first->cell->data.gridX && - Y==iter->first->cell->data.gridY) - break; - - ++iter; - } - - assert (iter!=mActiveCells.end()); - - mCurrentCell = iter->first; - - // adjust player - playerCellChange (&mExteriors[std::make_pair (X, Y)], position, adjustPlayerPos); - - // Sky system - adjustSky(); - - mCellChanged = true; + mWorldScene->changeCell(X, Y, position, adjustPlayerPos); } World::World (OEngine::Render::OgreRenderer& renderer, OEngine::Physic::PhysicEngine* physEng, const Files::Collections& fileCollections, const std::string& master, const boost::filesystem::path& resDir, bool newGame, Environment& environment, const std::string& encoding) - : mSkyManager (0), mScene (renderer,physEng), mPlayer (0), mCurrentCell (0), mGlobalVariables (0), - mSky (false), mCellChanged (false), mEnvironment (environment), mNextDynamicRecord (0) + : mSkyManager (0), mScene (renderer,physEng), mPlayer (0), mGlobalVariables (0), + mSky (false), mEnvironment (environment), mNextDynamicRecord (0) { mPhysEngine = physEng; @@ -445,14 +342,6 @@ namespace MWWorld World::~World() { - for (CellRenderCollection::iterator iter (mActiveCells.begin()); - iter!=mActiveCells.end(); ++iter) - delete iter->second; - - for (CellRenderCollection::iterator iter (mBufferedCells.begin()); - iter!=mBufferedCells.end(); ++iter) - delete iter->second; - delete mPlayer; delete mSkyManager; delete mGlobalVariables; @@ -480,7 +369,7 @@ namespace MWWorld bool World::hasCellChanged() const { - return mCellChanged; + return mWorldScene->hasCellChanged(); } Globals::Data& World::getGlobalVariable (const std::string& name) @@ -507,8 +396,8 @@ namespace MWWorld } // active cells - for (CellRenderCollection::iterator iter (mActiveCells.begin()); - iter!=mActiveCells.end(); ++iter) + for (CellRenderCollection::iterator iter (mWorldScene->getActiveCells().begin()); + iter!=mWorldScene->getActiveCells().end(); ++iter) { Ptr ptr = getPtr (name, *iter->first); @@ -529,8 +418,8 @@ namespace MWWorld if (mPlayer->getPlayer().getRefData().getHandle()==handle) return mPlayer->getPlayer(); - for (CellRenderCollection::iterator iter (mActiveCells.begin()); - iter!=mActiveCells.end(); ++iter) + for (CellRenderCollection::iterator iter (mWorldScene->getActiveCells().begin()); + iter!=mWorldScene->getActiveCells().end(); ++iter) { Ptr ptr = getPtrViaHandle (handle, *iter->first); @@ -551,7 +440,7 @@ namespace MWWorld { render->enable (reference.getRefData().getHandle()); - if (mActiveCells.find (reference.getCell())!=mActiveCells.end()) + if (mWorldScene->getActiveCells().find (reference.getCell())!=mWorldScene->getActiveCells().end()) Class::get (reference).enable (reference, mEnvironment); } } @@ -567,7 +456,7 @@ namespace MWWorld { render->disable (reference.getRefData().getHandle()); - if (mActiveCells.find (reference.getCell())!=mActiveCells.end()) + if (mWorldScene->getActiveCells().find (reference.getCell())!=mWorldScene->getActiveCells().end()) { Class::get (reference).disable (reference, mEnvironment); mEnvironment.mSoundManager->stopSound3D (reference); @@ -700,70 +589,22 @@ namespace MWWorld void World::changeToInteriorCell (const std::string& cellName, const ESM::Position& position) { - SuppressDoingPhysics scopeGuard; - - // remove active - CellRenderCollection::iterator active = mActiveCells.begin(); - - while (active!=mActiveCells.end()) - { - unloadCell (active++); - } - - // Load cell. - mInteriors[cellName].loadInt (cellName, mStore, mEsm); - Ptr::CellStore *cell = &mInteriors[cellName]; - - loadCell (cell, new MWRender::InteriorCellRender (*cell, mEnvironment, mScene)); - - // adjust player - mCurrentCell = cell; - playerCellChange (cell, position); - - // Sky system - adjustSky(); - - mCellChanged = true; - //currentRegion->name = ""; + return mWorldScene->changeToInteriorCell(cellName, position); } void World::changeToExteriorCell (const ESM::Position& position) { - int x = 0; - int y = 0; - - positionToIndex (position.pos[0], position.pos[1], x, y); - - changeCell (x, y, position, true); + return mWorldScene->changeToExteriorCell(position); } const ESM::Cell *World::getExterior (const std::string& cellName) const { - // first try named cells - if (const ESM::Cell *cell = mStore.cells.searchExtByName (cellName)) - return cell; - - // didn't work -> now check for regions - std::string cellName2 = ESMS::RecListT::toLower (cellName); - - for (ESMS::RecListT::MapType::const_iterator iter (mStore.regions.list.begin()); - iter!=mStore.regions.list.end(); ++iter) - { - if (ESMS::RecListT::toLower (iter->second.name)==cellName2) - { - if (const ESM::Cell *cell = mStore.cells.searchExtByRegion (iter->first)) - return cell; - - break; - } - } - - return 0; + return mWorldScene->getExterior(cellName); } void World::markCellAsUnchanged() { - mCellChanged = false; + return mWorldScene->markCellAsUnchanged(); } std::string World::getFacedHandle() @@ -785,7 +626,7 @@ namespace MWWorld if (MWRender::CellRender *render = searchRender (ptr.getCell())) { - if (mActiveCells.find (ptr.getCell())!=mActiveCells.end()) + if (mWorldScene->getActiveCells().find (ptr.getCell())!=mWorldScene->getActiveCells().end()) { Class::get (ptr).disable (ptr, mEnvironment); mEnvironment.mSoundManager->stopSound3D (ptr); @@ -808,9 +649,10 @@ namespace MWWorld if (ptr==mPlayer->getPlayer()) { - if (mCurrentCell) + Ptr::CellStore *currentCell = mWorldScene->getCurrentCell(); + if (currentCell) { - if (!(mCurrentCell->cell->data.flags & ESM::Cell::Interior)) + if (!(currentCell->cell->data.flags & ESM::Cell::Interior)) { // exterior -> adjust loaded cells int cellX = 0; @@ -818,7 +660,7 @@ namespace MWWorld positionToIndex (x, y, cellX, cellY); - if (mCurrentCell->cell->data.gridX!=cellX || mCurrentCell->cell->data.gridY!=cellY) + if (currentCell->cell->data.gridX!=cellX || currentCell->cell->data.gridY!=cellY) { changeCell (cellX, cellY, mPlayer->getPlayer().getCellRef().pos, false); } diff --git a/apps/openmw/mwworld/world.hpp b/apps/openmw/mwworld/world.hpp index f9ff4d714..d0ae535ca 100644 --- a/apps/openmw/mwworld/world.hpp +++ b/apps/openmw/mwworld/world.hpp @@ -69,9 +69,6 @@ namespace MWWorld MWRender::MWScene mScene; MWWorld::Scene *mWorldScene; MWWorld::Player *mPlayer; - Ptr::CellStore *mCurrentCell; // the cell, the player is in - CellRenderCollection mActiveCells; - CellRenderCollection mBufferedCells; // loaded, but not active (buffering not implementd yet) ESM::ESMReader mEsm; ESMS::ESMStore mStore; std::map mInteriors; @@ -79,7 +76,6 @@ namespace MWWorld ScriptList mLocalScripts; MWWorld::Globals *mGlobalVariables; bool mSky; - bool mCellChanged; Environment& mEnvironment; int mNextDynamicRecord; From 97e4f698a7826ac4347ac8e8310e9b7b0a1034f5 Mon Sep 17 00:00:00 2001 From: Sebastian Wick Date: Mon, 1 Aug 2011 04:11:50 +0200 Subject: [PATCH 05/41] World::World looks good for now, cutting down World::Scene; still the to_utf8 error --- apps/openmw/mwworld/world.cpp | 29 +---------------------------- apps/openmw/mwworld/world.hpp | 14 +------------- 2 files changed, 2 insertions(+), 41 deletions(-) diff --git a/apps/openmw/mwworld/world.cpp b/apps/openmw/mwworld/world.cpp index 00d1cc631..d7963439a 100644 --- a/apps/openmw/mwworld/world.cpp +++ b/apps/openmw/mwworld/world.cpp @@ -264,28 +264,6 @@ namespace MWWorld } } - void World::unloadCell (CellRenderCollection::iterator iter) - { - return mWorldScene->unloadCell(iter); - } - - void World::loadCell (Ptr::CellStore *cell, MWRender::CellRender *render) - { - return mWorldScene->loadCell(cell, render); - } - - void World::playerCellChange (Ptr::CellStore *cell, const ESM::Position& position, - bool adjustPlayerPos) - { - if (adjustPlayerPos) - mPlayer->setPos (position.pos[0], position.pos[1], position.pos[2], false); - - mPlayer->setCell (cell); - // TODO orientation - mEnvironment.mMechanicsManager->addActor (mPlayer->getPlayer()); - mEnvironment.mMechanicsManager->watchActor (mPlayer->getPlayer()); - } - void World::adjustSky() { @@ -297,11 +275,6 @@ namespace MWWorld } } - void World::changeCell (int X, int Y, const ESM::Position& position, bool adjustPlayerPos) - { - mWorldScene->changeCell(X, Y, position, adjustPlayerPos); - } - World::World (OEngine::Render::OgreRenderer& renderer, OEngine::Physic::PhysicEngine* physEng, const Files::Collections& fileCollections, const std::string& master, const boost::filesystem::path& resDir, @@ -662,7 +635,7 @@ namespace MWWorld if (currentCell->cell->data.gridX!=cellX || currentCell->cell->data.gridY!=cellY) { - changeCell (cellX, cellY, mPlayer->getPlayer().getCellRef().pos, false); + mWorldScene->changeCell (cellX, cellY, mPlayer->getPlayer().getCellRef().pos, false); } } diff --git a/apps/openmw/mwworld/world.hpp b/apps/openmw/mwworld/world.hpp index d0ae535ca..cb0ab87f5 100644 --- a/apps/openmw/mwworld/world.hpp +++ b/apps/openmw/mwworld/world.hpp @@ -71,8 +71,6 @@ namespace MWWorld MWWorld::Player *mPlayer; ESM::ESMReader mEsm; ESMS::ESMStore mStore; - std::map mInteriors; - std::map, Ptr::CellStore> mExteriors; ScriptList mLocalScripts; MWWorld::Globals *mGlobalVariables; bool mSky; @@ -94,17 +92,7 @@ namespace MWWorld int getDaysPerMonth (int month) const; void removeScripts (Ptr::CellStore *cell); - - void unloadCell (CellRenderCollection::iterator iter); - - void loadCell (Ptr::CellStore *cell, MWRender::CellRender *render); - - void playerCellChange (Ptr::CellStore *cell, const ESM::Position& position, - bool adjustPlayerPos = true); - - void changeCell (int X, int Y, const ESM::Position& position, bool adjustPlayerPos); - ///< Move from exterior to interior or from interior cell to a different - /// interior cell. + public: World (OEngine::Render::OgreRenderer& renderer, OEngine::Physic::PhysicEngine* physEng, From af59f3c4756685322f40329a289a02f0f9e1566d Mon Sep 17 00:00:00 2001 From: Sebastian Wick Date: Mon, 1 Aug 2011 04:17:50 +0200 Subject: [PATCH 06/41] cut down World::Scene --- apps/openmw/mwworld/scene.cpp | 465 +--------------------------------- apps/openmw/mwworld/world.hpp | 4 +- 2 files changed, 7 insertions(+), 462 deletions(-) diff --git a/apps/openmw/mwworld/scene.cpp b/apps/openmw/mwworld/scene.cpp index 3d1b66aca..8fe6f4442 100644 --- a/apps/openmw/mwworld/scene.cpp +++ b/apps/openmw/mwworld/scene.cpp @@ -25,252 +25,10 @@ #include "doingphysics.hpp" #include "cellfunctors.hpp" -namespace -{ - template - void listCellScripts (const ESMS::ESMStore& store, - ESMS::CellRefList& cellRefList, MWWorld::Scene::ScriptList& scriptList, - MWWorld::Ptr::CellStore *cell) - { - for (typename ESMS::CellRefList::List::iterator iter ( - cellRefList.list.begin()); - iter!=cellRefList.list.end(); ++iter) - { - if (!iter->base->script.empty() && iter->mData.getCount()) - { - if (const ESM::Script *script = store.scripts.find (iter->base->script)) - { - iter->mData.setLocals (*script); - - scriptList.push_back ( - std::make_pair (iter->base->script, MWWorld::Ptr (&*iter, cell))); - } - } - } - } - - template - ESMS::LiveCellRef *searchViaHandle (const std::string& handle, - ESMS::CellRefList& refList) - { - typedef typename ESMS::CellRefList::List::iterator iterator; - - for (iterator iter (refList.list.begin()); iter!=refList.list.end(); ++iter) - { - if (iter->mData.getHandle()==handle) - { - return &*iter; - } - } - - return 0; - } -} namespace MWWorld { - void Scene::insertInteriorScripts (ESMS::CellStore& cell) - { - listCellScripts (mWorld->getStore(), cell.activators, mLocalScripts, &cell); - listCellScripts (mWorld->getStore(), cell.potions, mLocalScripts, &cell); - listCellScripts (mWorld->getStore(), cell.appas, mLocalScripts, &cell); - listCellScripts (mWorld->getStore(), cell.armors, mLocalScripts, &cell); - listCellScripts (mWorld->getStore(), cell.books, mLocalScripts, &cell); - listCellScripts (mWorld->getStore(), cell.clothes, mLocalScripts, &cell); - listCellScripts (mWorld->getStore(), cell.containers, mLocalScripts, &cell); - listCellScripts (mWorld->getStore(), cell.creatures, mLocalScripts, &cell); - listCellScripts (mWorld->getStore(), cell.doors, mLocalScripts, &cell); - listCellScripts (mWorld->getStore(), cell.ingreds, mLocalScripts, &cell); - listCellScripts (mWorld->getStore(), cell.lights, mLocalScripts, &cell); - listCellScripts (mWorld->getStore(), cell.lockpicks, mLocalScripts, &cell); - listCellScripts (mWorld->getStore(), cell.miscItems, mLocalScripts, &cell); - listCellScripts (mWorld->getStore(), cell.npcs, mLocalScripts, &cell); - listCellScripts (mWorld->getStore(), cell.probes, mLocalScripts, &cell); - listCellScripts (mWorld->getStore(), cell.repairs, mLocalScripts, &cell); - listCellScripts (mWorld->getStore(), cell.weapons, mLocalScripts, &cell); - } - - Ptr Scene::getPtr (const std::string& name, Ptr::CellStore& cell) - { - if (ESMS::LiveCellRef *ref = cell.activators.find (name)) - return Ptr (ref, &cell); - - if (ESMS::LiveCellRef *ref = cell.potions.find (name)) - return Ptr (ref, &cell); - - if (ESMS::LiveCellRef *ref = cell.appas.find (name)) - return Ptr (ref, &cell); - - if (ESMS::LiveCellRef *ref = cell.armors.find (name)) - return Ptr (ref, &cell); - - if (ESMS::LiveCellRef *ref = cell.books.find (name)) - return Ptr (ref, &cell); - - if (ESMS::LiveCellRef *ref = cell.clothes.find (name)) - return Ptr (ref, &cell); - - if (ESMS::LiveCellRef *ref = cell.containers.find (name)) - return Ptr (ref, &cell); - - if (ESMS::LiveCellRef *ref = cell.creatures.find (name)) - return Ptr (ref, &cell); - - if (ESMS::LiveCellRef *ref = cell.doors.find (name)) - return Ptr (ref, &cell); - - if (ESMS::LiveCellRef *ref = cell.ingreds.find (name)) - return Ptr (ref, &cell); - - if (ESMS::LiveCellRef *ref = cell.creatureLists.find (name)) - return Ptr (ref, &cell); - - if (ESMS::LiveCellRef *ref = cell.itemLists.find (name)) - return Ptr (ref, &cell); - - if (ESMS::LiveCellRef *ref = cell.lights.find (name)) - return Ptr (ref, &cell); - - if (ESMS::LiveCellRef *ref = cell.lockpicks.find (name)) - return Ptr (ref, &cell); - - if (ESMS::LiveCellRef *ref = cell.miscItems.find (name)) - return Ptr (ref, &cell); - - if (ESMS::LiveCellRef *ref = cell.npcs.find (name)) - return Ptr (ref, &cell); - - if (ESMS::LiveCellRef *ref = cell.probes.find (name)) - return Ptr (ref, &cell); - - if (ESMS::LiveCellRef *ref = cell.repairs.find (name)) - return Ptr (ref, &cell); - - if (ESMS::LiveCellRef *ref = cell.statics.find (name)) - return Ptr (ref, &cell); - - if (ESMS::LiveCellRef *ref = cell.weapons.find (name)) - return Ptr (ref, &cell); - - return Ptr(); - } - - Ptr Scene::getPtrViaHandle (const std::string& handle, Ptr::CellStore& cell) - { - if (ESMS::LiveCellRef *ref = - searchViaHandle (handle, cell.activators)) - return Ptr (ref, &cell); - - if (ESMS::LiveCellRef *ref = searchViaHandle (handle, cell.potions)) - return Ptr (ref, &cell); - - if (ESMS::LiveCellRef *ref = searchViaHandle (handle, cell.appas)) - return Ptr (ref, &cell); - - if (ESMS::LiveCellRef *ref = searchViaHandle (handle, cell.armors)) - return Ptr (ref, &cell); - - if (ESMS::LiveCellRef *ref = searchViaHandle (handle, cell.books)) - return Ptr (ref, &cell); - - if (ESMS::LiveCellRef *ref = searchViaHandle (handle, cell.clothes)) - return Ptr (ref, &cell); - - if (ESMS::LiveCellRef *ref = - searchViaHandle (handle, cell.containers)) - return Ptr (ref, &cell); - - if (ESMS::LiveCellRef *ref = - searchViaHandle (handle, cell.creatures)) - return Ptr (ref, &cell); - - if (ESMS::LiveCellRef *ref = searchViaHandle (handle, cell.doors)) - return Ptr (ref, &cell); - - if (ESMS::LiveCellRef *ref = - searchViaHandle (handle, cell.ingreds)) - return Ptr (ref, &cell); - - if (ESMS::LiveCellRef *ref = searchViaHandle (handle, cell.lights)) - return Ptr (ref, &cell); - - if (ESMS::LiveCellRef *ref = searchViaHandle (handle, cell.lockpicks)) - return Ptr (ref, &cell); - - if (ESMS::LiveCellRef *ref = searchViaHandle (handle, cell.miscItems)) - return Ptr (ref, &cell); - - if (ESMS::LiveCellRef *ref = searchViaHandle (handle, cell.npcs)) - return Ptr (ref, &cell); - - if (ESMS::LiveCellRef *ref = searchViaHandle (handle, cell.probes)) - return Ptr (ref, &cell); - - if (ESMS::LiveCellRef *ref = searchViaHandle (handle, cell.repairs)) - return Ptr (ref, &cell); - - if (ESMS::LiveCellRef *ref = searchViaHandle (handle, cell.statics)) - return Ptr (ref, &cell); - - if (ESMS::LiveCellRef *ref = searchViaHandle (handle, cell.weapons)) - return Ptr (ref, &cell); - - return Ptr(); - } - - MWRender::CellRender *Scene::searchRender (Ptr::CellStore *store) - { - CellRenderCollection::iterator iter = mActiveCells.find (store); - - if (iter!=mActiveCells.end()) - { - return iter->second; - } - else - { - iter = mBufferedCells.find (store); - if (iter!=mBufferedCells.end()) - return iter->second; - } - - return 0; - } - - int Scene::getDaysPerMonth (int month) const - { - switch (month) - { - case 0: return 31; - case 1: return 28; - case 2: return 31; - case 3: return 30; - case 4: return 31; - case 5: return 30; - case 6: return 31; - case 7: return 31; - case 8: return 30; - case 9: return 31; - case 10: return 30; - case 11: return 31; - } - - throw std::runtime_error ("month out of range"); - } - - void Scene::removeScripts (Ptr::CellStore *cell) - { - ScriptList::iterator iter = mLocalScripts.begin(); - - while (iter!=mLocalScripts.end()) - { - if (iter->second.getCell()==cell) - mLocalScripts.erase (iter++); - else - ++iter; - } - } - void Scene::unloadCell (CellRenderCollection::iterator iter) { ListHandles functor; @@ -282,7 +40,8 @@ namespace MWWorld mScene.removeObject (*iter); } - removeScripts (iter->first); + mWorld->removeScripts (iter->first); + mEnvironment.mMechanicsManager->dropActors (iter->first); mEnvironment.mSoundManager->stopSound (iter->first); delete iter->second; @@ -292,7 +51,7 @@ namespace MWWorld void Scene::loadCell (Ptr::CellStore *cell, MWRender::CellRender *render) { // register local scripts - insertInteriorScripts (*cell); + mWorld->insertInteriorScripts (*cell); // This connects the cell data with the rendering scene. std::pair result = @@ -418,115 +177,16 @@ namespace MWWorld delete mGlobalVariables; } - const Scene::ScriptList& Scene::getLocalScripts() const - { - return mLocalScripts; - } - bool Scene::hasCellChanged() const { return mCellChanged; } - - Globals::Data& Scene::getGlobalVariable (const std::string& name) - { - return (*mGlobalVariables)[name]; - } - - Globals::Data Scene::getGlobalVariable (const std::string& name) const - { - return (*mGlobalVariables)[name]; - } - - char Scene::getGlobalVariableType (const std::string& name) const - { - return mGlobalVariables->getType (name); - } - - Ptr Scene::getPtr (const std::string& name, bool activeOnly) - { - // the player is always in an active cell. - if (name=="player") - { - return mWorld->getPlayer().getPlayer(); - } - - // active cells - for (CellRenderCollection::iterator iter (mActiveCells.begin()); - iter!=mActiveCells.end(); ++iter) - { - Ptr ptr = getPtr (name, *iter->first); - - if (!ptr.isEmpty()) - return ptr; - } - - if (!activeOnly) - { - // TODO: inactive cells - } - - throw std::runtime_error ("unknown ID: " + name); - } - - Ptr Scene::getPtrViaHandle (const std::string& handle) - { - if (mWorld->getPlayer().getPlayer().getRefData().getHandle()==handle) - return mWorld->getPlayer().getPlayer(); - - for (CellRenderCollection::iterator iter (mActiveCells.begin()); - iter!=mActiveCells.end(); ++iter) - { - Ptr ptr = getPtrViaHandle (handle, *iter->first); - - if (!ptr.isEmpty()) - return ptr; - } - - throw std::runtime_error ("unknown Ogre handle: " + handle); - } - - void Scene::enable (Ptr reference) - { - if (!reference.getRefData().isEnabled()) - { - reference.getRefData().enable(); - - if (MWRender::CellRender *render = searchRender (reference.getCell())) - { - render->enable (reference.getRefData().getHandle()); - - if (mActiveCells.find (reference.getCell())!=mActiveCells.end()) - Class::get (reference).enable (reference, mEnvironment); - } - } - } - - void Scene::disable (Ptr reference) - { - if (reference.getRefData().isEnabled()) - { - reference.getRefData().disable(); - - if (MWRender::CellRender *render = searchRender (reference.getCell())) - { - render->disable (reference.getRefData().getHandle()); - - if (mActiveCells.find (reference.getCell())!=mActiveCells.end()) - { - Class::get (reference).disable (reference, mEnvironment); - mEnvironment.mSoundManager->stopSound3D (reference); - } - } - } - } std::map Scene::getActiveCells () { return mActiveCells; } - - + void Scene::changeToInteriorCell (const std::string& cellName, const ESM::Position& position) { SuppressDoingPhysics scopeGuard; @@ -561,7 +221,7 @@ namespace MWWorld int x = 0; int y = 0; - positionToIndex (position.pos[0], position.pos[1], x, y); + mWorld->positionToIndex (position.pos[0], position.pos[1], x, y); changeCell (x, y, position, true); } @@ -599,120 +259,5 @@ namespace MWWorld { mCellChanged = false; } - - std::string Scene::getFacedHandle() - { - // FIXME - /*std::pair result = mScene.getFacedHandle (*this); - - if (result.first.empty() || - result.second>getStore().gameSettings.find ("iMaxActivateDist")->i) - return ""; - - return result.first;*/ - return std::string(""); - } - - void Scene::deleteObject (Ptr ptr) - { - if (ptr.getRefData().getCount()>0) - { - ptr.getRefData().setCount (0); - - if (MWRender::CellRender *render = searchRender (ptr.getCell())) - { - if (mActiveCells.find (ptr.getCell())!=mActiveCells.end()) - { - Class::get (ptr).disable (ptr, mEnvironment); - mEnvironment.mSoundManager->stopSound3D (ptr); - - if (!DoingPhysics::isDoingPhysics()) - mScene.removeObject (ptr.getRefData().getHandle()); - } - - render->deleteObject (ptr.getRefData().getHandle()); - ptr.getRefData().setHandle (""); - } - } - } - - void Scene::moveObject (Ptr ptr, float x, float y, float z) - { - ptr.getCellRef().pos.pos[0] = x; - ptr.getCellRef().pos.pos[1] = y; - ptr.getCellRef().pos.pos[2] = z; - - if (ptr==mWorld->getPlayer().getPlayer()) - { - if (mCurrentCell) - { - if (!(mCurrentCell->cell->data.flags & ESM::Cell::Interior)) - { - // exterior -> adjust loaded cells - int cellX = 0; - int cellY = 0; - - positionToIndex (x, y, cellX, cellY); - - if (mCurrentCell->cell->data.gridX!=cellX || mCurrentCell->cell->data.gridY!=cellY) - { - changeCell (cellX, cellY, mWorld->getPlayer().getPlayer().getCellRef().pos, false); - } - - } - } - } - - mScene.moveObject (ptr.getRefData().getHandle(), Ogre::Vector3 (x, y, z), - !DoingPhysics::isDoingPhysics()); - - // TODO cell change for non-player ref - } - - void Scene::indexToPosition (int cellX, int cellY, float &x, float &y, bool centre) const - { - const int cellSize = 8192; - - x = cellSize * cellX; - y = cellSize * cellY; - - if (centre) - { - x += cellSize/2; - y += cellSize/2; - } - } - - void Scene::positionToIndex (float x, float y, int &cellX, int &cellY) const - { - const int cellSize = 8192; - - cellX = static_cast (x/cellSize); - - if (x<0) - --cellX; - - cellY = static_cast (y/cellSize); - - if (y<0) - --cellY; - } - - void Scene::doPhysics (const std::vector >& actors, - float duration) - { - // FIXME - // mScene.doPhysics (duration, *this, actors); - } - - bool Scene::toggleCollisionMode() - { - return mScene.toggleCollisionMode(); - } - - bool Scene::toggleRenderMode (RenderMode mode) - { - return mScene.toggleRenderMode (mode); - } } diff --git a/apps/openmw/mwworld/world.hpp b/apps/openmw/mwworld/world.hpp index cb0ab87f5..47848d6a3 100644 --- a/apps/openmw/mwworld/world.hpp +++ b/apps/openmw/mwworld/world.hpp @@ -90,8 +90,6 @@ namespace MWWorld MWRender::CellRender *searchRender (Ptr::CellStore *store); int getDaysPerMonth (int month) const; - - void removeScripts (Ptr::CellStore *cell); public: @@ -102,6 +100,8 @@ namespace MWWorld ~World(); + void removeScripts (Ptr::CellStore *cell); + void insertInteriorScripts (ESMS::CellStore& cell); void adjustSky(); From 380cd5ca358ad8456956e6ad750c7beb51e8677b Mon Sep 17 00:00:00 2001 From: Sebastian Wick Date: Mon, 1 Aug 2011 04:30:21 +0200 Subject: [PATCH 07/41] World::Scene improvements --- apps/openmw/mwworld/scene.cpp | 25 ++-------- apps/openmw/mwworld/scene.hpp | 89 ++--------------------------------- 2 files changed, 8 insertions(+), 106 deletions(-) diff --git a/apps/openmw/mwworld/scene.cpp b/apps/openmw/mwworld/scene.cpp index 8fe6f4442..f6518f961 100644 --- a/apps/openmw/mwworld/scene.cpp +++ b/apps/openmw/mwworld/scene.cpp @@ -1,13 +1,6 @@ #include "scene.hpp" #include "world.hpp" -#include -#include - -#include -#include - -#include "../mwrender/sky.hpp" #include "../mwrender/interior.hpp" #include "../mwrender/exterior.hpp" @@ -17,11 +10,8 @@ #include "ptr.hpp" #include "environment.hpp" -#include "class.hpp" #include "player.hpp" -#include "refdata.hpp" -#include "globals.hpp" #include "doingphysics.hpp" #include "cellfunctors.hpp" @@ -42,8 +32,8 @@ namespace MWWorld mWorld->removeScripts (iter->first); - mEnvironment.mMechanicsManager->dropActors (iter->first); - mEnvironment.mSoundManager->stopSound (iter->first); + mEnvironment.mMechanicsManager->dropActors (iter->first); // FIXME: gehört in world? + mEnvironment.mSoundManager->stopSound (iter->first); // FIXME: same delete iter->second; mActiveCells.erase (iter); } @@ -158,8 +148,8 @@ namespace MWWorld const Files::Collections& fileCollections, const std::string& master, const boost::filesystem::path& resDir, bool newGame, Environment& environment, const std::string& encoding, World *world, MWRender::MWScene& scene) - : mSkyManager (0), mScene (scene), mCurrentCell (0), mGlobalVariables (0), - mSky (false), mCellChanged (false), mEnvironment (environment), mNextDynamicRecord (0), mWorld(world) + : mScene (scene), mCurrentCell (0), + mCellChanged (false), mEnvironment (environment), mWorld(world) { } @@ -168,13 +158,6 @@ namespace MWWorld for (CellRenderCollection::iterator iter (mActiveCells.begin()); iter!=mActiveCells.end(); ++iter) delete iter->second; - - for (CellRenderCollection::iterator iter (mBufferedCells.begin()); - iter!=mBufferedCells.end(); ++iter) - delete iter->second; - - delete mSkyManager; - delete mGlobalVariables; } bool Scene::hasCellChanged() const diff --git a/apps/openmw/mwworld/scene.hpp b/apps/openmw/mwworld/scene.hpp index c9b8390f8..334e1832a 100644 --- a/apps/openmw/mwworld/scene.hpp +++ b/apps/openmw/mwworld/scene.hpp @@ -47,55 +47,25 @@ namespace MWWorld class Environment; class Player; - /// \brief The game world and its visual representation - class Scene { public: - typedef std::list > ScriptList; - - enum RenderMode - { - Render_CollisionDebug - }; private: typedef std::map CellRenderCollection; - MWRender::SkyManager* mSkyManager; MWRender::MWScene mScene; Ptr::CellStore *mCurrentCell; // the cell, the player is in CellRenderCollection mActiveCells; - CellRenderCollection mBufferedCells; // loaded, but not active (buffering not implementd yet) ESM::ESMReader mEsm; - ESMS::ESMStore mStore; std::map mInteriors; std::map, Ptr::CellStore> mExteriors; - ScriptList mLocalScripts; - MWWorld::Globals *mGlobalVariables; - bool mSky; bool mCellChanged; Environment& mEnvironment; - int mNextDynamicRecord; World *mWorld; - OEngine::Physic::PhysicEngine* mPhysEngine; - - // not implemented - Scene (const Scene&); - Scene& operator= (const Scene&); - - Ptr getPtr (const std::string& name, Ptr::CellStore& cellStore); - - Ptr getPtrViaHandle (const std::string& handle, Ptr::CellStore& cellStore); - - MWRender::CellRender *searchRender (Ptr::CellStore *store); - - int getDaysPerMonth (int month) const; - - void removeScripts (Ptr::CellStore *cell); void playerCellChange (Ptr::CellStore *cell, const ESM::Position& position, bool adjustPlayerPos = true); @@ -120,72 +90,21 @@ namespace MWWorld CellRenderCollection getActiveCells (); - void insertInteriorScripts (ESMS::CellStore& cell); - - MWWorld::Player& getPlayer(); - - const ESMS::ESMStore& getStore() const; - - const ScriptList& getLocalScripts() const; - ///< Names and local variable state of all local scripts in active cells. - bool hasCellChanged() const; ///< Has the player moved to a different cell, since the last frame? - Globals::Data& getGlobalVariable (const std::string& name); - - Globals::Data getGlobalVariable (const std::string& name) const; - - char getGlobalVariableType (const std::string& name) const; - ///< Return ' ', if there is no global variable with this name. - - Ptr getPtr (const std::string& name, bool activeOnly); - ///< Return a pointer to a liveCellRef with the given name. - /// \param activeOnly do non search inactive cells. - - Ptr getPtrViaHandle (const std::string& handle); - ///< Return a pointer to a liveCellRef with the given Ogre handle. - - void enable (Ptr reference); - - void disable (Ptr reference); - - void changeToInteriorCell (const std::string& cellName, const ESM::Position& position); // FIXME: YEAH! + void changeToInteriorCell (const std::string& cellName, const ESM::Position& position); ///< Move to interior cell. - void changeToExteriorCell (const ESM::Position& position); // FIXME: YEAH! + void changeToExteriorCell (const ESM::Position& position); ///< Move to exterior cell. - const ESM::Cell *getExterior (const std::string& cellName) const; // FIXME: YEAH! + const ESM::Cell *getExterior (const std::string& cellName) const; ///< Return a cell matching the given name or a 0-pointer, if there is no such cell. - void markCellAsUnchanged(); // FIXME: YEAH! + void markCellAsUnchanged(); std::string getFacedHandle(); - ///< Return handle of the object the player is looking at - - void deleteObject (Ptr ptr); // FIXME: DONT KNOW - - void moveObject (Ptr ptr, float x, float y, float z); // FIXME: DONT KNOW - - void indexToPosition (int cellX, int cellY, float &x, float &y, bool centre = false) const; - ///< Convert cell numbers to position. - - void positionToIndex (float x, float y, int &cellX, int &cellY) const; - ///< Convert position to cell numbers - - void doPhysics (const std::vector >& actors, - float duration); - ///< Run physics simulation and modify \a world accordingly. - - bool toggleCollisionMode(); - ///< Toggle collision mode for player. If disabled player object should ignore - /// collisions and gravity. - ///< \return Resulting mode - - bool toggleRenderMode (RenderMode mode); - ///< Toggle a render mode. - ///< \return Resulting mode }; } From b131f022ba746b581026d836e303fb24ced23fc3 Mon Sep 17 00:00:00 2001 From: Sebastian Wick Date: Mon, 1 Aug 2011 04:36:23 +0200 Subject: [PATCH 08/41] constructor & destructor --- apps/openmw/mwworld/scene.cpp | 5 +---- apps/openmw/mwworld/scene.hpp | 5 +---- apps/openmw/mwworld/world.cpp | 3 ++- 3 files changed, 4 insertions(+), 9 deletions(-) diff --git a/apps/openmw/mwworld/scene.cpp b/apps/openmw/mwworld/scene.cpp index f6518f961..8019df5c1 100644 --- a/apps/openmw/mwworld/scene.cpp +++ b/apps/openmw/mwworld/scene.cpp @@ -144,10 +144,7 @@ namespace MWWorld mCellChanged = true; } - Scene::Scene (OEngine::Render::OgreRenderer& renderer, OEngine::Physic::PhysicEngine* physEng, - const Files::Collections& fileCollections, - const std::string& master, const boost::filesystem::path& resDir, - bool newGame, Environment& environment, const std::string& encoding, World *world, MWRender::MWScene& scene) + Scene::Scene (Environment& environment, World *world, MWRender::MWScene& scene) : mScene (scene), mCurrentCell (0), mCellChanged (false), mEnvironment (environment), mWorld(world) { diff --git a/apps/openmw/mwworld/scene.hpp b/apps/openmw/mwworld/scene.hpp index 334e1832a..668b1a448 100644 --- a/apps/openmw/mwworld/scene.hpp +++ b/apps/openmw/mwworld/scene.hpp @@ -71,10 +71,7 @@ namespace MWWorld bool adjustPlayerPos = true); public: - Scene (OEngine::Render::OgreRenderer& renderer, OEngine::Physic::PhysicEngine* physEng, - const Files::Collections& fileCollections, - const std::string& master, const boost::filesystem::path& resDir, bool newGame, - Environment& environment, const std::string& encoding, World* world, MWRender::MWScene& scene); + Scene (Environment& environment, World *world, MWRender::MWScene& scene); ~Scene(); diff --git a/apps/openmw/mwworld/world.cpp b/apps/openmw/mwworld/world.cpp index d7963439a..69d52c172 100644 --- a/apps/openmw/mwworld/world.cpp +++ b/apps/openmw/mwworld/world.cpp @@ -310,7 +310,7 @@ namespace MWWorld mPhysEngine = physEng; - mWorldScene = new Scene(renderer, physEng, fileCollections, master, resDir, newGame, environment, encoding, this, mScene); + mWorldScene = new Scene(environment, this, mScene); } World::~World() @@ -318,6 +318,7 @@ namespace MWWorld delete mPlayer; delete mSkyManager; delete mGlobalVariables; + delete mWorldScene; } MWWorld::Player& World::getPlayer() From 6baf904f0f4272686a8eaf2340201ab01970826c Mon Sep 17 00:00:00 2001 From: Sebastian Wick Date: Mon, 1 Aug 2011 04:53:06 +0200 Subject: [PATCH 09/41] mStore fixed; glibc detected in shutdown process --- apps/openmw/mwrender/player.hpp | 2 +- apps/openmw/mwworld/player.cpp | 2 -- apps/openmw/mwworld/scene.cpp | 5 +++-- apps/openmw/mwworld/scene.hpp | 1 - 4 files changed, 4 insertions(+), 6 deletions(-) diff --git a/apps/openmw/mwrender/player.hpp b/apps/openmw/mwrender/player.hpp index 399d3f485..f2d819116 100644 --- a/apps/openmw/mwrender/player.hpp +++ b/apps/openmw/mwrender/player.hpp @@ -22,7 +22,7 @@ namespace MWRender Ogre::Camera *getCamera() { return mCamera; } - std::string getHandle() const { std::cout << "mHandle " << mHandle << std::endl; return mHandle; } + std::string getHandle() const { return mHandle; } }; } diff --git a/apps/openmw/mwworld/player.cpp b/apps/openmw/mwworld/player.cpp index d28569a9d..8b9bc747b 100644 --- a/apps/openmw/mwworld/player.cpp +++ b/apps/openmw/mwworld/player.cpp @@ -17,9 +17,7 @@ namespace MWWorld mMale = !(player->flags & ESM::NPC::Female); mRace = player->race; mPlayer.ref.pos.pos[0] = mPlayer.ref.pos.pos[1] = mPlayer.ref.pos.pos[2] = 0; - std::cout << "mData.setHandle" << std::endl; std::cout << renderer->getHandle(); - std::cout << "mData end" << std::endl; mPlayer.mData.setHandle (renderer->getHandle()); mClass = new ESM::Class (*world.getStore().classes.find (player->cls)); } diff --git a/apps/openmw/mwworld/scene.cpp b/apps/openmw/mwworld/scene.cpp index 8019df5c1..3d85aa60f 100644 --- a/apps/openmw/mwworld/scene.cpp +++ b/apps/openmw/mwworld/scene.cpp @@ -110,7 +110,7 @@ namespace MWWorld if (iter==mActiveCells.end()) { - mExteriors[std::make_pair (x, y)].loadExt (x, y, mWorld->getStore(), mEsm); + mExteriors[std::make_pair (x, y)].loadExt (x, y, mWorld->getStore(), mWorld->getEsmReader()); Ptr::CellStore *cell = &mExteriors[std::make_pair (x, y)]; loadCell (cell, new MWRender::ExteriorCellRender (*cell, mEnvironment, mScene)); @@ -180,7 +180,8 @@ namespace MWWorld } // Load cell. - mInteriors[cellName].loadInt (cellName, mWorld->getStore(), mEsm); + std::cout << "cellName:" << cellName << std::endl; + mInteriors[cellName].loadInt (cellName, mWorld->getStore(), mWorld->getEsmReader()); Ptr::CellStore *cell = &mInteriors[cellName]; loadCell (cell, new MWRender::InteriorCellRender (*cell, mEnvironment, mScene)); diff --git a/apps/openmw/mwworld/scene.hpp b/apps/openmw/mwworld/scene.hpp index 668b1a448..0c06e24b0 100644 --- a/apps/openmw/mwworld/scene.hpp +++ b/apps/openmw/mwworld/scene.hpp @@ -59,7 +59,6 @@ namespace MWWorld MWRender::MWScene mScene; Ptr::CellStore *mCurrentCell; // the cell, the player is in CellRenderCollection mActiveCells; - ESM::ESMReader mEsm; std::map mInteriors; std::map, Ptr::CellStore> mExteriors; bool mCellChanged; From 3f007d29ccd36b348508b8f6f4aa8472c5b24430 Mon Sep 17 00:00:00 2001 From: Sebastian Wick Date: Mon, 1 Aug 2011 14:34:50 +0200 Subject: [PATCH 10/41] move mInteriors and mExterior back to World::World --- apps/openmw/mwworld/scene.cpp | 10 +++++----- apps/openmw/mwworld/scene.hpp | 2 -- apps/openmw/mwworld/world.cpp | 10 ++++++++++ apps/openmw/mwworld/world.hpp | 7 +++++++ 4 files changed, 22 insertions(+), 7 deletions(-) diff --git a/apps/openmw/mwworld/scene.cpp b/apps/openmw/mwworld/scene.cpp index 3d85aa60f..444e3b334 100644 --- a/apps/openmw/mwworld/scene.cpp +++ b/apps/openmw/mwworld/scene.cpp @@ -110,8 +110,8 @@ namespace MWWorld if (iter==mActiveCells.end()) { - mExteriors[std::make_pair (x, y)].loadExt (x, y, mWorld->getStore(), mWorld->getEsmReader()); - Ptr::CellStore *cell = &mExteriors[std::make_pair (x, y)]; + mWorld->getExterior(x, y)->loadExt (x, y, mWorld->getStore(), mWorld->getEsmReader()); + Ptr::CellStore *cell = mWorld->getExterior(x, y); loadCell (cell, new MWRender::ExteriorCellRender (*cell, mEnvironment, mScene)); } @@ -136,7 +136,7 @@ namespace MWWorld mCurrentCell = iter->first; // adjust player - playerCellChange (&mExteriors[std::make_pair (X, Y)], position, adjustPlayerPos); + playerCellChange (mWorld->getExterior(X, Y), position, adjustPlayerPos); // Sky system mWorld->adjustSky(); @@ -181,8 +181,8 @@ namespace MWWorld // Load cell. std::cout << "cellName:" << cellName << std::endl; - mInteriors[cellName].loadInt (cellName, mWorld->getStore(), mWorld->getEsmReader()); - Ptr::CellStore *cell = &mInteriors[cellName]; + mWorld->getInterior(cellName)->loadInt (cellName, mWorld->getStore(), mWorld->getEsmReader()); + Ptr::CellStore *cell = mWorld->getInterior(cellName); loadCell (cell, new MWRender::InteriorCellRender (*cell, mEnvironment, mScene)); diff --git a/apps/openmw/mwworld/scene.hpp b/apps/openmw/mwworld/scene.hpp index 0c06e24b0..f7e3fc7e6 100644 --- a/apps/openmw/mwworld/scene.hpp +++ b/apps/openmw/mwworld/scene.hpp @@ -59,8 +59,6 @@ namespace MWWorld MWRender::MWScene mScene; Ptr::CellStore *mCurrentCell; // the cell, the player is in CellRenderCollection mActiveCells; - std::map mInteriors; - std::map, Ptr::CellStore> mExteriors; bool mCellChanged; Environment& mEnvironment; World *mWorld; diff --git a/apps/openmw/mwworld/world.cpp b/apps/openmw/mwworld/world.cpp index 69d52c172..4d2c1590a 100644 --- a/apps/openmw/mwworld/world.cpp +++ b/apps/openmw/mwworld/world.cpp @@ -320,6 +320,16 @@ namespace MWWorld delete mGlobalVariables; delete mWorldScene; } + + Ptr::CellStore *World::getExterior (int x, int y) + { + return &mExteriors[std::make_pair (x, y)]; + } + + Ptr::CellStore *World::getInterior (std::string name) + { + return &mInteriors[name]; + } MWWorld::Player& World::getPlayer() { diff --git a/apps/openmw/mwworld/world.hpp b/apps/openmw/mwworld/world.hpp index 47848d6a3..a9e2668db 100644 --- a/apps/openmw/mwworld/world.hpp +++ b/apps/openmw/mwworld/world.hpp @@ -76,6 +76,9 @@ namespace MWWorld bool mSky; Environment& mEnvironment; int mNextDynamicRecord; + + std::map mInteriors; + std::map, Ptr::CellStore> mExteriors; OEngine::Physic::PhysicEngine* mPhysEngine; @@ -99,6 +102,10 @@ namespace MWWorld Environment& environment, const std::string& encoding); ~World(); + + Ptr::CellStore *getExterior (int x, int y); + + Ptr::CellStore *getInterior (std::string name); void removeScripts (Ptr::CellStore *cell); From 8d4dc096a4c5bc25a0f273b925ec48783c3e5cd0 Mon Sep 17 00:00:00 2001 From: Sebastian Wick Date: Mon, 1 Aug 2011 14:41:15 +0200 Subject: [PATCH 11/41] move getExterior back --- apps/openmw/mwworld/scene.cpp | 24 ------------------------ apps/openmw/mwworld/scene.hpp | 3 --- apps/openmw/mwworld/world.cpp | 29 ++++++++++++++++++++++++----- 3 files changed, 24 insertions(+), 32 deletions(-) diff --git a/apps/openmw/mwworld/scene.cpp b/apps/openmw/mwworld/scene.cpp index 444e3b334..2080653fa 100644 --- a/apps/openmw/mwworld/scene.cpp +++ b/apps/openmw/mwworld/scene.cpp @@ -206,30 +206,6 @@ namespace MWWorld changeCell (x, y, position, true); } - - const ESM::Cell *Scene::getExterior (const std::string& cellName) const - { - // first try named cells - if (const ESM::Cell *cell = mWorld->getStore().cells.searchExtByName (cellName)) - return cell; - - // didn't work -> now check for regions - std::string cellName2 = ESMS::RecListT::toLower (cellName); - - for (ESMS::RecListT::MapType::const_iterator iter (mWorld->getStore().regions.list.begin()); - iter!=mWorld->getStore().regions.list.end(); ++iter) - { - if (ESMS::RecListT::toLower (iter->second.name)==cellName2) - { - if (const ESM::Cell *cell = mWorld->getStore().cells.searchExtByRegion (iter->first)) - return cell; - - break; - } - } - - return 0; - } Ptr::CellStore* Scene::getCurrentCell () { diff --git a/apps/openmw/mwworld/scene.hpp b/apps/openmw/mwworld/scene.hpp index f7e3fc7e6..bfb7a5537 100644 --- a/apps/openmw/mwworld/scene.hpp +++ b/apps/openmw/mwworld/scene.hpp @@ -93,9 +93,6 @@ namespace MWWorld void changeToExteriorCell (const ESM::Position& position); ///< Move to exterior cell. - const ESM::Cell *getExterior (const std::string& cellName) const; - ///< Return a cell matching the given name or a 0-pointer, if there is no such cell. - void markCellAsUnchanged(); std::string getFacedHandle(); diff --git a/apps/openmw/mwworld/world.cpp b/apps/openmw/mwworld/world.cpp index 4d2c1590a..0e9f65e8c 100644 --- a/apps/openmw/mwworld/world.cpp +++ b/apps/openmw/mwworld/world.cpp @@ -320,6 +320,30 @@ namespace MWWorld delete mGlobalVariables; delete mWorldScene; } + + const ESM::Cell *World::getExterior (const std::string& cellName) const + { + // first try named cells + if (const ESM::Cell *cell = mStore.cells.searchExtByName (cellName)) + return cell; + + // didn't work -> now check for regions + std::string cellName2 = ESMS::RecListT::toLower (cellName); + + for (ESMS::RecListT::MapType::const_iterator iter (mStore.regions.list.begin()); + iter!=mStore.regions.list.end(); ++iter) + { + if (ESMS::RecListT::toLower (iter->second.name)==cellName2) + { + if (const ESM::Cell *cell = mStore.cells.searchExtByRegion (iter->first)) + return cell; + + break; + } + } + + return 0; + } Ptr::CellStore *World::getExterior (int x, int y) { @@ -581,11 +605,6 @@ namespace MWWorld return mWorldScene->changeToExteriorCell(position); } - const ESM::Cell *World::getExterior (const std::string& cellName) const - { - return mWorldScene->getExterior(cellName); - } - void World::markCellAsUnchanged() { return mWorldScene->markCellAsUnchanged(); From 4b846a54f1ea67afa637cecbe5f19088aef6b9be Mon Sep 17 00:00:00 2001 From: Sebastian Wick Date: Mon, 1 Aug 2011 15:55:36 +0200 Subject: [PATCH 12/41] PhysicsSystem --- apps/openmw/CMakeLists.txt | 2 + apps/openmw/mwrender/exterior.cpp | 10 +- apps/openmw/mwrender/exterior.hpp | 4 +- apps/openmw/mwrender/interior.cpp | 6 +- apps/openmw/mwrender/interior.hpp | 9 +- apps/openmw/mwrender/mwscene.cpp | 115 ----------------- apps/openmw/mwrender/mwscene.hpp | 24 ---- apps/openmw/mwworld/physicssystem.cpp | 171 ++++++++++++++++++++++++++ apps/openmw/mwworld/physicssystem.hpp | 45 +++++++ apps/openmw/mwworld/physikssystem.cpp | 7 -- apps/openmw/mwworld/physikssystem.hpp | 4 - apps/openmw/mwworld/scene.cpp | 10 +- apps/openmw/mwworld/scene.hpp | 4 +- apps/openmw/mwworld/world.cpp | 13 +- apps/openmw/mwworld/world.hpp | 2 + 15 files changed, 256 insertions(+), 170 deletions(-) create mode 100644 apps/openmw/mwworld/physicssystem.cpp create mode 100644 apps/openmw/mwworld/physicssystem.hpp delete mode 100644 apps/openmw/mwworld/physikssystem.cpp delete mode 100644 apps/openmw/mwworld/physikssystem.hpp diff --git a/apps/openmw/CMakeLists.txt b/apps/openmw/CMakeLists.txt index 8fc10079c..6322c4080 100644 --- a/apps/openmw/CMakeLists.txt +++ b/apps/openmw/CMakeLists.txt @@ -140,6 +140,7 @@ source_group(apps\\openmw\\mwsound FILES ${GAMESOUND} ${GAMESOUND_HEADER}) set(GAMEWORLD mwworld/world.cpp mwworld/scene.cpp + mwworld/physicssystem.cpp mwworld/globals.cpp mwworld/class.cpp mwworld/actionteleport.cpp @@ -152,6 +153,7 @@ set(GAMEWORLD set(GAMEWORLD_HEADER mwworld/refdata.hpp mwworld/world.hpp + mwworld/physicssystem.hpp mwworld/scene.hpp mwworld/environment.hpp mwworld/globals.hpp diff --git a/apps/openmw/mwrender/exterior.cpp b/apps/openmw/mwrender/exterior.cpp index 513fdac2a..6e6908a62 100644 --- a/apps/openmw/mwrender/exterior.cpp +++ b/apps/openmw/mwrender/exterior.cpp @@ -34,8 +34,8 @@ bool ExteriorCellRender::lightOutQuadInLin = false; int ExteriorCellRender::uniqueID = 0; ExteriorCellRender::ExteriorCellRender(ESMS::CellStore &_cell, MWWorld::Environment& environment, - MWScene &_scene) - : mCell(_cell), mEnvironment (environment), mScene(_scene), mBase(NULL), mInsert(NULL), mAmbientMode (0) + MWScene &_scene, MWWorld::PhysicsSystem *physics) + : mCell(_cell), mEnvironment (environment), mScene(_scene), mBase(NULL), mInsert(NULL), mAmbientMode (0), mPhysics(physics) { uniqueID = uniqueID +1; sg = mScene.getMgr()->createStaticGeometry( "sg" + Ogre::StringConverter::toString(uniqueID)); @@ -233,13 +233,15 @@ void ExteriorCellRender::insertMesh(const std::string &mesh) void ExteriorCellRender::insertObjectPhysics() { if (!mInsertMesh.empty()) - mScene.addObject (mInsert->getName(), mInsertMesh, mInsert->getOrientation(), + { + mPhysics->addObject (mInsert->getName(), mInsertMesh, mInsert->getOrientation(), mInsert->getScale().x, mInsert->getPosition()); + } } void ExteriorCellRender::insertActorPhysics() { - mScene.addActor (mInsert->getName(), mInsertMesh, mInsert->getPosition()); + mPhysics->addActor (mInsert->getName(), mInsertMesh, mInsert->getPosition()); } // insert a light related to the most recent insertBegin call. diff --git a/apps/openmw/mwrender/exterior.hpp b/apps/openmw/mwrender/exterior.hpp index 6c7f6effc..d8f6b9b96 100644 --- a/apps/openmw/mwrender/exterior.hpp +++ b/apps/openmw/mwrender/exterior.hpp @@ -3,6 +3,7 @@ #include "cell.hpp" #include "cellimp.hpp" +#include "../mwworld/physicssystem.hpp" #include "OgreColourValue.h" #include @@ -49,6 +50,7 @@ namespace MWRender ESMS::CellStore &mCell; MWWorld::Environment &mEnvironment; MWScene &mScene; + MWWorld::PhysicsSystem *mPhysics; /// The scene node that contains all objects belonging to this /// cell. @@ -101,7 +103,7 @@ namespace MWRender public: ExteriorCellRender(ESMS::CellStore &_cell, MWWorld::Environment& environment, - MWScene &_scene); + MWScene &_scene, MWWorld::PhysicsSystem *physics); virtual ~ExteriorCellRender() { destroy(); } diff --git a/apps/openmw/mwrender/interior.cpp b/apps/openmw/mwrender/interior.cpp index 02bed0898..bfde4b04e 100644 --- a/apps/openmw/mwrender/interior.cpp +++ b/apps/openmw/mwrender/interior.cpp @@ -195,13 +195,15 @@ void InteriorCellRender::insertMesh(const std::string &mesh) void InteriorCellRender::insertObjectPhysics() { if (!mInsertMesh.empty()) - scene.addObject (insert->getName(), mInsertMesh, insert->getOrientation(), + { + mPhysics->addObject (insert->getName(), mInsertMesh, insert->getOrientation(), insert->getScale().x, insert->getPosition()); + } } void InteriorCellRender::insertActorPhysics() { - scene.addActor (insert->getName(), mInsertMesh, insert->getPosition()); + mPhysics->addActor (insert->getName(), mInsertMesh, insert->getPosition()); } // insert a light related to the most recent insertBegin call. diff --git a/apps/openmw/mwrender/interior.hpp b/apps/openmw/mwrender/interior.hpp index 295eaa475..16fca0898 100644 --- a/apps/openmw/mwrender/interior.hpp +++ b/apps/openmw/mwrender/interior.hpp @@ -3,6 +3,7 @@ #include "cell.hpp" #include "cellimp.hpp" +#include "../mwworld/physicssystem.hpp" #include "OgreColourValue.h" #include @@ -48,6 +49,7 @@ namespace MWRender ESMS::CellStore &cell; MWWorld::Environment &mEnvironment; MWScene &scene; + MWWorld::PhysicsSystem *mPhysics; /// The scene node that contains all objects belonging to this /// cell. @@ -93,8 +95,11 @@ namespace MWRender public: InteriorCellRender(ESMS::CellStore &_cell, MWWorld::Environment& environment, - MWScene &_scene) - : cell(_cell), mEnvironment (environment), scene(_scene), base(NULL), insert(NULL), ambientMode (0) {} + MWScene &_scene, MWWorld::PhysicsSystem *physics) + : cell(_cell), mEnvironment (environment), scene(_scene), base(NULL), insert(NULL), ambientMode (0) + { + mPhysics = physics; + } virtual ~InteriorCellRender() { destroy(); } diff --git a/apps/openmw/mwrender/mwscene.cpp b/apps/openmw/mwrender/mwscene.cpp index e4d449bf2..a1d4aed03 100644 --- a/apps/openmw/mwrender/mwscene.cpp +++ b/apps/openmw/mwrender/mwscene.cpp @@ -76,121 +76,6 @@ std::pair MWScene::getFacedHandle (MWWorld::World& world) return eng->rayTest(from,to); } -void MWScene::doPhysics (float duration, MWWorld::World& world, - const std::vector >& actors) -{ - // stop changes to world from being reported back to the physics system - MWWorld::DoingPhysics scopeGuard; - - //set the DebugRenderingMode. To disable it,set it to 0 - //eng->setDebugRenderingMode(1); - - //set the walkdirection to 0 (no movement) for every actor) - for(std::map::iterator it = eng->PhysicActorMap.begin(); it != eng->PhysicActorMap.end();it++) - { - OEngine::Physic::PhysicActor* act = it->second; - act->setWalkDirection(btVector3(0,0,0)); - } - - for (std::vector >::const_iterator iter (actors.begin()); - iter!=actors.end(); ++iter) - { - OEngine::Physic::PhysicActor* act = eng->getCharacter(iter->first); - - //dirty stuff to get the camera orientation. Must be changed! - - Ogre::SceneNode *sceneNode = rend.getScene()->getSceneNode (iter->first); - Ogre::Vector3 dir; - Ogre::Node* yawNode = sceneNode->getChildIterator().getNext(); - Ogre::Node* pitchNode = yawNode->getChildIterator().getNext(); - if(mFreeFly) - { - Ogre::Quaternion yawQuat = yawNode->getOrientation(); - Ogre::Quaternion pitchQuat = pitchNode->getOrientation(); - Ogre::Vector3 dir1(iter->second.x,iter->second.z,-iter->second.y); - dir = 0.07*(yawQuat*pitchQuat*dir1); - } - else - { - Ogre::Quaternion quat = yawNode->getOrientation(); - Ogre::Vector3 dir1(iter->second.x,iter->second.z,-iter->second.y); - dir = 0.025*(quat*dir1); - } - - //set the walk direction - act->setWalkDirection(btVector3(dir.x,-dir.z,dir.y)); - } - eng->stepSimulation(duration); - - for(std::map::iterator it = eng->PhysicActorMap.begin(); it != eng->PhysicActorMap.end();it++) - { - OEngine::Physic::PhysicActor* act = it->second; - btVector3 newPos = act->getPosition(); - MWWorld::Ptr ptr = world.getPtrViaHandle (it->first); - world.moveObject (ptr, newPos.x(), newPos.y(), newPos.z()); - } -} - -void MWScene::addObject (const std::string& handle, const std::string& mesh, - const Ogre::Quaternion& rotation, float scale, const Ogre::Vector3& position) -{ - OEngine::Physic::RigidBody* body = eng->createRigidBody(mesh,handle); - eng->addRigidBody(body); - btTransform tr; - tr.setOrigin(btVector3(position.x,position.y,position.z)); - tr.setRotation(btQuaternion(rotation.x,rotation.y,rotation.z,rotation.w)); - body->setWorldTransform(tr); -} - -void MWScene::addActor (const std::string& handle, const std::string& mesh, - const Ogre::Vector3& position) -{ - //TODO:optimize this. Searching the std::map isn't very efficient i think. - eng->addCharacter(handle); - OEngine::Physic::PhysicActor* act = eng->getCharacter(handle); - act->setPosition(btVector3(position.x,position.y,position.z)); -} - -void MWScene::removeObject (const std::string& handle) -{ - //TODO:check if actor??? - eng->removeCharacter(handle); - eng->removeRigidBody(handle); - eng->deleteRigidBody(handle); -} - -void MWScene::moveObject (const std::string& handle, const Ogre::Vector3& position, bool updatePhysics) -{ - rend.getScene()->getSceneNode(handle)->setPosition(position); - - if(updatePhysics)//TODO: is it an actor? Done? - { - if (OEngine::Physic::RigidBody* body = eng->getRigidBody(handle)) - { - // TODO very dirty hack to avoid crash during setup -> needs cleaning up to allow - // start positions others than 0, 0, 0 - btTransform tr = body->getWorldTransform(); - tr.setOrigin(btVector3(position.x,position.y,position.z)); - body->setWorldTransform(tr); - } - if (OEngine::Physic::PhysicActor* act = eng->getCharacter(handle)) - { - // TODO very dirty hack to avoid crash during setup -> needs cleaning up to allow - // start positions others than 0, 0, 0 - act->setPosition(btVector3(position.x,position.y,position.z)); - } - } -} - -void MWScene::rotateObject (const std::string& handle, const Ogre::Quaternion& rotation) -{ -} - -void MWScene::scaleObject (const std::string& handle, float scale) -{ - -} - bool MWScene::toggleCollisionMode() { for(std::map::iterator it = eng->PhysicActorMap.begin(); it != eng->PhysicActorMap.end();it++) diff --git a/apps/openmw/mwrender/mwscene.hpp b/apps/openmw/mwrender/mwscene.hpp index 7429ff21e..a9dfad7b5 100644 --- a/apps/openmw/mwrender/mwscene.hpp +++ b/apps/openmw/mwrender/mwscene.hpp @@ -65,30 +65,6 @@ namespace MWRender /// can be faced std::pair getFacedHandle (MWWorld::World& world); - /// Run physics simulation and modify \a world accordingly. - void doPhysics (float duration, MWWorld::World& world, - const std::vector >& actors); - - /// Add object to physics system. - void addObject (const std::string& handle, const std::string& mesh, - const Ogre::Quaternion& rotation, float scale, const Ogre::Vector3& position); - - /// Add actor to physics system. - void addActor (const std::string& handle, const std::string& mesh, - const Ogre::Vector3& position); - - /// Remove object from physic systems. - void removeObject (const std::string& handle); - - /// Move object. - void moveObject (const std::string& handle, const Ogre::Vector3& position, bool updatePhysics); - - /// Change object's orientation. - void rotateObject (const std::string& handle, const Ogre::Quaternion& rotation); - - /// Change object's scale. - void scaleObject (const std::string& handle, float scale); - /// Toggle collision mode for player. If disabled player object should ignore /// collisions and gravity. /// \return Resulting mode diff --git a/apps/openmw/mwworld/physicssystem.cpp b/apps/openmw/mwworld/physicssystem.cpp new file mode 100644 index 000000000..07a822ffa --- /dev/null +++ b/apps/openmw/mwworld/physicssystem.cpp @@ -0,0 +1,171 @@ +#include "physicssystem.hpp" +#include "../mwworld/doingphysics.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) + { + + } + + PhysicsSystem::~PhysicsSystem() + { + + } + + void PhysicsSystem::doPhysics (float duration, MWWorld::World& world, + const std::vector >& actors) + { + // stop changes to world from being reported back to the physics system + MWWorld::DoingPhysics scopeGuard; + + //set the DebugRenderingMode. To disable it,set it to 0 + //eng->setDebugRenderingMode(1); + + //set the walkdirection to 0 (no movement) for every actor) + for(std::map::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 >::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); + + for(std::map::iterator it = mEngine->PhysicActorMap.begin(); it != mEngine->PhysicActorMap.end();it++) + { + OEngine::Physic::PhysicActor* act = it->second; + btVector3 newPos = act->getPosition(); + MWWorld::Ptr ptr = world.getPtrViaHandle (it->first); + world.moveObject (ptr, newPos.x(), newPos.y(), newPos.z()); + } + } + + void 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, bool updatePhysics) + { + mRender.getScene()->getSceneNode(handle)->setPosition(position); + + if(updatePhysics)//TODO: is it an actor? Done? + { + 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::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. + } + +} diff --git a/apps/openmw/mwworld/physicssystem.hpp b/apps/openmw/mwworld/physicssystem.hpp new file mode 100644 index 000000000..3465c0eae --- /dev/null +++ b/apps/openmw/mwworld/physicssystem.hpp @@ -0,0 +1,45 @@ +#ifndef GAME_MWWORLD_PHYSICSSYSTEM_H +#define GAME_MWWORLD_PHYSICSSYSTEM_H + +#include +#include +#include + +namespace MWWorld +{ + + class PhysicsSystem + { + public: + PhysicsSystem (OEngine::Render::OgreRenderer &_rend , OEngine::Physic::PhysicEngine* physEng); + ~PhysicsSystem (); + + void doPhysics (float duration, MWWorld::World& world, + const std::vector >& 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, bool updatePhysics); + + 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; + + }; + +} + +#endif diff --git a/apps/openmw/mwworld/physikssystem.cpp b/apps/openmw/mwworld/physikssystem.cpp deleted file mode 100644 index 5e2042937..000000000 --- a/apps/openmw/mwworld/physikssystem.cpp +++ /dev/null @@ -1,7 +0,0 @@ -#include "physikssystem.hpp" - - -namespace MWWorld -{ - -} diff --git a/apps/openmw/mwworld/physikssystem.hpp b/apps/openmw/mwworld/physikssystem.hpp deleted file mode 100644 index 450f630b5..000000000 --- a/apps/openmw/mwworld/physikssystem.hpp +++ /dev/null @@ -1,4 +0,0 @@ -#ifndef GAME_MWWORLD_PHYSIKSSYSTEM_H -#define GAME_MWWORLD_PHYSIKSSYSTEM_H - -#endif diff --git a/apps/openmw/mwworld/scene.cpp b/apps/openmw/mwworld/scene.cpp index 2080653fa..d9ce68dcd 100644 --- a/apps/openmw/mwworld/scene.cpp +++ b/apps/openmw/mwworld/scene.cpp @@ -27,7 +27,7 @@ namespace MWWorld { // silence annoying g++ warning for (std::vector::const_iterator iter (functor.mHandles.begin()); iter!=functor.mHandles.end(); ++iter) - mScene.removeObject (*iter); + mPhysics->removeObject (*iter); } mWorld->removeScripts (iter->first); @@ -113,7 +113,7 @@ namespace MWWorld mWorld->getExterior(x, y)->loadExt (x, y, mWorld->getStore(), mWorld->getEsmReader()); Ptr::CellStore *cell = mWorld->getExterior(x, y); - loadCell (cell, new MWRender::ExteriorCellRender (*cell, mEnvironment, mScene)); + loadCell (cell, new MWRender::ExteriorCellRender (*cell, mEnvironment, mScene, mPhysics)); } } @@ -144,9 +144,9 @@ namespace MWWorld mCellChanged = true; } - Scene::Scene (Environment& environment, World *world, MWRender::MWScene& scene) + Scene::Scene (Environment& environment, World *world, MWRender::MWScene& scene, PhysicsSystem *physics) : mScene (scene), mCurrentCell (0), - mCellChanged (false), mEnvironment (environment), mWorld(world) + mCellChanged (false), mEnvironment (environment), mWorld(world), mPhysics(physics) { } @@ -184,7 +184,7 @@ namespace MWWorld mWorld->getInterior(cellName)->loadInt (cellName, mWorld->getStore(), mWorld->getEsmReader()); Ptr::CellStore *cell = mWorld->getInterior(cellName); - loadCell (cell, new MWRender::InteriorCellRender (*cell, mEnvironment, mScene)); + loadCell (cell, new MWRender::InteriorCellRender (*cell, mEnvironment, mScene, mPhysics)); // adjust player mCurrentCell = cell; diff --git a/apps/openmw/mwworld/scene.hpp b/apps/openmw/mwworld/scene.hpp index bfb7a5537..c6d996364 100644 --- a/apps/openmw/mwworld/scene.hpp +++ b/apps/openmw/mwworld/scene.hpp @@ -9,6 +9,7 @@ #include #include "../mwrender/mwscene.hpp" +#include "physicssystem.hpp" #include "refdata.hpp" #include "ptr.hpp" @@ -62,13 +63,14 @@ namespace MWWorld 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); + Scene (Environment& environment, World *world, MWRender::MWScene& scene, PhysicsSystem *physics); ~Scene(); diff --git a/apps/openmw/mwworld/world.cpp b/apps/openmw/mwworld/world.cpp index 0e9f65e8c..17830248f 100644 --- a/apps/openmw/mwworld/world.cpp +++ b/apps/openmw/mwworld/world.cpp @@ -283,6 +283,8 @@ namespace MWWorld mSky (false), mEnvironment (environment), mNextDynamicRecord (0) { mPhysEngine = physEng; + + mPhysics = new PhysicsSystem(renderer, physEng); boost::filesystem::path masterPath (fileCollections.getCollection (".esm").getPath (master)); @@ -294,7 +296,7 @@ namespace MWWorld mStore.load (mEsm); mPlayer = new MWWorld::Player (mScene.getPlayer(), mStore.npcs.find ("player"), *this); - mScene.addActor (mPlayer->getPlayer().getRefData().getHandle(), "", Ogre::Vector3 (0, 0, 0)); + mPhysics->addActor (mPlayer->getPlayer().getRefData().getHandle(), "", Ogre::Vector3 (0, 0, 0)); // global variables mGlobalVariables = new Globals (mStore); @@ -310,7 +312,7 @@ namespace MWWorld mPhysEngine = physEng; - mWorldScene = new Scene(environment, this, mScene); + mWorldScene = new Scene(environment, this, mScene, mPhysics); } World::~World() @@ -319,6 +321,7 @@ namespace MWWorld delete mSkyManager; delete mGlobalVariables; delete mWorldScene; + delete mPhysics; } const ESM::Cell *World::getExterior (const std::string& cellName) const @@ -635,7 +638,7 @@ namespace MWWorld mEnvironment.mSoundManager->stopSound3D (ptr); if (!DoingPhysics::isDoingPhysics()) - mScene.removeObject (ptr.getRefData().getHandle()); + mPhysics->removeObject (ptr.getRefData().getHandle()); } render->deleteObject (ptr.getRefData().getHandle()); @@ -672,7 +675,7 @@ namespace MWWorld } } - mScene.moveObject (ptr.getRefData().getHandle(), Ogre::Vector3 (x, y, z), + mPhysics->moveObject (ptr.getRefData().getHandle(), Ogre::Vector3 (x, y, z), !DoingPhysics::isDoingPhysics()); // TODO cell change for non-player ref @@ -710,7 +713,7 @@ namespace MWWorld void World::doPhysics (const std::vector >& actors, float duration) { - mScene.doPhysics (duration, *this, actors); + mPhysics->doPhysics (duration, *this, actors); } bool World::toggleCollisionMode() diff --git a/apps/openmw/mwworld/world.hpp b/apps/openmw/mwworld/world.hpp index a9e2668db..045d37aac 100644 --- a/apps/openmw/mwworld/world.hpp +++ b/apps/openmw/mwworld/world.hpp @@ -14,6 +14,7 @@ #include "ptr.hpp" #include "globals.hpp" #include "scene.hpp" +#include "physicssystem.hpp" #include @@ -73,6 +74,7 @@ namespace MWWorld ESMS::ESMStore mStore; ScriptList mLocalScripts; MWWorld::Globals *mGlobalVariables; + MWWorld::PhysicsSystem *mPhysics; bool mSky; Environment& mEnvironment; int mNextDynamicRecord; From 52bf3af565472b56787eef4bc36679e01f8ef294 Mon Sep 17 00:00:00 2001 From: Sebastian Wick Date: Tue, 2 Aug 2011 18:16:39 +0200 Subject: [PATCH 13/41] make World::PhysicsSystem not depending on World::World --- apps/openmw/mwworld/physicssystem.cpp | 12 +++++++----- apps/openmw/mwworld/physicssystem.hpp | 2 +- apps/openmw/mwworld/world.cpp | 7 ++++++- 3 files changed, 14 insertions(+), 7 deletions(-) diff --git a/apps/openmw/mwworld/physicssystem.cpp b/apps/openmw/mwworld/physicssystem.cpp index 07a822ffa..55b6e532c 100644 --- a/apps/openmw/mwworld/physicssystem.cpp +++ b/apps/openmw/mwworld/physicssystem.cpp @@ -25,7 +25,7 @@ namespace MWWorld } - void PhysicsSystem::doPhysics (float duration, MWWorld::World& world, + std::vector< std::pair > PhysicsSystem::doPhysics (float duration, const std::vector >& actors) { // stop changes to world from being reported back to the physics system @@ -71,13 +71,15 @@ namespace MWWorld } mEngine->stepSimulation(duration); + std::vector< std::pair > response; for(std::map::iterator it = mEngine->PhysicActorMap.begin(); it != mEngine->PhysicActorMap.end();it++) { - OEngine::Physic::PhysicActor* act = it->second; - btVector3 newPos = act->getPosition(); - MWWorld::Ptr ptr = world.getPtrViaHandle (it->first); - world.moveObject (ptr, newPos.x(), newPos.y(), newPos.z()); + btVector3 newPos = it->second->getPosition(); + Ogre::Vector3 coord(newPos.x(), newPos.y(), newPos.z()); + + response.push_back(std::pair(&it->first, coord)); } + return response; } void PhysicsSystem::addObject (const std::string& handle, const std::string& mesh, diff --git a/apps/openmw/mwworld/physicssystem.hpp b/apps/openmw/mwworld/physicssystem.hpp index 3465c0eae..fde3162ea 100644 --- a/apps/openmw/mwworld/physicssystem.hpp +++ b/apps/openmw/mwworld/physicssystem.hpp @@ -14,7 +14,7 @@ namespace MWWorld PhysicsSystem (OEngine::Render::OgreRenderer &_rend , OEngine::Physic::PhysicEngine* physEng); ~PhysicsSystem (); - void doPhysics (float duration, MWWorld::World& world, + std::vector< std::pair > doPhysics (float duration, const std::vector >& actors); void addObject (const std::string& handle, const std::string& mesh, diff --git a/apps/openmw/mwworld/world.cpp b/apps/openmw/mwworld/world.cpp index 17830248f..02d0d0d5c 100644 --- a/apps/openmw/mwworld/world.cpp +++ b/apps/openmw/mwworld/world.cpp @@ -713,7 +713,12 @@ namespace MWWorld void World::doPhysics (const std::vector >& actors, float duration) { - mPhysics->doPhysics (duration, *this, actors); + std::vector< std::pair > vectors = mPhysics->doPhysics (duration, actors); + std::vector< std::pair >::iterator it; + for(it = vectors.begin(); it != vectors.end(); it++) { + MWWorld::Ptr ptr = getPtrViaHandle (*it->first); + moveObject (ptr, it->second.x, it->second.y, it->second.z); + } } bool World::toggleCollisionMode() From 7cf66443df791408efe4b6b79d081c411d63b234 Mon Sep 17 00:00:00 2001 From: Sebastian Wick Date: Tue, 2 Aug 2011 18:44:10 +0200 Subject: [PATCH 14/41] const std::string* to std::string --- apps/openmw/mwworld/physicssystem.cpp | 6 +++--- apps/openmw/mwworld/physicssystem.hpp | 2 +- apps/openmw/mwworld/world.cpp | 6 +++--- 3 files changed, 7 insertions(+), 7 deletions(-) diff --git a/apps/openmw/mwworld/physicssystem.cpp b/apps/openmw/mwworld/physicssystem.cpp index 55b6e532c..e9a270c53 100644 --- a/apps/openmw/mwworld/physicssystem.cpp +++ b/apps/openmw/mwworld/physicssystem.cpp @@ -25,7 +25,7 @@ namespace MWWorld } - std::vector< std::pair > PhysicsSystem::doPhysics (float duration, + std::vector< std::pair > PhysicsSystem::doPhysics (float duration, const std::vector >& actors) { // stop changes to world from being reported back to the physics system @@ -71,13 +71,13 @@ namespace MWWorld } mEngine->stepSimulation(duration); - std::vector< std::pair > response; + std::vector< std::pair > response; for(std::map::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(&it->first, coord)); + response.push_back(std::pair(it->first, coord)); } return response; } diff --git a/apps/openmw/mwworld/physicssystem.hpp b/apps/openmw/mwworld/physicssystem.hpp index fde3162ea..57e3f363d 100644 --- a/apps/openmw/mwworld/physicssystem.hpp +++ b/apps/openmw/mwworld/physicssystem.hpp @@ -14,7 +14,7 @@ namespace MWWorld PhysicsSystem (OEngine::Render::OgreRenderer &_rend , OEngine::Physic::PhysicEngine* physEng); ~PhysicsSystem (); - std::vector< std::pair > doPhysics (float duration, + std::vector< std::pair > doPhysics (float duration, const std::vector >& actors); void addObject (const std::string& handle, const std::string& mesh, diff --git a/apps/openmw/mwworld/world.cpp b/apps/openmw/mwworld/world.cpp index 02d0d0d5c..1a424d7c8 100644 --- a/apps/openmw/mwworld/world.cpp +++ b/apps/openmw/mwworld/world.cpp @@ -713,10 +713,10 @@ namespace MWWorld void World::doPhysics (const std::vector >& actors, float duration) { - std::vector< std::pair > vectors = mPhysics->doPhysics (duration, actors); - std::vector< std::pair >::iterator it; + std::vector< std::pair > vectors = mPhysics->doPhysics (duration, actors); + std::vector< std::pair >::iterator it; for(it = vectors.begin(); it != vectors.end(); it++) { - MWWorld::Ptr ptr = getPtrViaHandle (*it->first); + MWWorld::Ptr ptr = getPtrViaHandle (it->first); moveObject (ptr, it->second.x, it->second.y, it->second.z); } } From 41d4ad93f8609a906e54210c7d8ef4a7470001b8 Mon Sep 17 00:00:00 2001 From: Sebastian Wick Date: Tue, 2 Aug 2011 18:50:31 +0200 Subject: [PATCH 15/41] World::moveObjectImp --- apps/openmw/mwworld/world.cpp | 7 ++++++- apps/openmw/mwworld/world.hpp | 2 ++ 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/apps/openmw/mwworld/world.cpp b/apps/openmw/mwworld/world.cpp index 1a424d7c8..2a89b1f42 100644 --- a/apps/openmw/mwworld/world.cpp +++ b/apps/openmw/mwworld/world.cpp @@ -647,7 +647,7 @@ namespace MWWorld } } - void World::moveObject (Ptr ptr, float x, float y, float z) + void World::moveObjectImp (Ptr ptr, float x, float y, float z) { ptr.getCellRef().pos.pos[0] = x; ptr.getCellRef().pos.pos[1] = y; @@ -674,6 +674,11 @@ namespace MWWorld } } } + } + + void World::moveObject (Ptr ptr, float x, float y, float z) + { + moveObjectImp(ptr, x, y, z); mPhysics->moveObject (ptr.getRefData().getHandle(), Ogre::Vector3 (x, y, z), !DoingPhysics::isDoingPhysics()); diff --git a/apps/openmw/mwworld/world.hpp b/apps/openmw/mwworld/world.hpp index 045d37aac..53dd2c86c 100644 --- a/apps/openmw/mwworld/world.hpp +++ b/apps/openmw/mwworld/world.hpp @@ -179,6 +179,8 @@ namespace MWWorld ///< Return handle of the object the player is looking at void deleteObject (Ptr ptr); + + void moveObjectImp (Ptr ptr, float x, float y, float z); void moveObject (Ptr ptr, float x, float y, float z); From 74b4a0cbe5769824cae0f46c00163743e9f2a574 Mon Sep 17 00:00:00 2001 From: Sebastian Wick Date: Tue, 2 Aug 2011 19:46:21 +0200 Subject: [PATCH 16/41] World::moveObjectImp private --- apps/openmw/mwworld/world.hpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/apps/openmw/mwworld/world.hpp b/apps/openmw/mwworld/world.hpp index 53dd2c86c..d59474295 100644 --- a/apps/openmw/mwworld/world.hpp +++ b/apps/openmw/mwworld/world.hpp @@ -96,6 +96,8 @@ namespace MWWorld int getDaysPerMonth (int month) const; + void moveObjectImp (Ptr ptr, float x, float y, float z); + public: World (OEngine::Render::OgreRenderer& renderer, OEngine::Physic::PhysicEngine* physEng, @@ -179,8 +181,6 @@ namespace MWWorld ///< Return handle of the object the player is looking at void deleteObject (Ptr ptr); - - void moveObjectImp (Ptr ptr, float x, float y, float z); void moveObject (Ptr ptr, float x, float y, float z); From 1bf7c4e53dde506788e3f521effd98ae152495ef Mon Sep 17 00:00:00 2001 From: gugus Date: Wed, 3 Aug 2011 11:41:16 +0200 Subject: [PATCH 17/41] Improve bullet performances --- components/nifbullet/bullet_nif_loader.cpp | 10 ++++------ components/nifbullet/bullet_nif_loader.hpp | 3 ++- 2 files changed, 6 insertions(+), 7 deletions(-) diff --git a/components/nifbullet/bullet_nif_loader.cpp b/components/nifbullet/bullet_nif_loader.cpp index 94a3a5aac..32ca8c41c 100644 --- a/components/nifbullet/bullet_nif_loader.cpp +++ b/components/nifbullet/bullet_nif_loader.cpp @@ -88,8 +88,7 @@ void ManualBulletShapeLoader::loadResource(Ogre::Resource *resource) resourceName = cShape->getName(); cShape->collide = false; - currentShape = new btCompoundShape(); - cShape->Shape = currentShape; + mTriMesh = new btTriangleMesh(); if (!vfs) vfs = new OgreVFS(resourceGroup); @@ -135,6 +134,9 @@ void ManualBulletShapeLoader::loadResource(Ogre::Resource *resource) { handleNode(node,0,Ogre::Matrix3::IDENTITY,Ogre::Vector3::ZERO,1,hasCollisionNode,false,true); } + + currentShape = new btBvhTriangleMeshShape(mTriMesh,true); + cShape->Shape = currentShape; } bool ManualBulletShapeLoader::hasRootCollisionNode(Nif::Node* node) @@ -247,7 +249,6 @@ void ManualBulletShapeLoader::handleNiTriShape(Nif::NiTriShape *shape, int flags bool raycastingOnly) { assert(shape != NULL); - btCollisionShape* NodeShape; // Interpret flags bool hidden = (flags & 0x01) != 0; // Not displayed @@ -289,7 +290,6 @@ void ManualBulletShapeLoader::handleNiTriShape(Nif::NiTriShape *shape, int flags /* Do in-place transformation.the only needed transfo is the scale. (maybe not in fact) */ - btTriangleMesh *mTriMesh = new btTriangleMesh(); Nif::NiTriShapeData *data = shape->data.getPtr(); @@ -303,8 +303,6 @@ void ManualBulletShapeLoader::handleNiTriShape(Nif::NiTriShape *shape, int flags btVector3 b3(vertices[triangles[i+2]*3]*parentScale,vertices[triangles[i+2]*3+1]*parentScale,vertices[triangles[i+2]*3+2]*parentScale); mTriMesh->addTriangle(b1,b2,b3); } - NodeShape = new btBvhTriangleMeshShape(mTriMesh,true); - currentShape->addChildShape(tr,NodeShape); } void ManualBulletShapeLoader::load(const std::string &name,const std::string &group) diff --git a/components/nifbullet/bullet_nif_loader.hpp b/components/nifbullet/bullet_nif_loader.hpp index 360d9850b..1fa2b6aa5 100644 --- a/components/nifbullet/bullet_nif_loader.hpp +++ b/components/nifbullet/bullet_nif_loader.hpp @@ -125,7 +125,8 @@ private: std::string resourceGroup; BulletShape* cShape;//current shape - btCompoundShape* currentShape;//the shape curently under construction + btTriangleMesh *mTriMesh; + btBvhTriangleMeshShape* currentShape;//the shape curently under construction }; } From 54724d7e7f5d5a8e5f376b56d86adbd9c699e569 Mon Sep 17 00:00:00 2001 From: Sebastian Wick Date: Sun, 7 Aug 2011 16:40:01 +0200 Subject: [PATCH 18/41] start RenderingManager --- apps/openmw/CMakeLists.txt | 4 +- apps/openmw/mwrender/render_manager.cpp | 1 - apps/openmw/mwrender/render_manager.hpp | 9 ----- apps/openmw/mwrender/rendering_manager.cpp | 1 + apps/openmw/mwrender/rendering_manager.hpp | 43 ++++++++++++++++++++++ apps/openmw/mwworld/scene.cpp | 4 +- apps/openmw/mwworld/world.cpp | 2 +- 7 files changed, 49 insertions(+), 15 deletions(-) delete mode 100644 apps/openmw/mwrender/render_manager.cpp delete mode 100644 apps/openmw/mwrender/render_manager.hpp create mode 100644 apps/openmw/mwrender/rendering_manager.cpp create mode 100644 apps/openmw/mwrender/rendering_manager.hpp diff --git a/apps/openmw/CMakeLists.txt b/apps/openmw/CMakeLists.txt index 6322c4080..675c377a0 100644 --- a/apps/openmw/CMakeLists.txt +++ b/apps/openmw/CMakeLists.txt @@ -16,7 +16,7 @@ set(GAME_HEADER source_group(game FILES ${GAME} ${GAME_HEADER}) set(GAMEREND - mwrender/render_manager.cpp + mwrender/rendering_manager.cpp mwrender/mwscene.cpp mwrender/cellimp.cpp mwrender/interior.cpp @@ -25,7 +25,7 @@ set(GAMEREND mwrender/player.cpp ) set(GAMEREND_HEADER - mwrender/render_manager.hpp + mwrender/rendering_manager.hpp mwrender/cell.hpp mwrender/cellimp.hpp mwrender/mwscene.hpp diff --git a/apps/openmw/mwrender/render_manager.cpp b/apps/openmw/mwrender/render_manager.cpp deleted file mode 100644 index 4212c0cec..000000000 --- a/apps/openmw/mwrender/render_manager.cpp +++ /dev/null @@ -1 +0,0 @@ -#include "render_manager.hpp" diff --git a/apps/openmw/mwrender/render_manager.hpp b/apps/openmw/mwrender/render_manager.hpp deleted file mode 100644 index 67b2fb93f..000000000 --- a/apps/openmw/mwrender/render_manager.hpp +++ /dev/null @@ -1,9 +0,0 @@ -#ifndef _GAME_RENDER_MANAGER_H -#define _GAME_RENDER_MANAGER_H - -namespace MWRender -{ - -} - -#endif diff --git a/apps/openmw/mwrender/rendering_manager.cpp b/apps/openmw/mwrender/rendering_manager.cpp new file mode 100644 index 000000000..66d178606 --- /dev/null +++ b/apps/openmw/mwrender/rendering_manager.cpp @@ -0,0 +1 @@ +#include "rendering_manager.hpp" diff --git a/apps/openmw/mwrender/rendering_manager.hpp b/apps/openmw/mwrender/rendering_manager.hpp new file mode 100644 index 000000000..19ea73f5c --- /dev/null +++ b/apps/openmw/mwrender/rendering_manager.hpp @@ -0,0 +1,43 @@ +#ifndef _GAME_RENDERING_MANAGER_H +#define _GAME_RENDERING_MANAGER_H + +#include "../mwworld/ptr.hpp" +#include +#include + +namespace MWRender +{ + +class RenderingManager { + public: + + 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: + + +}; + +} + +#endif diff --git a/apps/openmw/mwworld/scene.cpp b/apps/openmw/mwworld/scene.cpp index d9ce68dcd..a6d06a75c 100644 --- a/apps/openmw/mwworld/scene.cpp +++ b/apps/openmw/mwworld/scene.cpp @@ -152,9 +152,9 @@ namespace MWWorld Scene::~Scene() { - for (CellRenderCollection::iterator iter (mActiveCells.begin()); + /*for (CellRenderCollection::iterator iter (mActiveCells.begin()); iter!=mActiveCells.end(); ++iter) - delete iter->second; + delete iter->second;*/ } bool Scene::hasCellChanged() const diff --git a/apps/openmw/mwworld/world.cpp b/apps/openmw/mwworld/world.cpp index 2a89b1f42..abb1cf5ba 100644 --- a/apps/openmw/mwworld/world.cpp +++ b/apps/openmw/mwworld/world.cpp @@ -320,7 +320,7 @@ namespace MWWorld delete mPlayer; delete mSkyManager; delete mGlobalVariables; - delete mWorldScene; + //delete mWorldScene; delete mPhysics; } From b7dbfb849ab7a37917852fe722ee47a0f8937dbe Mon Sep 17 00:00:00 2001 From: Sebastian Wick Date: Mon, 8 Aug 2011 21:11:30 +0200 Subject: [PATCH 19/41] moved skyManager into RenderingManager --- apps/openmw/mwrender/rendering_manager.cpp | 53 +++++++++++++++++++++- apps/openmw/mwrender/rendering_manager.hpp | 8 ++++ apps/openmw/mwworld/world.cpp | 32 ++++++------- apps/openmw/mwworld/world.hpp | 3 +- 4 files changed, 78 insertions(+), 18 deletions(-) diff --git a/apps/openmw/mwrender/rendering_manager.cpp b/apps/openmw/mwrender/rendering_manager.cpp index 66d178606..e7ef93858 100644 --- a/apps/openmw/mwrender/rendering_manager.cpp +++ b/apps/openmw/mwrender/rendering_manager.cpp @@ -1 +1,52 @@ -#include "rendering_manager.hpp" +#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); +} + +} diff --git a/apps/openmw/mwrender/rendering_manager.hpp b/apps/openmw/mwrender/rendering_manager.hpp index 19ea73f5c..d456716d3 100644 --- a/apps/openmw/mwrender/rendering_manager.hpp +++ b/apps/openmw/mwrender/rendering_manager.hpp @@ -1,6 +1,9 @@ #ifndef _GAME_RENDERING_MANAGER_H #define _GAME_RENDERING_MANAGER_H + +#include "sky.hpp" + #include "../mwworld/ptr.hpp" #include #include @@ -10,6 +13,8 @@ namespace MWRender class RenderingManager { public: + RenderingManager(SkyManager *skyManager); + ~RenderingManager(); void removeCell (MWWorld::Ptr::CellStore *store); // TODO do we want this? @@ -25,6 +30,7 @@ class RenderingManager { bool getPhysicsDebugRendering() const; void update (float duration); + void skyEnable (); void skyDisable (); void skySetHour (double hour); @@ -35,6 +41,8 @@ class RenderingManager { private: + SkyManager* mSkyManager; + }; diff --git a/apps/openmw/mwworld/world.cpp b/apps/openmw/mwworld/world.cpp index abb1cf5ba..31c00c5bc 100644 --- a/apps/openmw/mwworld/world.cpp +++ b/apps/openmw/mwworld/world.cpp @@ -279,7 +279,7 @@ namespace MWWorld const Files::Collections& fileCollections, const std::string& master, const boost::filesystem::path& resDir, bool newGame, Environment& environment, const std::string& encoding) - : mSkyManager (0), mScene (renderer,physEng), mPlayer (0), mGlobalVariables (0), + : mScene (renderer,physEng), mPlayer (0), mGlobalVariables (0), mSky (false), mEnvironment (environment), mNextDynamicRecord (0) { mPhysEngine = physEng; @@ -307,20 +307,20 @@ namespace MWWorld mGlobalVariables->setInt ("chargenstate", 1); } - mSkyManager = - MWRender::SkyManager::create(renderer.getWindow(), mScene.getCamera(), resDir); - mPhysEngine = physEng; mWorldScene = new Scene(environment, this, mScene, mPhysics); + mRenderingManager = new MWRender::RenderingManager( + MWRender::SkyManager::create(renderer.getWindow(), mScene.getCamera(), resDir) + ); } World::~World() { delete mPlayer; - delete mSkyManager; + delete mRenderingManager; delete mGlobalVariables; - //delete mWorldScene; + //delete mWorldScene; // FIXME sagfault in malloc.h when not commented out delete mPhysics; } @@ -499,7 +499,7 @@ namespace MWWorld mGlobalVariables->setFloat ("gamehour", hour); - mSkyManager->setHour (hour); + mRenderingManager->skySetHour (hour); if (days>0) setDay (days + mGlobalVariables->getInt ("day")); @@ -534,7 +534,7 @@ namespace MWWorld mGlobalVariables->setInt ("day", day); mGlobalVariables->setInt ("month", month); - mSkyManager->setDate (day, month); + mRenderingManager->skySetDate (day, month); } void World::setMonth (int month) @@ -555,7 +555,7 @@ namespace MWWorld if (years>0) mGlobalVariables->setInt ("year", years+mGlobalVariables->getInt ("year")); - mSkyManager->setDate (mGlobalVariables->getInt ("day"), month); + mRenderingManager->skySetDate (mGlobalVariables->getInt ("day"), month); } bool World::toggleSky() @@ -563,34 +563,34 @@ namespace MWWorld if (mSky) { mSky = false; - mSkyManager->disable(); + mRenderingManager->skyDisable(); return false; } else { mSky = true; // TODO check for extorior or interior with sky. - mSkyManager->setHour (mGlobalVariables->getFloat ("gamehour")); - mSkyManager->setDate (mGlobalVariables->getInt ("day"), + mRenderingManager->skySetHour (mGlobalVariables->getFloat ("gamehour")); + mRenderingManager->skySetDate (mGlobalVariables->getInt ("day"), mGlobalVariables->getInt ("month")); - mSkyManager->enable(); + mRenderingManager->skyEnable(); return true; } } int World::getMasserPhase() const { - return mSkyManager->getMasserPhase(); + return mRenderingManager->skyGetMasserPhase(); } int World::getSecundaPhase() const { - return mSkyManager->getSecundaPhase(); + return mRenderingManager->skyGetSecundaPhase(); } void World::setMoonColour (bool red) { - mSkyManager->setMoonColour (red); + mRenderingManager->skySetMoonColour (red); } float World::getTimeScaleFactor() const diff --git a/apps/openmw/mwworld/world.hpp b/apps/openmw/mwworld/world.hpp index d59474295..7b900fb09 100644 --- a/apps/openmw/mwworld/world.hpp +++ b/apps/openmw/mwworld/world.hpp @@ -9,6 +9,7 @@ #include #include "../mwrender/mwscene.hpp" +#include "../mwrender/rendering_manager.hpp" #include "refdata.hpp" #include "ptr.hpp" @@ -66,7 +67,6 @@ namespace MWWorld typedef std::map CellRenderCollection; - MWRender::SkyManager* mSkyManager; MWRender::MWScene mScene; MWWorld::Scene *mWorldScene; MWWorld::Player *mPlayer; @@ -77,6 +77,7 @@ namespace MWWorld MWWorld::PhysicsSystem *mPhysics; bool mSky; Environment& mEnvironment; + MWRender::RenderingManager *mRenderingManager; int mNextDynamicRecord; std::map mInteriors; From a13b958600c70cc678acf1ee9f4c3ce642c80b26 Mon Sep 17 00:00:00 2001 From: Sebastian Wick Date: Tue, 9 Aug 2011 00:05:16 +0200 Subject: [PATCH 20/41] MWWorld::Scene::insertCell --- apps/openmw/mwworld/scene.cpp | 64 +++++++++++++++++++++++++++++++++++ apps/openmw/mwworld/scene.hpp | 2 ++ 2 files changed, 66 insertions(+) diff --git a/apps/openmw/mwworld/scene.cpp b/apps/openmw/mwworld/scene.cpp index a6d06a75c..e92966470 100644 --- a/apps/openmw/mwworld/scene.cpp +++ b/apps/openmw/mwworld/scene.cpp @@ -11,11 +11,42 @@ #include "ptr.hpp" #include "environment.hpp" #include "player.hpp" +#include "class.hpp" #include "doingphysics.hpp" #include "cellfunctors.hpp" + +namespace { + +template +void insertCellRefList (T& cellRefList, ESMS::CellStore &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 { @@ -216,5 +247,38 @@ namespace MWWorld { mCellChanged = false; } + +/*#include +#include +#include + +#include "../mwworld/class.hpp" +#include "../mwworld/ptr.hpp"*/ + +void Scene::insertCell(ESMS::CellStore &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); +} + } diff --git a/apps/openmw/mwworld/scene.hpp b/apps/openmw/mwworld/scene.hpp index c6d996364..b03b1fee4 100644 --- a/apps/openmw/mwworld/scene.hpp +++ b/apps/openmw/mwworld/scene.hpp @@ -98,6 +98,8 @@ namespace MWWorld void markCellAsUnchanged(); std::string getFacedHandle(); + + void insertCell(ESMS::CellStore &cell); }; } From 6d8cfa7dfad44f56028319320ca3ca4ef0205f63 Mon Sep 17 00:00:00 2001 From: Marc Zinnschlag Date: Tue, 9 Aug 2011 09:56:09 +0200 Subject: [PATCH 21/41] fixed crash bug --- apps/openmw/mwworld/scene.cpp | 13 ++++++------- apps/openmw/mwworld/scene.hpp | 10 +++++----- apps/openmw/mwworld/world.cpp | 15 +++++++-------- 3 files changed, 18 insertions(+), 20 deletions(-) diff --git a/apps/openmw/mwworld/scene.cpp b/apps/openmw/mwworld/scene.cpp index a6d06a75c..38180c5e5 100644 --- a/apps/openmw/mwworld/scene.cpp +++ b/apps/openmw/mwworld/scene.cpp @@ -31,7 +31,7 @@ namespace MWWorld } mWorld->removeScripts (iter->first); - + mEnvironment.mMechanicsManager->dropActors (iter->first); // FIXME: gehört in world? mEnvironment.mSoundManager->stopSound (iter->first); // FIXME: same delete iter->second; @@ -152,21 +152,21 @@ namespace MWWorld Scene::~Scene() { - /*for (CellRenderCollection::iterator iter (mActiveCells.begin()); + for (CellRenderCollection::iterator iter (mActiveCells.begin()); iter!=mActiveCells.end(); ++iter) - delete iter->second;*/ + delete iter->second; } bool Scene::hasCellChanged() const { return mCellChanged; } - + std::map Scene::getActiveCells () { return mActiveCells; } - + void Scene::changeToInteriorCell (const std::string& cellName, const ESM::Position& position) { SuppressDoingPhysics scopeGuard; @@ -206,7 +206,7 @@ namespace MWWorld changeCell (x, y, position, true); } - + Ptr::CellStore* Scene::getCurrentCell () { return mCurrentCell; @@ -217,4 +217,3 @@ namespace MWWorld mCellChanged = false; } } - diff --git a/apps/openmw/mwworld/scene.hpp b/apps/openmw/mwworld/scene.hpp index c6d996364..cddf288c3 100644 --- a/apps/openmw/mwworld/scene.hpp +++ b/apps/openmw/mwworld/scene.hpp @@ -57,7 +57,7 @@ namespace MWWorld typedef std::map CellRenderCollection; - MWRender::MWScene mScene; + MWRender::MWScene& mScene; Ptr::CellStore *mCurrentCell; // the cell, the player is in CellRenderCollection mActiveCells; bool mCellChanged; @@ -81,9 +81,9 @@ namespace MWWorld 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 (); - + CellRenderCollection getActiveCells (); bool hasCellChanged() const; @@ -92,10 +92,10 @@ namespace MWWorld void changeToInteriorCell (const std::string& cellName, const ESM::Position& position); ///< Move to interior cell. - void changeToExteriorCell (const ESM::Position& position); + void changeToExteriorCell (const ESM::Position& position); ///< Move to exterior cell. - void markCellAsUnchanged(); + void markCellAsUnchanged(); std::string getFacedHandle(); }; diff --git a/apps/openmw/mwworld/world.cpp b/apps/openmw/mwworld/world.cpp index abb1cf5ba..3d4f1d4e8 100644 --- a/apps/openmw/mwworld/world.cpp +++ b/apps/openmw/mwworld/world.cpp @@ -283,7 +283,7 @@ namespace MWWorld mSky (false), mEnvironment (environment), mNextDynamicRecord (0) { mPhysEngine = physEng; - + mPhysics = new PhysicsSystem(renderer, physEng); boost::filesystem::path masterPath (fileCollections.getCollection (".esm").getPath (master)); @@ -311,16 +311,16 @@ namespace MWWorld MWRender::SkyManager::create(renderer.getWindow(), mScene.getCamera(), resDir); mPhysEngine = physEng; - + mWorldScene = new Scene(environment, this, mScene, mPhysics); } World::~World() { - delete mPlayer; + delete mWorldScene; delete mSkyManager; delete mGlobalVariables; - //delete mWorldScene; + delete mPlayer; delete mPhysics; } @@ -347,12 +347,12 @@ namespace MWWorld return 0; } - + Ptr::CellStore *World::getExterior (int x, int y) { return &mExteriors[std::make_pair (x, y)]; } - + Ptr::CellStore *World::getInterior (std::string name) { return &mInteriors[name]; @@ -367,7 +367,7 @@ namespace MWWorld { return mStore; } - + ESM::ESMReader& World::getEsmReader() { return mEsm; @@ -768,4 +768,3 @@ namespace MWWorld return std::make_pair (stream.str(), created); } } - From 29b8a5374b497611ce8b378571b3a6eccec7c1b2 Mon Sep 17 00:00:00 2001 From: Sebastian Wick Date: Fri, 19 Aug 2011 17:03:47 +0200 Subject: [PATCH 22/41] get rid of the warnings --- apps/openmw/engine.cpp | 3 ++- apps/openmw/mwrender/exterior.cpp | 9 +++++---- apps/openmw/mwworld/scene.cpp | 4 +--- 3 files changed, 8 insertions(+), 8 deletions(-) diff --git a/apps/openmw/engine.cpp b/apps/openmw/engine.cpp index 264cf5347..5dcc412c6 100644 --- a/apps/openmw/engine.cpp +++ b/apps/openmw/engine.cpp @@ -523,4 +523,5 @@ void OMW::Engine::setCompileAll (bool all) void OMW::Engine::setEncoding(const std::string& encoding) { mEncoding = encoding; -} \ No newline at end of file +} + diff --git a/apps/openmw/mwrender/exterior.cpp b/apps/openmw/mwrender/exterior.cpp index 6e6908a62..9dd82c68f 100644 --- a/apps/openmw/mwrender/exterior.cpp +++ b/apps/openmw/mwrender/exterior.cpp @@ -35,7 +35,7 @@ int ExteriorCellRender::uniqueID = 0; ExteriorCellRender::ExteriorCellRender(ESMS::CellStore &_cell, MWWorld::Environment& environment, MWScene &_scene, MWWorld::PhysicsSystem *physics) - : mCell(_cell), mEnvironment (environment), mScene(_scene), mBase(NULL), mInsert(NULL), mAmbientMode (0), mPhysics(physics) + : mCell(_cell), mEnvironment (environment), mScene(_scene), mPhysics(physics), mBase(NULL), mInsert(NULL), mAmbientMode (0) { uniqueID = uniqueID +1; sg = mScene.getMgr()->createStaticGeometry( "sg" + Ogre::StringConverter::toString(uniqueID)); @@ -350,13 +350,14 @@ void ExteriorCellRender::setAmbientMode() void ExteriorCellRender::show() { + // FIXME: this one may be the bug mBase = mScene.getRoot()->createChildSceneNode(); - + configureAmbient(); configureFog(); - + insertCell(mCell, mEnvironment); - + sg->build(); } diff --git a/apps/openmw/mwworld/scene.cpp b/apps/openmw/mwworld/scene.cpp index e92966470..36a02d2d8 100644 --- a/apps/openmw/mwworld/scene.cpp +++ b/apps/openmw/mwworld/scene.cpp @@ -25,8 +25,7 @@ void insertCellRefList (T& cellRefList, ESMS::CellStore &cell) { if (!cellRefList.list.empty()) { - const MWWorld::Class& class_ = - MWWorld::Class::get (MWWorld::Ptr (&*cellRefList.list.begin(), &cell)); + //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++) @@ -100,7 +99,6 @@ namespace MWWorld void Scene::changeCell (int X, int Y, const ESM::Position& position, bool adjustPlayerPos) { SuppressDoingPhysics scopeGuard; - // remove active mEnvironment.mMechanicsManager->removeActor (mWorld->getPlayer().getPlayer()); From ea7eb7a62df0aaea761eab88f9e2f615bd9290e5 Mon Sep 17 00:00:00 2001 From: Lukasz Gromanowski Date: Fri, 19 Aug 2011 21:06:09 +0200 Subject: [PATCH 23/41] fixes #128 Configuration cleanup. Signed-off-by: Lukasz Gromanowski --- .gitignore | 3 + CMakeLists.txt | 31 +++- apps/launcher/CMakeLists.txt | 1 + apps/launcher/datafilespage.cpp | 9 +- apps/launcher/graphicspage.cpp | 16 +- apps/launcher/graphicspage.hpp | 2 + apps/launcher/maindialog.cpp | 9 +- apps/openmw/engine.cpp | 66 ++++--- apps/openmw/engine.hpp | 43 +++-- apps/openmw/main.cpp | 186 +++++++++---------- components/cfg/configurationmanager.cpp | 118 ++++++++++++ components/cfg/configurationmanager.hpp | 54 ++++++ components/files/collections.cpp | 28 +-- components/files/collections.hpp | 20 ++- components/files/fileops.cpp | 12 ++ components/files/fileops.hpp | 13 ++ components/files/linuxpath.cpp | 159 ++++++++++++++++ components/files/linuxpath.hpp | 90 ++++++++++ components/files/macospath.cpp | 118 ++++++++++++ components/files/macospath.hpp | 90 ++++++++++ components/files/path.cpp | 61 ------- components/files/path.hpp | 229 +++++++++++++++++++++++- components/files/windowspath.cpp | 72 ++++++++ components/files/windowspath.hpp | 90 ++++++++++ components/misc/fileops.cpp | 16 -- components/misc/fileops.hpp | 18 -- 26 files changed, 1267 insertions(+), 287 deletions(-) create mode 100644 components/cfg/configurationmanager.cpp create mode 100644 components/cfg/configurationmanager.hpp create mode 100644 components/files/fileops.cpp create mode 100644 components/files/fileops.hpp create mode 100644 components/files/linuxpath.cpp create mode 100644 components/files/linuxpath.hpp create mode 100644 components/files/macospath.cpp create mode 100644 components/files/macospath.hpp delete mode 100644 components/files/path.cpp create mode 100644 components/files/windowspath.cpp create mode 100644 components/files/windowspath.hpp delete mode 100644 components/misc/fileops.cpp delete mode 100644 components/misc/fileops.hpp diff --git a/.gitignore b/.gitignore index b17b5a584..ada874bb2 100644 --- a/.gitignore +++ b/.gitignore @@ -4,3 +4,6 @@ Doxygen prebuilt apps/openmw/config.hpp Docs/mainpage.hpp +CMakeFiles +*/CMakeFiles +CMakeCache.txt diff --git a/CMakeLists.txt b/CMakeLists.txt index 91d3f7dd3..f4be17e90 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -90,6 +90,14 @@ set(BSA_HEADER ${COMP_DIR}/bsa/bsa_file.hpp) source_group(components\\bsa FILES ${BSA} ${BSA_HEADER}) +set(CFG + ${COMP_DIR}/cfg/configurationmanager.cpp + ) +set(CFG_HEADER + ${COMP_DIR}/cfg/configurationmanager.hpp + ) +source_group(components\\cfg FILES ${CFG} ${CFG_HEADER}) + set(NIF ${COMP_DIR}/nif/nif_file.cpp) set(NIF_HEADER @@ -189,22 +197,29 @@ source_group(components\\esm FILES ${ESM_HEADER} ${ESM}) set(MISC ${COMP_DIR}/misc/stringops.cpp - ${COMP_DIR}/misc/fileops.cpp) + ) set(MISC_HEADER - ${COMP_DIR}/misc/fileops.hpp ${COMP_DIR}/misc/slice_array.hpp - ${COMP_DIR}/misc/stringops.hpp) + ${COMP_DIR}/misc/stringops.hpp + ) source_group(components\\misc FILES ${MISC} ${MISC_HEADER}) set(FILES - ${COMP_DIR}/files/path.cpp + ${COMP_DIR}/files/linuxpath.cpp + ${COMP_DIR}/files/windowspath.cpp + ${COMP_DIR}/files/macospath.cpp ${COMP_DIR}/files/multidircollection.cpp ${COMP_DIR}/files/collections.cpp + ${COMP_DIR}/files/fileops.cpp ) set(FILES_HEADER + ${COMP_DIR}/files/linuxpath.hpp + ${COMP_DIR}/files/windowspath.hpp + ${COMP_DIR}/files/macospath.hpp ${COMP_DIR}/files/path.hpp ${COMP_DIR}/files/multidircollection.hpp ${COMP_DIR}/files/collections.hpp + ${COMP_DIR}/files/fileops.hpp ) source_group(components\\files FILES ${FILES} ${FILES_HEADER}) @@ -217,10 +232,14 @@ file(GLOB INTERPRETER_HEADER ${COMP_DIR}/interpreter/*.hpp) source_group(components\\interpreter FILES ${INTERPRETER} ${INTERPRETER_HEADER}) set(COMPONENTS ${BSA} ${NIF} ${NIFOGRE} ${ESM_STORE} ${MISC} ${TO_UTF8} - ${COMPILER} ${INTERPRETER} ${ESM} ${FILE_FINDER} ${NIFBULLET} ${FILES}) + ${COMPILER} ${INTERPRETER} ${ESM} ${FILE_FINDER} ${NIFBULLET} ${FILES} + ${CFG} + ) set(COMPONENTS_HEADER ${BSA_HEADER} ${NIF_HEADER} ${NIFOGRE_HEADER} ${ESM_STORE_HEADER} ${ESM_HEADER} ${MISC_HEADER} ${COMPILER_HEADER} ${TO_UTF8_HEADER} - ${INTERPRETER_HEADER} ${FILE_FINDER_HEADER} ${NIFBULLET_HEADER} ${FILES_HEADER}) + ${INTERPRETER_HEADER} ${FILE_FINDER_HEADER} ${NIFBULLET_HEADER} ${FILES_HEADER} + ${CFG_HEADER} + ) # source directory: libs diff --git a/apps/launcher/CMakeLists.txt b/apps/launcher/CMakeLists.txt index 5090c167d..38a894866 100644 --- a/apps/launcher/CMakeLists.txt +++ b/apps/launcher/CMakeLists.txt @@ -52,6 +52,7 @@ add_executable(omwlauncher ${LAUNCHER} ${MISC} ${MISC_HEADER} ${FILES} ${FILES_HEADER} + ${CFG} ${CFG_HEADER} ${TO_UTF8} ${ESM} ${RCC_SRCS} diff --git a/apps/launcher/datafilespage.cpp b/apps/launcher/datafilespage.cpp index 2e8cdfbd2..2abe0aed4 100644 --- a/apps/launcher/datafilespage.cpp +++ b/apps/launcher/datafilespage.cpp @@ -1,9 +1,9 @@ #include #include -#include #include #include +#include #include "datafilespage.hpp" #include "lineedit.hpp" @@ -211,12 +211,13 @@ void DataFilesPage::setupDataFiles(const QStringList &paths, bool strict) void DataFilesPage::setupConfig() { - QString config = "./launcher.cfg"; + Cfg::ConfigurationManager cfg; + + QString config = (cfg.getRuntimeConfigPath() / "launcher.cfg").string().c_str(); QFile file(config); if (!file.exists()) { - config = QString::fromStdString(Files::getPath(Files::Path_ConfigUser, - "openmw", "launcher.cfg")); + config = QString::fromStdString((cfg.getLocalConfigPath() / "launcher.cfg").string()); } file.setFileName(config); // Just for displaying information diff --git a/apps/launcher/graphicspage.cpp b/apps/launcher/graphicspage.cpp index d97a915c9..622b00ef5 100644 --- a/apps/launcher/graphicspage.cpp +++ b/apps/launcher/graphicspage.cpp @@ -1,7 +1,5 @@ #include -#include - #include "graphicspage.hpp" GraphicsPage::GraphicsPage(QWidget *parent) : QWidget(parent) @@ -149,13 +147,11 @@ void GraphicsPage::createPages() void GraphicsPage::setupConfig() { - QString ogreCfg = "./ogre.cfg"; - + QString ogreCfg = (mCfg.getRuntimeConfigPath() / "ogre.cfg").string().c_str(); QFile file(ogreCfg); if (!file.exists()) { - ogreCfg = QString::fromStdString(Files::getPath(Files::Path_ConfigUser, - "openmw", "ogre.cfg")); + ogreCfg = QString::fromStdString((mCfg.getLocalConfigPath() / "ogre.cfg").string()); } mOgreConfig = new QSettings(ogreCfg, QSettings::IniFormat); @@ -164,12 +160,11 @@ void GraphicsPage::setupConfig() void GraphicsPage::setupOgre() { - QString pluginCfg = "./plugins.cfg"; + QString pluginCfg = (mCfg.getRuntimeConfigPath() / "plugins.cfg").string().c_str(); QFile file(pluginCfg); if (!file.exists()) { - pluginCfg = QString::fromStdString(Files::getPath(Files::Path_ConfigUser, - "openmw", "plugins.cfg")); + pluginCfg = QString::fromStdString((mCfg.getLocalConfigPath() / "plugins.cfg").string()); } // Reopen the file from user directory @@ -177,8 +172,7 @@ void GraphicsPage::setupOgre() if (!file.exists()) { // There's no plugins.cfg in the user directory, use global directory - pluginCfg = QString::fromStdString(Files::getPath(Files::Path_ConfigGlobal, - "openmw", "plugins.cfg")); + pluginCfg = QString::fromStdString((mCfg.getGlobalConfigPath() / "plugins.cfg").string()); } // Create a log manager so we can surpress debug text to stdout/stderr diff --git a/apps/launcher/graphicspage.hpp b/apps/launcher/graphicspage.hpp index 49ed92ac0..5d50cfc61 100644 --- a/apps/launcher/graphicspage.hpp +++ b/apps/launcher/graphicspage.hpp @@ -7,6 +7,7 @@ #include #include #include +#include class QComboBox; class QCheckBox; @@ -28,6 +29,7 @@ public slots: void rendererChanged(const QString &renderer); private: + Cfg::ConfigurationManager mCfg; Ogre::Root *mOgre; Ogre::RenderSystem *mSelectedRenderSystem; Ogre::RenderSystem *mOpenGLRenderSystem; diff --git a/apps/launcher/maindialog.cpp b/apps/launcher/maindialog.cpp index f51b3b549..b125bf13b 100644 --- a/apps/launcher/maindialog.cpp +++ b/apps/launcher/maindialog.cpp @@ -1,7 +1,5 @@ #include -#include - #include "maindialog.hpp" #include "playpage.hpp" #include "graphicspage.hpp" @@ -268,13 +266,14 @@ void MainDialog::play() void MainDialog::setupConfig() { + Cfg::ConfigurationManager cfg; + // First we read the OpenMW config - QString config = "./openmw.cfg"; + QString config = (cfg.getRuntimeConfigPath() / "openmw.cfg").string().c_str(); QFile file(config); if (!file.exists()) { - config = QString::fromStdString(Files::getPath(Files::Path_ConfigUser, - "openmw", "openmw.cfg")); + config = QString::fromStdString((cfg.getLocalConfigPath() / "openmw.cfg").string()); } file.close(); diff --git a/apps/openmw/engine.cpp b/apps/openmw/engine.cpp index d70631cf8..4854eae91 100644 --- a/apps/openmw/engine.cpp +++ b/apps/openmw/engine.cpp @@ -11,7 +11,7 @@ #include "components/esm/records.hpp" #include -#include +#include #include #include #include @@ -209,7 +209,7 @@ bool OMW::Engine::frameRenderingQueued (const Ogre::FrameEvent& evt) return true; } -OMW::Engine::Engine() +OMW::Engine::Engine(Cfg::ConfigurationManager& configurationManager) : mPhysicEngine (0) , mShowFPS (false) , mDebug (false) @@ -221,6 +221,7 @@ OMW::Engine::Engine() , mScriptContext (0) , mGuiManager (0) , mFSStrict (false) + , mCfgMgr(configurationManager) { MWClass::registerClasses(); } @@ -265,9 +266,9 @@ void OMW::Engine::addResourcesDirectory (const boost::filesystem::path& path) Ogre::ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME, true); } -void OMW::Engine::enableFSStrict() +void OMW::Engine::enableFSStrict(bool fsStrict) { - mFSStrict = true; + mFSStrict = fsStrict; } // Set data dir @@ -311,21 +312,40 @@ void OMW::Engine::addMaster (const std::string& master) } } -void OMW::Engine::enableDebugMode() +void OMW::Engine::setDebugMode(bool debugMode) { - mDebug = true; + mDebug = debugMode; } -void OMW::Engine::enableVerboseScripts() +void OMW::Engine::setScriptsVerbosity(bool scriptsVerbosity) { - mVerboseScripts = true; + mVerboseScripts = scriptsVerbosity; } -void OMW::Engine::setNewGame() +void OMW::Engine::setNewGame(bool newGame) { - mNewGame = true; + mNewGame = newGame; } +std::string OMW::Engine::getOgreFilesDir(const std::string& ogreFile) +{ + boost::filesystem::path cfgPath(mCfgMgr.getRuntimeConfigPath()); + if (!boost::filesystem::exists(cfgPath / ogreFile)) + { + cfgPath = mCfgMgr.getLocalConfigPath(); + if (!boost::filesystem::exists(cfgPath / ogreFile )) + { + cfgPath = mCfgMgr.getGlobalConfigPath(); + if (!boost::filesystem::exists(cfgPath / ogreFile)) + { + cfgPath.clear(); + } + } + } + + return (!cfgPath.empty()) ? cfgPath.string() + std::string("/") : std::string(); + } + // Initialise and enter main loop. void OMW::Engine::go() @@ -337,19 +357,11 @@ void OMW::Engine::go() test.name = ""; total = 0; - std::string cfgDir = Files::getPath (Files::Path_ConfigGlobal, "openmw", ""); - std::string cfgUserDir = Files::getPath (Files::Path_ConfigUser, "openmw", ""); - std::string plugCfg = "plugins.cfg"; - std::string ogreCfg = "ogre.cfg"; - ogreCfg.insert(0, cfgUserDir); - //A local plugins.cfg will be used if it exist, otherwise look in the default path - if(!Misc::isFile(plugCfg.c_str())) - { - plugCfg.insert(0, cfgDir); - } + std::string cfgDir(getOgreFilesDir("ogre.cfg")); + std::string pluginsFile(getOgreFilesDir("plugins.cfg") + std::string("plugins.cfg")); - mOgre.configure(!Misc::isFile(ogreCfg.c_str()), cfgUserDir, plugCfg, false); + mOgre.configure(cfgDir.empty(), cfgDir, pluginsFile, false); // This has to be added BEFORE MyGUI is initialized, as it needs // to find core.xml here. @@ -516,7 +528,17 @@ void OMW::Engine::setCompileAll (bool all) mCompileAll = all; } +void OMW::Engine::setSoundUsage(bool soundUsage) +{ + mUseSound = soundUsage; +} + +void OMW::Engine::showFPS(bool showFps) +{ + mShowFPS = showFps; +} + void OMW::Engine::setEncoding(const std::string& encoding) { mEncoding = encoding; -} \ No newline at end of file +} diff --git a/apps/openmw/engine.hpp b/apps/openmw/engine.hpp index 9d1466655..9ee3298d7 100644 --- a/apps/openmw/engine.hpp +++ b/apps/openmw/engine.hpp @@ -15,7 +15,7 @@ #include "mwworld/environment.hpp" #include "mwworld/ptr.hpp" #include - +#include namespace Compiler { @@ -53,7 +53,6 @@ namespace OEngine namespace OMW { /// \brief Main engine class, that brings together all the components of OpenMW - class Engine : private Ogre::FrameListener { std::string mEncoding; @@ -106,49 +105,44 @@ namespace OMW /// Process pending commands public: - - Engine(); - - ~Engine(); + Engine(Cfg::ConfigurationManager& configurationManager); + virtual ~Engine(); /// Enable strict filesystem mode (do not fold case) /// /// \attention The strict mode must be specified before any path-related settings /// are given to the engine. - void enableFSStrict(); + void enableFSStrict(bool fsStrict); /// Set data dirs - void setDataDirs (const std::vector& dataDirs); + void setDataDirs(const Files::Collections::PathContainer& dataDirs); /// Set resource dir - void setResourceDir (const boost::filesystem::path& parResDir); + void setResourceDir(const boost::filesystem::path& parResDir); /// Set start cell name (only interiors for now) - void setCell (const std::string& cellName); + void setCell(const std::string& cellName); /// Set master file (esm) /// - If the given name does not have an extension, ".esm" is added automatically /// - Currently OpenMW only supports one master at the same time. - void addMaster (const std::string& master); + void addMaster(const std::string& master); /// Enable fps counter - void showFPS() { mShowFPS = true; } + void showFPS(bool showFps); /// Enable debug mode: /// - non-exclusive input - void enableDebugMode(); + void setDebugMode(bool debugMode); - /// Enable the command server so external apps can send commands to the console. - /// Must be set before go(). + /// Enable or disable verbose script output + void setScriptsVerbosity(bool scriptsVerbosity); - /// Enable verbose script output - void enableVerboseScripts(); - - /// Disable all sound - void disableSound() { mUseSound = false; } + /// Disable or enable all sounds + void setSoundUsage(bool soundUsage); /// Start as a new game. - void setNewGame(); + void setNewGame(bool newGame); /// Initialise and enter main loop. void go(); @@ -161,7 +155,12 @@ namespace OMW /// Font encoding void setEncoding(const std::string& encoding); + + private: + std::string getOgreFilesDir(const std::string& ogreFile); + + Cfg::ConfigurationManager& mCfgMgr; }; } -#endif +#endif /* ENGINE_H */ diff --git a/apps/openmw/main.cpp b/apps/openmw/main.cpp index ed85f4beb..3fef2b0bd 100644 --- a/apps/openmw/main.cpp +++ b/apps/openmw/main.cpp @@ -5,8 +5,10 @@ #include -#include +#include #include +#include +#include #include "engine.hpp" @@ -35,56 +37,64 @@ using namespace std; -/// Parse command line options and openmw.cfg file (if one exists). Results are directly -/// written to \a engine. -/// \return Run OpenMW? - -bool parseOptions (int argc, char**argv, OMW::Engine& engine) +/** + * \brief Parses application command line and calls \ref Cfg::ConfigurationManager + * to parse configuration files. + * + * Results are directly written to \ref Engine class. + * + * \retval true - Everything goes OK + * \retval false - Error + */ +bool parseOptions (int argc, char** argv, OMW::Engine& engine, Cfg::ConfigurationManager& cfgMgr) { // Create a local alias for brevity namespace bpo = boost::program_options; + typedef std::vector StringsVector; - bpo::options_description desc ( - "Syntax: openmw \nAllowed options"); + bpo::options_description desc("Syntax: openmw \nAllowed options"); desc.add_options() - ("help", "print help message and quit") + ("help", "print help message") ("version", "print version information and quit") - ("data", bpo::value >() - ->default_value (std::vector(), "data") - ->multitoken(), - "set data directories (later directories have higher priority)") - ("data-local", bpo::value()->default_value (""), + ("data", bpo::value()->default_value(Files::Collections::PathContainer(), "data") + ->multitoken(), "set data directories (later directories have higher priority)") + + ("data-local", bpo::value()->default_value(""), "set local data directory (highest priority)") - ("resources", bpo::value()->default_value ("resources"), + + ("resources", bpo::value()->default_value("resources"), "set resources directory") - ("start", bpo::value()->default_value ("Beshara"), + + ("start", bpo::value()->default_value("Beshara"), "set initial cell") - ("master", bpo::value >() - ->default_value (std::vector(), "") - ->multitoken(), - "master file(s)") - ("plugin", bpo::value >() - ->default_value (std::vector(), "") - ->multitoken(), - "plugin file(s)") - ( "fps", boost::program_options::value()-> - implicit_value (true)->default_value (false), "show fps counter") - ( "debug", boost::program_options::value()-> - implicit_value (true)->default_value (false), "debug mode" ) - ( "nosound", boost::program_options::value()-> - implicit_value (true)->default_value (false), "disable all sound" ) - ( "script-verbose", boost::program_options::value()-> - implicit_value (true)->default_value (false), "verbose script output" ) - ( "new-game", boost::program_options::value()-> - implicit_value (true)->default_value (false), - "activate char gen/new game mechanics" ) - ( "script-all", boost::program_options::value()-> - implicit_value (true)->default_value (false), - "compile all scripts (excluding dialogue scripts) at startup") - ( "fs-strict", boost::program_options::value()-> - implicit_value (true)->default_value (false), - "strict file system handling (no case folding)") + + ("master", bpo::value()->default_value(StringsVector(), "") + ->multitoken(), "master file(s)") + + ("plugin", bpo::value()->default_value(StringsVector(), "") + ->multitoken(), "plugin file(s)") + + ("fps", boost::program_options::value()->implicit_value(true) + ->default_value(false), "show fps counter") + + ("debug", boost::program_options::value()->implicit_value(true) + ->default_value(false), "debug mode") + + ("nosound", boost::program_options::value()->implicit_value(true) + ->default_value(false), "disable all sounds") + + ("script-verbose", boost::program_options::value()->implicit_value(true) + ->default_value(false), "verbose script output") + + ("new-game", boost::program_options::value()->implicit_value(true) + ->default_value(false), "activate char gen/new game mechanics") + + ("script-all", boost::program_options::value()->implicit_value(true) + ->default_value(false), "compile all scripts (excluding dialogue scripts) at startup") + + ("fs-strict", boost::program_options::value()->implicit_value(true) + ->default_value(false), "strict file system handling (no case folding)") ( "encoding", boost::program_options::value()-> default_value("win1252"), @@ -94,32 +104,17 @@ bool parseOptions (int argc, char**argv, OMW::Engine& engine) "\n\twin1252 - Western European (Latin) alphabet, used by default") ; + bpo::parsed_options valid_opts = bpo::command_line_parser(argc, argv) + .options(desc).allow_unregistered().run(); + bpo::variables_map variables; - //If there is an openmw.cfg in the current path use that as global config - //Otherwise try getPath - std::string cfgFile = "openmw.cfg"; - if(!Misc::isFile(cfgFile.c_str())) - { - cfgFile = Files::getPath (Files::Path_ConfigGlobal, "openmw", "openmw.cfg"); - } - std::cout << "Using global config file: " << cfgFile << std::endl; - std::ifstream globalConfigFile(cfgFile.c_str()); - - cfgFile = Files::getPath (Files::Path_ConfigUser, "openmw", "openmw.cfg"); - std::cout << "Using user config file: " << cfgFile << std::endl; - std::ifstream userConfigFile(cfgFile.c_str()); - - bpo::parsed_options valid_opts = bpo::command_line_parser(argc, argv).options(desc).allow_unregistered().run(); + cfgMgr.readConfiguration(variables, desc); + // Runtime options override settings from all configs bpo::store(valid_opts, variables); bpo::notify(variables); - if (userConfigFile.is_open()) - bpo::store ( bpo::parse_config_file (userConfigFile, desc), variables); - if (globalConfigFile.is_open()) - bpo::store ( bpo::parse_config_file (globalConfigFile, desc), variables); - bool run = true; if (variables.count ("help")) @@ -156,63 +151,57 @@ bool parseOptions (int argc, char**argv, OMW::Engine& engine) } // directory settings - if (variables["fs-strict"].as()==true) - engine.enableFSStrict(); + engine.enableFSStrict(variables["fs-strict"].as()); - std::vector dataDirs = variables["data"].as >(); - std::vector dataDirs2 (dataDirs.begin(), dataDirs.end()); + Files::Collections::PathContainer dataDirs = variables["data"].as(); - std::string local = variables["data-local"].as(); + std::string local(variables["data-local"].as()); if (!local.empty()) - dataDirs.push_back (local); + { + dataDirs.push_back(local); + } - engine.setDataDirs (dataDirs2); + if (dataDirs.empty()) + { + dataDirs.push_back(cfgMgr.getLocalDataPath().string()); + } - engine.setResourceDir (variables["resources"].as()); + engine.setDataDirs(dataDirs); + + engine.setResourceDir(variables["resources"].as()); // master and plugin - std::vector master = variables["master"].as >(); + StringsVector master = variables["master"].as(); if (master.empty()) { std::cout << "No master file given. Assuming Morrowind.esm" << std::endl; - master.push_back ("Morrowind"); + master.push_back("Morrowind"); } - if (master.size()>1) + if (master.size() > 1) { std::cout << "Ignoring all but the first master file (multiple master files not yet supported)." << std::endl; } + engine.addMaster(master[0]); - engine.addMaster (master[0]); - - std::vector plugin = variables["plugin"].as >(); - + StringsVector plugin = variables["plugin"].as(); if (!plugin.empty()) + { std::cout << "Ignoring plugin files (plugins not yet supported)." << std::endl; + } // startup-settings - engine.setCell (variables["start"].as()); - - if (variables["new-game"].as()==true) - engine.setNewGame(); + engine.setCell(variables["start"].as()); + engine.setNewGame(variables["new-game"].as()); // other settings - if (variables["fps"].as()==true) - engine.showFPS(); - - if (variables["debug"].as()==true) - engine.enableDebugMode(); - - if (variables["nosound"].as()==true) - engine.disableSound(); - - if (variables["script-verbose"].as()==true) - engine.enableVerboseScripts(); - - if (variables["script-all"].as()==true) - engine.setCompileAll (true); + engine.showFPS(variables["fps"].as()); + engine.setDebugMode(variables["debug"].as()); + engine.setSoundUsage(!variables["nosound"].as()); + engine.setScriptsVerbosity(variables["script-verbose"].as()); + engine.setCompileAll(variables["script-all"].as()); return true; } @@ -227,16 +216,17 @@ int main(int argc, char**argv) try { - OMW::Engine engine; + Cfg::ConfigurationManager cfgMgr; + OMW::Engine engine(cfgMgr); - if (parseOptions (argc, argv, engine)) + if (parseOptions(argc, argv, engine, cfgMgr)) { engine.go(); } } - catch(exception &e) + catch (std::exception &e) { - cout << "\nERROR: " << e.what() << endl; + std::cout << "\nERROR: " << e.what() << std::endl; return 1; } diff --git a/components/cfg/configurationmanager.cpp b/components/cfg/configurationmanager.cpp new file mode 100644 index 000000000..7c210f72c --- /dev/null +++ b/components/cfg/configurationmanager.cpp @@ -0,0 +1,118 @@ +#include "configurationmanager.hpp" + +#include +#include +#include + +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") +{ +} + +ConfigurationManager::~ConfigurationManager() +{ +} + +void ConfigurationManager::readConfiguration(boost::program_options::variables_map& variables, + boost::program_options::options_description& description) +{ + loadConfig(mPath.getGlobalConfigPath(), variables, description); + loadConfig(mPath.getLocalConfigPath(), variables, description); + loadConfig(mPath.getRuntimeConfigPath(), 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); +} + +} /* namespace Cfg */ diff --git a/components/cfg/configurationmanager.hpp b/components/cfg/configurationmanager.hpp new file mode 100644 index 000000000..f0123d48a --- /dev/null +++ b/components/cfg/configurationmanager.hpp @@ -0,0 +1,54 @@ +#ifndef COMPONENTS_CFG_CONFIGURATIONMANAGER_HPP +#define COMPONENTS_CFG_CONFIGURATIONMANAGER_HPP + +#include +#include + +#include + +/** + * \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); + + private: + void loadConfig(const boost::filesystem::path& path, + boost::program_options::variables_map& variables, + boost::program_options::options_description& description); + + Files::Path<> mPath; +}; + +} /* namespace Cfg */ + +#endif /* COMPONENTS_CFG_CONFIGURATIONMANAGER_HPP */ diff --git a/components/files/collections.cpp b/components/files/collections.cpp index 8cd4865b3..cb32768b4 100644 --- a/components/files/collections.cpp +++ b/components/files/collections.cpp @@ -3,21 +3,27 @@ namespace Files { - Collections::Collections() : mFoldCase (false) {} - - Collections::Collections (const std::vector& directories, bool foldCase) - : mDirectories (directories), mFoldCase (foldCase) - {} - - const MultiDirCollection& Collections::getCollection (const std::string& extension) const + Collections::Collections() + : mDirectories() + , mFoldCase(false) + , mCollections() { - std::map::iterator iter = mCollections.find (extension); + } + Collections::Collections(const std::vector& directories, bool foldCase) + : mDirectories(directories) + , mFoldCase(foldCase) + , mCollections() + { + } + + const MultiDirCollection& Collections::getCollection(const std::string& extension) const + { + MultiDirCollectionContainer::iterator iter = mCollections.find(extension); if (iter==mCollections.end()) { - std::pair::iterator, bool> result = - mCollections.insert (std::make_pair (extension, - MultiDirCollection (mDirectories, extension, mFoldCase))); + std::pair result = + mCollections.insert(std::make_pair(extension, MultiDirCollection(mDirectories, extension, mFoldCase))); iter = result.first; } diff --git a/components/files/collections.hpp b/components/files/collections.hpp index 6eaf0303e..102ab3050 100644 --- a/components/files/collections.hpp +++ b/components/files/collections.hpp @@ -1,27 +1,35 @@ #ifndef COMPONENTS_FILES_COLLECTION_HPP #define COMPONENTS_FILES_COLLECTION_HPP +#include +#include +#include +#include + #include "multidircollection.hpp" namespace Files { class Collections { - std::vector mDirectories; - bool mFoldCase; - mutable std::map mCollections; - public: + typedef std::vector PathContainer; Collections(); - Collections (const std::vector& directories, bool foldCase); ///< Directories are listed with increasing priority. + Collections(const PathContainer& directories, bool foldCase); - const MultiDirCollection& getCollection (const std::string& extension) const; ///< Return a file collection for the given extension. Extension must contain the /// leading dot and must be all lower-case. + const MultiDirCollection& getCollection(const std::string& extension) const; + private: + typedef std::map MultiDirCollectionContainer; + PathContainer mDirectories; + + bool mFoldCase; + mutable MultiDirCollectionContainer mCollections; }; } diff --git a/components/files/fileops.cpp b/components/files/fileops.cpp new file mode 100644 index 000000000..329e4eb05 --- /dev/null +++ b/components/files/fileops.cpp @@ -0,0 +1,12 @@ +#include "fileops.hpp" +#include + +namespace Files +{ + +bool isFile(const char *name) +{ + return boost::filesystem::exists(boost::filesystem::path(name)); +} + +} diff --git a/components/files/fileops.hpp b/components/files/fileops.hpp new file mode 100644 index 000000000..a541beffc --- /dev/null +++ b/components/files/fileops.hpp @@ -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 */ diff --git a/components/files/linuxpath.cpp b/components/files/linuxpath.cpp new file mode 100644 index 000000000..9786e3898 --- /dev/null +++ b/components/files/linuxpath.cpp @@ -0,0 +1,159 @@ +/** + * 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 . + */ + +/** \file components/files/linuxpath.cpp */ + +#include "linuxpath.hpp" + +#if defined(__linux__) + +#include +#include +#include + +/** + * \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__) */ diff --git a/components/files/linuxpath.hpp b/components/files/linuxpath.hpp new file mode 100644 index 000000000..d6e717fc4 --- /dev/null +++ b/components/files/linuxpath.hpp @@ -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 . + */ + +/** \file components/files/linuxpath.hpp */ + +#ifndef COMPONENTS_FILES_LINUXPATH_H +#define COMPONENTS_FILES_LINUXPATH_H + +#if defined(__linux__) + +#include + +/** + * \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 */ diff --git a/components/files/macospath.cpp b/components/files/macospath.cpp new file mode 100644 index 000000000..46e775030 --- /dev/null +++ b/components/files/macospath.cpp @@ -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 . + */ + +/** \file components/files/macospath.cpp */ + +#include "macospath.hpp" + +#if defined(macintosh) || defined(Macintosh) || defined(__APPLE__) || defined(__MACH__) + +#include +#include +#include + +/** + * \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__) */ diff --git a/components/files/macospath.hpp b/components/files/macospath.hpp new file mode 100644 index 000000000..26f2c907f --- /dev/null +++ b/components/files/macospath.hpp @@ -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 . + */ + +/** \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 + +/** + * \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 */ diff --git a/components/files/path.cpp b/components/files/path.cpp deleted file mode 100644 index d540f1c14..000000000 --- a/components/files/path.cpp +++ /dev/null @@ -1,61 +0,0 @@ -#include "path.hpp" - -#include - -#include -#include - -#if OGRE_PLATFORM == OGRE_PLATFORM_APPLE -#include -#endif - -#if OGRE_PLATFORM == OGRE_PLATFORM_LINUX || OGRE_PLATFORM == OGRE_PLATFORM_APPLE -#include //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; -} diff --git a/components/files/path.hpp b/components/files/path.hpp index a42646404..0788cefb1 100644 --- a/components/files/path.hpp +++ b/components/files/path.hpp @@ -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 . + */ + +/** \file components/files/path.hpp */ + #ifndef COMPONENTS_FILES_PATH_HPP #define COMPONENTS_FILES_PATH_HPP #include +#include +#if defined(__linux__) + #include + namespace Files { typedef LinuxPath TargetPathType; } + +#elif defined(__WIN32) || defined(__WINDOWS__) + #include + namespace Files { typedef WindowsPath TargetPathType; } + +#elif defined(macintosh) || defined(Macintosh) || defined(__APPLE__) || defined(__MACH__) + #include + 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 */ diff --git a/components/files/windowspath.cpp b/components/files/windowspath.cpp new file mode 100644 index 000000000..f42f149c1 --- /dev/null +++ b/components/files/windowspath.cpp @@ -0,0 +1,72 @@ +#include "windowspath.hpp" + +#if defined(_WIN32) || defined(__WINDOWS__) + +#include + +#include +#include + +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__) */ diff --git a/components/files/windowspath.hpp b/components/files/windowspath.hpp new file mode 100644 index 000000000..47dfc08d8 --- /dev/null +++ b/components/files/windowspath.hpp @@ -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 . + */ + +/** \file components/files/windowspath.hpp */ + +#ifndef COMPONENTS_FILES_WINDOWSPATH_HPP +#define COMPONENTS_FILES_WINDOWSPATH_HPP + +#if defined(_WIN32) || defined(__WINDOWS__) + +#include + +/** + * \namespace Files + */ +namespace Files +{ + +/** + * \struct WindowsPath + */ +struct WindowsPath +{ + /** + * \brief Returns "X:\Documents And Settings\\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 */ diff --git a/components/misc/fileops.cpp b/components/misc/fileops.cpp deleted file mode 100644 index eb3b58d84..000000000 --- a/components/misc/fileops.cpp +++ /dev/null @@ -1,16 +0,0 @@ -#include "fileops.hpp" -#include -#include - -#include - -namespace Misc -{ - -bool isFile(const char *name) -{ - boost::filesystem::path cfg_file_path(name); - return boost::filesystem::exists(cfg_file_path); -} - -} diff --git a/components/misc/fileops.hpp b/components/misc/fileops.hpp deleted file mode 100644 index f4e7701bb..000000000 --- a/components/misc/fileops.hpp +++ /dev/null @@ -1,18 +0,0 @@ -#ifndef MISC_FILEOPS_H -#define MISC_FILEOPS_H - -#include - -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 From 48c24d49040a82f9531e6254a181c2d6b59cff8d Mon Sep 17 00:00:00 2001 From: Lukasz Gromanowski Date: Sat, 20 Aug 2011 10:11:34 +0200 Subject: [PATCH 24/41] Issue #128: Configuration cleanup - added missing cstring header. Signed-off-by: Lukasz Gromanowski --- components/files/linuxpath.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/components/files/linuxpath.cpp b/components/files/linuxpath.cpp index 9786e3898..c485002fd 100644 --- a/components/files/linuxpath.cpp +++ b/components/files/linuxpath.cpp @@ -25,6 +25,7 @@ #if defined(__linux__) #include +#include #include #include From 4191bb32d1a17829180d75d94ef81ae1c1453af0 Mon Sep 17 00:00:00 2001 From: Marc Zinnschlag Date: Mon, 22 Aug 2011 21:34:51 +0200 Subject: [PATCH 25/41] fixed an unitialised variable --- apps/openmw/mwworld/physicssystem.cpp | 12 ++++++------ apps/openmw/mwworld/physicssystem.hpp | 22 ++++++++++++---------- 2 files changed, 18 insertions(+), 16 deletions(-) diff --git a/apps/openmw/mwworld/physicssystem.cpp b/apps/openmw/mwworld/physicssystem.cpp index e9a270c53..f4433af8e 100644 --- a/apps/openmw/mwworld/physicssystem.cpp +++ b/apps/openmw/mwworld/physicssystem.cpp @@ -15,16 +15,16 @@ namespace MWWorld { PhysicsSystem::PhysicsSystem(OEngine::Render::OgreRenderer &_rend , OEngine::Physic::PhysicEngine* physEng) : - mRender(_rend), mEngine(physEng) + mRender(_rend), mEngine(physEng), mFreeFly (true) { - + } - + PhysicsSystem::~PhysicsSystem() { - + } - + std::vector< std::pair > PhysicsSystem::doPhysics (float duration, const std::vector >& actors) { @@ -76,7 +76,7 @@ namespace MWWorld { btVector3 newPos = it->second->getPosition(); Ogre::Vector3 coord(newPos.x(), newPos.y(), newPos.z()); - + response.push_back(std::pair(it->first, coord)); } return response; diff --git a/apps/openmw/mwworld/physicssystem.hpp b/apps/openmw/mwworld/physicssystem.hpp index 57e3f363d..4fbbb2ee6 100644 --- a/apps/openmw/mwworld/physicssystem.hpp +++ b/apps/openmw/mwworld/physicssystem.hpp @@ -13,31 +13,33 @@ namespace MWWorld public: PhysicsSystem (OEngine::Render::OgreRenderer &_rend , OEngine::Physic::PhysicEngine* physEng); ~PhysicsSystem (); - + std::vector< std::pair > doPhysics (float duration, const std::vector >& 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, bool updatePhysics); - + 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&); }; } From f8029aaa9ed47f3a8092e6561dd1e8cf68e7a351 Mon Sep 17 00:00:00 2001 From: Marc Zinnschlag Date: Sat, 27 Aug 2011 10:30:38 +0200 Subject: [PATCH 26/41] more cleanup; fixes for player handling during physics (unrelated to the actual refactoring bugs); fixed minor bug in character initialisation --- apps/openmw/mwrender/mwscene.cpp | 2 +- apps/openmw/mwworld/physicssystem.cpp | 2 -- apps/openmw/mwworld/player.cpp | 3 +++ apps/openmw/mwworld/scene.cpp | 2 +- apps/openmw/mwworld/world.cpp | 34 +++++++++++++++++++++------ 5 files changed, 32 insertions(+), 11 deletions(-) diff --git a/apps/openmw/mwrender/mwscene.cpp b/apps/openmw/mwrender/mwscene.cpp index a1d4aed03..ebcfefe6a 100644 --- a/apps/openmw/mwrender/mwscene.cpp +++ b/apps/openmw/mwrender/mwscene.cpp @@ -43,7 +43,7 @@ MWScene::MWScene(OEngine::Render::OgreRenderer &_rend , OEngine::Physic::PhysicE //used to obtain ingame information of ogre objects (which are faced or selected) mRaySceneQuery = rend.getScene()->createRayQuery(Ray()); - Ogre::SceneNode *playerNode = mwRoot->createChildSceneNode(); + Ogre::SceneNode *playerNode = mwRoot->createChildSceneNode ("player"); playerNode->pitch(Degree(90)); Ogre::SceneNode *cameraYawNode = playerNode->createChildSceneNode(); Ogre::SceneNode *cameraPitchNode = cameraYawNode->createChildSceneNode(); diff --git a/apps/openmw/mwworld/physicssystem.cpp b/apps/openmw/mwworld/physicssystem.cpp index f4433af8e..36b962f08 100644 --- a/apps/openmw/mwworld/physicssystem.cpp +++ b/apps/openmw/mwworld/physicssystem.cpp @@ -112,8 +112,6 @@ namespace MWWorld void PhysicsSystem::moveObject (const std::string& handle, const Ogre::Vector3& position, bool updatePhysics) { - mRender.getScene()->getSceneNode(handle)->setPosition(position); - if(updatePhysics)//TODO: is it an actor? Done? { if (OEngine::Physic::RigidBody* body = mEngine->getRigidBody(handle)) diff --git a/apps/openmw/mwworld/player.cpp b/apps/openmw/mwworld/player.cpp index 8b9bc747b..0888b4231 100644 --- a/apps/openmw/mwworld/player.cpp +++ b/apps/openmw/mwworld/player.cpp @@ -13,12 +13,14 @@ namespace MWWorld mAutoMove (false), mForwardBackward (0) { mPlayer.base = player; + mPlayer.ref.refID = "player"; mName = player->name; mMale = !(player->flags & ESM::NPC::Female); mRace = player->race; mPlayer.ref.pos.pos[0] = mPlayer.ref.pos.pos[1] = mPlayer.ref.pos.pos[2] = 0; std::cout << renderer->getHandle(); mPlayer.mData.setHandle (renderer->getHandle()); + /// \todo Do not make a copy of classes defined in esm/p records. mClass = new ESM::Class (*world.getStore().classes.find (player->cls)); } @@ -29,6 +31,7 @@ namespace MWWorld void Player::setPos(float x, float y, float z, bool updateCamera) { + /// \todo This fcuntion should be removed during the mwrender-refactoring. mWorld.moveObject (getPlayer(), x, y, z); if (updateCamera) diff --git a/apps/openmw/mwworld/scene.cpp b/apps/openmw/mwworld/scene.cpp index 49cf7ae08..9566ac7a0 100644 --- a/apps/openmw/mwworld/scene.cpp +++ b/apps/openmw/mwworld/scene.cpp @@ -245,7 +245,7 @@ namespace MWWorld { mCellChanged = false; } - + /*#include #include #include diff --git a/apps/openmw/mwworld/world.cpp b/apps/openmw/mwworld/world.cpp index c5f027daf..bf2ac9212 100644 --- a/apps/openmw/mwworld/world.cpp +++ b/apps/openmw/mwworld/world.cpp @@ -673,6 +673,12 @@ namespace MWWorld } } } + + // \todo cell change for non-player ref + + // \todo this should go into the new scene class and eventually into the objects/actors classes. + mScene.getMgr()->getSceneNode (ptr.getRefData().getHandle())-> + setPosition (Ogre::Vector3 (x, y, z)); } void World::moveObject (Ptr ptr, float x, float y, float z) @@ -680,9 +686,7 @@ namespace MWWorld moveObjectImp(ptr, x, y, z); mPhysics->moveObject (ptr.getRefData().getHandle(), Ogre::Vector3 (x, y, z), - !DoingPhysics::isDoingPhysics()); - - // TODO cell change for non-player ref + true); } void World::indexToPosition (int cellX, int cellY, float &x, float &y, bool centre) const @@ -718,11 +722,27 @@ namespace MWWorld float duration) { std::vector< std::pair > vectors = mPhysics->doPhysics (duration, actors); - std::vector< std::pair >::iterator it; - for(it = vectors.begin(); it != vectors.end(); it++) { - MWWorld::Ptr ptr = getPtrViaHandle (it->first); - moveObject (ptr, it->second.x, it->second.y, it->second.z); + std::vector< std::pair >::iterator player = vectors.end(); + + for (std::vector< std::pair >::iterator it = vectors.begin(); + it!= vectors.end(); ++it) + { + if (it->first=="player") + { + player = it; + } + else + { + MWWorld::Ptr ptr = getPtrViaHandle (it->first); + moveObjectImp (ptr, it->second.x, it->second.y, it->second.z); + } } + + // Make sure player is moved last (otherwise the cell might change in the middle of an update + // loop) + if (player!=vectors.end()) + moveObjectImp (getPtrViaHandle (player->first), + player->second.x, player->second.y, player->second.z); } bool World::toggleCollisionMode() From 0a2979caf215e987da6d06bec484680f26e1e7f8 Mon Sep 17 00:00:00 2001 From: Marc Zinnschlag Date: Sat, 27 Aug 2011 10:45:09 +0200 Subject: [PATCH 27/41] more cleanup --- apps/openmw/CMakeLists.txt | 2 -- apps/openmw/mwrender/mwscene.cpp | 1 - apps/openmw/mwworld/doingphysics.cpp | 33 ------------------- apps/openmw/mwworld/doingphysics.hpp | 46 --------------------------- apps/openmw/mwworld/physicssystem.cpp | 4 --- apps/openmw/mwworld/scene.cpp | 6 ---- apps/openmw/mwworld/world.cpp | 4 +-- 7 files changed, 1 insertion(+), 95 deletions(-) delete mode 100644 apps/openmw/mwworld/doingphysics.cpp delete mode 100644 apps/openmw/mwworld/doingphysics.hpp diff --git a/apps/openmw/CMakeLists.txt b/apps/openmw/CMakeLists.txt index 675c377a0..8b8fd9823 100644 --- a/apps/openmw/CMakeLists.txt +++ b/apps/openmw/CMakeLists.txt @@ -148,7 +148,6 @@ set(GAMEWORLD mwworld/actiontake.cpp mwworld/containerutil.cpp mwworld/player.cpp - mwworld/doingphysics.cpp ) set(GAMEWORLD_HEADER mwworld/refdata.hpp @@ -168,7 +167,6 @@ set(GAMEWORLD_HEADER mwworld/manualref.hpp mwworld/containerutil.hpp mwworld/player.hpp - mwworld/doingphysics.hpp mwworld/cellfunctors.hpp ) source_group(apps\\openmw\\mwworld FILES ${GAMEWORLD} ${GAMEWORLD_HEADER}) diff --git a/apps/openmw/mwrender/mwscene.cpp b/apps/openmw/mwrender/mwscene.cpp index ebcfefe6a..a4ebff94d 100644 --- a/apps/openmw/mwrender/mwscene.cpp +++ b/apps/openmw/mwrender/mwscene.cpp @@ -11,7 +11,6 @@ #include "../mwworld/world.hpp" // these includes can be removed once the static-hack is gone #include "../mwworld/ptr.hpp" -#include "../mwworld/doingphysics.hpp" #include #include "player.hpp" diff --git a/apps/openmw/mwworld/doingphysics.cpp b/apps/openmw/mwworld/doingphysics.cpp deleted file mode 100644 index 84fb4e2ab..000000000 --- a/apps/openmw/mwworld/doingphysics.cpp +++ /dev/null @@ -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; - } -} diff --git a/apps/openmw/mwworld/doingphysics.hpp b/apps/openmw/mwworld/doingphysics.hpp deleted file mode 100644 index d38e4bb15..000000000 --- a/apps/openmw/mwworld/doingphysics.hpp +++ /dev/null @@ -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 diff --git a/apps/openmw/mwworld/physicssystem.cpp b/apps/openmw/mwworld/physicssystem.cpp index 36b962f08..dae79ccb1 100644 --- a/apps/openmw/mwworld/physicssystem.cpp +++ b/apps/openmw/mwworld/physicssystem.cpp @@ -1,5 +1,4 @@ #include "physicssystem.hpp" -#include "../mwworld/doingphysics.hpp" #include "../mwworld/ptr.hpp" #include "../mwworld/world.hpp" // FIXME @@ -28,9 +27,6 @@ namespace MWWorld std::vector< std::pair > PhysicsSystem::doPhysics (float duration, const std::vector >& actors) { - // stop changes to world from being reported back to the physics system - MWWorld::DoingPhysics scopeGuard; - //set the DebugRenderingMode. To disable it,set it to 0 //eng->setDebugRenderingMode(1); diff --git a/apps/openmw/mwworld/scene.cpp b/apps/openmw/mwworld/scene.cpp index 9566ac7a0..f7ad72cdd 100644 --- a/apps/openmw/mwworld/scene.cpp +++ b/apps/openmw/mwworld/scene.cpp @@ -13,11 +13,8 @@ #include "player.hpp" #include "class.hpp" -#include "doingphysics.hpp" #include "cellfunctors.hpp" - - namespace { template @@ -98,7 +95,6 @@ namespace MWWorld void Scene::changeCell (int X, int Y, const ESM::Position& position, bool adjustPlayerPos) { - SuppressDoingPhysics scopeGuard; // remove active mEnvironment.mMechanicsManager->removeActor (mWorld->getPlayer().getPlayer()); @@ -198,8 +194,6 @@ namespace MWWorld void Scene::changeToInteriorCell (const std::string& cellName, const ESM::Position& position) { - SuppressDoingPhysics scopeGuard; - // remove active CellRenderCollection::iterator active = mActiveCells.begin(); diff --git a/apps/openmw/mwworld/world.cpp b/apps/openmw/mwworld/world.cpp index bf2ac9212..71b37e1ff 100644 --- a/apps/openmw/mwworld/world.cpp +++ b/apps/openmw/mwworld/world.cpp @@ -21,7 +21,6 @@ #include "refdata.hpp" #include "globals.hpp" -#include "doingphysics.hpp" #include "cellfunctors.hpp" namespace @@ -636,8 +635,7 @@ namespace MWWorld Class::get (ptr).disable (ptr, mEnvironment); mEnvironment.mSoundManager->stopSound3D (ptr); - if (!DoingPhysics::isDoingPhysics()) - mPhysics->removeObject (ptr.getRefData().getHandle()); + mPhysics->removeObject (ptr.getRefData().getHandle()); } render->deleteObject (ptr.getRefData().getHandle()); From 54cb6deab95fcc9f2690b7a98a6cd7f87b8fb818 Mon Sep 17 00:00:00 2001 From: Lukasz Gromanowski Date: Fri, 2 Sep 2011 20:01:24 +0200 Subject: [PATCH 28/41] Issue #168: Configuration cleanup, part 2 --- apps/launcher/graphicspage.cpp | 26 +++----------- apps/openmw/engine.cpp | 32 ++++-------------- apps/openmw/engine.hpp | 2 -- apps/openmw/main.cpp | 4 +-- components/cfg/configurationmanager.cpp | 45 ++++++++++++++++++++++++- components/cfg/configurationmanager.hpp | 8 +++++ 6 files changed, 65 insertions(+), 52 deletions(-) diff --git a/apps/launcher/graphicspage.cpp b/apps/launcher/graphicspage.cpp index 622b00ef5..300be2791 100644 --- a/apps/launcher/graphicspage.cpp +++ b/apps/launcher/graphicspage.cpp @@ -147,37 +147,19 @@ void GraphicsPage::createPages() void GraphicsPage::setupConfig() { - QString ogreCfg = (mCfg.getRuntimeConfigPath() / "ogre.cfg").string().c_str(); + QString ogreCfg = mCfg.getOgreConfigPath().string().c_str(); QFile file(ogreCfg); - - if (!file.exists()) { - ogreCfg = QString::fromStdString((mCfg.getLocalConfigPath() / "ogre.cfg").string()); - } - mOgreConfig = new QSettings(ogreCfg, QSettings::IniFormat); - } void GraphicsPage::setupOgre() { - QString pluginCfg = (mCfg.getRuntimeConfigPath() / "plugins.cfg").string().c_str(); + QString pluginCfg = mCfg.getPluginsConfigPath().string().c_str(); QFile file(pluginCfg); - - if (!file.exists()) { - pluginCfg = QString::fromStdString((mCfg.getLocalConfigPath() / "plugins.cfg").string()); - } - - // Reopen the file from user directory - file.setFileName(pluginCfg); - - if (!file.exists()) { - // There's no plugins.cfg in the user directory, use global directory - pluginCfg = QString::fromStdString((mCfg.getGlobalConfigPath() / "plugins.cfg").string()); - } // Create a log manager so we can surpress debug text to stdout/stderr Ogre::LogManager* logMgr = OGRE_NEW Ogre::LogManager; - logMgr->createLog("launcherOgre.log", true, false, false); + logMgr->createLog((mCfg.getLogPath().string() + "/launcherOgre.log"), true, false, false); try { @@ -475,4 +457,4 @@ void GraphicsPage::rendererChanged(const QString &renderer) } mSelectedRenderSystem = mOgre->getRenderSystemByName(renderer.toStdString()); -} \ No newline at end of file +} diff --git a/apps/openmw/engine.cpp b/apps/openmw/engine.cpp index 4854eae91..03e8a6838 100644 --- a/apps/openmw/engine.cpp +++ b/apps/openmw/engine.cpp @@ -327,25 +327,6 @@ void OMW::Engine::setNewGame(bool newGame) mNewGame = newGame; } -std::string OMW::Engine::getOgreFilesDir(const std::string& ogreFile) -{ - boost::filesystem::path cfgPath(mCfgMgr.getRuntimeConfigPath()); - if (!boost::filesystem::exists(cfgPath / ogreFile)) - { - cfgPath = mCfgMgr.getLocalConfigPath(); - if (!boost::filesystem::exists(cfgPath / ogreFile )) - { - cfgPath = mCfgMgr.getGlobalConfigPath(); - if (!boost::filesystem::exists(cfgPath / ogreFile)) - { - cfgPath.clear(); - } - } - } - - return (!cfgPath.empty()) ? cfgPath.string() + std::string("/") : std::string(); - } - // Initialise and enter main loop. void OMW::Engine::go() @@ -357,11 +338,10 @@ void OMW::Engine::go() test.name = ""; total = 0; - - std::string cfgDir(getOgreFilesDir("ogre.cfg")); - std::string pluginsFile(getOgreFilesDir("plugins.cfg") + std::string("plugins.cfg")); - - mOgre.configure(cfgDir.empty(), cfgDir, pluginsFile, false); + mOgre.configure(!boost::filesystem::is_regular_file(mCfgMgr.getOgreConfigPath()), + mCfgMgr.getOgreConfigPath().string(), + mCfgMgr.getLogPath().string() + std::string("/"), + mCfgMgr.getPluginsConfigPath().string(), false); // This has to be added BEFORE MyGUI is initialized, as it needs // to find core.xml here. @@ -381,7 +361,9 @@ void OMW::Engine::go() mResDir, mNewGame, mEnvironment, mEncoding); // Set up the GUI system - mGuiManager = new OEngine::GUI::MyGUIManager(mOgre.getWindow(), mOgre.getScene(), false, cfgDir); + mGuiManager = new OEngine::GUI::MyGUIManager(mOgre.getWindow(), mOgre.getScene(), false, + mCfgMgr.getLogPath().string() + std::string("/")); + MyGUI::FactoryManager::getInstance().registerFactory("Widget"); MyGUI::FactoryManager::getInstance().registerFactory("Widget"); MyGUI::FactoryManager::getInstance().registerFactory("Widget"); diff --git a/apps/openmw/engine.hpp b/apps/openmw/engine.hpp index 9ee3298d7..306c475e1 100644 --- a/apps/openmw/engine.hpp +++ b/apps/openmw/engine.hpp @@ -157,8 +157,6 @@ namespace OMW void setEncoding(const std::string& encoding); private: - std::string getOgreFilesDir(const std::string& ogreFile); - Cfg::ConfigurationManager& mCfgMgr; }; } diff --git a/apps/openmw/main.cpp b/apps/openmw/main.cpp index 3fef2b0bd..ff5725690 100644 --- a/apps/openmw/main.cpp +++ b/apps/openmw/main.cpp @@ -109,12 +109,12 @@ bool parseOptions (int argc, char** argv, OMW::Engine& engine, Cfg::Configuratio bpo::variables_map variables; - cfgMgr.readConfiguration(variables, desc); - // Runtime options override settings from all configs bpo::store(valid_opts, variables); bpo::notify(variables); + cfgMgr.readConfiguration(variables, desc); + bool run = true; if (variables.count ("help")) diff --git a/components/cfg/configurationmanager.cpp b/components/cfg/configurationmanager.cpp index 7c210f72c..9b4aa5a26 100644 --- a/components/cfg/configurationmanager.cpp +++ b/components/cfg/configurationmanager.cpp @@ -15,19 +15,47 @@ 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 setupPath(const char* const cfgFile, boost::filesystem::path& path) +{ +} + void ConfigurationManager::readConfiguration(boost::program_options::variables_map& variables, boost::program_options::options_description& description) { - loadConfig(mPath.getGlobalConfigPath(), variables, 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, @@ -115,4 +143,19 @@ void ConfigurationManager::setRuntimeDataPath(const boost::filesystem::path& new 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 */ diff --git a/components/cfg/configurationmanager.hpp b/components/cfg/configurationmanager.hpp index f0123d48a..7f13d0914 100644 --- a/components/cfg/configurationmanager.hpp +++ b/components/cfg/configurationmanager.hpp @@ -41,12 +41,20 @@ struct ConfigurationManager 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 */ From d43455fd571ec2567040fa7468525e846868e512 Mon Sep 17 00:00:00 2001 From: Lukasz Gromanowski Date: Fri, 2 Sep 2011 22:45:21 +0200 Subject: [PATCH 29/41] Issue #168: Configuration cleanup, part 2 Corrected --data and --data-local parameters handling. Signed-off-by: Lukasz Gromanowski --- apps/launcher/datafilespage.cpp | 12 ++++++------ apps/openmw/engine.cpp | 10 ++++------ apps/openmw/engine.hpp | 2 +- apps/openmw/main.cpp | 8 ++++---- components/files/collections.cpp | 2 +- components/files/collections.hpp | 7 ++----- components/files/multidircollection.cpp | 18 +++++++++++------- components/files/multidircollection.hpp | 4 +++- 8 files changed, 32 insertions(+), 31 deletions(-) diff --git a/apps/launcher/datafilespage.cpp b/apps/launcher/datafilespage.cpp index 2abe0aed4..7f4662e42 100644 --- a/apps/launcher/datafilespage.cpp +++ b/apps/launcher/datafilespage.cpp @@ -127,7 +127,7 @@ DataFilesPage::DataFilesPage(QWidget *parent) : QWidget(parent) void DataFilesPage::setupDataFiles(const QStringList &paths, bool strict) { // Put the paths in a boost::filesystem vector to use with Files::Collections - std::vector dataDirs; + Files::PathContainer dataDirs; foreach (const QString ¤tPath, paths) { dataDirs.push_back(boost::filesystem::path(currentPath.toStdString())); @@ -142,8 +142,8 @@ void DataFilesPage::setupDataFiles(const QStringList &paths, bool strict) for (Files::MultiDirCollection::TIter iter(esm.begin()); iter!=esm.end(); ++iter) { - std::string filename = boost::filesystem::path (iter->second.filename()).string(); - QString currentMaster = QString::fromStdString(filename); + QString currentMaster = QString::fromStdString( + boost::filesystem::path (iter->second.filename()).string()); const QList itemList = mMastersWidget->findItems(currentMaster, Qt::MatchExactly); @@ -164,7 +164,7 @@ void DataFilesPage::setupDataFiles(const QStringList &paths, bool strict) ESMReader fileReader; QStringList availableMasters; // Will contain all found masters - fileReader.setEncoding("win1252"); + fileReader.setEncoding("win1252"); // FIXME: This should be configurable! fileReader.open(iter->second.string()); // First we fill the availableMasters and the mMastersWidget @@ -190,8 +190,8 @@ void DataFilesPage::setupDataFiles(const QStringList &paths, bool strict) // Now we put the current plugin in the mDataFilesModel under its masters QStandardItem *parent = new QStandardItem(availableMasters.join(",")); - std::string filename = boost::filesystem::path (iter->second.filename()).string(); - QStandardItem *child = new QStandardItem(QString::fromStdString(std::string(filename))); + QStandardItem *child = new QStandardItem(QString::fromStdString( + boost::filesystem::path (iter->second.filename()).string())); const QList masterList = mDataFilesModel->findItems(availableMasters.join(",")); diff --git a/apps/openmw/engine.cpp b/apps/openmw/engine.cpp index 03e8a6838..e9ceea2f3 100644 --- a/apps/openmw/engine.cpp +++ b/apps/openmw/engine.cpp @@ -252,9 +252,8 @@ void OMW::Engine::loadBSA() Bsa::addBSA (iter->second.string()); } - std::string m = mDataDir.string(); - std::cout << "Data dir" << m << "\n"; - Bsa::addDir(m, mFSStrict); + std::cout << "Data dir " << mDataDir.string() << std::endl; + Bsa::addDir(mDataDir.string(), mFSStrict); } // add resources directory @@ -273,12 +272,11 @@ void OMW::Engine::enableFSStrict(bool fsStrict) // Set data dir -void OMW::Engine::setDataDirs (const std::vector& dataDirs) +void OMW::Engine::setDataDirs (const Files::PathContainer& dataDirs) { /// \todo remove mDataDir, once resources system can handle multiple directories assert (!dataDirs.empty()); - mDataDir = dataDirs[0]; - + mDataDir = dataDirs.back(); mFileCollections = Files::Collections (dataDirs, !mFSStrict); } diff --git a/apps/openmw/engine.hpp b/apps/openmw/engine.hpp index 306c475e1..3df0d0b3a 100644 --- a/apps/openmw/engine.hpp +++ b/apps/openmw/engine.hpp @@ -115,7 +115,7 @@ namespace OMW void enableFSStrict(bool fsStrict); /// Set data dirs - void setDataDirs(const Files::Collections::PathContainer& dataDirs); + void setDataDirs(const Files::PathContainer& dataDirs); /// Set resource dir void setResourceDir(const boost::filesystem::path& parResDir); diff --git a/apps/openmw/main.cpp b/apps/openmw/main.cpp index ff5725690..aa8b13b80 100644 --- a/apps/openmw/main.cpp +++ b/apps/openmw/main.cpp @@ -57,7 +57,7 @@ bool parseOptions (int argc, char** argv, OMW::Engine& engine, Cfg::Configuratio desc.add_options() ("help", "print help message") ("version", "print version information and quit") - ("data", bpo::value()->default_value(Files::Collections::PathContainer(), "data") + ("data", bpo::value()->default_value(Files::PathContainer(), "data") ->multitoken(), "set data directories (later directories have higher priority)") ("data-local", bpo::value()->default_value(""), @@ -153,17 +153,17 @@ bool parseOptions (int argc, char** argv, OMW::Engine& engine, Cfg::Configuratio // directory settings engine.enableFSStrict(variables["fs-strict"].as()); - Files::Collections::PathContainer dataDirs = variables["data"].as(); + Files::PathContainer dataDirs(variables["data"].as()); std::string local(variables["data-local"].as()); if (!local.empty()) { - dataDirs.push_back(local); + dataDirs.push_back(Files::PathContainer::value_type(local)); } if (dataDirs.empty()) { - dataDirs.push_back(cfgMgr.getLocalDataPath().string()); + dataDirs.push_back(cfgMgr.getLocalDataPath()); } engine.setDataDirs(dataDirs); diff --git a/components/files/collections.cpp b/components/files/collections.cpp index cb32768b4..424b558e6 100644 --- a/components/files/collections.cpp +++ b/components/files/collections.cpp @@ -10,7 +10,7 @@ namespace Files { } - Collections::Collections(const std::vector& directories, bool foldCase) + Collections::Collections(const Files::PathContainer& directories, bool foldCase) : mDirectories(directories) , mFoldCase(foldCase) , mCollections() diff --git a/components/files/collections.hpp b/components/files/collections.hpp index 102ab3050..1ddca9a5b 100644 --- a/components/files/collections.hpp +++ b/components/files/collections.hpp @@ -1,7 +1,6 @@ #ifndef COMPONENTS_FILES_COLLECTION_HPP #define COMPONENTS_FILES_COLLECTION_HPP -#include #include #include #include @@ -13,12 +12,10 @@ namespace Files class Collections { public: - typedef std::vector PathContainer; - Collections(); ///< Directories are listed with increasing priority. - Collections(const PathContainer& directories, bool foldCase); + Collections(const Files::PathContainer& directories, bool foldCase); ///< Return a file collection for the given extension. Extension must contain the /// leading dot and must be all lower-case. @@ -26,7 +23,7 @@ namespace Files private: typedef std::map MultiDirCollectionContainer; - PathContainer mDirectories; + Files::PathContainer mDirectories; bool mFoldCase; mutable MultiDirCollectionContainer mCollections; diff --git a/components/files/multidircollection.cpp b/components/files/multidircollection.cpp index 9a0d31c42..c64f64376 100644 --- a/components/files/multidircollection.cpp +++ b/components/files/multidircollection.cpp @@ -39,21 +39,25 @@ namespace Files } }; - MultiDirCollection::MultiDirCollection (const std::vector& directories, + MultiDirCollection::MultiDirCollection(const Files::PathContainer& directories, const std::string& extension, bool foldCase) : mFiles (NameLess (!foldCase)) { NameEqual equal (!foldCase); - for (std::vector::const_iterator iter = directories.begin(); + for (PathContainer::const_iterator iter = directories.begin(); iter!=directories.end(); ++iter) { - boost::filesystem::path dataDirectory = *iter; - - for (boost::filesystem::directory_iterator iter (dataDirectory); - iter!=boost::filesystem::directory_iterator(); ++iter) + if (!boost::filesystem::is_directory(*iter)) { - boost::filesystem::path path = *iter; + std::cout << "Skipping invalid directory: " << (*iter).string() << std::endl; + continue; + } + + for (boost::filesystem::directory_iterator dirIter(*iter); + dirIter != boost::filesystem::directory_iterator(); ++dirIter) + { + boost::filesystem::path path = *dirIter; if (!equal (extension, boost::filesystem::path (path.extension()).string())) continue; diff --git a/components/files/multidircollection.hpp b/components/files/multidircollection.hpp index 898700c06..391f8b6a4 100644 --- a/components/files/multidircollection.hpp +++ b/components/files/multidircollection.hpp @@ -11,6 +11,8 @@ namespace Files { + typedef std::vector PathContainer; + struct NameLess { bool mStrict; @@ -58,7 +60,7 @@ namespace Files public: - MultiDirCollection (const std::vector& directories, + MultiDirCollection (const Files::PathContainer& directories, const std::string& extension, bool foldCase); ///< Directories are listed with increasing priority. /// \param extension The extension that should be listed in this collection. Must From afa84b72e036cc903f33ba741b0b63c6c3b42cf9 Mon Sep 17 00:00:00 2001 From: Marc Zinnschlag Date: Sat, 3 Sep 2011 10:26:31 +0200 Subject: [PATCH 30/41] fixed exterior bug --- apps/openmw/mwworld/scene.cpp | 6 +++--- apps/openmw/mwworld/scene.hpp | 4 ++-- apps/openmw/mwworld/world.cpp | 7 ++++--- 3 files changed, 9 insertions(+), 8 deletions(-) diff --git a/apps/openmw/mwworld/scene.cpp b/apps/openmw/mwworld/scene.cpp index f7ad72cdd..339cf3194 100644 --- a/apps/openmw/mwworld/scene.cpp +++ b/apps/openmw/mwworld/scene.cpp @@ -59,8 +59,8 @@ namespace MWWorld mWorld->removeScripts (iter->first); - mEnvironment.mMechanicsManager->dropActors (iter->first); // FIXME: gehört in world? - mEnvironment.mSoundManager->stopSound (iter->first); // FIXME: same + mEnvironment.mMechanicsManager->dropActors (iter->first); + mEnvironment.mSoundManager->stopSound (iter->first); delete iter->second; mActiveCells.erase (iter); } @@ -187,7 +187,7 @@ namespace MWWorld return mCellChanged; } - std::map Scene::getActiveCells () + const std::map& Scene::getActiveCells () { return mActiveCells; } diff --git a/apps/openmw/mwworld/scene.hpp b/apps/openmw/mwworld/scene.hpp index 7e193de2a..0455ade00 100644 --- a/apps/openmw/mwworld/scene.hpp +++ b/apps/openmw/mwworld/scene.hpp @@ -84,7 +84,7 @@ namespace MWWorld Ptr::CellStore* getCurrentCell (); - CellRenderCollection getActiveCells (); + const CellRenderCollection& getActiveCells (); bool hasCellChanged() const; ///< Has the player moved to a different cell, since the last frame? @@ -98,7 +98,7 @@ namespace MWWorld void markCellAsUnchanged(); std::string getFacedHandle(); - + void insertCell(ESMS::CellStore &cell); }; } diff --git a/apps/openmw/mwworld/world.cpp b/apps/openmw/mwworld/world.cpp index 71b37e1ff..134662f54 100644 --- a/apps/openmw/mwworld/world.cpp +++ b/apps/openmw/mwworld/world.cpp @@ -219,7 +219,7 @@ namespace MWWorld MWRender::CellRender *World::searchRender (Ptr::CellStore *store) { - CellRenderCollection::iterator iter = mWorldScene->getActiveCells().find (store); + CellRenderCollection::const_iterator iter = mWorldScene->getActiveCells().find (store); if (iter!=mWorldScene->getActiveCells().end()) { @@ -405,7 +405,7 @@ namespace MWWorld } // active cells - for (CellRenderCollection::iterator iter (mWorldScene->getActiveCells().begin()); + for (CellRenderCollection::const_iterator iter (mWorldScene->getActiveCells().begin()); iter!=mWorldScene->getActiveCells().end(); ++iter) { Ptr ptr = getPtr (name, *iter->first); @@ -427,7 +427,7 @@ namespace MWWorld if (mPlayer->getPlayer().getRefData().getHandle()==handle) return mPlayer->getPlayer(); - for (CellRenderCollection::iterator iter (mWorldScene->getActiveCells().begin()); + for (CellRenderCollection::const_iterator iter (mWorldScene->getActiveCells().begin()); iter!=mWorldScene->getActiveCells().end(); ++iter) { Ptr ptr = getPtrViaHandle (handle, *iter->first); @@ -720,6 +720,7 @@ namespace MWWorld float duration) { std::vector< std::pair > vectors = mPhysics->doPhysics (duration, actors); + std::vector< std::pair >::iterator player = vectors.end(); for (std::vector< std::pair >::iterator it = vectors.begin(); From 40853e292f50aff0811584bd853c55a9f34a424a Mon Sep 17 00:00:00 2001 From: Marc Zinnschlag Date: Sun, 4 Sep 2011 09:48:50 +0200 Subject: [PATCH 31/41] various bits of clean up --- apps/openmw/mwrender/mwscene.cpp | 30 --------------------------- apps/openmw/mwrender/mwscene.hpp | 7 ------- apps/openmw/mwworld/physicssystem.cpp | 29 ++++++++++++-------------- apps/openmw/mwworld/physicssystem.hpp | 2 +- apps/openmw/mwworld/player.cpp | 8 +------ apps/openmw/mwworld/player.hpp | 2 +- apps/openmw/mwworld/scene.cpp | 4 ++-- apps/openmw/mwworld/scene.hpp | 11 +++++----- apps/openmw/mwworld/world.cpp | 11 +++++----- apps/openmw/mwworld/world.hpp | 14 ++++++------- 10 files changed, 34 insertions(+), 84 deletions(-) diff --git a/apps/openmw/mwrender/mwscene.cpp b/apps/openmw/mwrender/mwscene.cpp index a4ebff94d..900b4d249 100644 --- a/apps/openmw/mwrender/mwscene.cpp +++ b/apps/openmw/mwrender/mwscene.cpp @@ -50,8 +50,6 @@ MWScene::MWScene(OEngine::Render::OgreRenderer &_rend , OEngine::Physic::PhysicE mPlayer = new MWRender::Player (getCamera(), playerNode->getName()); - - mFreeFly = true; } MWScene::~MWScene() @@ -75,34 +73,6 @@ std::pair MWScene::getFacedHandle (MWWorld::World& world) return eng->rayTest(from,to); } -bool MWScene::toggleCollisionMode() -{ - for(std::map::iterator it = eng->PhysicActorMap.begin(); it != eng->PhysicActorMap.end();it++) - { - OEngine::Physic::PhysicActor* act = it->second; - bool cmode = act->getCollisionMode(); - if(cmode) - { - act->enableCollisions(false); - act->setGravity(0.); - act->setVerticalVelocity(0); - mFreeFly = true; - return false; - } - else - { - mFreeFly = false; - act->enableCollisions(true); - act->setGravity(4.); - act->setVerticalVelocity(0); - return true; - } - } - - return false; // This should never happen, but it shall not bother us now, since - // this part of the code needs a rewrite anyway. -} - bool MWScene::toggleRenderMode (int mode) { switch (mode) diff --git a/apps/openmw/mwrender/mwscene.hpp b/apps/openmw/mwrender/mwscene.hpp index a9dfad7b5..918679035 100644 --- a/apps/openmw/mwrender/mwscene.hpp +++ b/apps/openmw/mwrender/mwscene.hpp @@ -44,8 +44,6 @@ namespace MWRender MWRender::Player *mPlayer; - bool mFreeFly; - public: MWScene (OEngine::Render::OgreRenderer &_rend , OEngine::Physic::PhysicEngine* physEng); @@ -65,11 +63,6 @@ namespace MWRender /// can be faced std::pair getFacedHandle (MWWorld::World& world); - /// Toggle collision mode for player. If disabled player object should ignore - /// collisions and gravity. - /// \return Resulting mode - bool toggleCollisionMode(); - /// Toggle render mode /// \todo Using an int instead of a enum here to avoid cyclic includes. Will be fixed /// when the mw*-refactoring is done. diff --git a/apps/openmw/mwworld/physicssystem.cpp b/apps/openmw/mwworld/physicssystem.cpp index dae79ccb1..fa617a9c7 100644 --- a/apps/openmw/mwworld/physicssystem.cpp +++ b/apps/openmw/mwworld/physicssystem.cpp @@ -106,24 +106,21 @@ namespace MWWorld mEngine->deleteRigidBody(handle); } - void PhysicsSystem::moveObject (const std::string& handle, const Ogre::Vector3& position, bool updatePhysics) + void PhysicsSystem::moveObject (const std::string& handle, const Ogre::Vector3& position) { - if(updatePhysics)//TODO: is it an actor? Done? + if (OEngine::Physic::RigidBody* body = mEngine->getRigidBody(handle)) { - 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)); - } + // 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)); } } diff --git a/apps/openmw/mwworld/physicssystem.hpp b/apps/openmw/mwworld/physicssystem.hpp index 4fbbb2ee6..7f7bfdcbb 100644 --- a/apps/openmw/mwworld/physicssystem.hpp +++ b/apps/openmw/mwworld/physicssystem.hpp @@ -25,7 +25,7 @@ namespace MWWorld void removeObject (const std::string& handle); - void moveObject (const std::string& handle, const Ogre::Vector3& position, bool updatePhysics); + void moveObject (const std::string& handle, const Ogre::Vector3& position); void rotateObject (const std::string& handle, const Ogre::Quaternion& rotation); diff --git a/apps/openmw/mwworld/player.cpp b/apps/openmw/mwworld/player.cpp index 0888b4231..cad97c9ea 100644 --- a/apps/openmw/mwworld/player.cpp +++ b/apps/openmw/mwworld/player.cpp @@ -29,16 +29,10 @@ namespace MWWorld delete mClass; } - void Player::setPos(float x, float y, float z, bool updateCamera) + void Player::setPos(float x, float y, float z) { /// \todo This fcuntion should be removed during the mwrender-refactoring. mWorld.moveObject (getPlayer(), x, y, z); - - if (updateCamera) - mRenderer->getCamera()->setPosition (Ogre::Vector3 ( - mPlayer.ref.pos.pos[0], - mPlayer.ref.pos.pos[2], - -mPlayer.ref.pos.pos[1])); } void Player::setClass (const ESM::Class& class_) diff --git a/apps/openmw/mwworld/player.hpp b/apps/openmw/mwworld/player.hpp index fc29286a9..01c71da43 100644 --- a/apps/openmw/mwworld/player.hpp +++ b/apps/openmw/mwworld/player.hpp @@ -39,7 +39,7 @@ namespace MWWorld ~Player(); /// Set the player position. Uses Morrowind coordinates. - void setPos(float _x, float _y, float _z, bool updateCamera = false); + void setPos(float x, float y, float z); void setCell (MWWorld::Ptr::CellStore *cellStore) { diff --git a/apps/openmw/mwworld/scene.cpp b/apps/openmw/mwworld/scene.cpp index 339cf3194..53a0ed923 100644 --- a/apps/openmw/mwworld/scene.cpp +++ b/apps/openmw/mwworld/scene.cpp @@ -85,7 +85,7 @@ namespace MWWorld bool adjustPlayerPos) { if (adjustPlayerPos) - mWorld->getPlayer().setPos (position.pos[0], position.pos[1], position.pos[2], false); + mWorld->getPlayer().setPos (position.pos[0], position.pos[1], position.pos[2]); mWorld->getPlayer().setCell (cell); // TODO orientation @@ -187,7 +187,7 @@ namespace MWWorld return mCellChanged; } - const std::map& Scene::getActiveCells () + const Scene::CellRenderCollection& Scene::getActiveCells() const { return mActiveCells; } diff --git a/apps/openmw/mwworld/scene.hpp b/apps/openmw/mwworld/scene.hpp index 0455ade00..9e43a98a5 100644 --- a/apps/openmw/mwworld/scene.hpp +++ b/apps/openmw/mwworld/scene.hpp @@ -53,10 +53,10 @@ namespace MWWorld public: - private: - typedef std::map CellRenderCollection; + private: + MWRender::MWScene& mScene; Ptr::CellStore *mCurrentCell; // the cell, the player is in CellRenderCollection mActiveCells; @@ -65,12 +65,11 @@ namespace MWWorld 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 (Environment& environment, World *world, MWRender::MWScene& scene, PhysicsSystem *physics); ~Scene(); @@ -84,7 +83,7 @@ namespace MWWorld Ptr::CellStore* getCurrentCell (); - const CellRenderCollection& getActiveCells (); + const CellRenderCollection& getActiveCells () const; bool hasCellChanged() const; ///< Has the player moved to a different cell, since the last frame? @@ -97,7 +96,7 @@ namespace MWWorld void markCellAsUnchanged(); - std::string getFacedHandle(); +// std::string getFacedHandle(); void insertCell(ESMS::CellStore &cell); }; diff --git a/apps/openmw/mwworld/world.cpp b/apps/openmw/mwworld/world.cpp index 134662f54..86edd2b38 100644 --- a/apps/openmw/mwworld/world.cpp +++ b/apps/openmw/mwworld/world.cpp @@ -219,7 +219,7 @@ namespace MWWorld MWRender::CellRender *World::searchRender (Ptr::CellStore *store) { - CellRenderCollection::const_iterator iter = mWorldScene->getActiveCells().find (store); + Scene::CellRenderCollection::const_iterator iter = mWorldScene->getActiveCells().find (store); if (iter!=mWorldScene->getActiveCells().end()) { @@ -405,7 +405,7 @@ namespace MWWorld } // active cells - for (CellRenderCollection::const_iterator iter (mWorldScene->getActiveCells().begin()); + for (Scene::CellRenderCollection::const_iterator iter (mWorldScene->getActiveCells().begin()); iter!=mWorldScene->getActiveCells().end(); ++iter) { Ptr ptr = getPtr (name, *iter->first); @@ -427,7 +427,7 @@ namespace MWWorld if (mPlayer->getPlayer().getRefData().getHandle()==handle) return mPlayer->getPlayer(); - for (CellRenderCollection::const_iterator iter (mWorldScene->getActiveCells().begin()); + for (Scene::CellRenderCollection::const_iterator iter (mWorldScene->getActiveCells().begin()); iter!=mWorldScene->getActiveCells().end(); ++iter) { Ptr ptr = getPtrViaHandle (handle, *iter->first); @@ -683,8 +683,7 @@ namespace MWWorld { moveObjectImp(ptr, x, y, z); - mPhysics->moveObject (ptr.getRefData().getHandle(), Ogre::Vector3 (x, y, z), - true); + mPhysics->moveObject (ptr.getRefData().getHandle(), Ogre::Vector3 (x, y, z)); } void World::indexToPosition (int cellX, int cellY, float &x, float &y, bool centre) const @@ -746,7 +745,7 @@ namespace MWWorld bool World::toggleCollisionMode() { - return mScene.toggleCollisionMode(); + return mPhysics->toggleCollisionMode(); } bool World::toggleRenderMode (RenderMode mode) diff --git a/apps/openmw/mwworld/world.hpp b/apps/openmw/mwworld/world.hpp index 7b900fb09..8a5fc4bc4 100644 --- a/apps/openmw/mwworld/world.hpp +++ b/apps/openmw/mwworld/world.hpp @@ -65,8 +65,6 @@ namespace MWWorld private: - typedef std::map CellRenderCollection; - MWRender::MWScene mScene; MWWorld::Scene *mWorldScene; MWWorld::Player *mPlayer; @@ -79,7 +77,7 @@ namespace MWWorld Environment& mEnvironment; MWRender::RenderingManager *mRenderingManager; int mNextDynamicRecord; - + std::map mInteriors; std::map, Ptr::CellStore> mExteriors; @@ -96,9 +94,9 @@ namespace MWWorld MWRender::CellRender *searchRender (Ptr::CellStore *store); int getDaysPerMonth (int month) const; - + void moveObjectImp (Ptr ptr, float x, float y, float z); - + public: World (OEngine::Render::OgreRenderer& renderer, OEngine::Physic::PhysicEngine* physEng, @@ -107,9 +105,9 @@ namespace MWWorld Environment& environment, const std::string& encoding); ~World(); - + Ptr::CellStore *getExterior (int x, int y); - + Ptr::CellStore *getInterior (std::string name); void removeScripts (Ptr::CellStore *cell); @@ -121,7 +119,7 @@ namespace MWWorld MWWorld::Player& getPlayer(); const ESMS::ESMStore& getStore() const; - + ESM::ESMReader& getEsmReader(); const ScriptList& getLocalScripts() const; From 960654e58f9d8466f26bd6be48150671801e4762 Mon Sep 17 00:00:00 2001 From: Marc Zinnschlag Date: Tue, 6 Sep 2011 09:56:45 +0200 Subject: [PATCH 32/41] using new openengine version --- libs/openengine | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libs/openengine b/libs/openengine index 0f7d59b4f..0b1d6d433 160000 --- a/libs/openengine +++ b/libs/openengine @@ -1 +1 @@ -Subproject commit 0f7d59b4fb742c6479d988f6fc4ec9cdb4330b53 +Subproject commit 0b1d6d4330818ee3e491e1ec78928ff714e9bbaa From b63a2602c3ca8f5ff29aaf9f4e85c085ac9f09a7 Mon Sep 17 00:00:00 2001 From: Marc Zinnschlag Date: Tue, 6 Sep 2011 10:02:39 +0200 Subject: [PATCH 33/41] fixed a missing include --- components/files/multidircollection.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/components/files/multidircollection.cpp b/components/files/multidircollection.cpp index c64f64376..b44c42986 100644 --- a/components/files/multidircollection.cpp +++ b/components/files/multidircollection.cpp @@ -5,6 +5,7 @@ #include #include +#include #include From 34428f5a7c38b42e5860b7365b54e9ef15c441f7 Mon Sep 17 00:00:00 2001 From: Lukasz Gromanowski Date: Tue, 6 Sep 2011 17:59:40 +0200 Subject: [PATCH 34/41] Issue #168: Configuration cleanup, part 2 Tabs vs spaces cleanup. Removed unnecessary empty function. Signed-off-by: Lukasz Gromanowski --- components/cfg/configurationmanager.cpp | 50 ++++++++++++------------- 1 file changed, 23 insertions(+), 27 deletions(-) diff --git a/components/cfg/configurationmanager.cpp b/components/cfg/configurationmanager.cpp index 9b4aa5a26..0998debee 100644 --- a/components/cfg/configurationmanager.cpp +++ b/components/cfg/configurationmanager.cpp @@ -15,38 +15,34 @@ 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 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; + /** + * According to task #168 ogre.cfg file shall be located only + * in user configuration path. + */ + mOgreCfgPath = mPath.getLocalConfigPath() / ogreCfgFile; - mLogPath = mPath.getLocalConfigPath(); + mLogPath = mPath.getLocalConfigPath(); } ConfigurationManager::~ConfigurationManager() { } -void setupPath(const char* const cfgFile, boost::filesystem::path& path) -{ -} - void ConfigurationManager::readConfiguration(boost::program_options::variables_map& variables, boost::program_options::options_description& description) { @@ -145,17 +141,17 @@ void ConfigurationManager::setRuntimeDataPath(const boost::filesystem::path& new const boost::filesystem::path& ConfigurationManager::getOgreConfigPath() const { - return mOgreCfgPath; + return mOgreCfgPath; } const boost::filesystem::path& ConfigurationManager::getPluginsConfigPath() const { - return mPluginsCfgPath; + return mPluginsCfgPath; } const boost::filesystem::path& ConfigurationManager::getLogPath() const { - return mLogPath; + return mLogPath; } } /* namespace Cfg */ From e8632a799d4f879e0ef1e49ad63698a69906116a Mon Sep 17 00:00:00 2001 From: Marc Zinnschlag Date: Thu, 8 Sep 2011 11:02:55 +0200 Subject: [PATCH 35/41] Feature #28: refactored out cell management into a separate class --- apps/openmw/CMakeLists.txt | 2 ++ apps/openmw/mwworld/cells.cpp | 33 +++++++++++++++++++++++++++ apps/openmw/mwworld/cells.hpp | 43 +++++++++++++++++++++++++++++++++++ apps/openmw/mwworld/scene.cpp | 2 -- apps/openmw/mwworld/world.cpp | 8 +++---- apps/openmw/mwworld/world.hpp | 6 ++--- 6 files changed, 85 insertions(+), 9 deletions(-) create mode 100644 apps/openmw/mwworld/cells.cpp create mode 100644 apps/openmw/mwworld/cells.hpp diff --git a/apps/openmw/CMakeLists.txt b/apps/openmw/CMakeLists.txt index 8b8fd9823..21f3e18a2 100644 --- a/apps/openmw/CMakeLists.txt +++ b/apps/openmw/CMakeLists.txt @@ -148,6 +148,7 @@ set(GAMEWORLD mwworld/actiontake.cpp mwworld/containerutil.cpp mwworld/player.cpp + mwworld/cells.cpp ) set(GAMEWORLD_HEADER mwworld/refdata.hpp @@ -168,6 +169,7 @@ set(GAMEWORLD_HEADER mwworld/containerutil.hpp mwworld/player.hpp mwworld/cellfunctors.hpp + mwworld/cells.hpp ) source_group(apps\\openmw\\mwworld FILES ${GAMEWORLD} ${GAMEWORLD_HEADER}) diff --git a/apps/openmw/mwworld/cells.cpp b/apps/openmw/mwworld/cells.cpp new file mode 100644 index 000000000..062408ffd --- /dev/null +++ b/apps/openmw/mwworld/cells.cpp @@ -0,0 +1,33 @@ +#include "cells.hpp" + +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, Ptr::CellStore>::iterator result = + mExteriors.find (std::make_pair (x, y)); + + if (result==mExteriors.end()) + { + result = mExteriors.insert (std::make_pair (std::make_pair (x, y), Ptr::CellStore())).first; + + result->second.loadExt (x, y, mStore, mReader); + } + + return &result->second; +} + +MWWorld::Ptr::CellStore *MWWorld::Cells::getInterior (const std::string& name) +{ + std::map::iterator result = mInteriors.find (name); + + if (result==mInteriors.end()) + { + result = mInteriors.insert (std::make_pair (name, Ptr::CellStore())).first; + + result->second.loadInt (name, mStore, mReader); + } + + return &result->second; +} diff --git a/apps/openmw/mwworld/cells.hpp b/apps/openmw/mwworld/cells.hpp new file mode 100644 index 000000000..217f61360 --- /dev/null +++ b/apps/openmw/mwworld/cells.hpp @@ -0,0 +1,43 @@ +#ifndef GAME_MWWORLD_CELLS_H +#define GAME_MWWORLD_CELLS_H + +#include +#include + +#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 mInteriors; + std::map, Ptr::CellStore> mExteriors; + + Cells (const Cells&); + Cells& operator= (const Cells&); + + public: + + Cells (const ESMS::ESMStore& store, ESM::ESMReader& reader); + + Ptr::CellStore *getExterior (int x, int y); + + Ptr::CellStore *getInterior (const std::string& name); + + }; +} + +#endif diff --git a/apps/openmw/mwworld/scene.cpp b/apps/openmw/mwworld/scene.cpp index 53a0ed923..11bdad35f 100644 --- a/apps/openmw/mwworld/scene.cpp +++ b/apps/openmw/mwworld/scene.cpp @@ -135,7 +135,6 @@ namespace MWWorld if (iter==mActiveCells.end()) { - mWorld->getExterior(x, y)->loadExt (x, y, mWorld->getStore(), mWorld->getEsmReader()); Ptr::CellStore *cell = mWorld->getExterior(x, y); loadCell (cell, new MWRender::ExteriorCellRender (*cell, mEnvironment, mScene, mPhysics)); @@ -204,7 +203,6 @@ namespace MWWorld // Load cell. std::cout << "cellName:" << cellName << std::endl; - mWorld->getInterior(cellName)->loadInt (cellName, mWorld->getStore(), mWorld->getEsmReader()); Ptr::CellStore *cell = mWorld->getInterior(cellName); loadCell (cell, new MWRender::InteriorCellRender (*cell, mEnvironment, mScene, mPhysics)); diff --git a/apps/openmw/mwworld/world.cpp b/apps/openmw/mwworld/world.cpp index 86edd2b38..2e665fd1d 100644 --- a/apps/openmw/mwworld/world.cpp +++ b/apps/openmw/mwworld/world.cpp @@ -279,7 +279,7 @@ namespace MWWorld const std::string& master, const boost::filesystem::path& resDir, bool newGame, Environment& environment, const std::string& encoding) : mScene (renderer,physEng), mPlayer (0), mGlobalVariables (0), - mSky (false), mEnvironment (environment), mNextDynamicRecord (0) + mSky (false), mEnvironment (environment), mNextDynamicRecord (0), mCells (mStore, mEsm) { mPhysEngine = physEng; @@ -348,12 +348,12 @@ namespace MWWorld Ptr::CellStore *World::getExterior (int x, int y) { - return &mExteriors[std::make_pair (x, y)]; + return mCells.getExterior (x, y); } - Ptr::CellStore *World::getInterior (std::string name) + Ptr::CellStore *World::getInterior (const std::string& name) { - return &mInteriors[name]; + return mCells.getInterior (name); } MWWorld::Player& World::getPlayer() diff --git a/apps/openmw/mwworld/world.hpp b/apps/openmw/mwworld/world.hpp index 8a5fc4bc4..fd1195268 100644 --- a/apps/openmw/mwworld/world.hpp +++ b/apps/openmw/mwworld/world.hpp @@ -16,6 +16,7 @@ #include "globals.hpp" #include "scene.hpp" #include "physicssystem.hpp" +#include "cells.hpp" #include @@ -78,8 +79,7 @@ namespace MWWorld MWRender::RenderingManager *mRenderingManager; int mNextDynamicRecord; - std::map mInteriors; - std::map, Ptr::CellStore> mExteriors; + Cells mCells; OEngine::Physic::PhysicEngine* mPhysEngine; @@ -108,7 +108,7 @@ namespace MWWorld Ptr::CellStore *getExterior (int x, int y); - Ptr::CellStore *getInterior (std::string name); + Ptr::CellStore *getInterior (const std::string& name); void removeScripts (Ptr::CellStore *cell); From ce7202a1476c45a52662c5081500d97be8f8812c Mon Sep 17 00:00:00 2001 From: Marc Zinnschlag Date: Sat, 10 Sep 2011 11:22:32 +0200 Subject: [PATCH 36/41] Issue #28: shifting around functionality among CellStore, Cells and CellList --- apps/openmw/mwworld/cells.cpp | 13 +++++++++---- components/esm/loadcell.cpp | 17 +++++++++++++++++ components/esm/loadcell.hpp | 3 +++ components/esm_store/cell_store.hpp | 29 +++++------------------------ components/esm_store/reclists.hpp | 11 ++++++++++- 5 files changed, 44 insertions(+), 29 deletions(-) diff --git a/apps/openmw/mwworld/cells.cpp b/apps/openmw/mwworld/cells.cpp index 062408ffd..67a2a7590 100644 --- a/apps/openmw/mwworld/cells.cpp +++ b/apps/openmw/mwworld/cells.cpp @@ -10,9 +10,12 @@ MWWorld::Ptr::CellStore *MWWorld::Cells::getExterior (int x, int y) if (result==mExteriors.end()) { - result = mExteriors.insert (std::make_pair (std::make_pair (x, y), Ptr::CellStore())).first; + const ESM::Cell *cell = mStore.cells.findExt (x, y); - result->second.loadExt (x, y, mStore, mReader); + result = mExteriors.insert (std::make_pair ( + std::make_pair (x, y), Ptr::CellStore (cell))).first; + + result->second.load (mStore, mReader); } return &result->second; @@ -24,9 +27,11 @@ MWWorld::Ptr::CellStore *MWWorld::Cells::getInterior (const std::string& name) if (result==mInteriors.end()) { - result = mInteriors.insert (std::make_pair (name, Ptr::CellStore())).first; + const ESM::Cell *cell = mStore.cells.findInt (name); - result->second.loadInt (name, mStore, mReader); + result = mInteriors.insert (std::make_pair (name, Ptr::CellStore (cell))).first; + + result->second.load (mStore, mReader); } return &result->second; diff --git a/components/esm/loadcell.cpp b/components/esm/loadcell.cpp index 2d1085260..80a0f3e5a 100644 --- a/components/esm/loadcell.cpp +++ b/components/esm/loadcell.cpp @@ -1,5 +1,8 @@ #include "loadcell.hpp" +#include +#include + namespace ESM { @@ -47,6 +50,20 @@ void Cell::restore(ESMReader &esm) const esm.restoreContext(context); } +std::string Cell::getDescription() const +{ + if (data.flags & Interior) + { + return name; + } + else + { + std::ostringstream stream; + stream << data.gridX << ", " << data.gridY; + return stream.str(); + } +} + bool Cell::getNextRef(ESMReader &esm, CellRef &ref) { if (!esm.hasMoreSubs()) diff --git a/components/esm/loadcell.hpp b/components/esm/loadcell.hpp index bf3ec6f73..671f702ca 100644 --- a/components/esm/loadcell.hpp +++ b/components/esm/loadcell.hpp @@ -126,6 +126,9 @@ struct Cell // exactly. void restore(ESMReader &esm) const; + std::string getDescription() const; + ///< Return a short string describing the cell (mostly used for debugging/logging purpose) + /* Get the next reference in this cell, if any. Returns false when there are no more references in the cell. diff --git a/components/esm_store/cell_store.hpp b/components/esm_store/cell_store.hpp index 59464236f..0daf7258e 100644 --- a/components/esm_store/cell_store.hpp +++ b/components/esm_store/cell_store.hpp @@ -81,7 +81,8 @@ namespace ESMS class CellStore { public: - CellStore() : cell (0) {} + + CellStore (const ESM::Cell *cell_) : cell (cell_) {} const ESM::Cell *cell; @@ -107,31 +108,11 @@ namespace ESMS CellRefList statics; CellRefList weapons; - /** Look up and load an interior cell from the given ESM data - storage. */ - void loadInt(const std::string &name, const ESMStore &store, ESMReader &esm) + void load (const ESMStore &store, ESMReader &esm) { - std::cout << "loading cell '" << name << "'\n"; + std::cout << "loading cell " << cell->getDescription() << std::endl; - cell = store.cells.findInt(name); - - if(cell == NULL) - throw std::runtime_error("Cell not found - " + name); - - loadRefs(store, esm); - } - - /** Ditto for exterior cell. */ - void loadExt(int X, int Y, const ESMStore &store, ESMReader &esm) - { - std::cout << "loading exterior cell '" << X << ", " << Y << "'\n"; - - cell = store.cells.searchExt (X, Y); - - if(cell == NULL) - throw std::runtime_error("Exterior cell not found"); - - loadRefs(store, esm); + loadRefs (store, esm); } /// Call functor (ref) for each reference. functor must return a bool. Returning diff --git a/components/esm_store/reclists.hpp b/components/esm_store/reclists.hpp index 19ee18b62..008bdce0a 100644 --- a/components/esm_store/reclists.hpp +++ b/components/esm_store/reclists.hpp @@ -318,7 +318,7 @@ namespace ESMS IntCells::const_iterator it = intCells.find(id); if(it == intCells.end()) - return NULL; + throw std::runtime_error ("Interior cell not found - " + id); return it->second; } @@ -338,6 +338,15 @@ namespace ESMS return it2->second; } + const ESM::Cell *findExt (int x, int y) const + { + const ESM::Cell *cell = searchExt (x, y); + + if (!cell) + throw std::runtime_error ("Exterior cell not found"); + + return cell; + } const ESM::Cell *searchExtByName (const std::string& id) const { for (ExtCells::const_iterator iter = extCells.begin(); iter!=extCells.end(); ++iter) From e4a2f5547b55279e53c76b8adf54f92eac766882 Mon Sep 17 00:00:00 2001 From: Marc Zinnschlag Date: Thu, 22 Sep 2011 11:48:04 +0200 Subject: [PATCH 37/41] Issue #28: added load-state for cells --- components/esm_store/cell_store.hpp | 59 +++++++++++++++++++++++++++-- 1 file changed, 55 insertions(+), 4 deletions(-) diff --git a/components/esm_store/cell_store.hpp b/components/esm_store/cell_store.hpp index 0daf7258e..9d0fe5039 100644 --- a/components/esm_store/cell_store.hpp +++ b/components/esm_store/cell_store.hpp @@ -13,8 +13,10 @@ #include "store.hpp" #include "components/esm/records.hpp" #include "components/esm/loadcell.hpp" -#include +#include +#include +#include #include #include #include @@ -82,9 +84,16 @@ namespace ESMS { public: - CellStore (const ESM::Cell *cell_) : cell (cell_) {} + enum State + { + State_Unloaded, State_Preloaded, State_Loaded + }; + + CellStore (const ESM::Cell *cell_) : cell (cell_), mState (State_Unloaded) {} const ESM::Cell *cell; + State mState; + std::vector mIds; // Lists for each individual object type CellRefList activators; @@ -110,9 +119,27 @@ namespace ESMS void load (const ESMStore &store, ESMReader &esm) { - std::cout << "loading cell " << cell->getDescription() << std::endl; + if (mState!=State_Loaded) + { + if (mState==State_Preloaded) + mIds.clear(); - loadRefs (store, esm); + std::cout << "loading cell " << cell->getDescription() << std::endl; + + loadRefs (store, esm); + + mState = State_Loaded; + } + } + + void preload (const ESMStore &store, ESMReader &esm) + { + if (mState==State_Unloaded) + { + listRefs (store, esm); + + mState = State_Preloaded; + } } /// Call functor (ref) for each reference. functor must return a bool. Returning @@ -157,6 +184,30 @@ namespace ESMS return true; } + /// Run through references and store IDs + void listRefs(const ESMStore &store, ESMReader &esm) + { + assert (cell); + + // Reopen the ESM reader and seek to the right position. + cell->restore (esm); + + CellRef ref; + + // Get each reference in turn + while (cell->getNextRef (esm, ref)) + { + std::string lowerCase; + + std::transform (ref.refID.begin(), ref.refID.end(), std::back_inserter (lowerCase), + (int(*)(int)) std::tolower); + + mIds.push_back (ref.refID); + } + + std::sort (mIds.begin(), mIds.end()); + } + void loadRefs(const ESMStore &store, ESMReader &esm) { assert (cell); From aa87370d8f50f56a4e002d4200d51cac8257c74e Mon Sep 17 00:00:00 2001 From: Marc Zinnschlag Date: Thu, 22 Sep 2011 11:54:08 +0200 Subject: [PATCH 38/41] Issue #28: moved cell-specific getPtr function from World to Cells --- apps/openmw/mwworld/cells.cpp | 67 +++++++++++++++++++++++++++++++++++ apps/openmw/mwworld/cells.hpp | 1 + apps/openmw/mwworld/world.cpp | 67 +---------------------------------- apps/openmw/mwworld/world.hpp | 2 -- 4 files changed, 69 insertions(+), 68 deletions(-) diff --git a/apps/openmw/mwworld/cells.cpp b/apps/openmw/mwworld/cells.cpp index 67a2a7590..57960e321 100644 --- a/apps/openmw/mwworld/cells.cpp +++ b/apps/openmw/mwworld/cells.cpp @@ -36,3 +36,70 @@ MWWorld::Ptr::CellStore *MWWorld::Cells::getInterior (const std::string& name) return &result->second; } + +MWWorld::Ptr MWWorld::Cells::getPtr (const std::string& name, Ptr::CellStore& cell) +{ + cell.load (mStore, mReader); + + if (ESMS::LiveCellRef *ref = cell.activators.find (name)) + return Ptr (ref, &cell); + + if (ESMS::LiveCellRef *ref = cell.potions.find (name)) + return Ptr (ref, &cell); + + if (ESMS::LiveCellRef *ref = cell.appas.find (name)) + return Ptr (ref, &cell); + + if (ESMS::LiveCellRef *ref = cell.armors.find (name)) + return Ptr (ref, &cell); + + if (ESMS::LiveCellRef *ref = cell.books.find (name)) + return Ptr (ref, &cell); + + if (ESMS::LiveCellRef *ref = cell.clothes.find (name)) + return Ptr (ref, &cell); + + if (ESMS::LiveCellRef *ref = cell.containers.find (name)) + return Ptr (ref, &cell); + + if (ESMS::LiveCellRef *ref = cell.creatures.find (name)) + return Ptr (ref, &cell); + + if (ESMS::LiveCellRef *ref = cell.doors.find (name)) + return Ptr (ref, &cell); + + if (ESMS::LiveCellRef *ref = cell.ingreds.find (name)) + return Ptr (ref, &cell); + + if (ESMS::LiveCellRef *ref = cell.creatureLists.find (name)) + return Ptr (ref, &cell); + + if (ESMS::LiveCellRef *ref = cell.itemLists.find (name)) + return Ptr (ref, &cell); + + if (ESMS::LiveCellRef *ref = cell.lights.find (name)) + return Ptr (ref, &cell); + + if (ESMS::LiveCellRef *ref = cell.lockpicks.find (name)) + return Ptr (ref, &cell); + + if (ESMS::LiveCellRef *ref = cell.miscItems.find (name)) + return Ptr (ref, &cell); + + if (ESMS::LiveCellRef *ref = cell.npcs.find (name)) + return Ptr (ref, &cell); + + if (ESMS::LiveCellRef *ref = cell.probes.find (name)) + return Ptr (ref, &cell); + + if (ESMS::LiveCellRef *ref = cell.repairs.find (name)) + return Ptr (ref, &cell); + + if (ESMS::LiveCellRef *ref = cell.statics.find (name)) + return Ptr (ref, &cell); + + if (ESMS::LiveCellRef *ref = cell.weapons.find (name)) + return Ptr (ref, &cell); + + return Ptr(); +} diff --git a/apps/openmw/mwworld/cells.hpp b/apps/openmw/mwworld/cells.hpp index 217f61360..2e1e6a587 100644 --- a/apps/openmw/mwworld/cells.hpp +++ b/apps/openmw/mwworld/cells.hpp @@ -37,6 +37,7 @@ namespace MWWorld Ptr::CellStore *getInterior (const std::string& name); + Ptr getPtr (const std::string& name, Ptr::CellStore& cellStore); }; } diff --git a/apps/openmw/mwworld/world.cpp b/apps/openmw/mwworld/world.cpp index 2e665fd1d..961cda6df 100644 --- a/apps/openmw/mwworld/world.cpp +++ b/apps/openmw/mwworld/world.cpp @@ -89,71 +89,6 @@ namespace MWWorld listCellScripts (mStore, cell.weapons, mLocalScripts, &cell); } - Ptr World::getPtr (const std::string& name, Ptr::CellStore& cell) - { - if (ESMS::LiveCellRef *ref = cell.activators.find (name)) - return Ptr (ref, &cell); - - if (ESMS::LiveCellRef *ref = cell.potions.find (name)) - return Ptr (ref, &cell); - - if (ESMS::LiveCellRef *ref = cell.appas.find (name)) - return Ptr (ref, &cell); - - if (ESMS::LiveCellRef *ref = cell.armors.find (name)) - return Ptr (ref, &cell); - - if (ESMS::LiveCellRef *ref = cell.books.find (name)) - return Ptr (ref, &cell); - - if (ESMS::LiveCellRef *ref = cell.clothes.find (name)) - return Ptr (ref, &cell); - - if (ESMS::LiveCellRef *ref = cell.containers.find (name)) - return Ptr (ref, &cell); - - if (ESMS::LiveCellRef *ref = cell.creatures.find (name)) - return Ptr (ref, &cell); - - if (ESMS::LiveCellRef *ref = cell.doors.find (name)) - return Ptr (ref, &cell); - - if (ESMS::LiveCellRef *ref = cell.ingreds.find (name)) - return Ptr (ref, &cell); - - if (ESMS::LiveCellRef *ref = cell.creatureLists.find (name)) - return Ptr (ref, &cell); - - if (ESMS::LiveCellRef *ref = cell.itemLists.find (name)) - return Ptr (ref, &cell); - - if (ESMS::LiveCellRef *ref = cell.lights.find (name)) - return Ptr (ref, &cell); - - if (ESMS::LiveCellRef *ref = cell.lockpicks.find (name)) - return Ptr (ref, &cell); - - if (ESMS::LiveCellRef *ref = cell.miscItems.find (name)) - return Ptr (ref, &cell); - - if (ESMS::LiveCellRef *ref = cell.npcs.find (name)) - return Ptr (ref, &cell); - - if (ESMS::LiveCellRef *ref = cell.probes.find (name)) - return Ptr (ref, &cell); - - if (ESMS::LiveCellRef *ref = cell.repairs.find (name)) - return Ptr (ref, &cell); - - if (ESMS::LiveCellRef *ref = cell.statics.find (name)) - return Ptr (ref, &cell); - - if (ESMS::LiveCellRef *ref = cell.weapons.find (name)) - return Ptr (ref, &cell); - - return Ptr(); - } - Ptr World::getPtrViaHandle (const std::string& handle, Ptr::CellStore& cell) { if (ESMS::LiveCellRef *ref = @@ -408,7 +343,7 @@ namespace MWWorld for (Scene::CellRenderCollection::const_iterator iter (mWorldScene->getActiveCells().begin()); iter!=mWorldScene->getActiveCells().end(); ++iter) { - Ptr ptr = getPtr (name, *iter->first); + Ptr ptr = mCells.getPtr (name, *iter->first); if (!ptr.isEmpty()) return ptr; diff --git a/apps/openmw/mwworld/world.hpp b/apps/openmw/mwworld/world.hpp index fd1195268..90d612163 100644 --- a/apps/openmw/mwworld/world.hpp +++ b/apps/openmw/mwworld/world.hpp @@ -87,8 +87,6 @@ namespace MWWorld World (const World&); World& operator= (const World&); - Ptr getPtr (const std::string& name, Ptr::CellStore& cellStore); - Ptr getPtrViaHandle (const std::string& handle, Ptr::CellStore& cellStore); MWRender::CellRender *searchRender (Ptr::CellStore *store); From f0dd38b43162dedbb22d8a64240eb8079c23ce11 Mon Sep 17 00:00:00 2001 From: Marc Zinnschlag Date: Thu, 22 Sep 2011 12:21:24 +0200 Subject: [PATCH 39/41] Issue #28: replaced the nested map structure in the CellList --- components/esm_store/reclists.hpp | 38 +++++++------------------------ 1 file changed, 8 insertions(+), 30 deletions(-) diff --git a/components/esm_store/reclists.hpp b/components/esm_store/reclists.hpp index 008bdce0a..7d3afbb96 100644 --- a/components/esm_store/reclists.hpp +++ b/components/esm_store/reclists.hpp @@ -287,8 +287,7 @@ namespace ESMS IntCells intCells; // List of exterior cells. Indexed as extCells[gridX][gridY]. - typedef std::map ExtCellsCol; - typedef std::map ExtCells; + typedef std::map, ESM::Cell*> ExtCells; ExtCells extCells; virtual void listIdentifier (std::vector& identifier) const @@ -303,13 +302,7 @@ namespace ESMS delete it->second; for (ExtCells::iterator it = extCells.begin(); it!=extCells.end(); ++it) - { - ExtCellsCol& col = it->second; - for (ExtCellsCol::iterator it = col.begin(); it!=col.end(); ++it) - { delete it->second; - } - } } @@ -325,17 +318,12 @@ namespace ESMS const ESM::Cell *searchExt (int x, int y) const { - ExtCells::const_iterator it = extCells.find (x); + ExtCells::const_iterator it = extCells.find (std::make_pair (x, y)); if (it==extCells.end()) return 0; - ExtCellsCol::const_iterator it2 = it->second.find (y); - - if (it2 == it->second.end()) - return 0; - - return it2->second; + return it->second; } const ESM::Cell *findExt (int x, int y) const @@ -351,12 +339,8 @@ namespace ESMS { for (ExtCells::const_iterator iter = extCells.begin(); iter!=extCells.end(); ++iter) { - const ExtCellsCol& column = iter->second; - for (ExtCellsCol::const_iterator iter = column.begin(); iter!=column.end(); ++iter) - { - if ( toLower(iter->second->name) == toLower(id)) - return iter->second; - } + if (toLower (iter->second->name) == toLower (id)) + return iter->second; } return 0; @@ -367,14 +351,8 @@ namespace ESMS std::string id2 = toLower (id); for (ExtCells::const_iterator iter = extCells.begin(); iter!=extCells.end(); ++iter) - { - const ExtCellsCol& column = iter->second; - for (ExtCellsCol::const_iterator iter = column.begin(); iter!=column.end(); ++iter) - { - if (toLower (iter->second->region)==id) - return iter->second; - } - } + if (toLower (iter->second->region)==id) + return iter->second; return 0; } @@ -398,7 +376,7 @@ namespace ESMS else { // Store exterior cells by grid position - extCells[cell->data.gridX][cell->data.gridY] = cell; + extCells[std::make_pair (cell->data.gridX, cell->data.gridY)] = cell; } } }; From af4f48fd3f4f39009eee509caa36581a625de600 Mon Sep 17 00:00:00 2001 From: Marc Zinnschlag Date: Thu, 22 Sep 2011 12:44:17 +0200 Subject: [PATCH 40/41] Issue #28: implemented access to references outside of the active cells --- apps/openmw/mwworld/cells.cpp | 75 +++++++++++++++++++++++++++++++++++ apps/openmw/mwworld/cells.hpp | 4 ++ apps/openmw/mwworld/world.cpp | 5 ++- 3 files changed, 83 insertions(+), 1 deletion(-) diff --git a/apps/openmw/mwworld/cells.cpp b/apps/openmw/mwworld/cells.cpp index 57960e321..a0b434d99 100644 --- a/apps/openmw/mwworld/cells.cpp +++ b/apps/openmw/mwworld/cells.cpp @@ -1,5 +1,34 @@ #include "cells.hpp" +MWWorld::Ptr::CellStore *MWWorld::Cells::getCellStore (const ESM::Cell *cell) +{ + if (cell->data.flags & ESM::Cell::Interior) + { + std::map::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, 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) {} @@ -103,3 +132,49 @@ MWWorld::Ptr MWWorld::Cells::getPtr (const std::string& name, Ptr::CellStore& ce return Ptr(); } + +MWWorld::Ptr MWWorld::Cells::getPtr (const std::string& name) +{ + // First check cells that are already listed + for (std::map::iterator iter = mInteriors.begin(); + iter!=mInteriors.end(); ++iter) + { + Ptr ptr = getPtr (name, iter->second); + if (!ptr.isEmpty()) + return ptr; + } + + for (std::map, 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(); +} diff --git a/apps/openmw/mwworld/cells.hpp b/apps/openmw/mwworld/cells.hpp index 2e1e6a587..661969881 100644 --- a/apps/openmw/mwworld/cells.hpp +++ b/apps/openmw/mwworld/cells.hpp @@ -29,6 +29,8 @@ namespace MWWorld Cells (const Cells&); Cells& operator= (const Cells&); + Ptr::CellStore *getCellStore (const ESM::Cell *cell); + public: Cells (const ESMS::ESMStore& store, ESM::ESMReader& reader); @@ -38,6 +40,8 @@ namespace MWWorld Ptr::CellStore *getInterior (const std::string& name); Ptr getPtr (const std::string& name, Ptr::CellStore& cellStore); + + Ptr getPtr (const std::string& name); }; } diff --git a/apps/openmw/mwworld/world.cpp b/apps/openmw/mwworld/world.cpp index 961cda6df..ee1a0ad2d 100644 --- a/apps/openmw/mwworld/world.cpp +++ b/apps/openmw/mwworld/world.cpp @@ -351,7 +351,10 @@ namespace MWWorld if (!activeOnly) { - // TODO: inactive cells + Ptr ptr = mCells.getPtr (name); + + if (!ptr.isEmpty()) + return ptr; } throw std::runtime_error ("unknown ID: " + name); From 02ce672fdc1812c507d625f7c9a6065123b70b9a Mon Sep 17 00:00:00 2001 From: Marc Zinnschlag Date: Sat, 24 Sep 2011 11:45:59 +0200 Subject: [PATCH 41/41] preload cell's reference list when accessing a reference outside of the actice cells (memory usage and speed optimisation) --- apps/openmw/mwworld/cells.cpp | 20 +++++++++++++++++++- components/esm_store/cell_store.hpp | 2 +- 2 files changed, 20 insertions(+), 2 deletions(-) diff --git a/apps/openmw/mwworld/cells.cpp b/apps/openmw/mwworld/cells.cpp index a0b434d99..7d04cfc68 100644 --- a/apps/openmw/mwworld/cells.cpp +++ b/apps/openmw/mwworld/cells.cpp @@ -1,5 +1,9 @@ #include "cells.hpp" +#include + +#include + MWWorld::Ptr::CellStore *MWWorld::Cells::getCellStore (const ESM::Cell *cell) { if (cell->data.flags & ESM::Cell::Interior) @@ -68,7 +72,21 @@ MWWorld::Ptr::CellStore *MWWorld::Cells::getInterior (const std::string& name) MWWorld::Ptr MWWorld::Cells::getPtr (const std::string& name, Ptr::CellStore& cell) { - cell.load (mStore, mReader); + 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 *ref = cell.activators.find (name)) return Ptr (ref, &cell); diff --git a/components/esm_store/cell_store.hpp b/components/esm_store/cell_store.hpp index 9d0fe5039..1336cc2ab 100644 --- a/components/esm_store/cell_store.hpp +++ b/components/esm_store/cell_store.hpp @@ -202,7 +202,7 @@ namespace ESMS std::transform (ref.refID.begin(), ref.refID.end(), std::back_inserter (lowerCase), (int(*)(int)) std::tolower); - mIds.push_back (ref.refID); + mIds.push_back (lowerCase); } std::sort (mIds.begin(), mIds.end());