mirror of
				https://github.com/OpenMW/openmw.git
				synced 2025-10-25 17:56:37 +00:00 
			
		
		
		
	Static const is only required to provide a reference or a pointer when it is not possible with default constructed temporary.
		
			
				
	
	
		
			72 lines
		
	
	
	
		
			1.9 KiB
		
	
	
	
		
			C++
		
	
	
	
	
	
			
		
		
	
	
			72 lines
		
	
	
	
		
			1.9 KiB
		
	
	
	
		
			C++
		
	
	
	
	
	
| #include "loadsndg.hpp"
 | |
| 
 | |
| #include "components/esm/defs.hpp"
 | |
| #include "esmreader.hpp"
 | |
| #include "esmwriter.hpp"
 | |
| 
 | |
| namespace ESM
 | |
| {
 | |
|     void SoundGenerator::load(ESMReader& esm, bool& isDeleted)
 | |
|     {
 | |
|         isDeleted = false;
 | |
|         mRecordFlags = esm.getRecordFlags();
 | |
| 
 | |
|         bool hasName = false;
 | |
|         bool hasData = false;
 | |
|         while (esm.hasMoreSubs())
 | |
|         {
 | |
|             esm.getSubName();
 | |
|             switch (esm.retSubName().toInt())
 | |
|             {
 | |
|                 case SREC_NAME:
 | |
|                     mId = esm.getRefId();
 | |
|                     hasName = true;
 | |
|                     break;
 | |
|                 case fourCC("DATA"):
 | |
|                     esm.getHTSized<4>(mType);
 | |
|                     hasData = true;
 | |
|                     break;
 | |
|                 case fourCC("CNAM"):
 | |
|                     mCreature = esm.getRefId();
 | |
|                     break;
 | |
|                 case fourCC("SNAM"):
 | |
|                     mSound = esm.getRefId();
 | |
|                     break;
 | |
|                 case SREC_DELE:
 | |
|                     esm.skipHSub();
 | |
|                     isDeleted = true;
 | |
|                     break;
 | |
|                 default:
 | |
|                     esm.fail("Unknown subrecord");
 | |
|                     break;
 | |
|             }
 | |
|         }
 | |
| 
 | |
|         if (!hasName)
 | |
|             esm.fail("Missing NAME subrecord");
 | |
|         if (!hasData && !isDeleted)
 | |
|             esm.fail("Missing DATA subrecord");
 | |
|     }
 | |
|     void SoundGenerator::save(ESMWriter& esm, bool isDeleted) const
 | |
|     {
 | |
|         esm.writeHNCRefId("NAME", mId);
 | |
| 
 | |
|         if (isDeleted)
 | |
|         {
 | |
|             esm.writeHNString("DELE", "", 3);
 | |
|             return;
 | |
|         }
 | |
| 
 | |
|         esm.writeHNT("DATA", mType, 4);
 | |
|         esm.writeHNOCRefId("CNAM", mCreature);
 | |
|         esm.writeHNOCRefId("SNAM", mSound);
 | |
|     }
 | |
| 
 | |
|     void SoundGenerator::blank()
 | |
|     {
 | |
|         mRecordFlags = 0;
 | |
|         mType = LeftFoot;
 | |
|         mCreature = ESM::RefId();
 | |
|         mSound = ESM::RefId();
 | |
|     }
 | |
| }
 |