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

Legacy GM Help with using local networking for "multi threading", and various concepts

Hi. This is mainly at the concept stage as a process, but I am looking into using local networking to have two versions of a game communicating with each other, and they are working in tandem. Basically a crude version of multi threading.

That side of things I can get a handle on, so the question of how efficient it is doesn't bother me at this point, as I just want to see if it works. However: with this solution comes the downside of it being a bit limited, as whatever is communicated must be fairly limited in scope.

Data that can be sent in
(a) a recognized format to go into a buffer
(b) not be so big that the act of sending it makes this set up pointless (dunno if that would be true at this point)

SO:
I have Execute Shell - which will load up the second exe of my game, and it's being called from the first exe. These are going to be "server" and "client", which for the time being is the only definite order I have to all of this, due to the local networking process.

At this point I can either:
(A)
Give them particular roles - the "client" is doing the heavy lifting on the AI side, and the "server" is doing the graphical side and smaller tasks.

Data between the two is simple values:
Say that I want to put various paths into an mp grid, and want to find a spot that is not in collision. Any path is just points in an array, and that can be passed through in a buffer as straightforward values. At the other end the heavy leg work of filling in the grid is done, looping through it and finding a free spot, and then the end result (another simple value) is passed back.

The work flow is either fixed between the two, or if the cost of transmitting data between them like this isn't too high I will see if they can mix and match roles.

(B)
Do something even more technical (if possible, of course). If the means exists to directly affect each other, such as fully being able to access grids / paths / other indexes, then I would want to look into that.

As an example:
I have several objects I want to put into the grid, with the "master" handling x amount of them, and the "slave" handling the rest.

(1)
The question is whether they could both "share" the same grid and fill data to it simultaneously, thus speeding up the end result without either taking too long ( the process, as it happens currently in a single exe, is too long and has to be divided into smaller chunks)

(2)
Both have separate mp grids. Each fills its own, and the two are then merged into one grid....? I don't know of any GMS function that merges two mp grids, so I guess that would have to be self coded (if at all doable)

OR

Each fills in its own, and maybe outputs it into a ds grid. The two ds grids are merged.....assuming this data can be passed, can the new values overwrite the old ones in a way that is useful?

Say that a cell is either true, or false, just as an mp grid would be. If the cells that are true in the "slave" can be transferred into the "master", without the negative results overriding any positive cells that the "master" has.

If I have access to both ds grids, then looping through one would be enough to control what goes into the other. At this point I don't know if there is an inbuilt function that could handle this instead, should the two different builds be able to speak directly to each other.


The user YellowAfterlife pointed me to a function they made called "function_get_address" - I'm not sure if that can be utilized for some of option B? It sounds like it could be used for a global kind of variable that the two different exe could use, but at this point I haven't yet looked into it.


And there it is....I'm not looking for anyone to do this for me, but am just after suggestions of ways either attempt (local networking, or directly) could be done. Bare in mind that the networking side of things is fine: I already have that set up, so they can communicate.

If anyone can tell me about what could be passed in a buffer between them (a whole path as is, or would I have to break that down? grid details as is, or broken down? etc) then it would be appreciated.

Or if you have any ideas about "direct access" (option B) I would like to hear them. Thanks for taking the time to read this, sorry there was so much of it :)
 
Last edited:

Roa

Member
just make a DLL with a given task for threading. Call a function to make the threads, another to start, one to check if its done, and one to finally read the data back.

threads never share memory as that would cause conflicts. You need to designate a single task, or break it up into smaller ones and report the data back to the main thread.
 
just make a DLL with a given task for threading. Call a function to make the threads, another to start, one to check if its done, and one to finally read the data back.
Thanks for replying. At this point I'm trying to find out what any of this would entail, but I only understand it as a concept. I think I can get to grips with this in standard GML, and have them working together, but I don't know about DLL' or other programming languages.

What would be in the DLL? If you are referring to injecting any extra code, like C or C++, then that is beyond me. If the content of the DLL is simply GML / GMS functions, then I'm not sure what that changes?
 
@YellowAfterlife This is the project I was referring to, when you said about "function_get_address". I am wondering if it can be applied to "connecting" to path indexes / sprite indexes / grid indexes, so that in a local network the client could read the server directly and access those things. I have been told that it can't happen simultaneously (both accessing the memory location of a variable and using it), but could they access each others "pointers" (?) if they did so in turns?

I have an alternative if it can't, but it would be a duplication of something. I want my objects travelling on paths, and that is movement / actual collisions handled on the server side. But that path data is also used in the AI, and the client handles predicted collisions and avoidance, and finds new paths if necessary. Worst case scenario is the client having to make, and store, a path for each duplicated "partner" object, and then send a copy of new paths points back through a buffer to the server. Just a bit of duplication of resources, and time cost / performance cost.

To try and lower the cost in the client I won't have any sprites / sound / forms of input etc present. Because the client doesn't need any sprites, as it is not handling accurate collisions and uses rectangle_in_rectangle / circle etc for collisions. It will be given only the dimensions of the object it is building a path for, and that's an easily communicated value, as is returning a full path to the server.

But, if at all possible, I am curious to know if anything more direct can be managed. Thanks for taking the time to read this :)

EDIT: Unfortunately I get an error when trying to run the project you pointed me to.

"Extension function_get_address file function_get_address.dll does not exist" even though it's there in the extension library....?
 
Last edited:

YellowAfterlife

ᴏɴʟɪɴᴇ ᴍᴜʟᴛɪᴘʟᴀʏᴇʀ
Forum Staff
Moderator
"Extension function_get_address file function_get_address.dll does not exist" even though it's there in the extension library....?
Did you compile the included Visual Studio project? Also, as this is for multi-threading specifically, I might have a thing of interest soon.
 
  • Like
Reactions: Roa
Did you compile the included Visual Studio project? Also, as this is for multi-threading specifically, I might have a thing of interest soon.
I am just downloading Visual Studio to be able to compile it. I've never used it before, so hopefully compilation is fairly straightforward.

Sounds intriguing as to the other part about multi-threading. It was something I've wondered about for ages, and have been struggling to get my AI working without it wobbling enough to make me think running it as a single exe is not going to be doable.

The networking aspect seemed tricky at first, but it's nice to know there is one solution within my capabilities. A more direct method is pretty cool, though I'm probably (definitely) going to be in at the deep end with anything like C++

EDIT:
Hmmm, have downloaded Studio now and hopefully all of the C+ extensions required. Going to have to look through how you use it, as I can't figure out how to compile a project to look at function_get_address.

Is this "pointer" only the first part of the process? Does it need further coding to be used?
 
Last edited:
Top