| 164 | } |
| 165 | |
| 166 | void *ResourceManager::reload(StringId64 type, StringId64 name) |
| 167 | { |
| 168 | if (_resource_loader->_is_bundle) { |
| 169 | CE_ASSERT(false, "Reloading resources in bundle mode is not supported"); |
| 170 | return NULL; |
| 171 | } |
| 172 | |
| 173 | const ResourcePair id = { type, name }; |
| 174 | const ResourceData rd = hash_map::get(_resources, id, ResourceData::NOT_FOUND); |
| 175 | |
| 176 | if (rd == ResourceData::NOT_FOUND) |
| 177 | return NULL; |
| 178 | |
| 179 | // Save old state. |
| 180 | const u32 old_refs = rd.references; |
| 181 | |
| 182 | // Unload the old resource. |
| 183 | on_offline(type, name); |
| 184 | on_unload(type, rd.allocator, rd.data); |
| 185 | hash_map::remove(_resources, id); |
| 186 | |
| 187 | // Load the new resource. |
| 188 | while (!try_load(rd.package_name, type, name, 0)) { |
| 189 | complete_requests(); |
| 190 | } |
| 191 | |
| 192 | // Wait until the new resource has been loaded. |
| 193 | while (!hash_map::has(_resources, id)) |
| 194 | complete_requests(); |
| 195 | |
| 196 | // Restore old state into the new resource. |
| 197 | ResourceData &new_rd = hash_map::get(_resources, id, ResourceData::NOT_FOUND); |
| 198 | new_rd.references = old_refs; |
| 199 | return new_rd.data; |
| 200 | } |
| 201 | |
| 202 | bool ResourceManager::can_get(StringId64 type, StringId64 name) |
| 203 | { |