From 8a80c21661ce3ddc14c0c98afdc091f222ba5aef Mon Sep 17 00:00:00 2001 From: kaetemi Date: Tue, 5 Jun 2012 15:13:13 +0200 Subject: [PATCH] Changed: Reserve sheet id with short id 0 for unknown sheet for new sheet types --- code/nel/src/misc/sheet_id.cpp | 16 ++++++++++++++-- .../tools/misc/make_sheet_id/make_sheet_id.cpp | 15 +++++++++++++-- 2 files changed, 27 insertions(+), 4 deletions(-) diff --git a/code/nel/src/misc/sheet_id.cpp b/code/nel/src/misc/sheet_id.cpp index dd9753ded..a66d3c64f 100644 --- a/code/nel/src/misc/sheet_id.cpp +++ b/code/nel/src/misc/sheet_id.cpp @@ -157,13 +157,18 @@ bool CSheetId::buildSheetId(const std::string& sheetName) _DevSheetIdToName.push_back(std::vector()); typeId = _FileExtensions.size() - 1; _DevTypeNameToId[sheetType] = typeId; + std::string unknownNewType = std::string("unknown." + sheetType); + _DevSheetIdToName[typeId].push_back(unknownNewType); + _Id.IdInfos.Type = typeId; + _Id.IdInfos.Id = _DevSheetIdToName[typeId].size() - 1; + _DevSheetNameToId[unknownNewType] = _Id.Id; } else { typeId = tit->second; + _Id.IdInfos.Type = typeId; } - _DevSheetIdToName[typeId].push_back(sheetName); - _Id.IdInfos.Type = typeId; + _DevSheetIdToName[typeId].push_back(sheetNameLc); _Id.IdInfos.Id = _DevSheetIdToName[typeId].size() - 1; // nldebug("SHEETID: Type %i, id %i, sheetid %i", _Id.IdInfos.Type, _Id.IdInfos.Id, _Id.Id); _DevSheetNameToId[sheetNameLc] = _Id.Id; @@ -381,9 +386,16 @@ void CSheetId::init(bool removeUnknownSheet) if (typeFromFileExtension("sound") == std::numeric_limits::max()) { nlwarning("SHEETID: Loading without known sound sheet id, please update sheet_id.bin with .sound sheets"); + uint32 typeId = ((1 << (NL_SHEET_ID_TYPE_BITS)) - 1); nlassert(_FileExtensions.size() == 1 << (NL_SHEET_ID_TYPE_BITS)); _FileExtensions[((1 << (NL_SHEET_ID_TYPE_BITS)) - 1)] == "sound"; _DevSheetIdToName.push_back(std::vector()); + _DevSheetIdToName[0].push_back("unknown.sound"); + TSheetId id; + id.IdInfos.Type = typeId; + id.IdInfos.Id = _DevSheetIdToName[0].size() - 1; + nlassert(id.IdInfos.Id == 0); + _DevSheetNameToId["unknown.sound"] = id.Id; a_NoSoundSheetId = true; } #endif diff --git a/code/nel/tools/misc/make_sheet_id/make_sheet_id.cpp b/code/nel/tools/misc/make_sheet_id/make_sheet_id.cpp index 2756f1b09..b5dda0c06 100644 --- a/code/nel/tools/misc/make_sheet_id/make_sheet_id.cpp +++ b/code/nel/tools/misc/make_sheet_id/make_sheet_id.cpp @@ -336,16 +336,27 @@ void addId( string fileName ) if( firstFreeFileTypeId == -1 ) { nlwarning("MORE THAN 256 FILE TYPES!!!!"); + return; } else { FileTypeToId.insert( make_pair(fileType,(uint8)firstFreeFileTypeId) ); IdToFileType.insert( make_pair((uint8)firstFreeFileTypeId,fileType) ); - TypeToLastId.insert( make_pair((uint8)firstFreeFileTypeId,0) ); + // Reserve id 0 for unknown.newtype. + // User may supply a sheet called unknown.newtype + // that can safely be used as a fallback when a + // requested sheet does not exist. + // Only for newly added sheet types. fid.FormIDInfos.Type = (uint8)firstFreeFileTypeId; fid.FormIDInfos.Id = 0; - + std::string unknownNewType = std::string("unknown." + fileType); + FormToId.insert(make_pair(unknownNewType, fid)); + IdToForm.insert(make_pair(fid, unknownNewType)); + + TypeToLastId.insert( make_pair((uint8)firstFreeFileTypeId,1) ); + fid.FormIDInfos.Id = 1; + nlinfo("Adding file type '%s' with id %d", fileType.c_str(), firstFreeFileTypeId); NbTypesAdded++; }