| 276 | } |
| 277 | |
| 278 | static dmResource::Result ResCollectionRecreate(const dmResource::ResourceRecreateParams* params) |
| 279 | { |
| 280 | dmGameObjectDDF::CollectionDesc* collection_desc; |
| 281 | dmDDF::Result e = dmDDF::LoadMessage<dmGameObjectDDF::CollectionDesc>(params->m_Buffer, params->m_BufferSize, &collection_desc); |
| 282 | if ( e != dmDDF::RESULT_OK ) |
| 283 | { |
| 284 | return dmResource::RESULT_FORMAT_ERROR; |
| 285 | } |
| 286 | |
| 287 | HCollection prev_hcollection = (HCollection) ResourceDescriptorGetResource(params->m_Resource); |
| 288 | Collection* prev_collection = prev_hcollection->m_Collection; |
| 289 | Register* regist = (Register*) params->m_Context; |
| 290 | bool was_initialized = IsCollectionInitialized(prev_collection); |
| 291 | |
| 292 | if (was_initialized) |
| 293 | { |
| 294 | dmGameObject::Final(prev_hcollection); |
| 295 | } |
| 296 | dmGameObject::DetachCollection(prev_collection); |
| 297 | |
| 298 | HCollection delete_hcollection = 0; |
| 299 | dmResource::Result res = AcquireResources(collection_desc->m_Name, params->m_Factory, regist, collection_desc, params->m_Filename, &delete_hcollection); |
| 300 | if (dmResource::RESULT_OK == res) |
| 301 | { |
| 302 | // We cannot simply swap the HCollection, since that's the resource that has been handed out |
| 303 | // so we swap the internal pointers, and tag the new hcollection for deletion |
| 304 | Collection* new_collection = delete_hcollection->m_Collection; |
| 305 | |
| 306 | prev_hcollection->m_Collection = new_collection; |
| 307 | prev_collection->m_HCollection = delete_hcollection; |
| 308 | delete_hcollection->m_Collection = prev_collection; |
| 309 | new_collection->m_HCollection = prev_hcollection; |
| 310 | |
| 311 | if( was_initialized ) |
| 312 | { |
| 313 | if (!dmGameObject::Init(prev_hcollection) ) // this is the new collection |
| 314 | { |
| 315 | dmLogWarning("Failed to initialize collection: %s", collection_desc->m_Name); |
| 316 | |
| 317 | // For those things that actually did manage to initialize (e.g. send events) |
| 318 | dmGameObject::Final(prev_hcollection); |
| 319 | |
| 320 | // Swap them back |
| 321 | prev_hcollection->m_Collection = prev_collection; |
| 322 | prev_collection->m_HCollection = prev_hcollection; |
| 323 | delete_hcollection->m_Collection = new_collection; |
| 324 | new_collection->m_HCollection = delete_hcollection; |
| 325 | |
| 326 | dmGameObject::DeleteCollection(new_collection); |
| 327 | |
| 328 | // Reattach/reinit the collection |
| 329 | dmGameObject::AttachCollection(prev_collection, collection_desc->m_Name, params->m_Factory, regist, prev_hcollection); |
| 330 | if (was_initialized) |
| 331 | { |
| 332 | dmGameObject::Init(prev_hcollection); |
| 333 | } |
| 334 | |
| 335 | dmDDF::FreeMessage(collection_desc); |
nothing calls this directly
no test coverage detected