Added clear().

This commit is contained in:
Relintai 2019-10-21 23:04:11 +02:00
parent 9718212b9d
commit fe6c61d22d
2 changed files with 24 additions and 12 deletions

View File

@ -131,6 +131,27 @@ int TexturePacker::get_texture_count() {
return _rects.size(); 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<ImageTexture> TexturePacker::get_generated_texture(int index) { Ref<ImageTexture> TexturePacker::get_generated_texture(int index) {
ERR_FAIL_INDEX_V(index, _generated_textures.size(), Ref<ImageTexture>()); ERR_FAIL_INDEX_V(index, _generated_textures.size(), Ref<ImageTexture>());
@ -226,18 +247,7 @@ TexturePacker::TexturePacker() {
} }
TexturePacker::~TexturePacker() { TexturePacker::~TexturePacker() {
_bins.clear(); 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();
} }
void TexturePacker::_bind_methods() { 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_index", "index"), &TexturePacker::remove_texture_index);
ClassDB::bind_method(D_METHOD("remove_texture", "texture"), &TexturePacker::remove_texture); 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("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", "index"), &TexturePacker::get_generated_texture);
ClassDB::bind_method(D_METHOD("get_generated_texture_count"), &TexturePacker::get_generated_texture_count); ClassDB::bind_method(D_METHOD("get_generated_texture_count"), &TexturePacker::get_generated_texture_count);

View File

@ -29,6 +29,7 @@ public:
void remove_texture_index(int index); void remove_texture_index(int index);
void remove_texture(Ref<Texture> texture); void remove_texture(Ref<Texture> texture);
int get_texture_count(); int get_texture_count();
void clear();
Ref<ImageTexture> get_generated_texture(int index); Ref<ImageTexture> get_generated_texture(int index);
int get_generated_texture_count(); int get_generated_texture_count();