From fe6c61d22dea001ee9652446fd8488cea4659d90 Mon Sep 17 00:00:00 2001 From: Relintai Date: Mon, 21 Oct 2019 23:04:11 +0200 Subject: [PATCH] Added clear(). --- texture_packer.cpp | 35 +++++++++++++++++++++++------------ texture_packer.h | 1 + 2 files changed, 24 insertions(+), 12 deletions(-) diff --git a/texture_packer.cpp b/texture_packer.cpp index 345131a..c7798b9 100644 --- a/texture_packer.cpp +++ b/texture_packer.cpp @@ -131,6 +131,27 @@ int TexturePacker::get_texture_count() { return _rects.size(); } +void TexturePacker::clear() { + _bins.clear(); + + for (int i = 0; i < _rects.size(); ++i) { + rect_xywhf *r = _rects.get(i); + + r->atlas_texture.unref(); + r->original_texture.unref(); + + memdelete(r); + } + + _rects.clear(); + + for (int i = 0; i < _generated_textures.size(); ++i) { + _generated_textures.get(i).unref(); + } + + _generated_textures.clear(); +} + Ref TexturePacker::get_generated_texture(int index) { ERR_FAIL_INDEX_V(index, _generated_textures.size(), Ref()); @@ -226,18 +247,7 @@ TexturePacker::TexturePacker() { } TexturePacker::~TexturePacker() { - _bins.clear(); - - for (int i = 0; i < _rects.size(); ++i) { - rect_xywhf *r = _rects.get(i); - - r->atlas_texture.unref(); - r->original_texture.unref(); - - memdelete(r); - } - - _rects.clear(); + clear(); } void TexturePacker::_bind_methods() { @@ -259,6 +269,7 @@ void TexturePacker::_bind_methods() { ClassDB::bind_method(D_METHOD("remove_texture_index", "index"), &TexturePacker::remove_texture_index); ClassDB::bind_method(D_METHOD("remove_texture", "texture"), &TexturePacker::remove_texture); ClassDB::bind_method(D_METHOD("get_texture_count"), &TexturePacker::get_texture_count); + ClassDB::bind_method(D_METHOD("clear"), &TexturePacker::clear); ClassDB::bind_method(D_METHOD("get_generated_texture", "index"), &TexturePacker::get_generated_texture); ClassDB::bind_method(D_METHOD("get_generated_texture_count"), &TexturePacker::get_generated_texture_count); diff --git a/texture_packer.h b/texture_packer.h index e599182..3ca6778 100644 --- a/texture_packer.h +++ b/texture_packer.h @@ -29,6 +29,7 @@ public: void remove_texture_index(int index); void remove_texture(Ref texture); int get_texture_count(); + void clear(); Ref get_generated_texture(int index); int get_generated_texture_count();