• 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.

Discussion custom async events?

Tthecreator

Your Creator!
Hi folks,

I would like to propose an idea. It's one of those idea's not very likely or just to big for yyg to implement. It's just an idea maybe it gets torn apart at an instant but allow me to tell you what I would like.

I think it would be nice to see custom async events. Just to be able to have some kind of step event, but running it off the runner.
Now of course I don't know how the internals work here and maybe this would be, for example something possible on the yyc but not the vm, or not even at all.
There seems to be a very structured way on how events are currently laid out, and these custom events might not fit besides these.

Why though?
It allows me, and anyone else to create some bigger loading/saving of resources inside of a custom script, while still having something like a loading bar in a draw event.
There are some more scenario's one could think of.

possible features?
Maybe something to set how much processing power to allocate to this thread? I guess that would be very deep in the machine and if any other languages like c++, which the YYC uses don't allow you to do this then it's kinda the end of the story for allocation.
 
T

T-bond

Guest
I think you can do that already with extensions.
You call the loading process inside the extension, and when that is ready it triggers the Social Asynchronous Event (It has already worked for me in 1.4)
You can draw the progress bar in GMS, until the social event get triggered.

This is what you want?
 
T

T-bond

Guest
Extensions are available on every platform supported by GMS.
I only used in Android, and don't know about any other platform able to use the same API, but I think they should. (at least iOS as mentioned the post linked below)
I used this article: Returning values from an extension asynchronously
If other platform's aren't supported in GMS2 (or GMS1) I think this is a good suggestion.
 

Tthecreator

Your Creator!
I know that they are on every platform, but I would have to reprogram such an extension for all needed platforms.
 

DukeSoft

Member
You could go with setting a maximum amount of calculations per step, calculate the steps needed and let GM run it in an instance. This way you're implementing "async" within your game. Its not native (or multi-threaded).. But it works :) I do it quite a lot for rendering and loading big chunks of data.
 
C

CedSharp

Guest
I know that they are on every platform, but I would have to reprogram such an extension for all needed platforms.
Well, the concept of an extension is exactly that, to add normally restricted features to an engine that cannot afford to support it.
In this case, GameMaker doesn't support multi-threading ( this is what you want to do based on your description ) so you'd have to create threads manually,
using the native language of the platform for your game.

Because it's only one part that you need to fix, it won't require much coding. But of course, scalability takes a huge hit.

You could take a look at a language like haXe which can export to many platforms, like GameMaker, but isn't restricted by the VM sandbox that gamemaker has.
You could make your DLL, dylib and .js files using the same code. ( note that I never tried, just a proposition )
 

Tthecreator

Your Creator!
@CedSharp
I looked at it, but I'd have to do some research to see if haxe has any potential to make extensions, not to forget actual extensions that work with game maker.
 

Posh Indie

That Guy
I would give a kidney for multi-threading (Maybe not... but I would harvest them for YoYo Games employees)!

Seriously, though. This needs to be done. It is the last thing I can think of that could sway a decision to use another engine (I am heavy into procedural content generation, so it has actually crossed my mind many times).
 

Tthecreator

Your Creator!
The reason I am also asking it on this forum here is that I don't 100% need it right now at this exact instant, but because it would be a nice feature to have in withing game maker's workflow.

It's surely 100% theoretically possible on every platform, it's just not that streamlined to go trough an extension, as opposed to something build in.

The highest thing that I could ever hope this post could maybe achieve, is "yoyogame's wishlist" or that "they'll think about it", which some people somehow see as a confirmation, while it's more like a little box of work they can do with a enormous hopper on top with all feature requests XD.
 
C

CedSharp

Guest
I would love to see a "thread" or a "process" ( I'll call it process from now on ) event appear in the asynchronous section.
Because a process isn't an object, implementing the scope might be weird. Maybe use something similar to the room creation code? ( that isn't in an object either )
We could create processes with something like this:
Code:
/// scr_draw_frame()
var surface = surface_create( room_width, room_height );
surface_set_target( surface );
   {...}
surface_reset_target();
process_emit( "frame", surface );


// Create event of object FrameManager
last_frame = -1;
proc_draw_frame = process_create( scr_draw_frame ); // we give a script which will be the process code

// Process event of object FrameManager
if( async_load[? "id"] == proc_draw_frame ) {
    if( async_load[? "type"] == "create" ) {
        // 'create' is used when the process is created. Technically useless, but we never know. The keyword could also be 'start'.
    }

    if( async_load[? "type"] == "data" ) { // 'data' means that the process wants to send us stuff
        switch( async_load[? "name"] ) { // 'name' let's us react to different data types
             case "frame":
                if( surface_exists( last_frame ) ) surface_free( last_frame );
                last_frame = async_load[? "value"]; // 'value' is self explanatory
            break;
        }
    }

    if( async_load[? "type"] == "end" ) {
        // 'end' or 'destroy' would mean that the process ended. It could return a value too, since it's a script.
        // For example, 0 means no problem, while 1,2,57... would represent error codes :D
    }
}
If something like that gets implemented in GameMaker... I'll just... wow :O

the main concern I have is what would the process be allowed to interact with?
Would it have access to all the instances in the room?

What would happen when you change room?
What internal variable would a process have access to? ( obviously, sprite, object and physic related stuff wouldn't be accessible because a process isn't an object. )

So many questions, yet so many expectations... Such an awesome feature too :D
 
Last edited:
C

CedSharp

Guest
Also, not to forget, but when working with process you have to remember about race conditions...
That means implementing some form of variable lock access, like mutex or semaphor...
I guess processes would be something complex to implement in the current gamemaker environment :/
 

Tthecreator

Your Creator!
Race conditions could be somewhat of a problem,

But I can see the real use of this lying in random generation, loading of resources and etc... , Not in some game logic. Maybe AI? That could be somewhat problematic I guess at second thought. I also guess this feature would be for more intermediate users anyways. The race conditioning is also more of a problem for bugs and crashes within the game I guess, not for exploiting.

I would also like to add that yoyogames could implement this(, or something similar), or they could just keep going in current ways and add special async functions for every function dealing with resources like buffer_save_async, show_message_async, etc.... This is surely harder to implement but could end up nicer.

I wouldn't have to slowly execute one bit of my loop every step and then at the end just call buffer_save_async. I could just have it in one script, one "event" possibly without it interfering with the game.
 
Top