mirror of
				https://github.com/OpenMW/openmw.git
				synced 2025-10-25 11:26:37 +00:00 
			
		
		
		
	Optimize World::getTimeStamp
World::getTimeStamp was searching through the globals store on every call. Not a big issue, but slow enough to show up in the profiler.
This commit is contained in:
		
							parent
							
								
									38510a56c2
								
							
						
					
					
						commit
						71cd57a3b5
					
				
					 2 changed files with 44 additions and 25 deletions
				
			
		|  | @ -138,8 +138,7 @@ namespace MWWorld | ||||||
|     { |     { | ||||||
|         if (mSky && (isCellExterior() || isCellQuasiExterior())) |         if (mSky && (isCellExterior() || isCellQuasiExterior())) | ||||||
|         { |         { | ||||||
|             mRendering->skySetDate (mGlobalVariables["day"].getInteger(), |             mRendering->skySetDate (mDay->getInteger(), mMonth->getInteger()); | ||||||
|                 mGlobalVariables["month"].getInteger()); |  | ||||||
| 
 | 
 | ||||||
|             mRendering->setSkyEnabled(true); |             mRendering->setSkyEnabled(true); | ||||||
|         } |         } | ||||||
|  | @ -188,18 +187,30 @@ namespace MWWorld | ||||||
|         if (mEsm[0].getFormat() == 0) |         if (mEsm[0].getFormat() == 0) | ||||||
|             ensureNeededRecords(); |             ensureNeededRecords(); | ||||||
| 
 | 
 | ||||||
|  |         fillGlobalVariables(); | ||||||
|  | 
 | ||||||
|         mStore.setUp(); |         mStore.setUp(); | ||||||
|         mStore.movePlayerRecord(); |         mStore.movePlayerRecord(); | ||||||
| 
 | 
 | ||||||
|         mSwimHeightScale = mStore.get<ESM::GameSetting>().find("fSwimHeightScale")->getFloat(); |         mSwimHeightScale = mStore.get<ESM::GameSetting>().find("fSwimHeightScale")->getFloat(); | ||||||
| 
 | 
 | ||||||
|         mGlobalVariables.fill (mStore); |  | ||||||
| 
 |  | ||||||
|         mWeatherManager = new MWWorld::WeatherManager(*mRendering, mFallback, mStore); |         mWeatherManager = new MWWorld::WeatherManager(*mRendering, mFallback, mStore); | ||||||
| 
 | 
 | ||||||
|         mWorldScene = new Scene(*mRendering, mPhysics); |         mWorldScene = new Scene(*mRendering, mPhysics); | ||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
|  |     void World::fillGlobalVariables() | ||||||
|  |     { | ||||||
|  |         mGlobalVariables.fill (mStore); | ||||||
|  | 
 | ||||||
|  |         mGameHour = &mGlobalVariables["gamehour"]; | ||||||
|  |         mDaysPassed = &mGlobalVariables["dayspassed"]; | ||||||
|  |         mDay = &mGlobalVariables["day"]; | ||||||
|  |         mMonth = &mGlobalVariables["month"]; | ||||||
|  |         mYear = &mGlobalVariables["year"]; | ||||||
|  |         mTimeScale = &mGlobalVariables["timescale"]; | ||||||
|  |     } | ||||||
|  | 
 | ||||||
|     void World::startNewGame (bool bypass) |     void World::startNewGame (bool bypass) | ||||||
|     { |     { | ||||||
|         mGoToJail = false; |         mGoToJail = false; | ||||||
|  | @ -306,7 +317,7 @@ namespace MWWorld | ||||||
|         mTeleportEnabled = true; |         mTeleportEnabled = true; | ||||||
|         mLevitationEnabled = true; |         mLevitationEnabled = true; | ||||||
| 
 | 
 | ||||||
|         mGlobalVariables.fill (mStore); |         fillGlobalVariables(); | ||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
|     int World::countSavedGameRecords() const |     int World::countSavedGameRecords() const | ||||||
|  | @ -798,15 +809,15 @@ namespace MWWorld | ||||||
| 
 | 
 | ||||||
|         mWeatherManager->advanceTime (hours, incremental); |         mWeatherManager->advanceTime (hours, incremental); | ||||||
| 
 | 
 | ||||||
|         hours += mGlobalVariables["gamehour"].getFloat(); |         hours += mGameHour->getFloat(); | ||||||
| 
 | 
 | ||||||
|         setHour (hours); |         setHour (hours); | ||||||
| 
 | 
 | ||||||
|         int days = static_cast<int>(hours / 24); |         int days = static_cast<int>(hours / 24); | ||||||
| 
 | 
 | ||||||
|         if (days>0) |         if (days>0) | ||||||
|             mGlobalVariables["dayspassed"].setInteger ( |             mDaysPassed->setInteger ( | ||||||
|                 days + mGlobalVariables["dayspassed"].getInteger()); |                 days + mDaysPassed->getInteger()); | ||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
|     void World::setHour (double hour) |     void World::setHour (double hour) | ||||||
|  | @ -818,10 +829,10 @@ namespace MWWorld | ||||||
| 
 | 
 | ||||||
|         hour = std::fmod (hour, 24); |         hour = std::fmod (hour, 24); | ||||||
| 
 | 
 | ||||||
|         mGlobalVariables["gamehour"].setFloat(static_cast<float>(hour)); |         mGameHour->setFloat(static_cast<float>(hour)); | ||||||
| 
 | 
 | ||||||
|         if (days>0) |         if (days>0) | ||||||
|             setDay (days + mGlobalVariables["day"].getInteger()); |             setDay (days + mDay->getInteger()); | ||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
|     void World::setDay (int day) |     void World::setDay (int day) | ||||||
|  | @ -829,7 +840,7 @@ namespace MWWorld | ||||||
|         if (day<1) |         if (day<1) | ||||||
|             day = 1; |             day = 1; | ||||||
| 
 | 
 | ||||||
|         int month = mGlobalVariables["month"].getInteger(); |         int month = mMonth->getInteger(); | ||||||
| 
 | 
 | ||||||
|         while (true) |         while (true) | ||||||
|         { |         { | ||||||
|  | @ -844,14 +855,14 @@ namespace MWWorld | ||||||
|             else |             else | ||||||
|             { |             { | ||||||
|                 month = 0; |                 month = 0; | ||||||
|                 mGlobalVariables["year"].setInteger (mGlobalVariables["year"].getInteger()+1); |                 mYear->setInteger(mYear->getInteger()+1); | ||||||
|             } |             } | ||||||
| 
 | 
 | ||||||
|             day -= days; |             day -= days; | ||||||
|         } |         } | ||||||
| 
 | 
 | ||||||
|         mGlobalVariables["day"].setInteger (day); |         mDay->setInteger(day); | ||||||
|         mGlobalVariables["month"].setInteger (month); |         mMonth->setInteger(month); | ||||||
| 
 | 
 | ||||||
|         mRendering->skySetDate(day, month); |         mRendering->skySetDate(day, month); | ||||||
|     } |     } | ||||||
|  | @ -866,30 +877,30 @@ namespace MWWorld | ||||||
| 
 | 
 | ||||||
|         int days = getDaysPerMonth (month); |         int days = getDaysPerMonth (month); | ||||||
| 
 | 
 | ||||||
|         if (mGlobalVariables["day"].getInteger()>days) |         if (mDay->getInteger()>days) | ||||||
|             mGlobalVariables["day"].setInteger (days); |             mDay->setInteger (days); | ||||||
| 
 | 
 | ||||||
|         mGlobalVariables["month"].setInteger (month); |         mMonth->setInteger (month); | ||||||
| 
 | 
 | ||||||
|         if (years>0) |         if (years>0) | ||||||
|             mGlobalVariables["year"].setInteger (years+mGlobalVariables["year"].getInteger()); |             mYear->setInteger (years+mYear->getInteger()); | ||||||
| 
 | 
 | ||||||
|         mRendering->skySetDate (mGlobalVariables["day"].getInteger(), month); |         mRendering->skySetDate (mDay->getInteger(), month); | ||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
|     int World::getDay() const |     int World::getDay() const | ||||||
|     { |     { | ||||||
|         return mGlobalVariables["day"].getInteger(); |         return mDay->getInteger(); | ||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
|     int World::getMonth() const |     int World::getMonth() const | ||||||
|     { |     { | ||||||
|         return mGlobalVariables["month"].getInteger(); |         return mMonth->getInteger(); | ||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
|     int World::getYear() const |     int World::getYear() const | ||||||
|     { |     { | ||||||
|         return mGlobalVariables["year"].getInteger(); |         return mYear->getInteger(); | ||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
|     std::string World::getMonthName (int month) const |     std::string World::getMonthName (int month) const | ||||||
|  | @ -914,8 +925,7 @@ namespace MWWorld | ||||||
| 
 | 
 | ||||||
|     TimeStamp World::getTimeStamp() const |     TimeStamp World::getTimeStamp() const | ||||||
|     { |     { | ||||||
|         return TimeStamp (mGlobalVariables["gamehour"].getFloat(), |         return TimeStamp (mGameHour->getFloat(), mDaysPassed->getInteger()); | ||||||
|             mGlobalVariables["dayspassed"].getInteger()); |  | ||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
|     bool World::toggleSky() |     bool World::toggleSky() | ||||||
|  | @ -942,7 +952,7 @@ namespace MWWorld | ||||||
| 
 | 
 | ||||||
|     float World::getTimeScaleFactor() const |     float World::getTimeScaleFactor() const | ||||||
|     { |     { | ||||||
|         return mGlobalVariables["timescale"].getFloat(); |         return mTimeScale->getFloat(); | ||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
|     void World::changeToInteriorCell (const std::string& cellName, const ESM::Position& position) |     void World::changeToInteriorCell (const std::string& cellName, const ESM::Position& position) | ||||||
|  |  | ||||||
|  | @ -85,6 +85,13 @@ namespace MWWorld | ||||||
|             MWPhysics::PhysicsSystem *mPhysics; |             MWPhysics::PhysicsSystem *mPhysics; | ||||||
|             bool mSky; |             bool mSky; | ||||||
| 
 | 
 | ||||||
|  |             ESM::Variant* mGameHour; | ||||||
|  |             ESM::Variant* mDaysPassed; | ||||||
|  |             ESM::Variant* mDay; | ||||||
|  |             ESM::Variant* mMonth; | ||||||
|  |             ESM::Variant* mYear; | ||||||
|  |             ESM::Variant* mTimeScale; | ||||||
|  | 
 | ||||||
|             Cells mCells; |             Cells mCells; | ||||||
| 
 | 
 | ||||||
|             std::string mCurrentWorldSpace; |             std::string mCurrentWorldSpace; | ||||||
|  | @ -135,6 +142,8 @@ namespace MWWorld | ||||||
| 
 | 
 | ||||||
|             void ensureNeededRecords(); |             void ensureNeededRecords(); | ||||||
| 
 | 
 | ||||||
|  |             void fillGlobalVariables(); | ||||||
|  | 
 | ||||||
|             /**
 |             /**
 | ||||||
|              * @brief loadContentFiles - Loads content files (esm,esp,omwgame,omwaddon) |              * @brief loadContentFiles - Loads content files (esm,esp,omwgame,omwaddon) | ||||||
|              * @param fileCollections- Container which holds content file names and their paths |              * @param fileCollections- Container which holds content file names and their paths | ||||||
|  |  | ||||||
		Loading…
	
		Reference in a new issue