• Hey Guest! Ever feel like entering a Game Jam, but the time limit is always too much pressure? We get it... You lead a hectic life and dedicating 3 whole days to make a game just doesn't work for you! So, why not enter the GMC SLOW JAM? Take your time! Kick back and make your game over 4 months! Interested? Then just click here!

Legacy GM Tile Deactivation

Hello i have a lot of tiles in my level and its fairly large stage. I was wondering how i could deactivate tiles efficiently and reactivating them when in view sorta how i deactivate objects and such. I found this in an old GM post, however... when i turned on the profile it used about 88% of step%... not to mention it seems to slow down/ lag the game up. Is there an ideal way of doing so?

Code:
///Tile activation
for (var i=0; i<tile_get_count();i++)
   {
   t=tile_get_id(i)
   if(point_in_rectangle(tile_get_x(t),tile_get_y(t),view_xview[0]-64, view_yview[0]-64, view_xview[0]+view_wview[0]+64, view_yview[0]+view_hview[0]+64))
       {
       tile_set_visible(t, 1)
       }
   else
       {
       tile_set_visible(t, 0)
       }
   }
 
P

ParodyKnaveBob

Guest
Somebody correct me if I'm wrong, but don't tiles generally automatically not draw when out of view?
 
I dont think that is the case, i think that tiles draw regardless, when i put in that code and i disabled the use of views it only activated those in the view. However it also uses up quite a bit of memory
 

RangerX

Member
Tile get count and Tile get id most probably slow and using them alot is probably not a good idea. You have no gain there. Besides, tiles are very very fast to draw, I am sure you can optimise your game elsewhere.
 
P

ParodyKnaveBob

Guest
You can always test this instead of guessing, you know (unless you have hardware issues like I and literally cannot use the debugger).

Create a test where thousands upon thousands of tiles show directly in a view, and do not show due to being out of view. Check the debugger's awesome profiler for whether or not the drawing is going into overdrive when unnecessary, or if it's optimized out of the way. Due to bug reports (and other info) from years ago, I suspect it's optimized away -- but again, you can just test your own question.

I hope this helps,
Bob
 

RangerX

Member
Am curious of the results but am sure its better to just leave tiles "as is" and trying to draw or not draw them.
 

Nocturne

Friendly Tyrant
Forum Staff
Admin
In general, tiles are pretty fast and best left alone... I also believe that anything outside of the visible view won't be rendered, but not because of GMS, because of the GPU (I'm almost certain that most modern GPU will just discard any draw calls if the render area is not going to be visible, but I could be wrong). If you REALLY want to optimise, then the best solution is to draw all your tiles to a couple of surfaces and then create backgrounds from the surfaces and draw them.

So if your room is (for example) 1024x1024, you could create four 512x512 surfaces, draw the tiles to them, create backgrounds from the surfaces then discard all the tiles and the surfaces afterwards and just draw the four backgrounds. The initial processing will be slow, but after that you'll only be rendering 4 backgrounds, so you should get a huge speed boost.
 

TheouAegis

Member
I just tested. I used a code that placed tiles across the whole room. I set a view in the top corner (the view was smaller than the room). I drew the fps_real in the top corner. I ran the program and got an fps_real of {120...145}. I closed the program and changed the code to only add tiles within the view. I ran the program again and got the same fps_real values. I then changed the code to only draw tiles outside the view. I ran the program and got an fps_real around 1000. Then I reverted back to the original code that filled the whole room with tiles and disabled views. When I ran the program, I got an fps_real of {70...98}.

So after what I'd consider some pretty thorough testing, I think I debunked the myth that tiles outside the view are slowing down the game.

Now, with that said, if you try to read tiles, having tiles outside the view will slow down tile attribute reads simply because GM has to loop through all tiles in the room. But then again, that's a Step event issue, not a Draw event issue and constantly adding and removing tiles may be as detrimental - if not more so - than just letting GM loop through them all.
 
Top