#Performance lag - Font property changes at runtime.

3 messages · Page 1 of 1 (latest)

rugged dew
#

Update: Async calls were implemented! Questions below.

I'm working on a game template project where you can change a font's face and size. Whenever I make changes, however, the game locks up while processing the changes. I'm trying to mitigate this locking up by making this happen asynchronously. I tried creating just one thread to handle in the background, but the lag persisted. I went so far as the code below where I create a unique thread for each node type in my theme! But even that didn't improve performance. How can I adjust font size without getting this laggy lock-up issue I'm experiencing?

If you want to see the full project for context, you can take a look here: https://github.com/programnoir/GDTemplate/pull/19 But the code below gives the essential parts.

#  Above this code are the basic parts of setting up an array of null values so they can have threads created on them later.
func set_font_size_threaded( type: String, new_size: int ) -> void:
    theme.set_font_size( "font_size", type, new_size )


func set_font_size( new_size: int ) -> void:
    var i: int = 0
    for type in theme.get_type_list():
        if( thread_font_size_array[ i ] != null ):
            thread_font_size_array[ i ].wait_to_finish()
        thread_font_size_array[ i ] = Thread.new()
        thread_font_size_array[ i ].start( set_font_size_threaded.bind(
                type, new_size ) )
rugged dew
#

One thing that does improve performance is editing the number of items in my theme. I've got it reduced to just the stuff that I use the most often, but it still causes a lot of lag.

rugged dew
#

Got it! Threads were probably a good idea? But coroutines using timers per task did the job.

func set_font_size( new_size: int ) -> void:
    var i: int = 0
    for type in theme.get_type_list():
        var timer: SceneTreeTimer
        if( thread_font_size_array[ i ] != null ):
            thread_font_size_array[ i ].wait_to_finish()
        thread_font_size_array[ i ] = Thread.new()
        timer = get_tree().create_timer( 0.1 ) 
        thread_font_size_array[ i ].start( set_font_size_threaded.bind(
                type, new_size ) )
        await timer.timeout