[Plugin] Multiplayer Function Sync

Post your work in progress addons and get feedback

Post » Thu Jun 26, 2014 8:33 am

So I've created a really neat Multiplayer Function calling plugin that allows any player (host or peer) to call any function for every player at the same time with a single action call. It ties the officially supported plugins (Function/Multiplayer) together so you don't need to do anything other than add this plugin, create your functions as you normally do and then call them with this plugin instead of the Function plugin to enable calling it on multiple devices at the same time. This allows you to syncronize data with out having to associate objects or build your own method for encoding and decoding multiplayer messages. Just call a function and it happens on every device at the same time.

Example: When Player 1 calls "MoveLeft" on a key press he has the option to send that function call to everyone at the same time so they all call it at the same time and each players screen sees player 1 move left. Or when Player 1 scores a point the host can call a function to update it on everyones device. Simple!

Or in this example When a peer joins a room he calls a function spawn him self on everyones screen and then call a function on everyone elses devices for them to spawn them selves on his screen. 2 lines of code, 2 functions and all players are on the same screen.
help1.png

Supports calling a function for
- Everyone
- Everyone but him self
- Host Only
- Him self only (Like a normal function)
- Direct To Peer

It has advanced function calling methods as well that allows for triggering a function only once until reset or persisting the function call on the other end until reset. (IE MoveLeft could execute an action that simulates move left from a behavior and is sent only once by the player while hes holding the key down but is continuously called on the other end every tick until you tell it to stop by taking your finger off the key) Provides precision control and reduces bandwidth requirements for smooth movement. I'm sure some of you have seen my multiplayer example capx that uses this theory (not this plugin) that I have posted on other threads that proves this.

Example:
help2.png

It works flawlessly and set up is easy. Simply add the function and on start initialize it with the function.uid and multiplayer.uid and then set a multiplayer trigger for it. Thats it!! you can start calling functions at will from this point on.
help3.png


HOWEVER :( Here is where I have a problem. Currently because both Function and Multiplayer are global objects their UID's dont show up as select-able expressions. I had to modify the existing plugins to add it (this is frowned upon and i cant release the plugin if it requires the user to do that). Before i can release this plugin i need a way getting the UID for global objects? I could have missed something but can't seem to find it anywhere and I have scoured the code and event action options with no luck in finding the Function/Multiplayer UID, but does any else know if this can achieved. If a method doesn't exists @Ashley would you be willing to put the UID's as select-able expression for the Function and Multiplayer object so i can use them in the event sheet to init my plugin? I would really like to release to this plugin. Thank you
You do not have the required permissions to view the files attached to this post.
B
20
S
7
G
1
Posts: 221
Reputation: 2,077

Post » Thu Jun 26, 2014 11:14 am

No, don't hard code integration. Just provide link points in the event system, e.g. run a trigger when you want to really run a function, and the user can run a function in that trigger. What benefit does this have over the user making their own functions to manage multiplayer messages anyway? I'm particularly worried by your example of calling a "MoveLeft" function on all peers that appears to completely ignore and therefore probably break input prediction, which would make games far more laggy. On top of that trusting peers to call functions to create themselves on all other peers breaks the security model of the multiplayer engine where the host is authoritative, and allows peers to destructively hack multiplayer games. Since both examples are counter to a well-designed multiplayer game I'm not convinced by what you're trying to achieve here.
Scirra Founder
B
398
S
236
G
88
Posts: 24,433
Reputation: 194,635

Post » Thu Jun 26, 2014 2:38 pm

@Ashley I think your missing what im trying to go for. I have created a multiplayerPlatform example that works off of nothing but functions. There are no synced objects. Just functions. You will see my capx has basically no lag (compared to sync objects mine has none). , movement is smooth and control is fluid. Others have found this be helpful but too complicated. So I took the logic and turned it into a plugin so it wouldn't be as confusing for others to replicate.

Take a look at this example. It has no plugin. its just functions and a complicated algorithm. Open up 2,3,4 etc.. browser windows (supports more than 2 players) and click connect on each. Then move the players around with arrow keys. There is something to be said for using simulated actions that input prediction will never be as a good as. Please try it and tell me if you think all the code from this example isnt worth turning it into a plugin.

multiplayerPlatformFn.capx


All i need is reliable way to access the UID from Function/Multiplayer to eliminate half the code necessary that makes this capx work. There is a ton of benefit to syncing functions. Please, I'm genuinely asking you take a look at the capx, try it and let me know if you wont reconsider?
You do not have the required permissions to view the files attached to this post.
Last edited by troublesum on Thu Jun 26, 2014 5:04 pm, edited 1 time in total.
B
20
S
7
G
1
Posts: 221
Reputation: 2,077

Post » Thu Jun 26, 2014 3:52 pm

@troublesum - what, so you don't even implement interpolation or input prediction? Have you actually tested that over a real-world connection?
Scirra Founder
B
398
S
236
G
88
Posts: 24,433
Reputation: 194,635

Post » Thu Jun 26, 2014 4:27 pm

@Ashley Were you able to test the capx? Yes i tested it.. not across the world but it works over my 4g wireless connection without any problems. Since each device does all its own work you simply send the instruction of what work should be performed. (IE Move Left, Move Right Jump, etc..) If its work that needs to be ticked you simply latch it (persist) the call based on the tag (action group). So move left is latched until another instruction from the same tag (action group) is received whether that be stop, move right, etc.. It literally takes 3 instructions to move a player all the way across the screen in sync as long as you using a dt behavior. If latency is under 200 ms (by all accounts anything larger would make multiplayer useless anyway) functions are called near real time on all devices at the same. Just to account possible spikes in latency I send an additional set position instruction every half second to adjust. Sure some functions are always only called by the host like when a hit is registered (IE Player 1 will send the function that he fired when he presses the fire button but it only counts as a hit if the host sees it hit another player). Basic multiplayer mechanics still apply. But for movement i believe this is as good as gets.

I hope you see the value in this method of data transmission and maybe add the UID expressions for me (really for everyone else since i use this plugin anyway). Even if not for movement (which i think is what your against), the power of function synchronization adds tons of value to multiplayer plugin (which I still can't thank you enough for adding). Imagine how easy chat would be for someone if they have a text box with function that updates its text. The host/peer could update the text on every device with a single action by calling the very function that the text box is tied to. No funny code.. just call the function tht would normally just update it on your screen but instead, poof same text on all devices. Or if the host want to let every one know what the next level is they should load. Or updating dynamic data the host can update arrays/dictionaries on each device with a single function call.. and so on..
B
20
S
7
G
1
Posts: 221
Reputation: 2,077

Post » Thu Jun 26, 2014 7:46 pm

@Ashley - I think this more a suitable reason you might like than using functions for moving objects. Take a look at the screen shot. See how easy it is for the host to sync misc/dynamic data to all peers with a single function call. Very straight forward. No mess... just set the data and pass it in a function to all peers.

help3.png


Every peer has the "Update" function so when the host calls it they all receive the data he sent to it. Super easy.. any way sorry for ranting but I'm just tying to drive the point home that this is very powerful and adds a ton of flexibility with out any complicated algorithms. You don't have to use functions for moving objects if you dont wan't to but for syncing miscellaneous data its really helpful!
You do not have the required permissions to view the files attached to this post.
B
20
S
7
G
1
Posts: 221
Reputation: 2,077

Post » Thu Jun 26, 2014 10:26 pm

It sounds like you fundamentally misunderstand how networking programming works. I would strongly discourage you from publishing a plugin until you have a better grasp of the problems of real-time multi-peer networking, and I especially strongly discourage you from encouraging other users to design games like this, because it is absolutely the wrong way to design multiplayer games.
Scirra Founder
B
398
S
236
G
88
Posts: 24,433
Reputation: 194,635

Post » Thu Jun 26, 2014 10:31 pm

@Ashley Did you try the capx?
B
20
S
7
G
1
Posts: 221
Reputation: 2,077

Post » Thu Jun 26, 2014 11:45 pm

I had made a sync-function for multi-player already. I don't think the uid of instance need to be assign manually. It would be another story.
B
108
S
26
G
272
Posts: 4,472
Reputation: 152,279

Post » Fri Jun 27, 2014 12:17 am

@rexrainbow - THANKYOU!! I I just took a look at your MPwrap and saw how you found the instances.

This is what i needed. I was other wise lookup the instance based on the UID i passed. Since there is only one instance this will work perfectly.
Code: Select all
if (inst instanceof cr.plugins_.Multiplayer.prototype.Instance){
}


Can't believe i forgot i could check instanceof (facepalm). Yes I saw your plugin but ill admit i didn't use it because i wanted persisted function calling and different methods of directing the who receives the function call (Mine works the exact same was as the official Function plugin when calling except you specify who gets the call [Everyone, Everyone But Me, Host Only, PeerId etc]). Ashley seems to think I'm wrong about persisted function calling but if you would only try my capx provided in the above post (does not have my plugin but proves function calling the theory) you would see it makes a world of difference and works better than any multiplayer demo currently available. In any case ill respect his wishes and not publish my plugin less some specifically asks but im still using it for my self. :)

Thank you again!
B
20
S
7
G
1
Posts: 221
Reputation: 2,077

Next

Return to Work in Progress Addons

Who is online

Users browsing this forum: No registered users and 0 guests