• 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!
  • Hello [name]! Thanks for joining the GMC. Before making any posts in the Tech Support forum, can we suggest you read the forum rules? These are simple guidelines that we ask you to follow so that you can get the best help possible for your issue.

Windows Async image loading + local files?

vdweller

Member
Hello,

Is it possible to use asynchronous image loading with local files?

I have tried the default path with sprite_add -> no success.

I have tried faking an URL adress (like "file:///" etc) -> no success

Is there a trick to do it? Or is it just not possible? I'd prefer no extensions.
 
M

MarceloP

Guest
Hellow @vdweller,

I gotta say, what I'm about to suggest you I've never tested myself. But the thing is that GMS2 has an included files category. You can actually put anything there. It will get copied to your project but will retain its integrity in content and won't be loaded at the very glance of your game (as far as I recall).

You can try to put your image files there, then try to call sprite_add passing the working_directory + name of the file. This in theory should work without problems.
If sprite_add actually works, that would be a great way loading sprites dynamically, but it is important to mention that there's been some discussion about the efficiency of sprite_add when related to IDE sprites.
 

vdweller

Member
I know about included files. That's where I'm loading these sprites from.

EDIT: Also, these sprites are 1920x1080 this is why I don't use the built-in resource tree. Essentially they are background screens.
 
M

MarceloP

Guest
I know about included files. That's where I'm loading these sprites from.
EDIT: Also, these sprites are 1920x1080 this is why I don't use the built-in resource tree. Essentially they are background screens.
I'm sorry, I got a bit confused here. You already have this images in your resource tree in the included files category and sprite_add didn't work? Or you'd like to have an async load of that data from the disk?

I'm not soo sure about what I'm going to say but I think async calls with sprite_add only happen when you have an HTTP request to be resolved. Any other local case will have sync load from the disk. If what you meant was to have the async load and event happening with a local file, I don't think it is possible =(

I mean, I'm not totally sure of that, but I think that's how sprite_add actually behaves. It checks if that's an HTTP or HTTPS request by the path itself and works async or sync depending of the type of loading it will have to do.
 

vdweller

Member
I'd like to have an async load of that data from the disk. Yes, an initial experiment resulted in failure, I was just wondering if there was some clever workaround.
 

vdweller

Member
Well, actually there is a clever way to go around this issue.

Create a surface and paint it with the contents you want.

Create a buffer and dump the surface into the buffer.

Save the buffer.

Steps above happen once. What you will load externally will be the saved buffer from now on.

Next time:

Load the buffer you saved asynchronously.

Once done, dump contents onto a surface. Now this step can take more than 16 ms. on a potato PC like mine, so at 60fps there might be a slight hitch when buffer_set_surface is called for a 1920x1080 image.

If RAM is not a problem, one could still use this method and load buffers asynchronously for all such large images, it's still way faster then sprite_add().
 
S

Sozidar

Guest
dump the surface into the buffer.
dump contents onto a surface
Sorry for necromancy, but how exactly to do this? :oops:

Okay, figured it out. Here's the code.

Code:
//Create Event

w = 128;
h = 2176;
size = w * h * 4;
surf = surface_create(w,h);

surface_set_target(surf);
draw_sprite(sprite123,0,0,0);
surface_reset_target();

buff = buffer_create(size, buffer_fixed, 1);
buffer_get_surface(buff, surf, buffer_surface_copy, 0, 0);
buffer_save_ext(buff,"test.txt",0,size);
Code:
//Start Loading

loadid = buffer_load_async(buff,"test.txt",0,size);
Code:
//Async Save/Load Event

if ds_map_find_value(async_load, "id") == loadid {
    if ds_map_find_value(async_load, "status") == false {
        print("Load failed!");
    } else {
        buffer_set_surface(buff,surf,0,0,0);
        buffer_delete(buff);
    }
}
 
Last edited by a moderator:
Top