hallsofvallhalla wrote:Okay so I am a bit lost on the whole server to client setup. The engine does it completely different than what i am use to.
I am using the mouse multiplayer example and I have created an entity but where in the world do you spawn the entity and then tell the clients it was done. Normally I would just run a function the server that would handle when and where to spawn the entity then shoot a message to all clients to spawn that entity there but I am not seeing where to do this at on either side. I am confused by what all these classes are doing. I am assuming the server and client are speaking to each other via clientnetworkevents.js and servernetworkevents.js but I am not understanding how the server is handling this.
Hey ya!
So the engine's networking system is modelled on a triple-A game engine (Source Engine by Valve) and has a network "stream". The stream basically allows you to create an entity on the server and it will automatically exist on all connected clients.
To make an entity exist on all clients simply set the streamMode(1) e.g:
Code: Select all
var ent = new IgeEntity()
.streamMode(1);
Obviously this is the most simple example but the engine's networking expects that you take an OOP approach to your game's classes. This means that if you instantiate an entity, it should be able to set itself up almost completely without any other commands being issued to it. Take this example:
You have a game like pacman, so you have 3 types of entities:
1) Ghosts
2) Dots
3) Player
Ghosts can be different colours, dots are always just basic dots that pacman can eat, and the player is pacman.
Ghosts and Player have animations when they are moving.
In this case you need to set up three classes. The ghost class is a good example because it will show you how you can set a colour of the ghost on the server and then have that custom setting automatically "streamed" to all the clients when the ghost is created client-side.
Code: Select all
var Ghost = IgeEntity.extend({
classId: 'Ghost',
init: function (data) {
// If we were given a colour, set it now
if (data.colour) {
this.colour(data.colour);
}
},
// This is called by the stream system on the server to ask
// for the data that will be sent along with the initial entity
// create on the client. The object returned will be passed as
// the first parameter in the init() method when the ghost
// is instantiated client-side, allowing you to send along
// custom data for the entity automatically when a client is
// being told about the entity's existence.
streamCreateData: function () {
return {colour: this._colour};
},
colour: function (val) {
if (val !== undefined) {
this._colour = val;
return this;
}
return this._colour;
}
});
You also want ghosts to have a texture (probably a cell sheet with animation frames). You can set this in the init method:
Code: Select all
init: function (data) {
// If we were given a colour, set it now
if (data.colour) {
this.colour(data.colour);
}
if (!ige.isServer) {
this.texture(myTextures.ghostAnimation);
this.addComponent(IgeAnimationComponent);
// Define an animation called "walk" that loops frames 1 to 8
// at 25 frames per second indefinitely
this.animation.define('walk', [1, 2, 3, 4, 5, 6, 7, 8], 25, -1);
}
},
Isogenic's networking system is significantly more advanced than a standard "create this entity here" as it utilises interpolation and a data stream to ensure all clients see the same simulation at the same time. It does not send data for every update either. It will send changes to entity transformations at regular intervals and the client then interpolates over that data from current transformation to received transformation.
You can get more information in the docs on the site, and it would also be good to read up on how Source Engine from Valve works as Isogenic's networking is very similar:
https://developer.valvesoftware.com/wik ... Networking
I've seen a lot of people assume that Isogenic just has socket.io installed and then called "multiplayer" but there is a LOT more to it than that!
