GML [Solved] Help with Performant Minimap

NicoFIDI

Member
Halla everyone,
today i need an advise over optimizing something that runs every frame.
i'm obsessed with make a procedural generated world game,
i have at least 2 world builders working and building a randomized world.
now... in both cases i have the same issue. drawing a dinamic minimap it's way too slow.
i dont know where i'm failing or even if i'm failing
The basic logic is this:
Code:
for (var xx = minimap_left; xx < minimap_left + (minimap_width div zoom); xx++) {
for (var yy = minimap_top; yy < minimap_top + (minimap_height div zoom); yy++) {
    var relX = view_xview + minimap_offset_x + xx*zoom;
    var relY = view_yview + minimap_offset_y + yy*zoom;
   
    var color = c_black;
    switch(obj_config_map.actualMap[# xx,yy]) {
        case cell_type.water: color = c_aqua; break;
        case cell_type.grass: color = c_green; break;
        case cell_type.mountain: color = c_brown; break;
    }
   
    draw_sprite_ext(spr_whitePixel, 0,relX,relY,zoom,zoom,0,color,.5);
}
}
 

Simon Gust

Member
first, draw_sprite_ext is slower than draw_point_color.
second, don't make a switch, make a LUT
thrid, relX can be defined before the second for loop
fourth use surfaces
fifth, you don't have to update the whole map every step, only update new stuff. when you move in a direction, just shift the old area and add strips of new area.
 

NicoFIDI

Member
--first, draw_sprite_ext is slower than draw_point_color.
but in this case i should call it zoom^2 times to cover the same area than the draw_sprite_ext
that's still more performant?

--thrid, relX can be defined before the second for loop
easy to fix :p

--fourth use surfaces
one research behing this solution.

--fifth, you don't have to update the whole map every step, only update new stuff. when you move in a direction, just shift the old area and add strips of new area.
but how i whould draw it every step without runing this code? .-.
 

Simon Gust

Member
If you use surfaces you can leave the zoom and the view following for the surface when drawing it.

Code:
surface_set_target(minimap);
var minimap_wdt = minimap_width * zoom;
var minimap_hgt = minimap_height * zoom;
for (var xx = 0; xx < minimap_wdt; xx++) {
for (var yy = 0; yy < minimap_hgt; yy++) {  
   var color = c_black;
   switch(obj_config_map.actualMap[# xx,yy]) {
       case cell_type.water: color = c_aqua; break;
       case cell_type.grass: color = c_green; break;
       case cell_type.mountain: color = c_brown; break;
   }
   draw_point_colour(xx, yy, color);
}
}
surface_reset_target();

draw_surface_part_ext();
Something like this is what I wanted to suggest.
Most zoom settings can be decided inside draw_surface_part_ext().
 
Top