From e7057bed29e4c75d2d77596e43f349cff9cda841 Mon Sep 17 00:00:00 2001 From: Sebastian Wick Date: Sun, 31 Jul 2011 17:07:11 +0200 Subject: [PATCH 01/17] 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/17] 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/17] 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/17] 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/17] 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/17] 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/17] 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/17] 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/17] 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/17] 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/17] 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/17] 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/17] 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/17] 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/17] 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/17] 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 54724d7e7f5d5a8e5f376b56d86adbd9c699e569 Mon Sep 17 00:00:00 2001 From: Sebastian Wick Date: Sun, 7 Aug 2011 16:40:01 +0200 Subject: [PATCH 17/17] 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; }