Provide explicit argument for asset cache ID.
This will allow assets to cache compiled results with different parameters. For example, we could cache both an RGB version of a texture and a Mono version. PiperOrigin-RevId: 811341377 Change-Id: Ifd6a4ff88661a2b38be47c02d6a666de2c202885
This commit is contained in:
committed by
Copybara-Service
parent
0baac58999
commit
922aebbeed
@@ -64,17 +64,17 @@ const std::string* mjCCache::HasAsset(const std::string& id) {
|
||||
|
||||
// inserts an asset into the cache, if asset is already in the cache, its data
|
||||
// is updated only if the timestamps disagree
|
||||
bool mjCCache::Insert(const std::string& modelname, const mjResource *resource,
|
||||
bool mjCCache::Insert(const std::string& modelname, const std::string& id, const mjResource *resource,
|
||||
std::shared_ptr<const void> data, std::size_t size) {
|
||||
std::lock_guard<std::mutex> lock(mutex_);
|
||||
|
||||
// check if asset is too large to fit in the cache
|
||||
if ((size_ + size > capacity_) &&
|
||||
lookup_.find(resource->name) == lookup_.end()) {
|
||||
lookup_.find(id) == lookup_.end()) {
|
||||
return false;
|
||||
}
|
||||
mjCAsset asset(modelname, resource, data, size);
|
||||
auto [it, inserted] = lookup_.insert({resource->name, asset});
|
||||
mjCAsset asset(modelname, id, resource, data, size);
|
||||
auto [it, inserted] = lookup_.insert({id, asset});
|
||||
mjCAsset* asset_ptr = &(it->second);
|
||||
|
||||
if (!inserted) {
|
||||
@@ -104,9 +104,9 @@ bool mjCCache::Insert(const std::string& modelname, const mjResource *resource,
|
||||
|
||||
// populate data from the cache into the given function, return true if data was
|
||||
// copied
|
||||
bool mjCCache::PopulateData(const mjResource* resource, mjCDataFunc fn) {
|
||||
bool mjCCache::PopulateData(const std::string& id, const mjResource* resource, mjCDataFunc fn) {
|
||||
std::lock_guard<std::mutex> lock(mutex_);
|
||||
auto it = lookup_.find(resource->name);
|
||||
auto it = lookup_.find(id);
|
||||
if (it == lookup_.end()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user