Techniques for Better Loading

Posho

Member
Hello,

I want to discuss better ways for loading assets within games themselves or while they're being played. I am working on two projects at the moment, but I'm having frame drop issues. For example:

Game A has a system that turns SWF files with various frames into textures when needed during gameplay.
Game B loads about a thousand small PNG files from a web server upon loading.

Both games load one sprite or subimage respectively each step that passes in-game when needed. I'm assuming doing a while loop could do it faster but then the screen would seem frozen and reasonably bringing discomfort to the user/player.

What are better ways of doing this?
 

Simon Gust

Member
Reading from the tech log
Adding Assets At RunTime
Loading sprites and backgrounds from an external source can be done in GameMaker:Studio, as can creating new assets using functions like sprite_duplicate(). However each new asset that you create in this way will also create a new texture page, meaning that (for example) adding 10 new sprites will create 10 new texture pages! And each time you draw these sprites it is a new texture swap and a break in the batch to the graphics card.

As you can imagine, this is not very efficient, and so (unlike previous versions of GameMaker) it should be avoided, with all the graphic assets being added to the game bundle from the IDE. Note that you can use these functions for adding/creating small numbers of things and they won't adversely affect performance, but adding many, many images in this way should always be avoided as it will have an impact.
 

sylvain_l

Member
@Posho a workaround, is to draw multiple images on a surface and use draw_surface_part* function (or the same with a sprite image and draw_sprite_part* ), or for the server dist images, pre-pack multiple small sprite on the same images (like it's often done with traditional html5&CSS to limit the number of requests on the server (and use the CSS to display just the required piece/icon on the page)
Reading from the tech log
but with GMS2 I read mike saying they improved the swaps, so it's much less critical then in previous version.
also just playing with https://marketplace.yoyogames.com/assets/5359/random-space-ship-generator I got 1034 swaps, and still an avgFPS of 300-400 (on a highend PC with a GTX1080; not the avg player PC I assume, but still 1034 is a lot of swaps per frame; not what you should usually end with)
 

Simon Gust

Member
@Posho
but with GMS2 I read mike saying they improved the swaps, so it's much less critical then in previous version.
also just playing with https://marketplace.yoyogames.com/assets/5359/random-space-ship-generator I got 1034 swaps, and still an avgFPS of 300-400 (on a highend PC with a GTX1080; not the avg player PC I assume, but still 1034 is a lot of swaps per frame; not what you should usually end with)
I think that makes people use it as an excuse to make messy code. But I like the surface idea, though the Image files may be so large that you run out of vram on your 10th Image. You want to aim towards max 12 tex swaps if possible. Not a 1000 XD.
 

Posho

Member
@Posho a workaround, is to draw multiple images on a surface and use draw_surface_part* function (or the same with a sprite image and draw_sprite_part* ), or for the server dist images, pre-pack multiple small sprite on the same images (like it's often done with traditional html5&CSS to limit the number of requests on the server (and use the CSS to display just the required piece/icon on the page)
This sounds like a pretty effective idea. I will definitely try it. I imagine that by reducing the number of image file requests I'll be able to make things a lot more smoother (at least for the web one). Thanks!

Reading from the tech log
I am completely aware of this. I know GameMaker is not reliable in many performance areas but even though I'm not recommended to do RunTime asset loading my game really needs it.
If I didn't need a workaround method for this I wouldn't have made this thread.
 

Posho

Member
@Posho a workaround, is to draw multiple images on a surface and use draw_surface_part* function (or the same with a sprite image and draw_sprite_part* ), or for the server dist images, pre-pack multiple small sprite on the same images (like it's often done with traditional html5&CSS to limit the number of requests on the server (and use the CSS to display just the required piece/icon on the page)
I just tried doing this and the game runs just as slow as the previous method I was using.
I'm thinking if maybe there's a way to create some sort of cache locally to accelerate loading the next time an user loads the game, but I'm having issues with the HTML5 limits in GM:S.
 
Top