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

Android achieve multi threading in GMS [SOLVED]

E

electronic_entertainments

Guest
Hi there, i know game maker is purely single threaded but i am trying to find a way to do multi threading in game maker studio, first thing i tried out was using of extensions so i just released that game maker waits for the extension to return value, so it fails, a another way might be implementing whole solution in the extension and just return the result to game maker studio, i will be happy if you guys show me a better way to do this, i thinking about running a sub program running parallel with my game and share its results in a common scope on memory, so main program can read from it

thanks for taking time to read the message
 
D

Deleted member 45063

Guest
In theory you could spawn a thread from the extension that references the address of a buffer created in GameMaker, then use that buffer for communication. However, GameMaker has no concept of concurrency (in GML at least) so it will be difficult to synchronize access to the buffer. There is a possibility of triggering async events from an extension, so I think that would be your best bet. I'd search the forum for information on that, I only remember seeing it for C/C++ based extensions but there might be some Java equivalent.
 
E

electronic_entertainments

Guest
In theory you could spawn a thread from the extension that references the address of a buffer created in GameMaker, then use that buffer for communication. However, GameMaker has no concept of concurrency (in GML at least) so it will be difficult to synchronize access to the buffer. There is a possibility of triggering async events from an extension, so I think that would be your best bet. I'd search the forum for information on that, I only remember seeing it for C/C++ based extensions but there might be some Java equivalent.
thanks for the reply, i tried Async Event, i surfed through the yoyo packages and just learned how to use RunnerJNILib package and learned how to trigger a async event, i triggered an async event inside a java void method, unfortunately the game maker waits for the void method to execute completely then return to it rest of it self program flow, i just want to get benefits of more cores running my game parallel [currently i virtually simulated multi threading in game maker by servicing scripts in matter of time], i think the only way remains is implement all the database on the extension side and game maker just use the results
 
S

Sam (Deleted User)

Guest
My video player extension is a good example of basic multithreading: http://marketplace.yoyogames.com/assets/9207/video-player

Although it is not available for android the code it uses for the threading specifically is following the C++ standard, so the same basic concepts can be applied in your android threading. Note: my github account is banned as of just recent, you will need to download the asset from elsewhere such as the marketplace, my google drive, or itch.io, for access to the source code.
 
D

Deleted member 45063

Guest
thanks for the reply, i tried Async Event, i surfed through the yoyo packages and just learned how to use RunnerJNILib package and learned how to trigger a async event, i triggered an async event inside a java void method, unfortunately the game maker waits for the void method to execute completely then return to it rest of it self program flow, i just want to get benefits of more cores running my game parallel [currently i virtually simulated multi threading in game maker by servicing scripts in matter of time], i think the only way remains is implement all the database on the extension side and game maker just use the results
I think you might have missed a critical part there. You can trigger Async Events from the extension, but the extension itself needs to implement the Async part. So my suggestion would be you create a Thread in the method, return a unique identifier for the thread to GameMaker (some int or the thread name, etc). Then, in the Thread, you do the computation and trigger the Async Event. The ID allows you to match it from the GM side (as with regular Async Event functions) or potentially call into the extension to get status, abort the action, etc.
 
Top