Merge pull request #89493 from KoBeWi/just_download_more_ram

Fix call queue problems when loading TileSet
This commit is contained in:
Rémi Verschelde 2024-03-14 22:35:45 +01:00
commit 0175be8948
No known key found for this signature in database
GPG Key ID: C3336907360768E1
2 changed files with 52 additions and 17 deletions

View File

@ -4981,7 +4981,7 @@ void TileSetAtlasSource::create_tile(const Vector2i p_atlas_coords, const Vector
_create_coords_mapping_cache(p_atlas_coords); _create_coords_mapping_cache(p_atlas_coords);
_queue_update_padded_texture(); _queue_update_padded_texture();
emit_signal(SNAME("changed")); _try_emit_changed();
} }
void TileSetAtlasSource::remove_tile(Vector2i p_atlas_coords) { void TileSetAtlasSource::remove_tile(Vector2i p_atlas_coords) {
@ -5002,7 +5002,7 @@ void TileSetAtlasSource::remove_tile(Vector2i p_atlas_coords) {
_queue_update_padded_texture(); _queue_update_padded_texture();
emit_signal(SNAME("changed")); _try_emit_changed();
} }
bool TileSetAtlasSource::has_tile(Vector2i p_atlas_coords) const { bool TileSetAtlasSource::has_tile(Vector2i p_atlas_coords) const {
@ -5032,7 +5032,7 @@ void TileSetAtlasSource::set_tile_animation_columns(const Vector2i p_atlas_coord
_create_coords_mapping_cache(p_atlas_coords); _create_coords_mapping_cache(p_atlas_coords);
_queue_update_padded_texture(); _queue_update_padded_texture();
emit_signal(SNAME("changed")); _try_emit_changed();
} }
int TileSetAtlasSource::get_tile_animation_columns(const Vector2i p_atlas_coords) const { int TileSetAtlasSource::get_tile_animation_columns(const Vector2i p_atlas_coords) const {
@ -5055,7 +5055,7 @@ void TileSetAtlasSource::set_tile_animation_separation(const Vector2i p_atlas_co
_create_coords_mapping_cache(p_atlas_coords); _create_coords_mapping_cache(p_atlas_coords);
_queue_update_padded_texture(); _queue_update_padded_texture();
emit_signal(SNAME("changed")); _try_emit_changed();
} }
Vector2i TileSetAtlasSource::get_tile_animation_separation(const Vector2i p_atlas_coords) const { Vector2i TileSetAtlasSource::get_tile_animation_separation(const Vector2i p_atlas_coords) const {
@ -5069,7 +5069,7 @@ void TileSetAtlasSource::set_tile_animation_speed(const Vector2i p_atlas_coords,
tiles[p_atlas_coords].animation_speed = p_speed; 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 { real_t TileSetAtlasSource::get_tile_animation_speed(const Vector2i p_atlas_coords) const {
@ -5082,7 +5082,7 @@ void TileSetAtlasSource::set_tile_animation_mode(const Vector2i p_atlas_coords,
tiles[p_atlas_coords].animation_mode = p_mode; 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 { TileSetAtlasSource::TileAnimationMode TileSetAtlasSource::get_tile_animation_mode(const Vector2i p_atlas_coords) const {
@ -5116,7 +5116,7 @@ void TileSetAtlasSource::set_tile_animation_frames_count(const Vector2i p_atlas_
notify_property_list_changed(); notify_property_list_changed();
emit_signal(SNAME("changed")); _try_emit_changed();
} }
int TileSetAtlasSource::get_tile_animation_frames_count(const Vector2i p_atlas_coords) const { int TileSetAtlasSource::get_tile_animation_frames_count(const Vector2i p_atlas_coords) const {
@ -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; 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 { real_t TileSetAtlasSource::get_tile_animation_frame_duration(const Vector2i p_atlas_coords, int p_frame_index) const {
@ -5341,7 +5341,7 @@ void TileSetAtlasSource::move_tile_in_atlas(Vector2i p_atlas_coords, Vector2i p_
_create_coords_mapping_cache(new_atlas_coords); _create_coords_mapping_cache(new_atlas_coords);
_queue_update_padded_texture(); _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) { int TileSetAtlasSource::create_alternative_tile(const Vector2i p_atlas_coords, int p_alternative_id_override) {
@ -5359,7 +5359,7 @@ int TileSetAtlasSource::create_alternative_tile(const Vector2i p_atlas_coords, i
tiles[p_atlas_coords].alternatives_ids.sort(); tiles[p_atlas_coords].alternatives_ids.sort();
_compute_next_alternative_id(p_atlas_coords); _compute_next_alternative_id(p_atlas_coords);
emit_signal(SNAME("changed")); _try_emit_changed();
return new_alternative_id; return new_alternative_id;
} }
@ -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.erase(p_alternative_tile);
tiles[p_atlas_coords].alternatives_ids.sort(); 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) { void TileSetAtlasSource::set_alternative_tile_id(const Vector2i p_atlas_coords, int p_alternative_tile, int p_new_id) {
@ -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.erase(p_alternative_tile);
tiles[p_atlas_coords].alternatives_ids.sort(); 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 { bool TileSetAtlasSource::has_alternative_tile(const Vector2i p_atlas_coords, int p_alternative_tile) const {
@ -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]; 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() { void TileSetAtlasSource::_bind_methods() {
ClassDB::bind_method(D_METHOD("set_texture", "texture"), &TileSetAtlasSource::set_texture); ClassDB::bind_method(D_METHOD("set_texture", "texture"), &TileSetAtlasSource::set_texture);
ClassDB::bind_method(D_METHOD("get_texture"), &TileSetAtlasSource::get_texture); ClassDB::bind_method(D_METHOD("get_texture"), &TileSetAtlasSource::get_texture);
@ -5569,6 +5575,9 @@ void TileSetAtlasSource::_create_coords_mapping_cache(Vector2i p_atlas_coords) {
} }
void TileSetAtlasSource::_queue_update_padded_texture() { void TileSetAtlasSource::_queue_update_padded_texture() {
if (padded_texture_needs_update) {
return;
}
padded_texture_needs_update = true; padded_texture_needs_update = true;
callable_mp(this, &TileSetAtlasSource::_update_padded_texture).call_deferred(); callable_mp(this, &TileSetAtlasSource::_update_padded_texture).call_deferred();
} }
@ -5677,6 +5686,12 @@ void TileSetAtlasSource::_update_padded_texture() {
emit_changed(); emit_changed();
} }
void TileSetAtlasSource::_try_emit_changed() {
if (!initializing) {
emit_changed();
}
}
/////////////////////////////// TileSetScenesCollectionSource ////////////////////////////////////// /////////////////////////////// TileSetScenesCollectionSource //////////////////////////////////////
void TileSetScenesCollectionSource::_compute_next_alternative_id() { void TileSetScenesCollectionSource::_compute_next_alternative_id() {
@ -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 { int TileSetScenesCollectionSource::get_tiles_count() const {
return 1; return 1;
} }
@ -5725,7 +5746,7 @@ int TileSetScenesCollectionSource::create_scene_tile(Ref<PackedScene> p_packed_s
set_scene_tile_scene(new_scene_id, p_packed_scene); set_scene_tile_scene(new_scene_id, p_packed_scene);
_compute_next_alternative_id(); _compute_next_alternative_id();
emit_signal(SNAME("changed")); _try_emit_changed();
return new_scene_id; return new_scene_id;
} }
@ -5745,7 +5766,7 @@ void TileSetScenesCollectionSource::set_scene_tile_id(int p_id, int p_new_id) {
scenes.erase(p_id); scenes.erase(p_id);
scenes_ids.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) { void TileSetScenesCollectionSource::set_scene_tile_scene(int p_id, Ref<PackedScene> p_packed_scene) {
@ -5769,7 +5790,7 @@ void TileSetScenesCollectionSource::set_scene_tile_scene(int p_id, Ref<PackedSce
} else { } else {
scenes[p_id].scene = Ref<PackedScene>(); scenes[p_id].scene = Ref<PackedScene>();
} }
emit_signal(SNAME("changed")); _try_emit_changed();
} }
Ref<PackedScene> TileSetScenesCollectionSource::get_scene_tile_scene(int p_id) const { Ref<PackedScene> TileSetScenesCollectionSource::get_scene_tile_scene(int p_id) const {
@ -5782,7 +5803,7 @@ void TileSetScenesCollectionSource::set_scene_tile_display_placeholder(int p_id,
scenes[p_id].display_placeholder = p_display_placeholder; 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 { bool TileSetScenesCollectionSource::get_scene_tile_display_placeholder(int p_id) const {
@ -5795,7 +5816,7 @@ void TileSetScenesCollectionSource::remove_scene_tile(int p_id) {
scenes.erase(p_id); scenes.erase(p_id);
scenes_ids.erase(p_id); scenes_ids.erase(p_id);
emit_signal(SNAME("changed")); _try_emit_changed();
} }
int TileSetScenesCollectionSource::get_next_scene_tile_id() const { int TileSetScenesCollectionSource::get_next_scene_tile_id() const {
@ -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() { 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_tiles_count"), &TileSetScenesCollectionSource::get_scene_tiles_count);
ClassDB::bind_method(D_METHOD("get_scene_tile_id", "index"), &TileSetScenesCollectionSource::get_scene_tile_id); ClassDB::bind_method(D_METHOD("get_scene_tile_id", "index"), &TileSetScenesCollectionSource::get_scene_tile_id);

View File

@ -637,6 +637,8 @@ private:
int next_alternative_id = 1; int next_alternative_id = 1;
}; };
bool initializing = true;
Ref<Texture2D> texture; Ref<Texture2D> texture;
Vector2i margins; Vector2i margins;
Vector2i separation; Vector2i separation;
@ -660,12 +662,14 @@ private:
void _queue_update_padded_texture(); void _queue_update_padded_texture();
Ref<ImageTexture> _create_padded_image_texture(const Ref<Texture2D> &p_source); Ref<ImageTexture> _create_padded_image_texture(const Ref<Texture2D> &p_source);
void _update_padded_texture(); void _update_padded_texture();
void _try_emit_changed();
protected: protected:
bool _set(const StringName &p_name, const Variant &p_value); bool _set(const StringName &p_name, const Variant &p_value);
bool _get(const StringName &p_name, Variant &r_ret) const; bool _get(const StringName &p_name, Variant &r_ret) const;
void _get_property_list(List<PropertyInfo> *p_list) const; void _get_property_list(List<PropertyInfo> *p_list) const;
void _notification(int p_notification);
static void _bind_methods(); static void _bind_methods();
public: public:
@ -779,13 +783,17 @@ private:
HashMap<int, SceneData> scenes; HashMap<int, SceneData> scenes;
int next_scene_id = 1; int next_scene_id = 1;
bool initializing = true;
void _compute_next_alternative_id(); void _compute_next_alternative_id();
void _try_emit_changed();
protected: protected:
bool _set(const StringName &p_name, const Variant &p_value); bool _set(const StringName &p_name, const Variant &p_value);
bool _get(const StringName &p_name, Variant &r_ret) const; bool _get(const StringName &p_name, Variant &r_ret) const;
void _get_property_list(List<PropertyInfo> *p_list) const; void _get_property_list(List<PropertyInfo> *p_list) const;
void _notification(int p_notification);
static void _bind_methods(); static void _bind_methods();
public: public: