I find it easier with an alarm. When I'm generating my map, I set a few things up in the Create Event:
Code:
loading = true;
load_step = 0;
load_string = "Picking island coastal points";
alarm[0] = 1;
This first alarm timer allows me to draw something on the screen before the load starts. Since you only need one step between any loop you have that is taking time, do not make the "timer" larger than 1, otherwise you are literally adding time to the load for no reason. Then in alarm[0], I setup a switch statement which determines what part of the load should be being run each step. Alarm[0]:
Code:
switch (load_step) {
case 0:
ds_list_clear(coastal_points_list);
ds_queue_clear(fill_queue);
load_string = "Smoothing island coastal points";
etc...
break;
case 1:
load_string = "Connecting island coastal points";
etc...
break;
}
load_step++;
alarm[0] = 1;
This make it so that on the first step, it executes all the code within the first case statement. Then on the next step, since load_step is increased by 1, it executes all the code within the second case statement and so on. I have my final case statement change the room to whatever the room is after I have finished loading (room_goto(rm_village) in my particular case). Finally, I have in the Draw GUI Event:
Code:
if (loading) {
var gw = display_get_gui_width();
var gh = display_get_gui_height();
draw_set_color(c_black);
draw_rectangle(0,0,gw,gh,false);
draw_set_color(c_white);
var load_dots = load_step;
load_dots = load_dots mod 4;
var str = load_string;
repeat(load_dots) {
str += ".";
}
var str_w = string_width(str)/2;
draw_set_halign(fa_left);
draw_set_font(fnt_menu_normal);
draw_text(gw/2-str_w,gh/2,str);
}
This just covers the screen with a black rectangle (to hide any funny business going on that I might not want to be seen) and draws load_string in the middle of the screen, adding dots "." each step so that there is visible movement on the screen to confirm to the user that the load hasn't frozen. Unfortunately, since we don't have access to multithreading in GMS, it will still freeze while it is executing a particularly long loop (for instance, my height_map smoothing and cellular automata for forest growth both take a second or so to execute) but that is the best we are going to get in GMS right now.