Skip to content

Commit

Permalink
Merge pull request #89493 from KoBeWi/just_download_more_ram
Browse files Browse the repository at this point in the history
Fix call queue problems when loading TileSet
  • Loading branch information
akien-mga committed Mar 14, 2024
2 parents 4163fb9 + a85921a commit 0175be8
Show file tree
Hide file tree
Showing 2 changed files with 52 additions and 17 deletions.
61 changes: 44 additions & 17 deletions scene/resources/2d/tile_set.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4981,7 +4981,7 @@ void TileSetAtlasSource::create_tile(const Vector2i p_atlas_coords, const Vector
_create_coords_mapping_cache(p_atlas_coords);
_queue_update_padded_texture();

emit_signal(SNAME("changed"));
_try_emit_changed();
}

void TileSetAtlasSource::remove_tile(Vector2i p_atlas_coords) {
Expand All @@ -5002,7 +5002,7 @@ void TileSetAtlasSource::remove_tile(Vector2i p_atlas_coords) {

_queue_update_padded_texture();

emit_signal(SNAME("changed"));
_try_emit_changed();
}

bool TileSetAtlasSource::has_tile(Vector2i p_atlas_coords) const {
Expand Down Expand Up @@ -5032,7 +5032,7 @@ void TileSetAtlasSource::set_tile_animation_columns(const Vector2i p_atlas_coord
_create_coords_mapping_cache(p_atlas_coords);
_queue_update_padded_texture();

emit_signal(SNAME("changed"));
_try_emit_changed();
}

int TileSetAtlasSource::get_tile_animation_columns(const Vector2i p_atlas_coords) const {
Expand All @@ -5055,7 +5055,7 @@ void TileSetAtlasSource::set_tile_animation_separation(const Vector2i p_atlas_co
_create_coords_mapping_cache(p_atlas_coords);
_queue_update_padded_texture();

emit_signal(SNAME("changed"));
_try_emit_changed();
}

Vector2i TileSetAtlasSource::get_tile_animation_separation(const Vector2i p_atlas_coords) const {
Expand All @@ -5069,7 +5069,7 @@ void TileSetAtlasSource::set_tile_animation_speed(const Vector2i p_atlas_coords,

tiles[p_atlas_coords].animation_speed = p_speed;

emit_signal(SNAME("changed"));
_try_emit_changed();
}

real_t TileSetAtlasSource::get_tile_animation_speed(const Vector2i p_atlas_coords) const {
Expand All @@ -5082,7 +5082,7 @@ void TileSetAtlasSource::set_tile_animation_mode(const Vector2i p_atlas_coords,

tiles[p_atlas_coords].animation_mode = p_mode;

emit_signal(SNAME("changed"));
_try_emit_changed();
}

TileSetAtlasSource::TileAnimationMode TileSetAtlasSource::get_tile_animation_mode(const Vector2i p_atlas_coords) const {
Expand Down Expand Up @@ -5116,7 +5116,7 @@ void TileSetAtlasSource::set_tile_animation_frames_count(const Vector2i p_atlas_

notify_property_list_changed();

emit_signal(SNAME("changed"));
_try_emit_changed();
}

int TileSetAtlasSource::get_tile_animation_frames_count(const Vector2i p_atlas_coords) const {
Expand All @@ -5131,7 +5131,7 @@ void TileSetAtlasSource::set_tile_animation_frame_duration(const Vector2i p_atla

tiles[p_atlas_coords].animation_frames_durations[p_frame_index] = p_duration;

emit_signal(SNAME("changed"));
_try_emit_changed();
}

real_t TileSetAtlasSource::get_tile_animation_frame_duration(const Vector2i p_atlas_coords, int p_frame_index) const {
Expand Down Expand Up @@ -5341,7 +5341,7 @@ void TileSetAtlasSource::move_tile_in_atlas(Vector2i p_atlas_coords, Vector2i p_
_create_coords_mapping_cache(new_atlas_coords);
_queue_update_padded_texture();

emit_signal(SNAME("changed"));
_try_emit_changed();
}

int TileSetAtlasSource::create_alternative_tile(const Vector2i p_atlas_coords, int p_alternative_id_override) {
Expand All @@ -5359,7 +5359,7 @@ int TileSetAtlasSource::create_alternative_tile(const Vector2i p_atlas_coords, i
tiles[p_atlas_coords].alternatives_ids.sort();
_compute_next_alternative_id(p_atlas_coords);

emit_signal(SNAME("changed"));
_try_emit_changed();

return new_alternative_id;
}
Expand All @@ -5375,7 +5375,7 @@ void TileSetAtlasSource::remove_alternative_tile(const Vector2i p_atlas_coords,
tiles[p_atlas_coords].alternatives_ids.erase(p_alternative_tile);
tiles[p_atlas_coords].alternatives_ids.sort();

emit_signal(SNAME("changed"));
_try_emit_changed();
}

void TileSetAtlasSource::set_alternative_tile_id(const Vector2i p_atlas_coords, int p_alternative_tile, int p_new_id) {
Expand All @@ -5393,7 +5393,7 @@ void TileSetAtlasSource::set_alternative_tile_id(const Vector2i p_atlas_coords,
tiles[p_atlas_coords].alternatives_ids.erase(p_alternative_tile);
tiles[p_atlas_coords].alternatives_ids.sort();

emit_signal(SNAME("changed"));
_try_emit_changed();
}

bool TileSetAtlasSource::has_alternative_tile(const Vector2i p_atlas_coords, int p_alternative_tile) const {
Expand Down Expand Up @@ -5427,6 +5427,12 @@ TileData *TileSetAtlasSource::get_tile_data(const Vector2i p_atlas_coords, int p
return tiles[p_atlas_coords].alternatives[p_alternative_tile];
}

void TileSetAtlasSource::_notification(int p_notification) {
if (p_notification == NOTIFICATION_POSTINITIALIZE) {
initializing = false;
}
}

void TileSetAtlasSource::_bind_methods() {
ClassDB::bind_method(D_METHOD("set_texture", "texture"), &TileSetAtlasSource::set_texture);
ClassDB::bind_method(D_METHOD("get_texture"), &TileSetAtlasSource::get_texture);
Expand Down Expand Up @@ -5569,6 +5575,9 @@ void TileSetAtlasSource::_create_coords_mapping_cache(Vector2i p_atlas_coords) {
}

void TileSetAtlasSource::_queue_update_padded_texture() {
if (padded_texture_needs_update) {
return;
}
padded_texture_needs_update = true;
callable_mp(this, &TileSetAtlasSource::_update_padded_texture).call_deferred();
}
Expand Down Expand Up @@ -5677,6 +5686,12 @@ void TileSetAtlasSource::_update_padded_texture() {
emit_changed();
}

void TileSetAtlasSource::_try_emit_changed() {
if (!initializing) {
emit_changed();
}
}

/////////////////////////////// TileSetScenesCollectionSource //////////////////////////////////////

void TileSetScenesCollectionSource::_compute_next_alternative_id() {
Expand All @@ -5685,6 +5700,12 @@ void TileSetScenesCollectionSource::_compute_next_alternative_id() {
};
}

void TileSetScenesCollectionSource::_try_emit_changed() {
if (!initializing) {
emit_changed();
}
}

int TileSetScenesCollectionSource::get_tiles_count() const {
return 1;
}
Expand Down Expand Up @@ -5725,7 +5746,7 @@ int TileSetScenesCollectionSource::create_scene_tile(Ref<PackedScene> p_packed_s
set_scene_tile_scene(new_scene_id, p_packed_scene);
_compute_next_alternative_id();

emit_signal(SNAME("changed"));
_try_emit_changed();

return new_scene_id;
}
Expand All @@ -5745,7 +5766,7 @@ void TileSetScenesCollectionSource::set_scene_tile_id(int p_id, int p_new_id) {
scenes.erase(p_id);
scenes_ids.erase(p_id);

emit_signal(SNAME("changed"));
_try_emit_changed();
}

void TileSetScenesCollectionSource::set_scene_tile_scene(int p_id, Ref<PackedScene> p_packed_scene) {
Expand All @@ -5769,7 +5790,7 @@ void TileSetScenesCollectionSource::set_scene_tile_scene(int p_id, Ref<PackedSce
} else {
scenes[p_id].scene = Ref<PackedScene>();
}
emit_signal(SNAME("changed"));
_try_emit_changed();
}

Ref<PackedScene> TileSetScenesCollectionSource::get_scene_tile_scene(int p_id) const {
Expand All @@ -5782,7 +5803,7 @@ void TileSetScenesCollectionSource::set_scene_tile_display_placeholder(int p_id,

scenes[p_id].display_placeholder = p_display_placeholder;

emit_signal(SNAME("changed"));
_try_emit_changed();
}

bool TileSetScenesCollectionSource::get_scene_tile_display_placeholder(int p_id) const {
Expand All @@ -5795,7 +5816,7 @@ void TileSetScenesCollectionSource::remove_scene_tile(int p_id) {

scenes.erase(p_id);
scenes_ids.erase(p_id);
emit_signal(SNAME("changed"));
_try_emit_changed();
}

int TileSetScenesCollectionSource::get_next_scene_tile_id() const {
Expand Down Expand Up @@ -5854,6 +5875,12 @@ void TileSetScenesCollectionSource::_get_property_list(List<PropertyInfo> *p_lis
}
}

void TileSetScenesCollectionSource::_notification(int p_notification) {
if (p_notification == NOTIFICATION_POSTINITIALIZE) {
initializing = false;
}
}

void TileSetScenesCollectionSource::_bind_methods() {
ClassDB::bind_method(D_METHOD("get_scene_tiles_count"), &TileSetScenesCollectionSource::get_scene_tiles_count);
ClassDB::bind_method(D_METHOD("get_scene_tile_id", "index"), &TileSetScenesCollectionSource::get_scene_tile_id);
Expand Down
8 changes: 8 additions & 0 deletions scene/resources/2d/tile_set.h
Original file line number Diff line number Diff line change
Expand Up @@ -637,6 +637,8 @@ class TileSetAtlasSource : public TileSetSource {
int next_alternative_id = 1;
};

bool initializing = true;

Ref<Texture2D> texture;
Vector2i margins;
Vector2i separation;
Expand All @@ -660,12 +662,14 @@ class TileSetAtlasSource : public TileSetSource {
void _queue_update_padded_texture();
Ref<ImageTexture> _create_padded_image_texture(const Ref<Texture2D> &p_source);
void _update_padded_texture();
void _try_emit_changed();

protected:
bool _set(const StringName &p_name, const Variant &p_value);
bool _get(const StringName &p_name, Variant &r_ret) const;
void _get_property_list(List<PropertyInfo> *p_list) const;

void _notification(int p_notification);
static void _bind_methods();

public:
Expand Down Expand Up @@ -779,13 +783,17 @@ class TileSetScenesCollectionSource : public TileSetSource {
HashMap<int, SceneData> scenes;
int next_scene_id = 1;

bool initializing = true;

void _compute_next_alternative_id();
void _try_emit_changed();

protected:
bool _set(const StringName &p_name, const Variant &p_value);
bool _get(const StringName &p_name, Variant &r_ret) const;
void _get_property_list(List<PropertyInfo> *p_list) const;

void _notification(int p_notification);
static void _bind_methods();

public:
Expand Down

0 comments on commit 0175be8

Please sign in to comment.