Android run slowly with tile_layer_find function

L

Luto

Guest
hello this is my first post. i'm having troubles with a code that work slowly in android OS but it work good in Windows

the code, search a single tree tile in a 480x480px area and if found it then search 4 positions around it, and if it is surrounded by other trees then it do visible a fog tile above the center tree.

in android OS the code run slowly because of the use of the function tile_layer_find 4 times.... something weird because i made other codes more complex and they not run slowly....

my conclusion is that the tile_layer_find function is very intensive... but i don't know, i have reason? or maybe i am doing some wrong in the code?... please help

note: if you let only two code lines var x = tile_layer_find, it works good.

i have a Samsung Galaxy Ace 4, with android version 4.4.4

// in step event
var stx=0;
var sty=0;
var vxz=view_xview[0]+160; //my x GUI margen
var vyz=view_yview[0]+32; //my y GUI margen
var ts=0; //center tile shadow
var tpc=0; //center tile
var tpu=0; //upper tile
var tpr=0; //right tile
var tpd=0; //lower tile
var tpl=0; //left tile
for(stx=0;stx<512;stx+=32)
{

ts = tile_layer_find(999998,vxz+stx,vyz+sty);
tpc = tile_layer_find(1000000,vxz+stx,vyz+sty);
tpu = tile_layer_find(1000000,vxz+stx,vyz+sty-32);
tpr = tile_layer_find(1000000,vxz+stx+32,vyz+sty);
tpd = tile_layer_find(1000000,vxz+stx,vyz+sty+32);
tpl = tile_layer_find(1000000,vxz+stx-32,vyz+sty);

if (ts != -1) && (tpc != -1) && (tpu != -1) && (tpr != -1) && (tpd != -1) && (tpl != -1) // if exists tiles
{
if ((tile_get_left(tpc)==0) && (tile_get_top(tpc)==416)) && ((tile_get_left(tpu)==0) && (tile_get_top(tpu)==416))
&& ((tile_get_left(tpr)==0) && (tile_get_top(tpr)==416)) && ((tile_get_left(tpd)==0) && (tile_get_top(tpd)==416))
&& ((tile_get_left(tpl)==0) && (tile_get_top(tpl)==416)) // if the tile center is a tree and if it is surrounded by other trees
{
tile_set_visible(ts,true);
}
}
if stx==480 && !(sty==480) {sty+=32;stx=0;} // to search the next lower row from left to right
}
 

Bingdom

Googledom
The problem is that phones are MUCH slower than computers, you simply cannot compare 1Ghz Phone to a 1.5Ghz Laptop. This does not mean the laptop is 50% faster. :)

Probably the best alternative from using tile_find is using ds_grid. Im not entirely sure how big are your tiles but im going to assume that they're 32x32.

You'll want to do something like this:
Code:
global.grid = ds_grid_create(room_width/32,room_height/32);
//Grid now created, fill the grid with a void to prevent errors
ds_grid_set_region(global.grid, 0, 0, room_width/32, room_height/32, -9);
var xx,yy;

repeat(50) {
    xx = random(room_width) div 32;
    yy = random(room_height) div 32;
    tile_add(tree, 0, 0, 32, 32, xx*32, yy*32, depth);
    ds_grid_add(global.grid, xx,yy,-10);
}
The way how you want to put invisible fog is up to you. You can access the grid by doing ds_grid_get(global.grid, xx, yy), it will return either -9 for nothing or -10 for trees ;). Using macros will help, but that is also totally up to you :).
 
L

Luto

Guest
The problem is that phones are MUCH slower than computers, you simply cannot compare 1Ghz Phone to a 1.5Ghz Laptop. This does not mean the laptop is 50% faster. :)

Probably the best alternative from using tile_find is using ds_grid. Im not entirely sure how big are your tiles but im going to assume that they're 32x32.

You'll want to do something like this:
Code:
global.grid = ds_grid_create(room_width/32,room_height/32);
//Grid now created, fill the grid with a void to prevent errors
ds_grid_set_region(global.grid, 0, 0, room_width/32, room_height/32, -9);
var xx,yy;

repeat(50) {
    xx = random(room_width) div 32;
    yy = random(room_height) div 32;
    tile_add(tree, 0, 0, 32, 32, xx*32, yy*32, depth);
    ds_grid_add(global.grid, xx,yy,-10);
}
The way how you want to put invisible fog is up to you. You can access the grid by doing ds_grid_get(global.grid, xx, yy), it will return either -9 for nothing or -10 for trees ;). Using macros will help, but that is also totally up to you :).
thanks i will try something like that... but still is weird because i can put 50 enemies in the room with complex artificial intelligence script and the app goes excellent... =( ... but i will try other methods, thanks for help me =)
 
L

Luto

Guest
i found the answer to my question and i have two answers but only one sad conclusion. =(

in my first option i modified my past code to this:

//in my control obj
//in step event
if player.alarm[0]==1 && player.speed>0
{
var stx=0;
var sty=0;
var vxz=view_xview[0]+160; //my x GUI margen
var vyz=view_yview[0]+32; //my y GUI margen
var tpc=0; //center tile
for(stx=0;stx<512;stx+=32)
{
tpc = tile_layer_find(1000000,vxz+stx,vyz+sty); //central tile
if (tpc != -1) && ((tile_get_left(tpc)==0) && (tile_get_top(tpc)==416))
{
tpc = tile_layer_find(1000000,vxz+stx,vyz+sty-32); //upper tile
if (tpc != -1) && ((tile_get_left(tpc)==0) && (tile_get_top(tpc)==416))
{
tpc = tile_layer_find(1000000,vxz+stx+32,vyz+sty); //right tile
if (tpc != -1) && ((tile_get_left(tpc)==0) && (tile_get_top(tpc)==416))
{
tpc = tile_layer_find(1000000,vxz+stx,vyz+sty+32); //lower tile
if (tpc != -1) && ((tile_get_left(tpc)==0) && (tile_get_top(tpc)==416))
{
tpc = tile_layer_find(1000000,vxz+stx-32,vyz+sty); //left tile
if (tpc != -1) && ((tile_get_left(tpc)==0) && (tile_get_top(tpc)==416))
{
tpc = tile_layer_find(999998,vxz+stx,vyz+sty); //fog tile
if (tpc != -1)
{
tile_set_visible(ts,true);
}
}
}
}
}
}
if stx==480 && !(sty==480) {sty+=32;stx=0;} // to search the next lower row from left to right
}
}

but this code yet use the function tile_layer_find and in others devices, my game could work slowly. then this was not the correct answer. =(

in my second option, i made fog objects of 32x32px with a individual code for everyone and i filled the map with these. surprisingly fill a map of 1024x480 with this objects with a individual code for everyone works better than use the tile_layer_find function.... weird very weird...

// the code in every fog object
//in step event
if point_in_circle(player.x,player.y,id.x,id.y,72)
{
id.visible=false;
} else {id.visible=true;}

my conclusion is that the tile_layer_find function not works good in mobile devices and for some reason is very intensive. maybe someone in the game maker company should check this issue.... very weird.
 
Top