Clear image cache when tabbing out of canvas
This commit is contained in:
parent
c7024578af
commit
1f80107005
9 changed files with 32 additions and 0 deletions
|
|
@ -96,6 +96,8 @@ void MainProgram::update() {
|
||||||
|
|
||||||
std::shared_ptr<World> oldWorld = world;
|
std::shared_ptr<World> oldWorld = world;
|
||||||
world = worlds[worldIndex];
|
world = worlds[worldIndex];
|
||||||
|
if(oldWorld != world && oldWorld)
|
||||||
|
oldWorld->on_switch_out();
|
||||||
|
|
||||||
deltaTime.update_time_since();
|
deltaTime.update_time_since();
|
||||||
deltaTime.update_time_point();
|
deltaTime.update_time_point();
|
||||||
|
|
|
||||||
|
|
@ -287,6 +287,20 @@ ResourceDisplay::Type ImageResourceDisplay::get_type() const {
|
||||||
return ResourceDisplay::Type::IMAGE;
|
return ResourceDisplay::Type::IMAGE;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void ImageResourceDisplay::clear_cache() {
|
||||||
|
if(loadThread) {
|
||||||
|
shutdownLoadThread = true;
|
||||||
|
loadThread->join();
|
||||||
|
loadThread = nullptr;
|
||||||
|
}
|
||||||
|
for(auto& frame : frames) {
|
||||||
|
for(auto& mipmap : frame.mipmapLevels)
|
||||||
|
mipmap = nullptr;
|
||||||
|
}
|
||||||
|
for(auto& mipmapStatus : mipmapLevelsStatus)
|
||||||
|
mipmapStatus = MipmapLevelStatus::UNALLOCATED;
|
||||||
|
}
|
||||||
|
|
||||||
ImageResourceDisplay::~ImageResourceDisplay() {
|
ImageResourceDisplay::~ImageResourceDisplay() {
|
||||||
if(loadThread) {
|
if(loadThread) {
|
||||||
shutdownLoadThread = true;
|
shutdownLoadThread = true;
|
||||||
|
|
|
||||||
|
|
@ -16,6 +16,7 @@ class ImageResourceDisplay : public ResourceDisplay {
|
||||||
virtual float get_dimension_scale() const override;
|
virtual float get_dimension_scale() const override;
|
||||||
virtual Type get_type() const override;
|
virtual Type get_type() const override;
|
||||||
virtual void camera_view_update(const CoordSpaceHelper& compCoords, const SCollision::AABB<WorldScalar>& compAABB, const DrawData& drawData, const SkRect& imRect) override;
|
virtual void camera_view_update(const CoordSpaceHelper& compCoords, const SCollision::AABB<WorldScalar>& compAABB, const DrawData& drawData, const SkRect& imRect) override;
|
||||||
|
virtual void clear_cache() override;
|
||||||
virtual ~ImageResourceDisplay() override;
|
virtual ~ImageResourceDisplay() override;
|
||||||
|
|
||||||
static int IMAGE_LOAD_THREAD_COUNT_MAX;
|
static int IMAGE_LOAD_THREAD_COUNT_MAX;
|
||||||
|
|
|
||||||
|
|
@ -3,4 +3,7 @@
|
||||||
void ResourceDisplay::camera_view_update(const CoordSpaceHelper& compCoords, const SCollision::AABB<WorldScalar>& compAABB, const DrawData& drawData, const SkRect& imRect) {
|
void ResourceDisplay::camera_view_update(const CoordSpaceHelper& compCoords, const SCollision::AABB<WorldScalar>& compAABB, const DrawData& drawData, const SkRect& imRect) {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void ResourceDisplay::clear_cache() {
|
||||||
|
}
|
||||||
|
|
||||||
ResourceDisplay::~ResourceDisplay() {}
|
ResourceDisplay::~ResourceDisplay() {}
|
||||||
|
|
|
||||||
|
|
@ -27,5 +27,6 @@ class ResourceDisplay {
|
||||||
virtual float get_dimension_scale() const = 0;
|
virtual float get_dimension_scale() const = 0;
|
||||||
virtual Type get_type() const = 0;
|
virtual Type get_type() const = 0;
|
||||||
virtual void camera_view_update(const CoordSpaceHelper& compCoords, const SCollision::AABB<WorldScalar>& compAABB, const DrawData& drawData, const SkRect& imRect);
|
virtual void camera_view_update(const CoordSpaceHelper& compCoords, const SCollision::AABB<WorldScalar>& compAABB, const DrawData& drawData, const SkRect& imRect);
|
||||||
|
virtual void clear_cache();
|
||||||
virtual ~ResourceDisplay();
|
virtual ~ResourceDisplay();
|
||||||
};
|
};
|
||||||
|
|
|
||||||
|
|
@ -200,3 +200,8 @@ void ResourceManager::save_file(cereal::PortableBinaryOutputArchive& a) const {
|
||||||
});
|
});
|
||||||
a(strippedResources);
|
a(strippedResources);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void ResourceManager::clear_display_cache() {
|
||||||
|
for(auto& [id, display] : displays)
|
||||||
|
display->clear_cache();
|
||||||
|
}
|
||||||
|
|
|
||||||
|
|
@ -33,6 +33,7 @@ class ResourceManager {
|
||||||
const std::vector<NetworkingObjects::NetObjOwnerPtr<ResourceData>>& resource_list();
|
const std::vector<NetworkingObjects::NetObjOwnerPtr<ResourceData>>& resource_list();
|
||||||
float get_resource_retrieval_progress(const NetworkingObjects::NetObjID& id);
|
float get_resource_retrieval_progress(const NetworkingObjects::NetObjID& id);
|
||||||
std::unordered_map<NetworkingObjects::NetObjID, ResourceData> copy_resource_set_to_map(const std::unordered_set<NetworkingObjects::NetObjID>& resourceSet) const;
|
std::unordered_map<NetworkingObjects::NetObjID, ResourceData> copy_resource_set_to_map(const std::unordered_set<NetworkingObjects::NetObjID>& resourceSet) const;
|
||||||
|
void clear_display_cache();
|
||||||
|
|
||||||
void load_file(cereal::PortableBinaryInputArchive& a, VersionNumber version);
|
void load_file(cereal::PortableBinaryInputArchive& a, VersionNumber version);
|
||||||
void save_file(cereal::PortableBinaryOutputArchive& a) const;
|
void save_file(cereal::PortableBinaryOutputArchive& a) const;
|
||||||
|
|
|
||||||
|
|
@ -244,6 +244,10 @@ void World::unfocus_update() {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void World::on_switch_out() {
|
||||||
|
rMan.clear_display_cache();
|
||||||
|
}
|
||||||
|
|
||||||
void World::send_chat_message(const std::string& message) {
|
void World::send_chat_message(const std::string& message) {
|
||||||
if(!clientStillConnecting)
|
if(!clientStillConnecting)
|
||||||
ownClientData->send_chat_message(ownClientData, *this, message);
|
ownClientData->send_chat_message(ownClientData, *this, message);
|
||||||
|
|
|
||||||
|
|
@ -66,6 +66,7 @@ class World {
|
||||||
|
|
||||||
void focus_update();
|
void focus_update();
|
||||||
void unfocus_update();
|
void unfocus_update();
|
||||||
|
void on_switch_out();
|
||||||
|
|
||||||
void draw(SkCanvas* canvas);
|
void draw(SkCanvas* canvas);
|
||||||
void early_destroy();
|
void early_destroy();
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue