mirror of
				https://github.com/OpenMW/openmw.git
				synced 2025-10-25 11:26:37 +00:00 
			
		
		
		
	Remove NAME and DELE handling from IdCollection
This commit is contained in:
		
							parent
							
								
									42f9136141
								
							
						
					
					
						commit
						74a055f3cc
					
				
					 7 changed files with 118 additions and 66 deletions
				
			
		|  | @ -5,16 +5,13 @@ | ||||||
| 
 | 
 | ||||||
| void CSMWorld::Cell::load (ESM::ESMReader &esm) | void CSMWorld::Cell::load (ESM::ESMReader &esm) | ||||||
| { | { | ||||||
|     mName = mId; |  | ||||||
| 
 |  | ||||||
|     ESM::Cell::load (esm, false); |     ESM::Cell::load (esm, false); | ||||||
| 
 | 
 | ||||||
|  |     mId = mName; | ||||||
|     if (!(mData.mFlags & Interior)) |     if (!(mData.mFlags & Interior)) | ||||||
|     { |     { | ||||||
|         std::ostringstream stream; |         std::ostringstream stream; | ||||||
| 
 |  | ||||||
|         stream << "#" << mData.mX << " " << mData.mY; |         stream << "#" << mData.mX << " " << mData.mY; | ||||||
| 
 |  | ||||||
|         mId = stream.str(); |         mId = stream.str(); | ||||||
|     } |     } | ||||||
| } | } | ||||||
|  |  | ||||||
|  | @ -988,41 +988,41 @@ bool CSMWorld::Data::continueLoading (CSMDoc::Messages& messages) | ||||||
| 
 | 
 | ||||||
|         case ESM::REC_DIAL: |         case ESM::REC_DIAL: | ||||||
|         { |         { | ||||||
|             std::string id = mReader->getHNOString ("NAME"); |  | ||||||
| 
 |  | ||||||
|             ESM::Dialogue record; |             ESM::Dialogue record; | ||||||
|             record.mId = id; |  | ||||||
|             record.load (*mReader); |             record.load (*mReader); | ||||||
| 
 | 
 | ||||||
|             if (record.mType==ESM::Dialogue::Journal) |             if (record.mIsDeleted) | ||||||
|             { |             { | ||||||
|                 mJournals.load (record, mBase); |                 // record vector can be shuffled around which would make pointer to record invalid
 | ||||||
|                 mDialogue = &mJournals.getRecord (id).get(); |                 mDialogue = 0; | ||||||
|             } |  | ||||||
|             else if (record.mType==ESM::Dialogue::Deleted) |  | ||||||
|             { |  | ||||||
|                 mDialogue = 0; // record vector can be shuffled around which would make pointer
 |  | ||||||
|                                // to record invalid
 |  | ||||||
| 
 | 
 | ||||||
|                 if (mJournals.tryDelete (id)) |                 if (mJournals.tryDelete (record.mId)) | ||||||
|                 { |                 { | ||||||
|                     /// \todo handle info records
 |                     /// \todo handle info records
 | ||||||
|                 } |                 } | ||||||
|                 else if (mTopics.tryDelete (id)) |                 else if (mTopics.tryDelete (record.mId)) | ||||||
|                 { |                 { | ||||||
|                     /// \todo handle info records
 |                     /// \todo handle info records
 | ||||||
|                 } |                 } | ||||||
|                 else |                 else | ||||||
|                 { |                 { | ||||||
|                     messages.add (UniversalId::Type_None, |                     messages.add (UniversalId::Type_None, | ||||||
|                         "Trying to delete dialogue record " + id + " which does not exist", |                         "Trying to delete dialogue record " + record.mId + " which does not exist", | ||||||
|                         "", CSMDoc::Message::Severity_Warning); |                         "", CSMDoc::Message::Severity_Warning); | ||||||
|                 } |                 } | ||||||
|             } |             } | ||||||
|             else |             else | ||||||
|  |             { | ||||||
|  |                 if (record.mType == ESM::Dialogue::Journal) | ||||||
|  |                 { | ||||||
|  |                     mJournals.load (record, mBase); | ||||||
|  |                     mDialogue = &mJournals.getRecord (record.mId).get(); | ||||||
|  |                 } | ||||||
|  |                 else | ||||||
|                 { |                 { | ||||||
|                     mTopics.load (record, mBase); |                     mTopics.load (record, mBase); | ||||||
|                 mDialogue = &mTopics.getRecord (id).get(); |                     mDialogue = &mTopics.getRecord (record.mId).get();    | ||||||
|  |                 } | ||||||
|             } |             } | ||||||
| 
 | 
 | ||||||
|             break; |             break; | ||||||
|  |  | ||||||
|  | @ -2,6 +2,7 @@ | ||||||
| #define CSM_WOLRD_IDCOLLECTION_H | #define CSM_WOLRD_IDCOLLECTION_H | ||||||
| 
 | 
 | ||||||
| #include <components/esm/esmreader.hpp> | #include <components/esm/esmreader.hpp> | ||||||
|  | #include <components/esm/util.hpp> | ||||||
| 
 | 
 | ||||||
| #include "collection.hpp" | #include "collection.hpp" | ||||||
| 
 | 
 | ||||||
|  | @ -41,70 +42,44 @@ namespace CSMWorld | ||||||
|     template<typename ESXRecordT, typename IdAccessorT> |     template<typename ESXRecordT, typename IdAccessorT> | ||||||
|     int IdCollection<ESXRecordT, IdAccessorT>::load (ESM::ESMReader& reader, bool base) |     int IdCollection<ESXRecordT, IdAccessorT>::load (ESM::ESMReader& reader, bool base) | ||||||
|     { |     { | ||||||
|         std::string id = reader.getHNOString ("NAME"); |         ESXRecordT record; | ||||||
|  |         loadRecord (record, reader); | ||||||
| 
 | 
 | ||||||
|         if (reader.isNextSub ("DELE")) |         std::string id = IdAccessorT().getId (record); | ||||||
|  |         int index = searchId (id); | ||||||
|  | 
 | ||||||
|  |         if (ESM::isRecordDeleted (record)) | ||||||
|         { |         { | ||||||
|             int index = Collection<ESXRecordT, IdAccessorT>::searchId (id); |  | ||||||
| 
 |  | ||||||
|             reader.skipRecord(); |  | ||||||
| 
 |  | ||||||
|             if (index==-1) |             if (index==-1) | ||||||
|             { |             { | ||||||
|                 // deleting a record that does not exist
 |                 // deleting a record that does not exist
 | ||||||
| 
 |  | ||||||
|                 // ignore it for now
 |                 // ignore it for now
 | ||||||
| 
 |  | ||||||
|                 /// \todo report the problem to the user
 |                 /// \todo report the problem to the user
 | ||||||
|  |                 return -1; | ||||||
|             } |             } | ||||||
|             else if (base) | 
 | ||||||
|  |             if (base) | ||||||
|             { |             { | ||||||
|                 Collection<ESXRecordT, IdAccessorT>::removeRows (index, 1); |                 removeRows (index, 1); | ||||||
|             } |             } | ||||||
|             else |             else | ||||||
|             { |             { | ||||||
|                 Record<ESXRecordT> record = Collection<ESXRecordT, IdAccessorT>::getRecord (index); |                 Record<ESXRecordT> baseRecord = getRecord (index); | ||||||
|                 record.mState = RecordBase::State_Deleted; |                 baseRecord.mState = RecordBase::State_Deleted; | ||||||
|                 this->setRecord (index, record); |                 this->setRecord (index, baseRecord); | ||||||
|             } |             } | ||||||
| 
 | 
 | ||||||
|             return -1; |             return -1; | ||||||
|         } |         } | ||||||
|         else |  | ||||||
|         { |  | ||||||
|             ESXRecordT record; |  | ||||||
| 
 |  | ||||||
|             // Sometimes id (i.e. NAME of the cell) may be different to the id we stored
 |  | ||||||
|             // earlier.  e.g. NAME == "Vivec, Arena" but id == "#-4 11".  Sometime NAME is
 |  | ||||||
|             // missing altogether for scripts or cells.
 |  | ||||||
|         //
 |         //
 | ||||||
|             // In such cases the returned index will be -1.  We then try updating the
 |         //if (index != -1)
 | ||||||
|             // IdAccessor's id manually (e.g. set mId of the record to "Vivec, Arena")
 |         //{
 | ||||||
|             // and try getting the index once more after loading the record.  The mId of the
 |         //    ESXRecordT existedRecord = getRecord(index).get();
 | ||||||
|             // record would have changed to "#-4 11" after the load, and searchId() should find
 |         //    IdAccessorT().getId(record) = IdAccessorT().getId(existedRecord);
 | ||||||
|             // it (if this is a modify)
 |         //}
 | ||||||
|             int index = this->searchId (id); |  | ||||||
| 
 |  | ||||||
|             if (index==-1) |  | ||||||
|                 IdAccessorT().getId (record) = id; |  | ||||||
|             else |  | ||||||
|             { |  | ||||||
|                 record = this->getRecord (index).get(); |  | ||||||
|             } |  | ||||||
| 
 |  | ||||||
|             loadRecord (record, reader); |  | ||||||
| 
 |  | ||||||
|             if (index==-1) |  | ||||||
|             { |  | ||||||
|                 std::string newId = IdAccessorT().getId(record); |  | ||||||
|                 int newIndex = this->searchId(newId); |  | ||||||
|                 if (newIndex != -1 && id != newId) |  | ||||||
|                     index = newIndex; |  | ||||||
|             } |  | ||||||
| 
 | 
 | ||||||
|         return load (record, base, index); |         return load (record, base, index); | ||||||
|     } |     } | ||||||
|     } |  | ||||||
| 
 | 
 | ||||||
|     template<typename ESXRecordT, typename IdAccessorT> |     template<typename ESXRecordT, typename IdAccessorT> | ||||||
|     int IdCollection<ESXRecordT, IdAccessorT>::load (const ESXRecordT& record, bool base, |     int IdCollection<ESXRecordT, IdAccessorT>::load (const ESXRecordT& record, bool base, | ||||||
|  |  | ||||||
|  | @ -4,6 +4,7 @@ | ||||||
| #include <string> | #include <string> | ||||||
| #include <boost/shared_ptr.hpp> | #include <boost/shared_ptr.hpp> | ||||||
| #include <components/esm/loadland.hpp> | #include <components/esm/loadland.hpp> | ||||||
|  | #include <components/esm/util.hpp> | ||||||
| 
 | 
 | ||||||
| namespace CSMWorld | namespace CSMWorld | ||||||
| { | { | ||||||
|  | @ -26,4 +27,13 @@ namespace CSMWorld | ||||||
|     }; |     }; | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
|  | namespace ESM | ||||||
|  | { | ||||||
|  |     template <> | ||||||
|  |     bool isRecordDeleted<CSMWorld::Land>(const CSMWorld::Land &land) | ||||||
|  |     { | ||||||
|  |         return false; | ||||||
|  |     } | ||||||
|  | } | ||||||
|  | 
 | ||||||
| #endif | #endif | ||||||
|  |  | ||||||
|  | @ -5,6 +5,7 @@ | ||||||
| #include <string> | #include <string> | ||||||
| 
 | 
 | ||||||
| #include <components/esm/loadpgrd.hpp> | #include <components/esm/loadpgrd.hpp> | ||||||
|  | #include <components/esm/util.hpp> | ||||||
| 
 | 
 | ||||||
| namespace CSMWorld | namespace CSMWorld | ||||||
| { | { | ||||||
|  | @ -26,4 +27,13 @@ namespace CSMWorld | ||||||
|     }; |     }; | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
|  | namespace ESM | ||||||
|  | { | ||||||
|  |     template <> | ||||||
|  |     bool isRecordDeleted<CSMWorld::Pathgrid>(const CSMWorld::Pathgrid &pgrd) | ||||||
|  |     { | ||||||
|  |         return false; | ||||||
|  |     } | ||||||
|  | } | ||||||
|  | 
 | ||||||
| #endif | #endif | ||||||
|  |  | ||||||
|  | @ -36,4 +36,40 @@ namespace ESM | ||||||
|     { |     { | ||||||
|         return false; |         return false; | ||||||
|     } |     } | ||||||
|  | 
 | ||||||
|  |     template <> | ||||||
|  |     bool isRecordDeleted<Skill>(const Skill &skill) | ||||||
|  |     { | ||||||
|  |         return false; | ||||||
|  |     } | ||||||
|  | 
 | ||||||
|  |     template <> | ||||||
|  |     bool isRecordDeleted<MagicEffect>(const MagicEffect &mgef) | ||||||
|  |     { | ||||||
|  |         return false; | ||||||
|  |     } | ||||||
|  | 
 | ||||||
|  |     template <> | ||||||
|  |     bool isRecordDeleted<Pathgrid>(const Pathgrid &pgrd) | ||||||
|  |     { | ||||||
|  |         return false; | ||||||
|  |     } | ||||||
|  | 
 | ||||||
|  |     template <> | ||||||
|  |     bool isRecordDeleted<Land>(const Land &land) | ||||||
|  |     { | ||||||
|  |         return false; | ||||||
|  |     } | ||||||
|  | 
 | ||||||
|  |     template <> | ||||||
|  |     bool isRecordDeleted<DebugProfile>(const DebugProfile &profile) | ||||||
|  |     { | ||||||
|  |         return false; | ||||||
|  |     } | ||||||
|  | 
 | ||||||
|  |     template <> | ||||||
|  |     bool isRecordDeleted<Filter>(const Filter &filter) | ||||||
|  |     { | ||||||
|  |         return false; | ||||||
|  |     } | ||||||
| } | } | ||||||
|  |  | ||||||
|  | @ -12,6 +12,12 @@ | ||||||
| #include "loadglob.hpp" | #include "loadglob.hpp" | ||||||
| #include "loadrace.hpp" | #include "loadrace.hpp" | ||||||
| #include "loadgmst.hpp" | #include "loadgmst.hpp" | ||||||
|  | #include "loadskil.hpp" | ||||||
|  | #include "loadmgef.hpp" | ||||||
|  | #include "loadland.hpp" | ||||||
|  | #include "loadpgrd.hpp" | ||||||
|  | #include "debugprofile.hpp" | ||||||
|  | #include "filter.hpp" | ||||||
| 
 | 
 | ||||||
| namespace ESM | namespace ESM | ||||||
| { | { | ||||||
|  | @ -76,6 +82,24 @@ bool isRecordDeleted<Race>(const Race &race); | ||||||
| template <> | template <> | ||||||
| bool isRecordDeleted<GameSetting>(const GameSetting &gmst); | bool isRecordDeleted<GameSetting>(const GameSetting &gmst); | ||||||
| 
 | 
 | ||||||
|  | template <> | ||||||
|  | bool isRecordDeleted<Skill>(const Skill &skill); | ||||||
|  | 
 | ||||||
|  | template <> | ||||||
|  | bool isRecordDeleted<MagicEffect>(const MagicEffect &mgef); | ||||||
|  | 
 | ||||||
|  | template <> | ||||||
|  | bool isRecordDeleted<Pathgrid>(const Pathgrid &pgrd); | ||||||
|  | 
 | ||||||
|  | template <> | ||||||
|  | bool isRecordDeleted<Land>(const Land &land); | ||||||
|  | 
 | ||||||
|  | template <> | ||||||
|  | bool isRecordDeleted<DebugProfile>(const DebugProfile &profile); | ||||||
|  | 
 | ||||||
|  | template <> | ||||||
|  | bool isRecordDeleted<Filter>(const Filter &filter); | ||||||
|  | 
 | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| #endif | #endif | ||||||
|  |  | ||||||
		Loading…
	
		Reference in a new issue