-
-
Notifications
You must be signed in to change notification settings - Fork 23.3k
Ensure DPITexture::_update_texture
only gets called once at the end of the frame.
#110588
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Conversation
The usual pattern we use is to defer the update to the end of the frame using Exposing a redundant feature for a small theoretical optimization isn't something we like to do |
For example, If you have 100 icons for your game and you want to update their colors, scale and saturation when the theme changes it will emit changed signal 3 times for each texture instead of just once. All the setters do call |
I think you misunderstood my comment. Our usual pattern is to have an internal setter like this:
This ensures that the expensive parts are only called once per frame regardless of what updates you do. |
Ok I got it now, Thanks for making it clear. |
743db0b
to
700e26a
Compare
DPITexture::update
DPITexture::_update_texture
only gets called once at the end of the frame.
700e26a
to
e598614
Compare
Implemented |
DPITexture::_update_texture
only gets called once at the end of the frame.DPITexture::_update_texture
only gets called once at the end of the frame.
Co-authored-by: Clay John <[email protected]>
e598614
to
253c243
Compare
To test the changes I have made @tool
extends Control
func _ready():
var rect: TextureRect = TextureRect.new()
add_child(rect)
var svg: String = FileAccess.get_file_as_string("res://icon.svg")
var tex: DPITexture = DPITexture.create_from_string(svg)
rect.texture = tex
print("create_from_string(svg)")
print("\"Internal (Texture is updated)\" should print before \"create_from_string(svg)\"")
print()
tex.set_base_scale(0.5)
print("set_base_scale(0.5)")
tex.set_saturation(0.5)
print("set_saturation(0.5)")
tex.force_update_texture()
print("force_update_texture()")
print("\"Internal (Texture is updated)\" should print before \"force_update_texture()\"")
print()
tex.set_base_scale(0.5)
print("set_base_scale(0.5)")
tex.set_saturation(0.5)
print("set_saturation(0.5)")
tex.force_update_texture()
print("force_update_texture()")
print("\"Internal (Texture is updated)\" should not print (ressetting the same values shouldn't update)")
print()
tex.set_base_scale(0.2)
print("set_base_scale(0.2)")
tex.set_saturation(0.2)
print("set_saturation(0.2)")
tex.set_base_scale(4)
print("set_base_scale(4)")
tex.set_base_scale(2)
print("set_base_scale(2)")
tex.set_base_scale(1)
print("set_base_scale(1)")
print("\"Internal (Texture is updated)\" should print after this message (queued)")
await get_tree().process_frame
print()
print("await get_tree().process_frame")
print()
tex.force_update_texture()
print("force_update_texture()")
tex.force_update_texture()
print("force_update_texture()")
print("\"Internal (Texture is updated)\" should not print (already updated)")
|
Changes:
_request_update()
to avoid calling_update_texture()
more than once in a single frame.force_update_texture()
which applies the changes immediately if the texture needs to be updated.