MCPcopy Create free account
hub / github.com/crownengine/crown / try_load

Method try_load

src/resource/resource_manager.cpp:116–151  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

114}
115
116bool 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
153void ResourceManager::unload(StringId64 type, StringId64 name)
154{

Callers 2

loadMethod · 0.80
main_loopMethod · 0.80

Calls 4

getFunction · 0.85
to_stringMethod · 0.80
add_requestMethod · 0.80
pushMethod · 0.45

Tested by

no test coverage detected