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

Function CreateAndLoadResource

engine/resource/src/resource.cpp:863–904  ·  view source on GitHub ↗

Assumes m_LoadMutex is already held

Source from the content-addressed store, hash-verified

861
862// Assumes m_LoadMutex is already held
863static Result CreateAndLoadResource(HFactory factory, const char* path, void** resource)
864{
865 assert(path);
866 assert(resource);
867
868 DM_PROFILE(__FUNCTION__);
869
870 char canonical_path[RESOURCE_PATH_MAX];
871 GetCanonicalPath(path, canonical_path, sizeof(canonical_path));
872 dmhash_t canonical_path_hash = dmHashBuffer64(canonical_path, strlen(canonical_path));
873
874 ResourceType* resource_type;
875 Result res = CheckAndGetResourceAndType(factory, canonical_path, canonical_path_hash, resource, &resource_type);
876 if (res != RESULT_OK)
877 {
878 return res;
879 }
880 else if (*resource != 0x0)
881 {
882 // Resource already created
883 return RESULT_OK;
884 }
885
886 uint32_t preload_size = RESOURCE_INVALID_PRELOAD_SIZE;
887 if (ResourceTypeIsStreaming(resource_type))
888 {
889 preload_size = ResourceTypeGetPreloadSize(resource_type);
890 }
891
892 void* buffer = 0;
893 uint32_t buffer_size = 0;
894 uint32_t resource_size = 0;
895 Result result = LoadResource(factory, canonical_path, path, preload_size, &buffer, &buffer_size, &resource_size);
896 if (result != RESULT_OK)
897 {
898 return result;
899 }
900 assert(buffer == factory->m_Buffer.Begin());
901
902 return DoCreateResource(factory, resource_type, path, canonical_path, canonical_path_hash,
903 buffer, buffer_size, resource_size, resource);
904}
905
906Result CreateResourcePartial(HFactory factory, HResourceType type, const char* name, void* data, uint32_t data_size, uint32_t file_size, void** resource)
907{

Callers 1

GetWithExtFunction · 0.85

Calls 9

GetCanonicalPathFunction · 0.85
ResourceTypeIsStreamingFunction · 0.85
DoCreateResourceFunction · 0.85
LoadResourceFunction · 0.70
assertFunction · 0.50
dmHashBuffer64Function · 0.50
BeginMethod · 0.45

Tested by

no test coverage detected