You are not logged in.
Pages: 1
There is a function for copying a regular grid, but it is not suitable for mp_grid.
///@function mp_grid_copy(id,source);
///@description Copies one mp_grid to another mp_grid
///@param {real} id object_index
///@param {real} source object_index
{
var my_mp_grid_id=argument[0];
var other_mp_grid_id=argument[1];
mp_grid_clear_all(my_mp_grid_id);
for (var ix = 0; ix <= room_width; ix++;)
{
for (var iy = 0; iy <= room_height; iy++;)
{
if mp_grid_get_cell(other_mp_grid_id, ix , iy)=-1 mp_grid_add_cell(my_mp_grid_id, ix , iy);
}
}
}
Last edited by Kosta (2019-08-07 14:26:02)
Offline
Oh, interesting. This is a good idea for a script. It is a shame GML doesn't provide the tools to make it more elegant.
That said, I think this can be optimized quite a bit by measuring the destination mp_grid before copying to it. After it is cleared, it can be scanned along each axis, checking for -1, to determine its dimensions. With that known, we don't waste a lot of unnecessary effort scanning every pixel of the entire room (which might not even by the right room or size).
Beyond that (and some style changes), I would remove any reference to `object_index` from the comments because it doesn't apply in any way here.
Thanks for the script and welcome to the forums.
Abusing forum power since 1986.
Offline
Thanks for the welcome!
The size of the grid "from the room size" did not come out intentionally for me - this was relevant only for my situation (now I understand that it was worth passing the dimensions of the grid to the function from the outside, and not expect everyone to have the same room size).
Using it, I came to the conclusion that it is not optimized enough - its execution for large mp_grids (the size of a room) takes too long.
Therefore, today I would recommend using it only for small grids.
I took a different path: I entered the coordinates information into the ds_list, and then created a filled cell in these coordinates (in mp_grid). All this turned out to be not universal, so I do not send another function.
Thanks for your site!
Offline
Pages: 1