void ReleaseObject( RwObject *obj ) { EngineInterface *engineInterface = (EngineInterface*)obj->engineInterface; // Increase the reference count. if ( refCountManager *refMan = refCountRegister.GetPluginStruct( (EngineInterface*)engineInterface ) ) { if ( refCountPlugin *refCount = refMan->GetPluginStruct( engineInterface, obj ) ) { // We just delete the object. engineInterface->DeleteRwObject( obj ); } } }
void texDictionaryStreamPlugin::Deserialize( Interface *intf, BlockProvider& inputProvider, RwObject *objectToDeserialize ) const { EngineInterface *engineInterface = (EngineInterface*)intf; // Cast our object. TexDictionary *txdObj = (TexDictionary*)objectToDeserialize; // Read the textures. { BlockProvider texDictMetaStructBlock( &inputProvider ); uint32 textureBlockCount = 0; bool requiresRecommendedPlatform = true; uint16 recDevicePlatID = 0; texDictMetaStructBlock.EnterContext(); try { if ( texDictMetaStructBlock.getBlockID() == CHUNK_STRUCT ) { // Read the header block depending on version. LibraryVersion libVer = texDictMetaStructBlock.getBlockVersion(); if (libVer.rwLibMajor <= 2 || libVer.rwLibMajor == 3 && libVer.rwLibMinor <= 5) { textureBlockCount = texDictMetaStructBlock.readUInt32(); } else { textureBlockCount = texDictMetaStructBlock.readUInt16(); uint16 recommendedPlatform = texDictMetaStructBlock.readUInt16(); // So if there is a recommended platform set, we will also give it one if we will write it. requiresRecommendedPlatform = ( recommendedPlatform != 0 ); recDevicePlatID = recommendedPlatform; // we want to store it aswell. } } else { engineInterface->PushWarning( "could not find texture dictionary meta information" ); } } catch( ... ) { texDictMetaStructBlock.LeaveContext(); throw; } // We finished reading meta data. texDictMetaStructBlock.LeaveContext(); txdObj->hasRecommendedPlatform = requiresRecommendedPlatform; txdObj->recDevicePlatID = recDevicePlatID; // Now follow multiple TEXTURENATIVE blocks. // Deserialize all of them. for ( uint32 n = 0; n < textureBlockCount; n++ ) { BlockProvider textureNativeBlock( &inputProvider ); // Deserialize this block. RwObject *rwObj = NULL; std::string errDebugMsg; try { rwObj = engineInterface->DeserializeBlock( textureNativeBlock ); } catch( RwException& except ) { // Catch the exception and try to continue. rwObj = NULL; if ( textureNativeBlock.doesIgnoreBlockRegions() ) { // If we failed any texture parsing in the "ignoreBlockRegions" parse mode, // there is no point in continuing, since the environment does not recover. throw; } errDebugMsg = except.message; } if ( rwObj ) { // If it is a texture, add it to our TXD. bool hasBeenAddedToTXD = false; GenericRTTI *rttiObj = RwTypeSystem::GetTypeStructFromObject( rwObj ); RwTypeSystem::typeInfoBase *typeInfo = RwTypeSystem::GetTypeInfoFromTypeStruct( rttiObj ); if ( engineInterface->typeSystem.IsTypeInheritingFrom( engineInterface->textureTypeInfo, typeInfo ) ) { TextureBase *texture = (TextureBase*)rwObj; texture->AddToDictionary( txdObj ); hasBeenAddedToTXD = true; } // If it has not been added, delete it. if ( hasBeenAddedToTXD == false ) { engineInterface->DeleteRwObject( rwObj ); } } else { std::string pushWarning; if ( errDebugMsg.empty() == false ) { pushWarning = "texture native reading failure: "; pushWarning += errDebugMsg; } else { pushWarning = "failed to deserialize texture native block in texture dictionary"; } engineInterface->PushWarning( pushWarning.c_str() ); } } } // Read extensions. engineInterface->DeserializeExtensions( txdObj, inputProvider ); }