Simon Gust
Member
GM Version: GM:S
Target Platform: All
Download: N/A
Links: N/A
Summary:
I made a script that allows you to auto-tile with 47 images but it only works with "tiles" or more precisely a grid system using an array.
Tutorial:
The algorithm is use in this script is similar to the bitwise tiling system except it doesn't count or anything.
around and noticed that say 8 calculations (1 for every direction) takes longer than, on average, 6 if-statements.
so let's begin:
first we must understand how the bitwise calcs work:
the brown colour represents dirt and the green colour grass.
when we check our tile or in this image "0". we can have 8 other tiles surrounding it.
If there is a tile below, add 1 to the total count etc.
at the end our sum can go from 0 to 255, which is more than 46 (47 but indexes start at 0).
In the bitwise autotiler, the numbers that are faulty are just changed manually.
Here though we don't have to do that.
Code:
what we do is checking if the tile on whatever direction is NOT our own.
Using != instead of == is faster in this situation.
How it works:
first it checks below, if that tile is not one of ours then go ahead, next tile
right? not our tile, go on
above? yes this a tile we possess, let's else this up.
now we are at 1-2-8
we can see that 16 and 32 are no options anymore which saves time on average.
and so on...
Other stuff:
global.tiles represents my array which is filled with all tiles and potential collision.
On the side where we call this script from is just an iteration of our array with double for loops:
And here just the tileset for this to work properly:
!You may use it as reference!
If you have optimizations, complaints or questions post them here =]
Edit: Did some tests with comparing windows to yyc and this algorythm against the bitwise one
//>
x47 win (my) 1370ms 1380ms 1387ms
x47 win (bit) 2125ms 2136ms 2121ms
x47 yyc (my) 502ms 494ms 485ms
x47 yyc (bit) 657ms 676ms 686ms
//>
//>
x16 win (my) 1220ms 1216ms 1222ms
x16 win (bit) 1473ms 1462ms 1464ms
x16 yyc (my) 423ms 426ms 425ms
x16 yyc (bit) 439ms 430ms 442ms
//>
Target Platform: All
Download: N/A
Links: N/A
Summary:
I made a script that allows you to auto-tile with 47 images but it only works with "tiles" or more precisely a grid system using an array.
Tutorial:
The algorithm is use in this script is similar to the bitwise tiling system except it doesn't count or anything.
around and noticed that say 8 calculations (1 for every direction) takes longer than, on average, 6 if-statements.
so let's begin:
first we must understand how the bitwise calcs work:
the brown colour represents dirt and the green colour grass.
when we check our tile or in this image "0". we can have 8 other tiles surrounding it.
If there is a tile below, add 1 to the total count etc.
at the end our sum can go from 0 to 255, which is more than 46 (47 but indexes start at 0).
In the bitwise autotiler, the numbers that are faulty are just changed manually.
Here though we don't have to do that.
Code:
Code:
///scr_get_index(array, tile, x, y)
var array = argument0; // the array to check on
var tile = argument1; // The tile type to check for
var xx = argument2; // x of the tile
var yy = argument3; // y of the tile
// directional shortcuts
var lft = xx - 1;
var top = yy - 1;
var rgt = xx + 1;
var bot = yy + 1;
//1+
if (array[@ xx, bot] != tile)
{
//1-2+
if (array[@ rgt, yy] != tile)
{
//1-2-4+
if (array[@ xx, top] != tile)
{
//1-2-4-8
if (array[@ lft, yy] != tile)
{
return (15);
}
else return (7);
}
else
{
//1-2-8
if (array[@ lft, yy] != tile)
{
return (11);
}
else
{
//1-2-64
if (array[@ lft, top] != tile)
{
return (27);
}
else return (3);
}
}
}
else
{
//1-4+
if (array[@ xx, top] != tile)
{
//1-4-8
if (array[@ lft, yy] != tile)
{
return (13);
}
else return (5);
}
else
{
//1-8+
if (array[@ lft, yy] != tile)
{
//1-8-32
if (array[@ rgt, top] != tile)
{
return (23);
}
else return (9);
}
else
{
//1-32
if (array[@ rgt, top] != tile)
{
//1-32-64
if (array[@ lft, top] != tile)
{
return (43);
}
else return (21);
}
else
{
//1-64
if (array[@ lft, top] != tile)
{
return (25);
}
else return (1);
}
}
}
}
}
else
{
//2+
if (array[@ rgt, yy] != tile)
{
//2-4
if (array[@ xx, top] != tile)
{
//2-4-8
if (array[@ lft, yy] != tile)
{
return (14);
}
else
{
//2-4-128
if (array[@ lft, bot] != tile)
{
return (31);
}
else return (6);
}
}
else
{
//2-8
if (array[@ lft, yy] != tile)
{
return (10);
}
else
{
//2-64
if (array[@ lft, top] != tile)
{
//2-64-128
if (array[@ lft, bot] != tile)
{
return (44);
}
else return (26);
}
else
{
//2-128
if (array[@ lft, bot] != tile)
{
return (29);
}
else return (2);
}
}
}
}
else
{
//4+
if (array[@ xx, top] != tile)
{
//4-8
if (array[@ lft, yy] != tile)
{
//4-8-16
if (array[@ rgt, bot] != tile)
{
return (18);
}
else return (12);
}
else
{
//4-16
if (array[@ rgt, bot] != tile)
{
//4-16-128
if (array[@ lft, bot] != tile)
{
return (37);
}
else return (17);
}
else
{
//4-128
if (array[@ lft, bot] != tile)
{
return (30);
}
else return (4);
}
}
}
else
{
//8+
if (array[@ lft, yy] != tile)
{
//8-16
if (array[@ rgt, bot] != tile)
{
//8-16-32
if (array[@ rgt, top] != tile)
{
return (33);
}
else return (19);
}
else
{
//8-32)
if (array[@ rgt, top] != tile)
{
return (22);
}
else return (8);
}
}
//ONLY CORNERS
else
{
//16+
if (array[@ rgt, bot] != tile)
{
//16-32
if (array[@ rgt, top] != tile)
{
//16-32-64
if (array[@ lft, top] != tile)
{
//16-32-64-128
if (array[@ lft, bot] != tile)
{
return (39);
}
else return (35);
}
else
{
//16-32-128
if (array[@ lft, bot] != tile)
{
return (42);
}
else return (32);
}
}
else
{
//16-64
if (array[@ lft, top] != tile)
{
//16-64-128
if (array[@ lft, bot] != tile)
{
return (41);
}
else return (34);
}
else
{
//16-128
if (array[@ lft, bot] != tile)
{
return (36);
}
else return (16);
}
}
}
else
{
//32+
if (array[@ rgt, top] != tile)
{
//32-64
if (array[@ lft, top] != tile)
{
//32-64-128
if (array[@ lft, bot] != tile)
{
return (40);
}
else return (46);
}
else
{
//32-128
if (array[@ lft, bot] != tile)
{
return (38);
}
else return (20);
}
}
else
{
//64+
if (array[@ lft, top] != tile)
{
//64-128
if (array[@ lft, bot] != tile)
{
return (45);
}
else return (24);
}
else
{
//128+
if (array[@ lft, bot] != tile)
{
return (28);
}
else return (0);
}
}
}
}
}
}
}
Using != instead of == is faster in this situation.
How it works:
first it checks below, if that tile is not one of ours then go ahead, next tile
right? not our tile, go on
above? yes this a tile we possess, let's else this up.
now we are at 1-2-8
we can see that 16 and 32 are no options anymore which saves time on average.
and so on...
Other stuff:
global.tiles represents my array which is filled with all tiles and potential collision.
On the side where we call this script from is just an iteration of our array with double for loops:
Code:
//FUNCTIONS START
var array = global.tiles;
for (var i = 1; i < width-1; ++i)
{
for (var j = 1; j < height-1; ++j)
{
var tile = array[@ i, j];
var index = scr_get_index(array, tile,i,j);
//DRAW THE TILE
}
}
!You may use it as reference!
If you have optimizations, complaints or questions post them here =]
Edit: Did some tests with comparing windows to yyc and this algorythm against the bitwise one
//>
x47 win (my) 1370ms 1380ms 1387ms
x47 win (bit) 2125ms 2136ms 2121ms
x47 yyc (my) 502ms 494ms 485ms
x47 yyc (bit) 657ms 676ms 686ms
//>
//>
x16 win (my) 1220ms 1216ms 1222ms
x16 win (bit) 1473ms 1462ms 1464ms
x16 yyc (my) 423ms 426ms 425ms
x16 yyc (bit) 439ms 430ms 442ms
//>
Last edited: