Assumes m_LoadMutex is already held
| 700 | |
| 701 | // Assumes m_LoadMutex is already held |
| 702 | static Result DoCreateResource(HFactory factory, ResourceType* resource_type, const char* name, const char* canonical_path, |
| 703 | dmhash_t canonical_path_hash, void* buffer, uint32_t buffer_size, uint32_t resource_size, void** resource_out) |
| 704 | { |
| 705 | // TODO: We should *NOT* allocate SResource dynamically... |
| 706 | ResourceDescriptor tmp_resource; |
| 707 | memset(&tmp_resource, 0, sizeof(tmp_resource)); |
| 708 | tmp_resource.m_NameHash = canonical_path_hash; |
| 709 | tmp_resource.m_ReferenceCount = 1; |
| 710 | tmp_resource.m_ResourceType = resource_type; |
| 711 | |
| 712 | void* preload_data = 0; |
| 713 | Result create_error = RESULT_OK; |
| 714 | |
| 715 | bool is_partial = buffer_size != resource_size; |
| 716 | |
| 717 | if (resource_type->m_PreloadFunction) |
| 718 | { |
| 719 | ResourcePreloadParams params; |
| 720 | params.m_Factory = factory; |
| 721 | params.m_Type = resource_type; |
| 722 | params.m_Context = resource_type->m_Context; |
| 723 | params.m_Buffer = buffer; |
| 724 | params.m_BufferSize = buffer_size; |
| 725 | params.m_FileSize = resource_size; |
| 726 | params.m_IsBufferPartial = is_partial; |
| 727 | params.m_IsBufferTransferrable = 0; |
| 728 | params.m_Filename = name; |
| 729 | params.m_HintInfo = 0; // No hinting now |
| 730 | // out |
| 731 | params.m_PreloadData = &preload_data; |
| 732 | params.m_IsBufferOwnershipTransferred = 0; |
| 733 | create_error = (Result)resource_type->m_PreloadFunction(¶ms); |
| 734 | } |
| 735 | |
| 736 | if (create_error == RESULT_OK) |
| 737 | { |
| 738 | tmp_resource.m_ResourceSizeOnDisc = buffer_size; |
| 739 | tmp_resource.m_ResourceSize = 0; // Not everything will report a size (but instead rely on the disc size, sinze it's close enough) |
| 740 | |
| 741 | ResourceCreateParams params; |
| 742 | params.m_Factory = factory; |
| 743 | params.m_Type = resource_type; |
| 744 | params.m_Context = resource_type->m_Context; |
| 745 | params.m_Buffer = buffer; |
| 746 | params.m_BufferSize = buffer_size; |
| 747 | params.m_FileSize = resource_size; |
| 748 | params.m_IsBufferPartial= is_partial; |
| 749 | params.m_PreloadData = preload_data; |
| 750 | params.m_Resource = &tmp_resource; |
| 751 | params.m_Filename = name; |
| 752 | create_error = (Result)resource_type->m_CreateFunction(¶ms); |
| 753 | } |
| 754 | |
| 755 | if (create_error == RESULT_OK && resource_type->m_PostCreateFunction) |
| 756 | { |
| 757 | ResourcePostCreateParams params; |
| 758 | params.m_Factory = factory; |
| 759 | params.m_Type = resource_type; |
no test coverage detected