TextureAtlas is Slow

Anything about development not directly related to libgdx, e.g. OpenGL, Android APIs etc.

TextureAtlas is Slow

Postby VeldaDefense » Sat Jul 07, 2018 2:05 pm

Hello,

It takes a tremendous amount of time to create a TextureAtlas object. I have roughly 20 TextureAtlas objects I need to create, each of which takes roughly 200-500 milliseconds. I am not using the AssetManager as I have my own means of initializing defined assets. I am using LibGDX Texture Packer GUI.

Would using an AssetManager speed up this process at all?

Is there a way to speed up the creation of an TextureAtlas object?

This is what the settings for each atlas file is;
Image

Thank you,

Jason
VeldaDefense
 
Posts: 7
Joined: Mon Jun 25, 2018 2:46 pm

Re: TextureAtlas is Slow

Postby evilentity » Sat Jul 07, 2018 2:16 pm

The main benefit of asset manager is that you can load stuff off ui thread, so it doesnt block rendering. It doesnt speed things up, just hides the workload.
There are two main parts of creating texture atlas, loading texture and creating regions. Unless you have a lot of very small regions, loading the texture will take most of the load time.

The main question is, why do you need so many atlases in the first place?
Looking for a freelancer? PM me!
evilentity
 
Posts: 4548
Joined: Wed Aug 24, 2011 11:37 am

Re: TextureAtlas is Slow

Postby VeldaDefense » Sat Jul 07, 2018 2:23 pm

evilentity wrote:The main benefit of asset manager is that you can load stuff off ui thread, so it doesnt block rendering. It doesnt speed things up, just hides the workload.
There are two main parts of creating texture atlas, loading texture and creating regions. Unless you have a lot of very small regions, loading the texture will take most of the load time.

The main question is, why do you need so many atlases in the first place?


Unfortunately it sounds like AssetManager won't be any use to me then because I am looking to reduce the amount of time it takes for the game to initialize. I draw an animated background during the login phase which requires the TextureAtlas objects to be initialized so I don't want to elongate that phase from being drawn.

The reason I have so many TextureAtlas objects is because I have a total of 24 different characters at the moment, each of which have a variety of animations from walking to attacking, and dying. Each requiring their own atlas file.
VeldaDefense
 
Posts: 7
Joined: Mon Jun 25, 2018 2:46 pm

Re: TextureAtlas is Slow

Postby evilentity » Sat Jul 07, 2018 2:44 pm

Cool, do you need to load them all at once? Do you need to load anything thats not ui? Load essentials first, then show the menu or whatever. Load rest in the background.
Looking for a freelancer? PM me!
evilentity
 
Posts: 4548
Joined: Wed Aug 24, 2011 11:37 am

Re: TextureAtlas is Slow

Postby VeldaDefense » Sat Jul 07, 2018 4:15 pm

evilentity wrote:Cool, do you need to load them all at once? Do you need to load anything thats not ui? Load essentials first, then show the menu or whatever. Load rest in the background.

There are some assets that require information about other assets so there is a hierarchy. Any assets that don't require UI are submitted to a ExecutorService where they're completed concurrently.

The issue with loading some and not all at once is that pretty much all assets/definitions are required immediately after initialization to display an animated level. This is displayed in the GIF below for better illustration and shameless advertisement :').

If I can't find a way to reduce the overhead i'll take your advice and load them in the background. Thank you for the input, I appreciate it Evilentity.

Code: Select all
    public Map<DefinitionType, Collection<Definition>> loadBlocking() {
        Map<DefinitionType, Collection<Definition>> loaded = new HashMap<>();

        Gson gson = builder.create();

        Collection<Future<?>> futures = new ArrayList<>();

        for (Map.Entry<DefinitionType, FileHandle> load : loading.entrySet()) {
            DefinitionType type = load.getKey();

            FileHandle handle = load.getValue();

            if (this.loaded.contains(type)) {
                continue;
            }
            if (type == DefinitionType.ANIMATION || type == DefinitionType.TEXTURE_ATLAS) {
                loadEntry(gson, handle, type, loaded);
            } else {
                futures.add(service.submit(() -> loadEntry(gson, handle, type, loaded)));
            }
        }

        while (!futures.stream().allMatch(Future::isDone));

        return loaded;
    }


Image
VeldaDefense
 
Posts: 7
Joined: Mon Jun 25, 2018 2:46 pm

Re: TextureAtlas is Slow

Postby evilentity » Sat Jul 07, 2018 5:44 pm

Fake it. There are like 10 assets in this gif, make atlas from them and build a dummy scene.
Looking for a freelancer? PM me!
evilentity
 
Posts: 4548
Joined: Wed Aug 24, 2011 11:37 am

Re: TextureAtlas is Slow

Postby VeldaDefense » Mon Jul 09, 2018 9:16 am

evilentity wrote:Fake it. There are like 10 assets in this gif, make atlas from them and build a dummy scene.


Not a very good resolve, especially if I want to create a more complex background in the future. I'd rather have the bottleneck resolved then just 'fake it'. Thank you for your input regardless.
VeldaDefense
 
Posts: 7
Joined: Mon Jun 25, 2018 2:46 pm

Re: TextureAtlas is Slow

Postby evilentity » Mon Jul 09, 2018 12:10 pm

You cant make stuff load faster, io is slow. You can control what you load, how big it is and in what order. Its a menu. It doesnt need all them bells and whistles.
Looking for a freelancer? PM me!
evilentity
 
Posts: 4548
Joined: Wed Aug 24, 2011 11:37 am

Re: TextureAtlas is Slow

Postby VeldaDefense » Tue Jul 10, 2018 10:54 pm

evilentity wrote:You cant make stuff load faster, io is slow. You can control what you load, how big it is and in what order. Its a menu. It doesnt need all them bells and whistles.

Yes you can? Parallelism is an amazing thing. It's not just a menu, it's the first thing a player sees when they load the game. Nevertheless, I appreciate the input.
VeldaDefense
 
Posts: 7
Joined: Mon Jun 25, 2018 2:46 pm

Re: TextureAtlas is Slow

Postby evilentity » Wed Jul 11, 2018 6:41 am

Im not convinced that spinning more then one extra thread for io will make it any faster on a device, you are welcome to try. Perhaps it will help with your usecase.
Looking for a freelancer? PM me!
evilentity
 
Posts: 4548
Joined: Wed Aug 24, 2011 11:37 am

Next

Return to General Development

Who is online

Users browsing this forum: No registered users and 1 guest