• Hey Guest! Ever feel like entering a Game Jam, but the time limit is always too much pressure? We get it... You lead a hectic life and dedicating 3 whole days to make a game just doesn't work for you! So, why not enter the GMC SLOW JAM? Take your time! Kick back and make your game over 4 months! Interested? Then just click here!

type writer text performance

zampa

Member
I have textbox object that spells the text with a type writer effect, it works as intended but when i launch debug mode and start profiling it shows me that it is taking up of 60% of the step, the draw_text event in particular seems the worst offender, it this normal or am i doing something wrong
Code:
while(curr_char < max_char){
            char_list_len = ds_list_size(char_list);
            max_char = clamp(max_char,0,char_list_len);
          
            var next_modulo_pos = ds_grid_get(modulo_grid,mods_num,4) - 1;
            if(next_modulo_pos == curr_char){
                var what_mod = ds_grid_get(modulo_grid,mods_num,0);
                if(what_mod == "#"){
                    line++;
                    text_x_space = 0;
                    mods_num++;
                }
                else{
                    text_size = ds_grid_get(modulo_grid,mods_num,0);
                    text_color = ds_grid_get(modulo_grid,mods_num,1);
                    text_speed = ds_grid_get(modulo_grid,mods_num,2);
                    text_effect = ds_grid_get(modulo_grid,mods_num,3);
                    mods_num++;
                }
            }
            #region // apply effect
            switch(text_size){
                case(fnt_txt_small):
                    var txt_offset_y = font_get_size(text_size)/2;
                break;
                case(fnt_txt_normal):
                    var txt_offset_y = 0;
                break;
                case(fnt_txt_big):
                    var txt_offset_y = -font_get_size(text_size)/2;
                break;
            }
            switch(text_effect){
                case(0):
                    var extra_x = 0;
                    var extra_y = 0;
                break;
                case(1):
                    var extra_x = random_range(-0.5,0.5);
                    var extra_y = random_range(-0.5,0.5);
                break;
                case(2):
                    var extra_x = random_range(-1,1);
                    var extra_y = random_range(-1,1);
                break;
                case(3):
                    var extra_x = 0;
                    extra_y = 8*sin(wavy_angle+wavy_chars*0.5);
                    wavy_chars++;
                break;
            }
            #endregion
          
            var char = ds_list_find_value(char_list,curr_char);
            draw_set_font(text_size);
            draw_set_color(text_color);
            text_y_space = txt_offset_y + line * 30;
            draw_text(text_offset_x+text_x_space+extra_x,text_offset_y+text_y_space+extra_y,char);
            text_x_space = font_get_size(text_size) + text_x_space;
            draw_set_color(c_white);
            draw_set_font(fnt_txt_normal);
            curr_char++;
          
            if(wavy_chars == 1){
                wavy_angle+=0.1;
                if(wavy_angle == 360) wavy_angle = 0;
            }
        }
 

TsukaYuriko

☄️
Forum Staff
Moderator
What are you checking that performance against? If there isn't much else you're doing, then of course the only thing that's running will take up the majority... because it is the only thing running.

That aside, drawing text is essentially drawing one frame of a sprite per character, so if you're drawing a lot of text, the draw calls resulting from that can end up in the hundreds. That's not a problem unless this is actually draining your game's performance, though.
 

zampa

Member
You are right givving a percentage isn't a good way to explain my problem, i checked te game performance before and after a textbox appears and the averege fps went from 3000+ to 1000+ (this example i achived with a textbox filled with text) i know it may sound stupid to complain about it, but i fear that as i keep adding stuff the performance is going to get worse and worse, so i ask is this an expected performance drop?
 
W

Wigfrid

Guest
Do NOT draw_text per character! Instead, make a string variable and then draw that instead. Edit it as you go to make 'typewriter' effects.
 

zampa

Member
Do NOT draw_text per character! Instead, make a string variable and then draw that instead. Edit it as you go to make 'typewriter' effects.
I know, but if you do that you will not be able to add effects, such as different color text, shaky text, sine wave text ecc....
 

TsukaYuriko

☄️
Forum Staff
Moderator
You are right givving a percentage isn't a good way to explain my problem, i checked te game performance before and after a textbox appears and the averege fps went from 3000+ to 1000+ (this example i achived with a textbox filled with text) i know it may sound stupid to complain about it, but i fear that as i keep adding stuff the performance is going to get worse and worse, so i ask is this an expected performance drop?
Theoretical FPS is exponential. The difference between 3000 and 1000 theoretical FPS is probably smaller than the difference between 65 and 60 FPS. It's just an indicator how much more you can do before your game starts lagging, and this number will rise and fall exponentially according to how many times more than what you're currently doing you can theoretical do before you drop below your target frame rate.
 

GMWolf

aka fel666
Look at your performance in term of frame time, not FPS.

Let's have a look :
3000fps means each frame is 1/3000 seconds.
1000fps means each frame is 1/1000 seconds.

So drawing the text used (1/1000)-(1/3000) seconds. That's 0.000667.

If your target is 60 FPS, then you have a whole 1/60, or 0.016 seconds.

That means you could draw that text 24 times before you start lagging.


Depending on what else is going on, that could be fine.
But if you really want to get better performance, then grouping as many letters as possible into single draw calls will help.
GM will do some of that for you, as long as you don't change things like draw colour or colour..

So only change those if they are different from the previous character and you should see an improvement.

If you want more performance still, then, group letters with the same colour, etc, into the same draw call.
 

zampa

Member
Look at your performance in term of frame time, not FPS.

Let's have a look :
3000fps means each frame is 1/3000 seconds.
1000fps means each frame is 1/1000 seconds.

So drawing the text used (1/1000)-(1/3000) seconds. That's 0.000667.

If your target is 60 FPS, then you have a whole 1/60, or 0.016 seconds.

That means you could draw that text 24 times before you start lagging.


Depending on what else is going on, that could be fine.
But if you really want to get better performance, then grouping as many letters as possible into single draw calls will help.
GM will do some of that for you, as long as you don't change things like draw colour or colour..

So only change those if they are different from the previous character and you should see an improvement.

If you want more performance still, then, group letters with the same colour, etc, into the same draw call.
Thanks man that made it clear for me :)
 
Top