dimarts, 2 d’abril del 2013

Working On Networking

So, for starters i've been trying some tutorials about the whole networking thing. Every single one is like:drag those scripts and make the magic work. Finally, I sem to have found one that actually teaches you stuff. (thanks to paladin games for the comprehensive guide)

So basically there is two types of network communication methods:

1) Remote Procedure Calls (RPC): Basically, you can call functions stored on a different computer
2) State synchronization: You update the state of a variable or vector

I've been trying to work on both, essentially state synchronization seems faster and used for position, transformation, rotation etc of elements that the client cant affect (for example, other player's avatars). And RPC's are used for more complex actions like spawning elements or complex interactions (a sandstorm for example or an explosion)

For the first test, i've created an interface that acts both as a server and a client. 


When initializing a server, it spawns a cube in a fixed position:

When connected as a client, it spawns a second cube. Both cubes can be controlled from its screen and they update its position on the other. 


This serves as a preliminary test for client-server interaction. Also, the servers can hold up to 32 players (which can be changed) so each new client connection will spawn a new cube in all the screens and can also be controlled by its owner.

As it is now, the difference between server and client is purely anecdotic: they both act as a client with a cube that can be moved around. It is necessary to be connected to a server in order for the interaction to work, but I will elaborate on this later.