mirror of
				https://github.com/OpenMW/openmw.git
				synced 2025-10-31 20:26:43 +00:00 
			
		
		
		
	register actors in active cells with MechanicsManager
This commit is contained in:
		
							parent
							
								
									858f174355
								
							
						
					
					
						commit
						362605860b
					
				
					 5 changed files with 72 additions and 13 deletions
				
			
		|  | @ -187,7 +187,7 @@ void OMW::Engine::go() | |||
|     loadBSA(); | ||||
| 
 | ||||
|     // Create the world
 | ||||
|     mEnvironment.mWorld = new MWWorld::World (mOgre, mDataDir, mMaster, mNewGame); | ||||
|     mEnvironment.mWorld = new MWWorld::World (mOgre, mDataDir, mMaster, mNewGame, mEnvironment); | ||||
| 
 | ||||
|     // Set up the GUI system
 | ||||
|     mGuiManager = new OEngine::GUI::MyGUIManager(mOgre.getWindow(), | ||||
|  |  | |||
|  | @ -39,5 +39,23 @@ namespace MWMechanics | |||
|             mWindowManager.setLabel (names[i][0], label); | ||||
|         } | ||||
|     } | ||||
|      | ||||
|     void MechanicsManager::addActor (const MWWorld::Ptr& ptr) | ||||
|     { | ||||
|         mActors.insert (ptr); | ||||
|     } | ||||
|      | ||||
|     void MechanicsManager::dropActors (const MWWorld::Ptr::CellStore *cellStore) | ||||
|     { | ||||
|         std::set<MWWorld::Ptr>::iterator iter = mActors.begin(); | ||||
|          | ||||
|         while (iter!=mActors.end()) | ||||
|             if (iter->getCell()==cellStore) | ||||
|             { | ||||
|                 mActors.erase (iter++); | ||||
|             } | ||||
|             else | ||||
|                 ++iter; | ||||
|     } | ||||
| } | ||||
| 
 | ||||
|  |  | |||
|  | @ -1,6 +1,10 @@ | |||
| #ifndef GAME_MWMECHANICS_MECHANICSMANAGER_H | ||||
| #define GAME_MWMECHANICS_MECHANICSMANAGER_H | ||||
| 
 | ||||
| #include <set> | ||||
| 
 | ||||
| #include "../mwworld/ptr.hpp" | ||||
| 
 | ||||
| namespace ESMS | ||||
| { | ||||
|     class ESMStore; | ||||
|  | @ -15,14 +19,21 @@ namespace MWMechanics | |||
| { | ||||
|     class MechanicsManager | ||||
|     { | ||||
|         const ESMS::ESMStore& mStore; | ||||
|         MWGui::WindowManager& mWindowManager; | ||||
|             const ESMS::ESMStore& mStore; | ||||
|             MWGui::WindowManager& mWindowManager; | ||||
|             std::set<MWWorld::Ptr> mActors; | ||||
|      | ||||
|         public: | ||||
|          | ||||
|             MechanicsManager (const ESMS::ESMStore& store, MWGui::WindowManager& windowManager); | ||||
|              | ||||
|             void configureGUI(); | ||||
|              | ||||
|             void addActor (const MWWorld::Ptr& ptr); | ||||
|             ///< Register an actor for stats management
 | ||||
|              | ||||
|             void dropActors (const MWWorld::Ptr::CellStore *cellStore); | ||||
|             ///< Deregister all actors in the given cell.
 | ||||
|     }; | ||||
| } | ||||
| 
 | ||||
|  |  | |||
|  | @ -4,12 +4,15 @@ | |||
| #include <cmath> | ||||
| #include <iostream> | ||||
| 
 | ||||
| #include "components/bsa/bsa_archive.hpp" | ||||
| #include <components/bsa/bsa_archive.hpp> | ||||
| 
 | ||||
| #include "apps/openmw/mwrender/sky.hpp" | ||||
| #include "apps/openmw/mwrender/interior.hpp" | ||||
| #include "../mwrender/sky.hpp" | ||||
| #include "../mwrender/interior.hpp" | ||||
| 
 | ||||
| #include "../mwmechanics/mechanicsmanager.hpp" | ||||
| 
 | ||||
| #include "ptr.hpp" | ||||
| #include "environment.hpp" | ||||
| 
 | ||||
| namespace | ||||
| { | ||||
|  | @ -164,9 +167,9 @@ namespace MWWorld | |||
|     } | ||||
|      | ||||
|     World::World (OEngine::Render::OgreRenderer& renderer, const boost::filesystem::path& dataDir, | ||||
|         const std::string& master, bool newGame) | ||||
|         const std::string& master, bool newGame, Environment& environment) | ||||
|     : mSkyManager (0), mScene (renderer), mPlayerPos (0), mCurrentCell (0), mGlobalVariables (0), | ||||
|       mSky (false), mCellChanged (false) | ||||
|       mSky (false), mCellChanged (false), mEnvironment (environment) | ||||
|     {    | ||||
|         boost::filesystem::path masterPath (dataDir); | ||||
|         masterPath /= master; | ||||
|  | @ -413,35 +416,59 @@ namespace MWWorld | |||
|     { | ||||
|         // Load cell.       
 | ||||
|         mInteriors[cellName].loadInt (cellName, mStore, mEsm); | ||||
|         Ptr::CellStore *cell = &mInteriors[cellName]; | ||||
|       | ||||
|         // remove active
 | ||||
|         CellRenderCollection::iterator active = mActiveCells.begin(); | ||||
|          | ||||
|         if (active!=mActiveCells.end()) | ||||
|         { | ||||
|             mEnvironment.mMechanicsManager->dropActors (active->first); | ||||
|             active->second->destroy(); | ||||
|             delete active->second; | ||||
|             mActiveCells.erase (active); | ||||
|         } | ||||
| 
 | ||||
|         // register local scripts
 | ||||
|         mLocalScripts.clear(); // FIXME won't work with exteriors        
 | ||||
|         insertInteriorScripts (mInteriors[cellName]); | ||||
|         insertInteriorScripts (*cell); | ||||
| 
 | ||||
|         // adjust player
 | ||||
|         mPlayerPos->setPos (position.pos[0], position.pos[1], position.pos[2]); | ||||
|         mPlayerPos->setCell (&mInteriors[cellName]); | ||||
|         mPlayerPos->setCell (cell); | ||||
|         // TODO orientation
 | ||||
| 
 | ||||
|         // This connects the cell data with the rendering scene.
 | ||||
|         std::pair<CellRenderCollection::iterator, bool> result = | ||||
|             mActiveCells.insert (std::make_pair (&mInteriors[cellName], | ||||
|             new MWRender::InteriorCellRender (mInteriors[cellName], mScene))); | ||||
|             mActiveCells.insert (std::make_pair (cell, | ||||
|             new MWRender::InteriorCellRender (*cell, mScene))); | ||||
| 
 | ||||
|         if (result.second) | ||||
|         {         | ||||
|             // Load the cell and insert it into the renderer
 | ||||
|             result.first->second->show(); | ||||
|         } | ||||
|          | ||||
|         // Actors
 | ||||
|         mEnvironment.mMechanicsManager->addActor (mPlayerPos->getPlayer()); | ||||
| 
 | ||||
|         for (ESMS::CellRefList<ESM::Creature, RefData>::List::iterator iter ( | ||||
|             cell->creatures.list.begin()); | ||||
|             iter!=cell->creatures.list.end(); ++iter) | ||||
|         { | ||||
|             Ptr ptr (&*iter, cell); | ||||
|             mEnvironment.mMechanicsManager->addActor (ptr); | ||||
|         } | ||||
| 
 | ||||
|         for (ESMS::CellRefList<ESM::NPC, RefData>::List::iterator iter ( | ||||
|             cell->npcs.list.begin()); | ||||
|             iter!=cell->npcs.list.end(); ++iter) | ||||
|         { | ||||
|             Ptr ptr (&*iter, cell); | ||||
|             mEnvironment.mMechanicsManager->addActor (ptr); | ||||
|         } | ||||
| 
 | ||||
|         // Sky system
 | ||||
|         if (mSky) | ||||
|         { | ||||
|             toggleSky(); | ||||
|  |  | |||
|  | @ -33,6 +33,8 @@ namespace MWRender | |||
|   | ||||
| namespace MWWorld | ||||
| { | ||||
|     class Environment; | ||||
| 
 | ||||
|     /// \brief The game world and its visual representation
 | ||||
|      | ||||
|     class World | ||||
|  | @ -58,6 +60,7 @@ namespace MWWorld | |||
|             MWWorld::Globals *mGlobalVariables; | ||||
|             bool mSky; | ||||
|             bool mCellChanged; | ||||
|             Environment& mEnvironment; | ||||
|      | ||||
|             // not implemented
 | ||||
|             World (const World&); | ||||
|  | @ -74,7 +77,7 @@ namespace MWWorld | |||
|         public: | ||||
|          | ||||
|            World (OEngine::Render::OgreRenderer& renderer, const boost::filesystem::path& master, | ||||
|                 const std::string& dataDir, bool newGame); | ||||
|                 const std::string& dataDir, bool newGame, Environment& environment); | ||||
|                  | ||||
|             ~World(); | ||||
|              | ||||
|  |  | |||
		Loading…
	
		Reference in a new issue