| 114 | } |
| 115 | |
| 116 | bool ResourceManager::try_load(StringId64 package_name, StringId64 type, StringId64 name, u32 online_order, const PackageResource *package_resource) |
| 117 | { |
| 118 | ResourcePair id = { type, name }; |
| 119 | ResourceData &rd = hash_map::get(_resources, id, ResourceData::NOT_FOUND); |
| 120 | |
| 121 | ResourceRequest rr; |
| 122 | rr.package_name = package_name; |
| 123 | rr.package_resource = package_resource; |
| 124 | rr.type = type; |
| 125 | rr.name = name; |
| 126 | rr.online_order = online_order; |
| 127 | rr.data = NULL; |
| 128 | |
| 129 | if (rd == ResourceData::NOT_FOUND) { |
| 130 | char buf[STRING_ID64_BUF_LEN]; |
| 131 | ResourceTypeData rtd = hash_map::get(_types, type, ResourceTypeData::NOT_FOUND); |
| 132 | CE_ASSERT(rtd != ResourceTypeData::NOT_FOUND |
| 133 | , "Unregistered resource type '%s'" |
| 134 | , type.to_string(buf, sizeof(buf)) |
| 135 | ); |
| 136 | CE_UNUSED(buf); |
| 137 | |
| 138 | rr.allocator = &_resource_heap; |
| 139 | rr.load_function = rtd.load; |
| 140 | return _resource_loader->add_request(rr); |
| 141 | } |
| 142 | |
| 143 | rd.references++; |
| 144 | |
| 145 | // Push a spurious loaded resource event. This avoids blocking forever |
| 146 | // in complete_requests() by keeping the online_sequence_num updated. |
| 147 | rr.allocator = NULL; |
| 148 | rr.load_function = NULL; |
| 149 | _resource_loader->_loaded.push(rr); |
| 150 | return true; |
| 151 | } |
| 152 | |
| 153 | void ResourceManager::unload(StringId64 type, StringId64 name) |
| 154 | { |