MCPcopy Create free account
hub / github.com/defold/defold / AttachCollection

Function AttachCollection

engine/gameobject/src/gameobject/gameobject.cpp:448–495  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

446 }
447
448 Result AttachCollection(Collection* collection, const char* name, dmResource::HFactory factory, HRegister regist, HCollection hcollection)
449 {
450 collection->m_HCollection = hcollection;
451 collection->m_Register = regist;
452 hcollection->m_Collection = collection;
453 collection->m_Factory = factory;
454
455 // if there exists a collection with the same name and that collection
456 // is to be deleted we immediately delete it so that we can attach the
457 // the new one
458 HCollection existing = GetCollectionByHash(regist, dmHashString64(name));
459 if (existing && existing->m_Collection->m_ToBeDeleted)
460 {
461 DeleteCollection(existing->m_Collection);
462 }
463
464 char name_frame[128];
465 dmStrlCpy(name_frame, name, sizeof(name_frame));
466 dmStrlCat(name_frame, "_frame", sizeof(name_frame));
467 const char* socket_names[] = {name, name_frame};
468 dmMessage::HSocket* sockets[] = {&collection->m_ComponentSocket, &collection->m_FrameSocket};
469 for (int i = 0; i < 2; ++i)
470 {
471 dmMessage::Result result = dmMessage::NewSocket(socket_names[i], sockets[i]);
472 if (result != dmMessage::RESULT_OK)
473 {
474 if (result == dmMessage::RESULT_SOCKET_EXISTS)
475 {
476 dmLogError("The collection '%s' could not be created since there is already a socket with the same name.", socket_names[i]);
477 }
478 else if (result == dmMessage::RESULT_INVALID_SOCKET_NAME)
479 {
480 dmLogError("The collection '%s' could not be created since the name is invalid for sockets.", socket_names[i]);
481 }
482 return RESULT_UNKNOWN_ERROR;
483 }
484 }
485
486 dmResource::RegisterResourceReloadedCallback(factory, ResourceReloadedCallback, collection);
487
488 DM_MUTEX_SCOPED_LOCK(regist->m_Mutex);
489 if (regist->m_Collections.Full())
490 {
491 regist->m_Collections.OffsetCapacity(4);
492 }
493 regist->m_Collections.Push(collection);
494 return RESULT_OK;
495 }
496
497 void DetachCollection(Collection* collection)
498 {

Callers 2

NewCollectionFunction · 0.85
ResCollectionRecreateFunction · 0.85

Calls 9

GetCollectionByHashFunction · 0.85
DeleteCollectionFunction · 0.85
dmStrlCpyFunction · 0.85
dmStrlCatFunction · 0.85
NewSocketFunction · 0.85
FullMethod · 0.45
OffsetCapacityMethod · 0.45
PushMethod · 0.45

Tested by

no test coverage detected